-
-
Notifications
You must be signed in to change notification settings - Fork 130
/
customize.sh
136 lines (120 loc) · 4.96 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
#!/system/bin/sh
# Script configuration variables
SKIPUNZIP=1
SKIPMOUNT=false
PROPFILE=true
POSTFSDATA=false
LATESTARTSERVICE=true
# Check installation conditions
if [ "$BOOTMODE" != true ]; then
abort "-----------------------------------------------------------"
ui_print "! Please install in Magisk/KernelSU/APatch Manager"
ui_print "! Install from recovery is NOT supported"
abort "-----------------------------------------------------------"
elif [ "$KSU" = true ] && [ "$KSU_VER_CODE" -lt 10670 ]; then
abort "-----------------------------------------------------------"
ui_print "! Please update your KernelSU and KernelSU Manager"
abort "-----------------------------------------------------------"
fi
service_dir="/data/adb/service.d"
if [ "$KSU" = "true" ]; then
ui_print "- KernelSU version: $KSU_VER ($KSU_VER_CODE)"
[ "$KSU_VER_CODE" -lt 10683 ] && service_dir="/data/adb/ksu/service.d"
elif [ "$APATCH" = "true" ]; then
APATCH_VER=$(cat "/data/adb/ap/version")
ui_print "- APatch version: $APATCH_VER"
else
ui_print "- Magisk version: $MAGISK_VER ($MAGISK_VER_CODE)"
fi
# Set up service directory and clean old installations
mkdir -p "${service_dir}"
if [ -d "/data/adb/modules/box_for_magisk" ]; then
rm -rf "/data/adb/modules/box_for_magisk"
ui_print "- Old module deleted."
fi
# Extract files and configure directories
ui_print "- Installing Box for Magisk/KernelSU/APatch"
unzip -o "$ZIPFILE" -x 'META-INF/*' -x 'webroot/*' -d "$MODPATH" >&2
if [ -d "/data/adb/box" ]; then
ui_print "- Backup existing box data"
temp_bak=$(mktemp -d "/data/adb/box/box.XXXXXXXXXX")
temp_dir="${temp_bak}"
mv /data/adb/box/* "${temp_dir}/"
mv "$MODPATH/box/"* /data/adb/box/
backup_box="true"
else
mv "$MODPATH/box" /data/adb/
fi
# Directory creation and file extraction
ui_print "- Create directories"
mkdir -p /data/adb/box/ /data/adb/box/run/ /data/adb/box/bin/xclash/
ui_print "- Extracting uninstall.sh and box_service.sh"
unzip -j -o "$ZIPFILE" 'uninstall.sh' -d "$MODPATH" >&2
unzip -j -o "$ZIPFILE" 'box_service.sh' -d "${service_dir}" >&2
# Set permissions
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 ${service_dir}/box_service.sh 0 0 0755
set_perm $MODPATH/uninstall.sh 0 0 0755
chmod ugo+x ${service_dir}/box_service.sh $MODPATH/uninstall.sh /data/adb/box/scripts/*
# Download prompt for optional kernel components
ui_print "-----------------------------------------------------------"
ui_print "- Do you want to download Kernel(xray hysteria clash v2fly sing-box) and GeoX(geosite geoip mmdb)? size: ±100MB."
ui_print "- Ensure a good internet connection."
ui_print "- [ Vol UP(+): Yes ]"
ui_print "- [ Vol DOWN(-): No ]"
START_TIME=$(date +%s)
while true ; do
NOW_TIME=$(date +%s)
timeout 1 getevent -lc 1 2>&1 | grep KEY_VOLUME > "$TMPDIR/events"
if [ $(( NOW_TIME - START_TIME )) -gt 9 ]; then
ui_print "- No input detected after 10 seconds, skipping download."
break
elif $(cat $TMPDIR/events | grep -q KEY_VOLUMEUP); then
ui_print "- Starting download..."
/data/adb/box/scripts/box.tool all
break
elif $(cat $TMPDIR/events | grep -q KEY_VOLUMEDOWN); then
ui_print "- Skipping download."
break
fi
done
# Restore backup configurations if present
if [ "${backup_box}" = "true" ]; then
ui_print "- Restoring configurations (xray, hysteria, clash, sing-box, v2fly)"
restore_config() {
config_dir="$1"
[ -d "${temp_dir}/${config_dir}" ] && cp -rf "${temp_dir}/${config_dir}/"* "/data/adb/box/${config_dir}/"
}
for dir in clash xray v2fly sing-box hysteria; do
restore_config "$dir"
done
restore_kernel() {
kernel_name="$1"
[ ! -f "/data/adb/box/bin/$kernel_name" ] && [ -f "${temp_dir}/bin/${kernel_name}" ] && cp -rf "${temp_dir}/bin/${kernel_name}" "/data/adb/box/bin/${kernel_name}"
}
for kernel in curl yq xray sing-box v2fly hysteria xclash/mihomo xclash/premium; do
restore_kernel "$kernel"
done
ui_print "- Restoring logs, pid, and uid.list"
cp "${temp_dir}/run/"* "/data/adb/box/run/"
fi
# Update module description if no kernel binaries are found
[ -z "$(find /data/adb/box/bin -type f)" ] && sed -Ei 's/^description=(\[.*][[:space:]]*)?/description=[ 😱 Module installed but manual Kernel download required ] /g' $MODPATH/module.prop
# Customize module name based on environment
if [ "$KSU" = "true" ]; then
sed -i "s/name=.*/name=Box for KernelSU/g" $MODPATH/module.prop
elif [ "$APATCH" = "true" ]; then
sed -i "s/name=.*/name=Box for APatch/g" $MODPATH/module.prop
else
sed -i "s/name=.*/name=Box for Magisk/g" $MODPATH/module.prop
fi
unzip -o "$ZIPFILE" 'webroot/*' -d "$MODPATH" >&2
# Clean up temporary files
ui_print "- Cleaning up leftover files"
rm -rf /data/adb/box/bin/.bin $MODPATH/box $MODPATH/box_service.sh
# Complete installation
ui_print "- Installation complete. Please reboot your device."
ui_print "- Report issues to t.me.taamarin"