-
Notifications
You must be signed in to change notification settings - Fork 44
/
customize.sh
executable file
·307 lines (281 loc) · 11.3 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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
#####################
# xray Customization
#####################
SKIPUNZIP=1
ASH_STANDALONE=1
module_path="/data/adb/xray"
chooseport_legacy() {
# Keycheck binary by someone755 @Github, idea for code below by Zappo @xda-developers
# Calling it first time detects previous input. Calling it second time will do what we want
[ "$1" ] && local delay=$1 || local delay=15
local error=false
while true; do
timeout 0 ${TMPDIR}/keycheck
timeout $delay ${TMPDIR}/keycheck
local sel=$?
if [ $sel -eq 42 ]; then
return 0
elif [ $sel -eq 41 ]; then
return 1
elif $error; then
abort "- Volume key not detected!"
else
error=true
ui_print "- Volume key not detected. Try again"
fi
done
}
chooseport() {
# Original idea by chainfire and ianmacd @xda-developers
[ "$1" ] && local delay=$1 || local delay=15
local error=false
while true; do
local count=0
while true; do
timeout 1 /system/bin/getevent -lqc 1 2>&1 >$TMPDIR/events &
sleep 0.5
if ($(grep -q 'KEY_VOLUMEUP *DOWN' $TMPDIR/events)); then
return 0
elif ($(grep -q 'KEY_VOLUMEDOWN *DOWN' $TMPDIR/events)); then
return 1
fi
count=$((count + 1))
[ $count -gt 29 ] && break
done
if $error; then
# abort "Volume key not detected!"
ui_print "- Volume key not detected. Trying keycheck method"
export chooseport=chooseport_legacy VKSEL=chooseport_legacy
chooseport_legacy $delay
return $?
else
error=true
ui_print "- Volume key not detected. Try again"
fi
done
}
VKSEL=chooseport
installCore() {
case "$1" in
xray)
sed -i 's/coreType: .*/coreType: xray/g' ${module_path}/xrayhelper.yml
sed -i 's/corePath: .*/corePath: \/data\/adb\/xray\/bin\/xray/g' ${module_path}/xrayhelper.yml
sed -i 's/coreConfig: .*/coreConfig: \/data\/adb\/xray\/confs\//g' ${module_path}/xrayhelper.yml
ui_print "- Install geodata asset"
su -c ${module_path}/bin/xrayhelper -c ${module_path}/xrayhelper.yml update geodata
ui_print "- Install xray core"
su -c ${module_path}/bin/xrayhelper -c ${module_path}/xrayhelper.yml update core
;;
v2ray)
sed -i 's/coreType: .*/coreType: v2ray/g' ${module_path}/xrayhelper.yml
sed -i 's/corePath: .*/corePath: \/data\/adb\/xray\/bin\/v2ray/g' ${module_path}/xrayhelper.yml
sed -i 's/coreConfig: .*/coreConfig: \/data\/adb\/xray\/v2rayconfs\/config.json/g' ${module_path}/xrayhelper.yml
ui_print "- Install geodata asset"
su -c ${module_path}/bin/xrayhelper -c ${module_path}/xrayhelper.yml update geodata
ui_print "- Install v2ray core"
su -c ${module_path}/bin/xrayhelper -c ${module_path}/xrayhelper.yml update core
;;
sing-box)
sed -i 's/coreType: .*/coreType: sing-box/g' ${module_path}/xrayhelper.yml
sed -i 's/corePath: .*/corePath: \/data\/adb\/xray\/bin\/sing-box/g' ${module_path}/xrayhelper.yml
sed -i 's/coreConfig: .*/coreConfig: \/data\/adb\/xray\/singconfs\//g' ${module_path}/xrayhelper.yml
ui_print "- Install sing-box core"
su -c ${module_path}/bin/xrayhelper -c ${module_path}/xrayhelper.yml update core
;;
mihomo)
sed -i 's/coreType: .*/coreType: mihomo/g' ${module_path}/xrayhelper.yml
sed -i 's/corePath: .*/corePath: \/data\/adb\/xray\/bin\/mihomo/g' ${module_path}/xrayhelper.yml
sed -i 's/coreConfig: .*/coreConfig: \/data\/adb\/xray\/mihomoconfs\//g' ${module_path}/xrayhelper.yml
sed -i 's/template: .*/template: \/data\/adb\/xray\/mihomoconfs\/template\.yaml/g' ${module_path}/xrayhelper.yml
if [ "$use_param" != true ]; then
ui_print
ui_print "- Please select mihomo web UI"
ui_print "* VOL+ = yacd-meta, VOL- = metacubexd *"
if $VKSEL; then
ui_print "- Install yacd-meta"
su -c ${module_path}/bin/xrayhelper -c ${module_path}/xrayhelper.yml update yacd-meta
else
ui_print "- Install metacubexd"
su -c ${module_path}/bin/xrayhelper -c ${module_path}/xrayhelper.yml update metacubexd
fi
else
if [ "$param_uitype" != "2" ]; then
ui_print "- Install yacd-meta UI"
su -c ${module_path}/bin/xrayhelper -c ${module_path}/xrayhelper.yml update yacd-meta
else
ui_print "- Install metacubexd UI"
su -c ${module_path}/bin/xrayhelper -c ${module_path}/xrayhelper.yml update metacubexd
fi
fi
ui_print "- Install mihomo core"
su -c ${module_path}/bin/xrayhelper -c ${module_path}/xrayhelper.yml update core
;;
hysteria2)
sed -i 's/coreType: .*/coreType: hysteria2/g' ${module_path}/xrayhelper.yml
sed -i 's/corePath: .*/corePath: \/data\/adb\/xray\/bin\/hysteria2/g' ${module_path}/xrayhelper.yml
sed -i 's/coreConfig: .*/coreConfig: \/data\/adb\/xray\/hy2confs\/config.yaml/g' ${module_path}/xrayhelper.yml
ui_print "- Install hysteria2 core"
su -c ${module_path}/bin/xrayhelper -c ${module_path}/xrayhelper.yml update core
;;
*)
ui_print "- Skip core installation"
ui_print "- You need install core and configure xrayhelper.yml after module installation"
;;
esac
}
installCore_VK() {
ui_print
ui_print "- Do you need install core online?"
ui_print "* VOL+ = YES, VOL- = NO *"
if $VKSEL; then
ui_print
ui_print "- Please select your core"
ui_print "* VOL+ = xray/v2ray, VOL- = sing-box/mihomo/hysteria2 *"
if $VKSEL; then
ui_print
ui_print "- Please select xray or v2ray"
ui_print "* VOL+ = xray, VOL- = v2ray *"
if $VKSEL; then
installCore xray
else
installCore v2ray
fi
else
ui_print
ui_print "- Please select your core"
ui_print "* VOL+ = sing-box/mihomo, VOL- = hysteria2 *"
if $VKSEL; then
ui_print
ui_print "- Please select sing-box or mihomo"
ui_print "* VOL+ = sing-box, VOL- = mihomo *"
if $VKSEL; then
installCore sing-box
else
installCore mihomo
fi
else
installCore hysteria2
fi
fi
else
installCore skip
fi
}
releaseConfig() {
ui_print "- Release xrayhelper config"
unzip -j -o "${ZIPFILE}" 'xray/etc/xrayhelper.yml' -d ${module_path} >&2
ui_print "- Release xray configs"
if [ ! -d ${module_path}/confs ]; then
mkdir -p ${module_path}/confs
unzip -j -o "${ZIPFILE}" 'xray/etc/confs/proxy.json' -d ${module_path}/confs >&2
fi
unzip -j -o "${ZIPFILE}" 'xray/etc/confs/base.json' -d ${module_path}/confs >&2
unzip -j -o "${ZIPFILE}" 'xray/etc/confs/dns.json' -d ${module_path}/confs >&2
unzip -j -o "${ZIPFILE}" 'xray/etc/confs/policy.json' -d ${module_path}/confs >&2
unzip -j -o "${ZIPFILE}" 'xray/etc/confs/routing.json' -d ${module_path}/confs >&2
ui_print "- Release v2ray v5 config"
if [ ! -d ${module_path}/v2rayconfs ]; then
mkdir -p ${module_path}/v2rayconfs
unzip -j -o "${ZIPFILE}" 'xray/etc/v2rayconfs/config.json' -d ${module_path}/v2rayconfs >&2
fi
ui_print "- Release sing-box configs"
if [ ! -d ${module_path}/singconfs ]; then
mkdir -p ${module_path}/singconfs
unzip -j -o "${ZIPFILE}" 'xray/etc/singconfs/proxy.json' -d ${module_path}/singconfs >&2
fi
unzip -j -o "${ZIPFILE}" 'xray/etc/singconfs/base.json' -d ${module_path}/singconfs >&2
unzip -j -o "${ZIPFILE}" 'xray/etc/singconfs/dns.json' -d ${module_path}/singconfs >&2
unzip -j -o "${ZIPFILE}" 'xray/etc/singconfs/route.json' -d ${module_path}/singconfs >&2
ui_print "- Release mihomo configs"
if [ ! -d ${module_path}/mihomoconfs ]; then
mkdir -p ${module_path}/mihomoconfs
fi
unzip -j -o "${ZIPFILE}" 'xray/etc/mihomoconfs/template.yaml' -d ${module_path}/mihomoconfs >&2
ui_print "- Release hysteria2 configs"
if [ ! -d ${module_path}/hy2confs ]; then
mkdir -p ${module_path}/hy2confs
fi
unzip -j -o "${ZIPFILE}" 'xray/etc/hy2confs/config.yaml' -d ${module_path}/hy2confs >&2
ui_print "- Release adguardhome configs"
if [ ! -d ${module_path}/adghomeconfs ]; then
mkdir -p ${module_path}/adghomeconfs
fi
unzip -j -o "${ZIPFILE}" 'xray/etc/adghomeconfs/config.yaml' -d ${module_path}/adghomeconfs >&2
}
# Global parameters
use_param=false
param_core=""
param_keep=""
param_uitype=""
installModule() {
# Params for no value key device
if [ -f /sdcard/xray4magisk.setup ]; then
use_param=true
param_core=$(sed -n 1p /sdcard/xray4magisk.setup)
param_keep=$(sed -n 2p /sdcard/xray4magisk.setup)
param_uitype=$(sed -n 3p /sdcard/xray4magisk.setup)
fi
# Install xrayhelper
ui_print "- Install xrayhelper"
mkdir -p ${module_path}/bin
unzip -j -o "${ZIPFILE}" "xray/bin/${ARCH}/xrayhelper" -d ${module_path}/bin >&2
set_perm ${module_path}/bin/xrayhelper 0 0 0755
# Release module config files
if [ -f ${module_path}/xrayhelper.yml ]; then
if [ "$use_param" != true ]; then
ui_print
ui_print "- Old config files detected, overwrite them?"
ui_print "* VOL+ = YES, VOL- = NO *"
if $VKSEL; then
releaseConfig
fi
else
if [ "$param_keep" != "keep" ]; then
releaseConfig
fi
fi
else
releaseConfig
fi
# Install core
if [ "$use_param" != true ]; then
installCore_VK
else
installCore $param_core
fi
# Release module scripts
ui_print "- Release scripts"
mkdir -p ${module_path}/run
mkdir -p ${module_path}/scripts
unzip -j -o "${ZIPFILE}" 'xray/scripts/*' -d ${module_path}/scripts >&2
if [ ! -d /data/adb/service.d ]; then
mkdir -p /data/adb/service.d
fi
unzip -j -o "${ZIPFILE}" 'xray4magisk_service.sh' -d /data/adb/service.d >&2
unzip -j -o "${ZIPFILE}" 'uninstall.sh' -d $MODPATH >&2
# Release KernelSU WebUI
ui_print "- Release KernelSU WebUI"
mkdir -p $MODPATH/webroot
unzip -o "${ZIPFILE}" 'webroot/*' -d $MODPATH >&2
# Set module files' permission
ui_print "- Set permission"
set_perm /data/adb/service.d/xray4magisk_service.sh 0 0 0755
set_perm $MODPATH/uninstall.sh 0 0 0755
set_perm_recursive ${module_path}/scripts 0 0 0755 0755
set_perm ${module_path} 0 0 0755
# Release module prop
unzip -j -o "${ZIPFILE}" "module.prop" -d $MODPATH >&2
}
main() {
if [ ! $BOOTMODE ]; then
abort "Error: Please install in Magisk Manager or KernelSU Manager"
fi
if [ ! -d ${module_path} ]; then
mkdir -p ${module_path}
fi
# Release keycheck to tmp dir for install module
unzip -j -o "${ZIPFILE}" "xray/bin/${ARCH}/keycheck" -d ${TMPDIR} >&2
set_perm ${TMPDIR}/keycheck 0 0 0755
installModule
}
main