-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsurun
executable file
·61 lines (54 loc) · 1.66 KB
/
surun
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/bin/sh
##
## surun - Wrapper running command via su or sudo
## Copyright 2013,2018 by Michal Nazarewicz ([email protected])
##
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 3 of the License, or
## (at your option) any later version.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program; if not, see <http://www.gnu.org/licenses/>.
##
## This is part of Tiny Applications Collection
## -> http://tinyapps.sourceforge.net/
##
case $1 in --help|-h)
cat <<EOF
usage: $0 [ <command> <argument> ... ]
Start a root shell (if no command given) or run given command as root.
Use either sudo or su depending on which is available, unless user is already
a super-user at which point calling sudo/su is skipped all together.
EOF
exit 0
esac
umask 022
if [ $(id -u) -eq 0 ]; then
if [ $# -eq 0 ]; then
set -- "${SHELL:-/bin/sh}"
fi
exec "$@"
fi
sudo=$(which sudo 2>/dev/null)
if [ $# -eq 0 ]; then
exec "${sudo:-su}" ${sudo:+-s}
elif [ -n "$sudo" ]; then
exec "$sudo" "$@"
fi
if test=$(printf %q aoeu\ \'\"\ aoeu 2>/dev/null) &&
[ x"$test" = x"aoeu\\ \\'\\\"\\ aoeu" ]; then
escaped=$(printf ' %q' "$@")
else
escaped=
for arg; do
arg=\'$(printf %s "$arg" | sed -e "s/'/'\\\\''/g")\'
escaped="$escaped $arg"
done
fi
exec su -c "$escaped"