-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsystemctl
executable file
·58 lines (46 loc) · 1.1 KB
/
systemctl
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
#!/bin/sh
SYSTEMCTL_PY="systemctl3.py"
get_cmd(){
local cmd="$1"
command -v "$cmd" || printf "${0%/*}/$cmd"
}
SYSTEMCTL=$(get_cmd $SYSTEMCTL_PY)
COMMAND="$SYSTEMCTL"
no_sudo_commands="-h --help --version version \
cat command default-services environment get-default \
get-preset help is-enabled list-dependencies \
list-start-dependencies list-unit-files listen log"
out() { printf "$1 $2\n" "${@:3}"; }
error() { out "==> ERROR:" "$@"; } >&2
die() { error "$@"; exit 1; }
ignore_error() {
"$@" 2>/dev/null
return 0
}
prepare(){
[ ! -L "/tmp/run" ] && ln -sfr /tmp /tmp/run
[ ! -x $SYSTEMCTL ] && die "${0##*/}: command not found: $SYSTEMCTL_PY"
[ ! -x /usr/bin/python3 ] && die "${0##*/}: command not found: python3"
}
sudo_command(){
if [ "$(id -u)" -ne 0 ] ; then
if SUDO="$(which sudo)" ; then
COMMAND="$SUDO $COMMAND"
else
die "Failed to ${@}: Interactive authentication required."
fi
fi
}
systemctl() {
prepare
[ -z "$1" ] && sudo_command
case " $no_sudo_commands " in
*" $1 "*)
;;
*)
sudo_command
;;
esac
exec ${COMMAND} "$@"
}
systemctl ${@}