]> gitweb.factorcode.org Git - factor.git/blob - basis/elevate/elevate.factor
elevate rewrite
[factor.git] / basis / elevate / elevate.factor
1 USING: arrays command-line fry io.launcher kernel math namespaces
2 sequences system unix.ffi ;
3 IN: elevate
4
5 : apple-script-elevate ( command -- ) 2drop ;
6
7 GENERIC: glue-command ( prefix command -- glued )
8
9 M: array glue-command
10     swap prefix ;
11
12 M: string glue-command
13     " " glue ;
14
15 ERROR: elevated-failed path ;
16
17 HOOK: elevated os ( command win-console? posix-graphical? -- process )
18
19 M: windows elevated
20     2drop run-process ;
21
22 M: macosx elevated
23     nip [ ! graphical (through applescript)
24         apple-script-elevate
25     ] [
26         f f linux os [ elevated ] with-variable
27     ] if ;
28
29 M: linux elevated
30     nip getuid zero? [
31         drop ! we are already root: do nothing
32     ] [
33         { "gksudo" "kdesudo" "sudo" } { "sudo" } ? ! graphical handled
34         swap '[ _ glue-command ] map
35         [ " " split [ first utf8 string>alien ] [ rest ] execvp ] map
36         [ -1 = ] all? elevated-failed
37     ] if ;
38
39 : elevate ( option? -- ) (command-line) elevated ;
40
41 HOOK: lowered os ( relaunch? -- )
42