From 0a2e8ac4d516b98dbd6395695dcfd007b4b13fce Mon Sep 17 00:00:00 2001 From: twnesss Date: Wed, 6 Nov 2024 20:17:04 +0700 Subject: [PATCH] Refined customize.sh --- customize.sh | 113 ++++++++++++++++++++------------------------------- 1 file changed, 44 insertions(+), 69 deletions(-) diff --git a/customize.sh b/customize.sh index a09af8ad..95bf3f31 100644 --- a/customize.sh +++ b/customize.sh @@ -1,11 +1,13 @@ #!/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" @@ -17,16 +19,9 @@ elif [ "$KSU" = true ] && [ "$KSU_VER_CODE" -lt 10670 ]; then abort "-----------------------------------------------------------" fi -# 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 - service_dir="/data/adb/service.d" if [ "$KSU" = "true" ]; then - ui_print "- kernelSU version: $KSU_VER ($KSU_VER_CODE)" + 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") @@ -35,18 +30,18 @@ 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 box" + 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}/" @@ -56,31 +51,26 @@ else mv "$MODPATH/box" /data/adb/ fi +# Directory creation and file extraction ui_print "- Create directories" -mkdir -p /data/adb/box/ -mkdir -p /data/adb/box/run/ -mkdir -p /data/adb/box/bin/xclash/ - -ui_print "- Extract the files uninstall.sh and box_service.sh into the $MODPATH folder and ${service_dir}" +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 -set_perm /data/adb/box/scripts/ 0 0 0755 - -# fix "set_perm_recursive /data/adb/box/scripts" not working on some phones. -chmod ugo+x ${service_dir}/box_service.sh -chmod ugo+x $MODPATH/uninstall.sh -chmod ugo+x /data/adb/box/scripts/* +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 "- Make sure you have a good internet connection." +ui_print "- Ensure a good internet connection." ui_print "- [ Vol UP(+): Yes ]" ui_print "- [ Vol DOWN(-): No ]" @@ -88,61 +78,46 @@ 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" + 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 - else - if $(cat $TMPDIR/events | grep -q KEY_VOLUMEUP) ; then - ui_print "- It will take a while...." - /data/adb/box/scripts/box.tool all - break - elif $(cat $TMPDIR/events | grep -q KEY_VOLUMEDOWN) ; then - ui_print "- Skip download Kernel and Geox" - break - fi fi done +# Restore backup configurations if present if [ "${backup_box}" = "true" ]; then - ui_print "- Restore configuration xray, hysteria, clash, sing-box, and v2fly" + ui_print "- Restoring configurations (xray, hysteria, clash, sing-box, v2fly)" restore_config() { config_dir="$1" - if [ -d "${temp_dir}/${config_dir}" ]; then - cp -rf "${temp_dir}/${config_dir}/"* "/data/adb/box/${config_dir}/" - fi + [ -d "${temp_dir}/${config_dir}" ] && cp -rf "${temp_dir}/${config_dir}/"* "/data/adb/box/${config_dir}/" } - - restore_config "clash" - restore_config "xray" - restore_config "v2fly" - restore_config "sing-box" - restore_config "hysteria" + for dir in clash xray v2fly sing-box hysteria; do + restore_config "$dir" + done restore_kernel() { kernel_name="$1" - if [ ! -f "/data/adb/box/bin/$kernel_name" ] && [ -f "${temp_dir}/bin/${kernel_name}" ]; then - ui_print "- Restore ${kernel_name} kernel" - cp -rf "${temp_dir}/bin/${kernel_name}" "/data/adb/box/bin/${kernel_name}" - fi + [ ! -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 - restore_kernel "curl" - restore_kernel "yq" - restore_kernel "xray" - restore_kernel "sing-box" - restore_kernel "v2fly" - restore_kernel "hysteria" - restore_kernel "xclash/mihomo" - restore_kernel "xclash/premium" - - ui_print "- Restore logs, pid and uid.list" + ui_print "- Restoring logs, pid, and uid.list" cp "${temp_dir}/run/"* "/data/adb/box/run/" fi -if [ -z "$(find /data/adb/box/bin -type f)" ]; then - sed -Ei 's/^description=(\[.*][[:space:]]*)?/description=[ 😱 Module installed but you need to download Kernel(xray hysteria clash v2fly sing-box) and GeoX(geosite geoip mmdb) manually ] /g' $MODPATH/module.prop -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 unzip -o "$ZIPFILE" 'webroot/*' -d "$MODPATH" >&2 @@ -153,10 +128,10 @@ else sed -i "s/name=.*/name=Box for Magisk/g" $MODPATH/module.prop fi -ui_print "- Delete leftover files" -rm -rf /data/adb/box/bin/.bin -rm -rf $MODPATH/box -rm -f $MODPATH/box_service.sh +# Clean up temporary files +ui_print "- Cleaning up leftover files" +rm -rf /data/adb/box/bin/.bin $MODPATH/box $MODPATH/box_service.sh -ui_print "- Installation is complete, reboot your device" +# Complete installation +ui_print "- Installation complete. Please reboot your device." ui_print "- Report issues to t.me.taamarin"