forked from larsyencken/marelle
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsudo.pl
More file actions
38 lines (35 loc) · 890 Bytes
/
sudo.pl
File metadata and controls
38 lines (35 loc) · 890 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
%
% sudo.pl
% computer
%
% sudo_tell/1.
% Like tell/1, but works on files which you need to sudo to get privileges
% for.
sudo_tell(Filename) :-
expand_path(Filename, ExpFilename),
join(['cat >', ExpFilename], BashCmd),
which('sudo', Sudo),
process_create(
Sudo,
['/bin/sh', '-c', BashCmd],
[stdin(pipe(Stream))]
),
tell(Stream).
% sudo_or_empty/1.
% Returns an empty string when ran as root, path to sudo with
% a trailing space otherwise.
sudo_or_empty(Command) :-
( sh_output('whoami', root) ->
Command = ''
;
which('sudo', Sudo),
join([Sudo, ' '], Command)
).
sudo_sh(Command0) :-
sudo_or_empty(Sudo),
join_if_list(Command0, Command),
tmp_file_stream(text, File, Stream),
write(Stream, Command),
close(Stream),
sh([Sudo, 'sh "', File, '"']),
delete_file(File).