-
Notifications
You must be signed in to change notification settings - Fork 0
/
init
executable file
·58 lines (46 loc) · 1.22 KB
/
init
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)
usage() {
cat <<EOF
${0##*/} [OPTIONS...] COMMAND
Send control commands to the init daemon.
Commands:
0 Power-off the machine
6 Reboot the machine
2, 3, 4, 5 Start runlevelX.target unit
1, s, S Enter rescue mode
q, Q Reload init daemon configuration
u, U Reexecute init daemon
Options:
--help Show this help
This is a fake init script, See $(readlink -f ${0}) file for details.
EOF
}
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"
}
system_init(){
prepare
mount -a -v
}
case $1 in
-h|--help) usage && exit 0 ;;
0) COMMAND=$(get_cmd poweroff) ;;
6) COMMAND=$(get_cmd reboot) ;;
1|s|S) COMMAND="/bin/sh" ;;
q|Q|u|U)
SHELL="/bin/sh $SYSTEMCTL halt \
&& $SYSTEMCTL init" && exit 0 ;;
*)
system_init
COMMAND="$SYSTEMCTL init" ;;
esac
[ "$(id -u)" -ne 0 ] && printf "Must be root\n" && exit 1
exec $COMMAND