forked from taamarin/box_for_magisk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcustomize.sh
executable file
·190 lines (169 loc) · 6.35 KB
/
customize.sh
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
SKIPUNZIP=1
ASH_STANDALONE=1
status=""
architecture=""
latest=$(date +%Y%m%d%H%M)
if $BOOTMODE; then
ui_print "- Installing from Magisk app"
else
ui_print "*********************************************************"
ui_print "! Install from recovery is NOT supported"
ui_print "! Some recovery has broken implementations, install with such recovery will finally cause BFM modules not working"
ui_print "! Please install from Magisk app"
abort "*********************************************************"
fi
# check Magisk
ui_print "- Magisk version: $MAGISK_VER ($MAGISK_VER_CODE)"
# check android
if [ "$API" -lt 28 ]; then
ui_print "! Unsupported sdk: $API"
abort "! Minimal supported sdk is 28 (Android 9)"
else
ui_print "- Device sdk: $API"
fi
ui_print "- check architecture"
case $ARCH in
arm|arm64|x86|x64)
ui_print "- Device platform: $ARCH"
;;
*)
abort "! Unsupported platform: $ARCH"
;;
esac
ui_print "- Installing Box for Magisk"
if [ -d "/data/adb/box" ] ; then
ui_print "- Backup box"
mkdir -p "/data/adb/box/${latest}"
mv /data/adb/box/* "/data/adb/box/${latest}/"
fi
ui_print "- Set architecture ${ARCH}"
case "${ARCH}" in
arm)
architecture="armv7"
;;
arm64)
architecture="armv8"
;;
x86)
architecture="386"
;;
x64)
architecture="amd64"
;;
*)
abort "Error: Unsupported architecture ${ARCH}"
;;
esac
ui_print "- Create directories"
mkdir -p "${MODPATH}/system/bin"
mkdir -p "${MODPATH}/system/etc/security/cacerts"
mkdir -p "/data/adb/box"
mkdir -p "/data/adb/box/bin"
mkdir -p "/data/adb/box/run"
mkdir -p "/data/adb/box/scripts"
mkdir -p "/data/adb/box/xray"
mkdir -p "/data/adb/box/v2fly"
mkdir -p "/data/adb/box/sing-box"
mkdir -p "/data/adb/box/clash"
mkdir -p "/data/adb/box/dashboard"
mkdir -p "/data/adb/box/clash/dashboard"
mkdir -p "/data/adb/box/sing-box/dashboard"
ui_print "- Extract the ZIP file and skip the META-INF folder into the ${MODPATH} folder"
unzip -o "${ZIPFILE}" -x 'META-INF/*' -d "${MODPATH}" >&2
ui_print "- Extract the files uninstall.sh and box_service.sh into the ${MODPATH} folder and /data/adb/service.d"
unzip -j -o "${ZIPFILE}" 'uninstall.sh' -d "${MODPATH}" >&2
unzip -j -o "${ZIPFILE}" 'box_service.sh' -d /data/adb/service.d >&2
ui_print "- Extract the files from the binary archive and copy them to the /system/bin and /data/adb/box/bin"
tar -xjf "${MODPATH}/binary/${ARCH}.tar.bz2" -C "${MODPATH}/system/bin" >&2
tar -xjf "${MODPATH}/binary/${ARCH}.tar.bz2" "mlbox" -C /data/adb/box/bin >&2
ui_print "- Extract the dashboard.zip file to the folder /data/adb/box/clash/dashboard and /data/adb/box/sing-box/dashboard"
unzip -o "${MODPATH}/dashboard.zip" -d /data/adb/box/dashboard/ >&2
unzip -o "${MODPATH}/dashboard.zip" -d /data/adb/box/clash/dashboard/ >&2
unzip -o "${MODPATH}/dashboard.zip" -d /data/adb/box/sing-box/dashboard/ >&2
ui_print ""
ui_print "********************************************************"
ui_print "- do you want to add DNS nameservers in resolve.conf?"
ui_print "- Vol Up: to create the resolve.conf file."
ui_print "- Vol Down: to ignore the resolve.conf file."
while true ; do
getevent -lc 1 2>&1 | grep KEY_VOLUME > $TMPDIR/events
sleep 1
if $(cat $TMPDIR/events | grep -q KEY_VOLUMEUP) ; then
ui_print "- Create a resolve.conf file if it doesn't already exist and add server nameservers."
if [ ! -f "/data/adb/modules/box_for_magisk/system/etc/resolv.conf" ]; then
cat > "${MODPATH}/system/etc/resolv.conf" <<EOF
nameserver 8.8.8.8
nameserver 1.1.1.1
nameserver 9.9.9.9
nameserver 94.140.14.14
EOF
ui_print "[+] /data/adb/modules/box_for_magisk/system/etc/resolv.conf"
ui_print "[+] nameserver 8.8.8.8"
ui_print "[+] nameserver 1.1.1.1"
ui_print "[+] nameserver 9.9.9.9"
ui_print "[+] nameserver 94.140.14.14"
fi
break
elif $(cat $TMPDIR/events | grep -q KEY_VOLUMEDOWN) ; then
ui_print "- ignore creating file resolve.conf"
break
fi
done
ui_print "- Move BFM files"
mv "$MODPATH/scripts/cacert.pem" "$MODPATH/system/etc/security/cacerts"
mv "$MODPATH/scripts/src/"* "/data/adb/box/scripts/"
mv "$MODPATH/scripts/clash/"* "/data/adb/box/clash/"
mv "$MODPATH/scripts/settings.ini" "/data/adb/box/"
mv "$MODPATH/scripts/xray" "/data/adb/box/"
mv "$MODPATH/scripts/v2fly" "/data/adb/box/"
mv "$MODPATH/scripts/sing-box" "/data/adb/box/"
ui_print "- Delete leftover files"
rm -rf "${MODPATH}/scripts"
rm -rf "${MODPATH}/binary"
rm -f "${MODPATH}/box_service.sh"
rm -f "${MODPATH}/dashboard.zip"
sleep 1
ui_print "- Setting permissions"
set_perm_recursive "${MODPATH}" 0 0 0755 0644
set_perm_recursive "/data/adb/box/" 0 3005 0755 0644
set_perm_recursive "/data/adb/box/scripts/" 0 3005 0755 0700
set_perm "/data/adb/service.d/box_service.sh" 0 0 0755
set_perm "${MODPATH}/service.sh" 0 0 0755
set_perm "${MODPATH}/uninstall.sh" 0 0 0755
set_perm "${MODPATH}/system/etc/security/cacerts/cacert.pem" 0 0 0644
set_perm "${MODPATH}/system/bin/curl" 0 0 0755
set_perm /data/adb/box/scripts/box.inotify 0 0 0755
set_perm /data/adb/box/scripts/box.service 0 0 0755
set_perm /data/adb/box/scripts/box.iptables 0 0 0755
set_perm /data/adb/box/scripts/box.tool 0 0 0755
set_perm /data/adb/box/scripts/start.sh 0 0 0755
set_perm /data/adb/box/bin/mlbox 0 0 0755
sleep 1
ui_print ""
ui_print "********************************************************"
ui_print "- do you want to download KERNEL and GEOX?"
ui_print "- Make sure you have a good internet connection."
ui_print "- Vol Up: to download GEOX and KERNEL."
ui_print "- Vol Down: to ignore downloading GEOX and KERNEL."
while true ; do
getevent -lc 1 2>&1 | grep KEY_VOLUME > $TMPDIR/events
sleep 1
if $(cat $TMPDIR/events | grep -q KEY_VOLUMEUP) ; then
ui_print "- it will take a while...."
# if [ ! -f /data/adb/box/run/box.pid ]; then
/data/adb/box/scripts/box.tool all && echo "- downloads are complete."
# else
# ui_print " - BFM service is still running, Cannot update geo and kernel, as it will cause conflicts"
# ui_print " - Download manually after reboot is complete"
# fi
break
elif $(cat $TMPDIR/events | grep -q KEY_VOLUMEDOWN) ; then
ui_print "- ignore download GEOX and KERNEL"
break
fi
done
ui_print "- Installation is complete, reboot your device"
ui_print ""
ui_print "- Notes: "
ui_print "- report issues to @taamarin on Telegram"
ui_print "- Join @taamarin on telegram to get more updates"