-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstart
executable file
·92 lines (74 loc) · 1.75 KB
/
start
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/bin/bash
SYSTEMCTL_PY="systemctl3.py"
get_cmd(){
local cmd="$1"
command -v "$cmd" || printf "${0%/*}/$cmd"
}
SYSTEMCTL=$(get_cmd $SYSTEMCTL_PY)
UNCHROOT=$(get_cmd unchroot)
COMMAND="${0##*/}"
SYSTEM_BIN=/system/bin
[ -n "$2" ] && shift
out() { printf "$1 $2\n" "${@:3}"; }
error() { out "==> ERROR:" "$@"; } >&2
die() { error "$@"; exit 1; }
usage() {
cat <<EOF
$COMMAND [OPTIONS...] COMMAND
Send $COMMAND commands to the Host, or stop this Chroot Container.
Applet
EOF
case $COMMAND in
reboot|poweroff|halt|shutdown) cat <<EOF
reboot|poweroff|halt|shutdown
Send $COMMAND commands to the Host,
and Stop this Chroot Container
EOF
;;
*) cat <<EOF
$COMMAND Send $COMMAND commands to the Host
EOF
;;
esac
cat <<EOF
Options:
--help Show this help
This is a fake $COMMAND script, See $(readlink -f ${0}) file for details.
EOF
exec $UNCHROOT $COMMAND --help
}
umount_dest(){
[ -n "$dest" ] && mountpoint -q "$dest" && umount -l $dest
out "\033[37m[\033[0m\033[0;32m OK \033[0m\033[37m] Umounted\033[0m $dest"
}
umount_fstab() {
while read src dest fstype opts dump pass; do
umount_dest
done <<< "$(grep -vE '^\s*(#|$)' /etc/fstab)"
}
unchroot(){
if [ -x /bin/bash ] ;then
$UNCHROOT ${@}
else
error unchroot: command not found: bash
fi
}
system_command(){
unchroot "$SYSTEM_BIN/$@"
}
system_halt(){
$SYSTEMCTL halt
umount_fstab
}
case $1 in
-h|--help) usage && exit 0 ;;
*) ;;
esac
[ "$(id -u)" -ne 0 ] && die "This script must be run with root privileges"
case $COMMAND in
reboot|poweroff|halt|shutdown)
system_command $COMMAND $@
system_halt ;;
*)
system_command $COMMAND $@;;
esac