2
build.sh
2
build.sh
@@ -1,3 +1,3 @@
|
||||
#!/bin/sh
|
||||
|
||||
zip -r -o -X -ll box_for_magisk-$(cat module.prop | grep 'version=' | awk -F '=' '{print $2}').zip ./ -x '.git/*' -x 'index_id.md' -x 'index_en.md' -x 'CHANGELOG.md' -x 'update.json' -x 'build.sh' -x '.github/*' -x 'docs/*'
|
||||
zip -r -o -X -ll box_for_magisk-$(cat module.prop | grep 'version=' | awk -F '=' '{print $2}').zip ./ -x '.git/*' -x 'index_id.md' -x 'index_en.md' -x 'index_cn.md' -x 'CHANGELOG.md' -x 'update.json' -x 'build.sh' -x '.github/*' -x 'docs/*'
|
||||
52
customize.sh
52
customize.sh
@@ -2,21 +2,23 @@
|
||||
SKIPUNZIP=1
|
||||
ASH_STANDALONE=1
|
||||
|
||||
status=""
|
||||
architecture=""
|
||||
SKIPUNZIP=1
|
||||
ASH_STANDALONE=1
|
||||
|
||||
if $BOOTMODE; then
|
||||
ui_print "- Installing from Magisk app"
|
||||
else
|
||||
if [ "$BOOTMODE" ! = true ] ; then
|
||||
ui_print "*********************************************************"
|
||||
ui_print "! Please install in Magisk Manager or KernelSU Manager"
|
||||
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 "*********************************************************"
|
||||
elif [ "$KSU" = true ] && [ "$KSU_VER_CODE" -lt 10670 ] ; then
|
||||
abort "Error: Please update your KernelSU and KernelSU Manager or KernelSU Manager"
|
||||
fi
|
||||
|
||||
# check Magisk
|
||||
ui_print "- Magisk version: $MAGISK_VER ($MAGISK_VER_CODE)"
|
||||
if [ "$KSU" ! = true ] ; then
|
||||
ui_print "- Magisk version: $MAGISK_VER ($MAGISK_VER_CODE)"
|
||||
fi
|
||||
|
||||
# check android
|
||||
if [ "$API" -lt 28 ]; then
|
||||
@@ -26,18 +28,21 @@ 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
|
||||
if [ "$KSU" = true ] && [ "$KSU_VER_CODE" -lt 10683 ] ; then
|
||||
service_dir="/data/adb/ksu/service.d"
|
||||
else
|
||||
service_dir="/data/adb/service.d"
|
||||
fi
|
||||
|
||||
ui_print "- Installing Box for Magisk"
|
||||
if [ ! -d "${service_dir}" ] ; then
|
||||
mkdir -p "${service_dir}"
|
||||
fi
|
||||
|
||||
if [ "$KSU" = true ] ; then
|
||||
sed -i "s/name=.*/name=Box for KernelSU/g" "${MODPATH}/module.prop"
|
||||
fi
|
||||
|
||||
ui_print "- Installing Box for Magisk/KernelSU"
|
||||
if [ -d "/data/adb/box" ]; then
|
||||
ui_print "- Backup box"
|
||||
latest=$(date '+%Y-%m-%d_%H-%M-%S')
|
||||
@@ -82,9 +87,9 @@ 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"
|
||||
ui_print "- Extract the files uninstall.sh and box_service.sh into the ${MODPATH} folder and ${service_dir}"
|
||||
unzip -j -o "${ZIPFILE}" 'uninstall.sh' -d "${MODPATH}" >&2
|
||||
unzip -j -o "${ZIPFILE}" 'box_service.sh' -d /data/adb/service.d >&2
|
||||
unzip -j -o "${ZIPFILE}" 'box_service.sh' -d "${service_dir}" >&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
|
||||
@@ -115,11 +120,13 @@ 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 "${service_dir}/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
|
||||
# fix "set_perm_recursive /data/adb/box/scripts" not working on some phones.
|
||||
chmod ugo+x /data/adb/box/scripts/*
|
||||
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
|
||||
@@ -140,12 +147,7 @@ while true ; do
|
||||
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"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#!/system/bin/sh
|
||||
|
||||
export PATH="$(magisk --path)/.magisk/busybox:$PATH:/system/bin"
|
||||
export PATH="/data/adb/magisk:/data/adb/ksu/bin:$PATH:/system/bin"
|
||||
|
||||
# define the settings and paths
|
||||
settings="/data/adb/box/settings.ini"
|
||||
|
||||
@@ -15,13 +15,13 @@ tun_device=""
|
||||
|
||||
# Looking for value from "fake-ip-range: / listen: / tun_device" block in YAML / JSON configuration file
|
||||
if [ "${bin_name}" = "clash" ]; then
|
||||
tun_device=$(awk '/device: / { print $2;found=1; exit } END{ if(!found) print "utun" }' "${clash_config}" 2>/dev/null)
|
||||
tun_device=$(busybox awk '/device: / { print $2;found=1; exit } END{ if(!found) print "utun" }' "${clash_config}" 2>/dev/null)
|
||||
elif [ "${bin_name}" = "sing-box" ]; then
|
||||
tun_device=$(find "${data_dir}/sing-box/" -type f -name "*.json" -exec awk -F'"' '/interface_name/{ if ($4 != "tun0") {print $4; found=1; exit} } END{ if(!found) print "tun0" }' {} \; 2>/dev/null | head -n 1)
|
||||
tun_device=$(find "${data_dir}/sing-box/" -type f -name "*.json" -exec busybox awk -F'"' '/interface_name/{ if ($4 != "tun0") {print $4; found=1; exit} } END{ if(!found) print "tun0" }' {} \; 2>/dev/null | head -n 1)
|
||||
fi
|
||||
clash_fake_ip_range=$(awk '/fake-ip-range: / { print $2;found=1; exit } END{ if(!found) print "198.18.0.1/16" }' "${clash_config}" 2>/dev/null)
|
||||
clash_enhanced_mode=$(awk '/enhanced-mode: / { print $2;found=1; exit } END{ if(!found) print "fake-ip" }' "${clash_config}" 2>/dev/null)
|
||||
clash_dns_port=$(awk -F ':' '/listen:/ { print $3;found=1; exit } END{ if(!found) print "1053" }' "${clash_config}" 2>/dev/null)
|
||||
clash_fake_ip_range=$(busybox awk '/fake-ip-range: / { print $2;found=1; exit } END{ if(!found) print "198.18.0.1/16" }' "${clash_config}" 2>/dev/null)
|
||||
clash_enhanced_mode=$(busybox awk '/enhanced-mode: / { print $2;found=1; exit } END{ if(!found) print "fake-ip" }' "${clash_config}" 2>/dev/null)
|
||||
clash_dns_port=$(busybox awk -F ':' '/listen:/ { print $3;found=1; exit } END{ if(!found) print "1053" }' "${clash_config}" 2>/dev/null)
|
||||
|
||||
probe_empty () {
|
||||
if [ "${bin_name}" = "clash" ]; then
|
||||
@@ -36,23 +36,23 @@ fi
|
||||
|
||||
network_port() {
|
||||
if [ "${network_mode}" = "tproxy" ] && [ "${proxy_mode}" != "tun" ]; then
|
||||
/system/bin/netstat -tnulp | grep -q "${tproxy_port}" || log error "tproxy_port: ${tproxy_port} out of sync with config"
|
||||
netstat -tnulp | grep -q "${tproxy_port}" || log error "tproxy_port: ${tproxy_port} out of sync with config"
|
||||
fi
|
||||
if [ "${network_mode}" = "mixed" ] || [ "${proxy_mode}" = "tun" ]; then
|
||||
sleep 1
|
||||
/system/bin/ifconfig | grep -q "${tun_device}" || log error "tun_device: '${tun_device}' not found"
|
||||
ifconfig | grep -q "${tun_device}" || log error "tun_device: '${tun_device}' not found"
|
||||
fi
|
||||
}
|
||||
|
||||
find_packages_uid() {
|
||||
echo -n "" > "${uid_list}"
|
||||
for package in "${packages_list[@]}"; do
|
||||
awk -v p="${package}" '$1~p{print $2}' "${system_packages_file}" >> "${uid_list}"
|
||||
busybox awk -v p="${package}" '$1~p{print $2}' "${system_packages_file}" >> "${uid_list}"
|
||||
done
|
||||
}
|
||||
|
||||
probe_user_group() {
|
||||
if bin_pid=$(pidof ${bin_name}) ; then
|
||||
if bin_pid=$(busybox pidof ${bin_name}) ; then
|
||||
box_user=$(stat -c %U /proc/${bin_pid})
|
||||
box_group=$(stat -c %G /proc/${bin_pid})
|
||||
return 0
|
||||
@@ -537,13 +537,13 @@ if [ "${proxy_mode}" != "tun" ]; then
|
||||
log info "use tproxy: tcp + udp."
|
||||
log info "creating iptables transparent proxy rules."
|
||||
iptables="iptables -w 100"
|
||||
intranet+=($(ip address | awk '/inet / && !/127\.0\.0\.1/ {print $2}'))
|
||||
intranet+=($(ip address | busybox awk '/inet / && !/127\.0\.0\.1/ {print $2}'))
|
||||
start_tproxy && log info "create iptables transparent proxy rules done." || { log error "create iptables transparent proxy rules failed." && stop_tproxy >> /dev/null 2>&1; }
|
||||
if [ "${ipv6}" = "true" ]; then
|
||||
log debug "use IPv6."
|
||||
ipv6_enable
|
||||
iptables="ip6tables -w 100"
|
||||
intranet6+=($(ip address | awk '/inet6/ && !/::1/ && !/fe80/ {print $2}'))
|
||||
intranet6+=($(ip address | busybox awk '/inet6/ && !/::1/ && !/fe80/ {print $2}'))
|
||||
start_tproxy && log info "create ip6tables transparent proxy rules done." || { log error "create ip6tables transparent proxy rules failed." && stop_tproxy >> /dev/null 2>&1; }
|
||||
else
|
||||
disable_ipv6
|
||||
@@ -554,13 +554,13 @@ if [ "${proxy_mode}" != "tun" ]; then
|
||||
log info "use redirect: tcp only"
|
||||
log info "creating iptables transparent proxy rules."
|
||||
iptables="iptables -w 100"
|
||||
intranet+=($(ip address | awk '/inet / && !/127\.0\.0\.1/ {print $2}'))
|
||||
intranet+=($(ip address | busybox awk '/inet / && !/127\.0\.0\.1/ {print $2}'))
|
||||
start_redirect && log info "create iptables transparent proxy rules done." || { log error "create iptables transparent proxy rule failed." && stop_redirect >> /dev/null 2>&1; }
|
||||
if [ "${ipv6}" = "true" ]; then
|
||||
log debug "use IPv6."
|
||||
ipv6_enable
|
||||
iptables="ip6tables -w 100"
|
||||
intranet6+=($(ip address | awk '/inet6/ && !/::1/ && !/fe80/ {print $2}'))
|
||||
intranet6+=($(ip address | busybox awk '/inet6/ && !/::1/ && !/fe80/ {print $2}'))
|
||||
start_redirect && log info "create ip6tables transparent proxy rules done." || { log error "create ip6tables transparent proxy rule failed." && stop_redirect >> /dev/null 2>&1; }
|
||||
else
|
||||
disable_ipv6
|
||||
@@ -572,13 +572,13 @@ if [ "${proxy_mode}" != "tun" ]; then
|
||||
log info "creating iptables transparent proxy rules."
|
||||
iptables="iptables -w 100"
|
||||
forward -I || forward -D >> /dev/null 2>&1
|
||||
intranet+=($(ip address | awk '/inet / && !/127\.0\.0\.1/ {print $2}'))
|
||||
intranet+=($(ip address | busybox awk '/inet / && !/127\.0\.0\.1/ {print $2}'))
|
||||
start_redirect && log info "create iptables transparent proxy rules done." || (log error "create iptables transparent proxy rule failed." && stop_redirect >> /dev/null 2>&1)
|
||||
if [ "${ipv6}" = "true" ]; then
|
||||
log debug "use IPv6."
|
||||
ipv6_enable
|
||||
iptables="ip6tables -w 100"
|
||||
intranet6+=($(ip address | awk '/inet6/ && !/::1/ && !/fe80/ {print $2}'))
|
||||
intranet6+=($(ip address | busybox awk '/inet6/ && !/::1/ && !/fe80/ {print $2}'))
|
||||
forward -I || forward -D >> /dev/null 2>&1
|
||||
start_redirect && log info "create ip6tables transparent proxy rules done." || (log error "create ip6tables transparent proxy rule failed." && stop_redirect >> /dev/null 2>&1)
|
||||
else
|
||||
@@ -615,13 +615,13 @@ if [ "${proxy_mode}" != "tun" ]; then
|
||||
log info "use tproxy: tcp + udp."
|
||||
log info "creating iptables transparent proxy rules."
|
||||
iptables="iptables -w 100"
|
||||
intranet+=($(ip address | awk '/inet / && !/127\.0\.0\.1/ {print $2}'))
|
||||
intranet+=($(ip address | busybox awk '/inet / && !/127\.0\.0\.1/ {print $2}'))
|
||||
start_tproxy && log info "create iptables transparent proxy rules done." || { log error "create iptables transparent proxy rules failed." && stop_tproxy >> /dev/null 2>&1; }
|
||||
if [ "${ipv6}" = "true" ]; then
|
||||
log debug "use IPv6."
|
||||
ipv6_enable
|
||||
iptables="ip6tables -w 100"
|
||||
intranet6+=($(ip address | awk '/inet6/ && !/::1/ && !/fe80/ {print $2}'))
|
||||
intranet6+=($(ip address | busybox awk '/inet6/ && !/::1/ && !/fe80/ {print $2}'))
|
||||
start_tproxy && log info "create ip6tables transparent proxy rules done." || { log error "create ip6tables transparent proxy rules failed." && stop_tproxy >> /dev/null 2>&1; }
|
||||
else
|
||||
disable_ipv6
|
||||
@@ -632,13 +632,13 @@ if [ "${proxy_mode}" != "tun" ]; then
|
||||
log info "use redirect: tcp only"
|
||||
log info "creating iptables transparent proxy rules."
|
||||
iptables="iptables -w 100"
|
||||
intranet+=($(ip address | awk '/inet / && !/127\.0\.0\.1/ {print $2}'))
|
||||
intranet+=($(ip address | busybox awk '/inet / && !/127\.0\.0\.1/ {print $2}'))
|
||||
start_redirect && log info "create iptables transparent proxy rules done." || { log error "create iptables transparent proxy rule failed." && stop_redirect >> /dev/null 2>&1; }
|
||||
if [ "${ipv6}" = "true" ]; then
|
||||
log debug "use IPv6."
|
||||
ipv6_enable
|
||||
iptables="ip6tables -w 100"
|
||||
intranet6+=($(ip address | awk '/inet6/ && !/::1/ && !/fe80/ {print $2}'))
|
||||
intranet6+=($(ip address | busybox awk '/inet6/ && !/::1/ && !/fe80/ {print $2}'))
|
||||
start_redirect && log info "create ip6tables transparent proxy rules done." || { log error "create ip6tables transparent proxy rule failed." && stop_redirect >> /dev/null 2>&1; }
|
||||
else
|
||||
disable_ipv6
|
||||
@@ -650,13 +650,13 @@ if [ "${proxy_mode}" != "tun" ]; then
|
||||
log info "creating iptables transparent proxy rules."
|
||||
iptables="iptables -w 100"
|
||||
forward -I || forward -D >> /dev/null 2>&1
|
||||
intranet+=($(ip address | awk '/inet / && !/127\.0\.0\.1/ {print $2}'))
|
||||
intranet+=($(ip address | busybox awk '/inet / && !/127\.0\.0\.1/ {print $2}'))
|
||||
start_redirect && log info "create iptables transparent proxy rules done." || { log error "create iptables transparent proxy rule failed." && stop_redirect >> /dev/null 2>&1; }
|
||||
if [ "${ipv6}" = "true" ]; then
|
||||
log debug "use IPv6."
|
||||
ipv6_enable
|
||||
iptables="ip6tables -w 100"
|
||||
intranet6+=($(ip address | awk '/inet6/ && !/::1/ && !/fe80/ {print $2}'))
|
||||
intranet6+=($(ip address | busybox awk '/inet6/ && !/::1/ && !/fe80/ {print $2}'))
|
||||
forward -I || forward -D >> /dev/null 2>&1
|
||||
start_redirect && log info "create ip6tables transparent proxy rules done." || { log error "create ip6tables transparent proxy rule failed." && stop_redirect >> /dev/null 2>&1; }
|
||||
else
|
||||
|
||||
@@ -5,8 +5,8 @@ scripts_dir=$(dirname ${scripts})
|
||||
source /data/adb/box/settings.ini
|
||||
|
||||
# Reads the enable value from the tun configuration
|
||||
# singbox_tun=$(find /data/adb/box/sing-box/ -name "*.json" -exec awk -F':' '/"type":[[:space:]]*"tun"/{gsub(/^[[:space:]]+|[",[:space:]]+$/,"",$2); print $2}' {} \; | tr -d '"')
|
||||
clash_tun_status=$(awk -F ': ' '/^tun: *$/{getline; print $2}' "${clash_config}")
|
||||
# singbox_tun=$(find /data/adb/box/sing-box/ -name "*.json" -exec busybox awk -F':' '/"type":[[:space:]]*"tun"/{gsub(/^[[:space:]]+|[",[:space:]]+$/,"",$2); print $2}' {} \; | tr -d '"')
|
||||
clash_tun_status=$(busybox awk -F ': ' '/^tun: *$/{getline; print $2}' "${clash_config}")
|
||||
|
||||
delete_logs() {
|
||||
# Delete logs for each bin in the list
|
||||
@@ -42,7 +42,7 @@ detected_port() {
|
||||
|
||||
still_alive() {
|
||||
sleep 1.5
|
||||
pid=$(pidof ${bin_name} 2>/dev/null)
|
||||
pid=$(busybox pidof ${bin_name} 2>/dev/null)
|
||||
if [ -z "${pid}" ]; then
|
||||
log error "${bin_name} service is not running."
|
||||
log error "Please check ${bin_name}.log for more information."
|
||||
@@ -52,7 +52,7 @@ still_alive() {
|
||||
if ! kill -0 "${pid}" 2>/dev/null; then
|
||||
log error "${bin_name} service is not running."
|
||||
log error "Killing stale pid '${pid}'"
|
||||
pkill -15 "${bin_list[@]}" >/dev/null 2>&1 || killall -15 "${bin_list[@]}" >/dev/null 2>&1
|
||||
busybox pkill -15 "${bin_list[@]}" >/dev/null 2>&1 || killall -15 "${bin_list[@]}" >/dev/null 2>&1
|
||||
${scripts_dir}/box.iptables disable >/dev/null 2>&1
|
||||
exit 1
|
||||
fi
|
||||
@@ -74,8 +74,8 @@ check_permission() {
|
||||
log info "use the kernel located in '${bin_path}'"
|
||||
else
|
||||
if which ${bin_name} | grep -q "/system/bin/" ; then
|
||||
box_user=$(echo ${box_user_group} | awk -F ':' '{print $1}')
|
||||
box_group=$(echo ${box_user_group} | awk -F ':' '{print $2}')
|
||||
box_user=$(echo ${box_user_group} | busybox awk -F ':' '{print $1}')
|
||||
box_group=$(echo ${box_user_group} | busybox awk -F ':' '{print $2}')
|
||||
box_user_id=$(id -u ${box_user})
|
||||
box_group_id=$(id -g ${box_group})
|
||||
# Check if box_user and box_group exist
|
||||
@@ -179,11 +179,13 @@ prepare_singbox() {
|
||||
}
|
||||
|
||||
prepare_clash() {
|
||||
clash_external_ui=$(awk '/external-ui: /{print $1}' "${clash_config}")
|
||||
ipv6=$(busybox awk '/ipv6:/ { print $2; found=1; exit } END{ if(!found) print "false" }' "${clash_config}" | head -n 1 2>/dev/null)
|
||||
sed -i "s/ipv6=.*/ipv6=${ipv6}/g" /data/adb/box/settings.ini
|
||||
clash_external_ui=$(busybox awk '/external-ui: /{print $1}' "${clash_config}")
|
||||
[ -z "${clash_external_ui}" ] && printf "\nexternal-ui: ./dashboard/dist" >> "${clash_config}"
|
||||
clash_tproxy_port=$(awk '/tproxy-port: /{print $1}' "${clash_config}")
|
||||
clash_tproxy_port=$(busybox awk '/tproxy-port: /{print $1}' "${clash_config}")
|
||||
[ -z "${clash_tproxy_port}" ] && printf "\ntproxy-port: ${tproxy_port}" >> "${clash_config}"
|
||||
clash_redir_port=$(awk '/redir-port: /{print $1}' "${clash_config}")
|
||||
clash_redir_port=$(busybox awk '/redir-port: /{print $1}' "${clash_config}")
|
||||
[ -z "${clash_redir_port}" ] && printf "\nredir-port: ${redir_port}" >> "${clash_config}"
|
||||
if [ "${clash_tun_status}" != "true" ]; then
|
||||
sed -i -E "s/(tproxy-port: )[0-9]+/\1${tproxy_port}/" "${clash_config}"
|
||||
@@ -210,7 +212,7 @@ run_box() {
|
||||
sing-box)
|
||||
prepare_singbox
|
||||
if ${bin_path} check -D "${data_dir}/${bin_name}" --config-directory "${data_dir}/sing-box" > "${run_path}/${bin_name}-report.log" 2>&1 ; then
|
||||
nohup setuidgid 0:3005 ${bin_path} run -D "${data_dir}/${bin_name}" --config-directory "${data_dir}/sing-box" > "${run_path}/${bin_name}.log" 2>&1 &
|
||||
nohup busybox setuidgid 0:3005 ${bin_path} run -D "${data_dir}/${bin_name}" --config-directory "${data_dir}/sing-box" > "${run_path}/${bin_name}.log" 2>&1 &
|
||||
echo -n $! > "${pid_file}"
|
||||
else
|
||||
log error "Configuration failed, please check the ${run_path}/${bin_name}-report.log file." >&2
|
||||
@@ -220,7 +222,7 @@ run_box() {
|
||||
clash)
|
||||
prepare_clash
|
||||
if ${bin_path} -t -d "${data_dir}/${bin_name}" -f "${clash_config}" > "${run_path}/${bin_name}-report.log" 2>&1; then
|
||||
nohup setuidgid 0:3005 ${bin_path} -d "${data_dir}/${bin_name}" -f "${clash_config}" > "${run_path}/${bin_name}.log" 2>&1 &
|
||||
nohup busybox setuidgid 0:3005 ${bin_path} -d "${data_dir}/${bin_name}" -f "${clash_config}" > "${run_path}/${bin_name}.log" 2>&1 &
|
||||
echo -n $! > "${pid_file}"
|
||||
else
|
||||
log error "configuration failed, please check the ${run_path}/${bin_name}-report.log file."
|
||||
@@ -233,7 +235,7 @@ run_box() {
|
||||
export XRAY_LOCATION_ASSET="${data_dir}/${bin_name}"
|
||||
export XRAY_LOCATION_CONFDIR="${data_dir}/${bin_name}"
|
||||
if ${bin_path} -test > "${run_path}/${bin_name}-report.log" 2>&1; then
|
||||
nohup setuidgid 0:3005 ${bin_path} > "${run_path}/${bin_name}.log" 2>&1 &
|
||||
nohup busybox setuidgid 0:3005 ${bin_path} > "${run_path}/${bin_name}.log" 2>&1 &
|
||||
echo -n $! > "${pid_file}"
|
||||
else
|
||||
log error "configuration failed, please check the ${run_path}/${bin_name}-report.log file."
|
||||
@@ -246,7 +248,7 @@ run_box() {
|
||||
export V2RAY_LOCATION_ASSET="${data_dir}/${bin_name}"
|
||||
export V2RAY_LOCATION_CONFDIR="${data_dir}/${bin_name}"
|
||||
if (${bin_path} test > "${run_path}/${bin_name}-report.log" 2>&1) ; then
|
||||
nohup setuidgid 0:3005 ${bin_path} run > "${run_path}/${bin_name}.log" 2>&1 &
|
||||
nohup busybox setuidgid 0:3005 ${bin_path} run > "${run_path}/${bin_name}.log" 2>&1 &
|
||||
echo -n $! > ${pid_file}
|
||||
else
|
||||
log error "configuration failed, please check the ${run_path}/${bin_name}-report.log file."
|
||||
@@ -278,18 +280,18 @@ fi
|
||||
# Function to display the usage of a binary
|
||||
bin_usage() {
|
||||
# Get the process ID of the binary
|
||||
bin_pid=$(pidof ${bin_name})
|
||||
bin_pid=$(busybox pidof ${bin_name})
|
||||
if [ -z "${bin_pid}" ]; then
|
||||
log error "${bin_name} is not running"
|
||||
return
|
||||
fi
|
||||
# Get the memory usage of the binary
|
||||
rss=$(grep VmRSS /proc/${bin_pid}/status | awk '{print $2}')
|
||||
rss=$(grep VmRSS /proc/${bin_pid}/status | busybox awk '{print $2}')
|
||||
[ "${rss}" -ge 1024 ] && bin_rss="$(expr ${rss} / 1024) MB" || bin_rss="${rss} KB"
|
||||
swap=$(grep VmSwap /proc/${bin_pid}/status | awk '{print $2}')
|
||||
swap=$(grep VmSwap /proc/${bin_pid}/status | busybox awk '{print $2}')
|
||||
[ "${swap}" -ge 1024 ] && bin_swap="$(expr ${swap} / 1024) MB" || bin_swap="${swap} KB"
|
||||
# Get the state of the binary
|
||||
state=$(grep State /proc/${bin_pid}/status | awk '{print $2}')
|
||||
state=$(grep State /proc/${bin_pid}/status | busybox awk '{print $2}')
|
||||
# Get the user and group of the binary
|
||||
user_group=$(stat -c %U:%G /proc/${bin_pid})
|
||||
# Log the information
|
||||
@@ -297,14 +299,14 @@ bin_usage() {
|
||||
log info "${bin_name} status: ${state}, PID: (${bin_pid})"
|
||||
log info "${bin_name} memory usage: ${bin_rss}, swap: ${bin_swap}"
|
||||
# Get the CPU usage of the binary
|
||||
cpu=$(/system/bin/ps -p ${bin_pid} -o pcpu | awk 'NR==2{print $1}' 2> /dev/null)
|
||||
cpu=$(ps -p ${bin_pid} -o pcpu | busybox awk 'NR==2{print $1}' 2> /dev/null)
|
||||
if [ -n "${cpu}" ]; then
|
||||
log info "${bin_name} cpu usage: ${cpu}%"
|
||||
else
|
||||
log info "${bin_name} cpu usage: not available"
|
||||
fi
|
||||
# Get the running time of the binary
|
||||
running_time=$(/system/bin/ps -p ${bin_pid} -o etime | awk 'NR==2{print $1}' 2> /dev/null)
|
||||
running_time=$(ps -p ${bin_pid} -o etime | busybox awk 'NR==2{print $1}' 2> /dev/null)
|
||||
if [ -n "${running_time}" ]; then
|
||||
log info "${bin_name} running time: ${running_time} seconds"
|
||||
else
|
||||
@@ -321,7 +323,7 @@ display_bin_pid() {
|
||||
return 1
|
||||
fi
|
||||
# Look up the PID of bin_name
|
||||
bin_pid=$(pidof "${bin_name}")
|
||||
bin_pid=$(busybox pidof "${bin_name}")
|
||||
# Checks if bin_name is running
|
||||
if [ -n "${bin_pid}" ]; then
|
||||
# If so, prints a message and calls the bin_usage function
|
||||
@@ -359,6 +361,11 @@ crontab_alive() {
|
||||
start_box() {
|
||||
# Cleared the log file and added the timestamp and delimiter
|
||||
echo -n "" > "${logs_file}"
|
||||
# command command -v to check whether busybox is installed or not on your system.
|
||||
if ! command -v busybox &> /dev/null; then
|
||||
log error "Perintah busybox tidak ditemukan"
|
||||
exit 1
|
||||
fi
|
||||
# Then use the chmod command to set file permissions to 755
|
||||
if [ -t 1 ]; then
|
||||
echo -e "\033[1;31m$(date)\033[0m"
|
||||
@@ -368,7 +375,7 @@ start_box() {
|
||||
echo "--------------------------------------------" | tee -a "${logs_file}" > /dev/null 2>&1
|
||||
fi
|
||||
# Update iptables if bin_name is still running
|
||||
if bin_pid=$(pidof "${bin_name}"); then
|
||||
if bin_pid=$(busybox pidof "${bin_name}"); then
|
||||
log info "${bin_name} service is still running, refreshing iptables"
|
||||
if "${scripts_dir}/box.iptables" renew; then
|
||||
log info "iptables refreshed successfully"
|
||||
@@ -415,12 +422,12 @@ stop_box() {
|
||||
done
|
||||
# Using a loop to kill each binary
|
||||
for bin in ${bin_list[@]}; do
|
||||
# Use `pkill` to kill the binary with signal 15
|
||||
pkill -15 "${bin}" || killall -15 "${bin}"
|
||||
# Use `busybox pkill` to kill the binary with signal 15
|
||||
busybox pkill -15 "${bin}" || killall -15 "${bin}"
|
||||
done
|
||||
sleep 1
|
||||
# Check if the binary has stopped
|
||||
if ! pidof ${bin_name} >/dev/null 2>&1; then
|
||||
if ! busybox pidof ${bin_name} >/dev/null 2>&1; then
|
||||
# Delete the `box.pid` file if it exists
|
||||
if [ -f ${run_path}/box.pid ]; then
|
||||
rm -f "${pid_file}"
|
||||
@@ -431,12 +438,12 @@ stop_box() {
|
||||
log error "failed to stop ${bin_name}"
|
||||
log warn "force stop ${bin_name}."
|
||||
for bin in "${bin_list[@]}"; do
|
||||
# Use `pkill` to kill the binary with signal 9
|
||||
pkill -9 "${bin}" >/dev/null 2>&1 || killall -9 "${bin}" >/dev/null 2>&1
|
||||
# Use `busybox pkill` to kill the binary with signal 9
|
||||
busybox pkill -9 "${bin}" >/dev/null 2>&1 || killall -9 "${bin}" >/dev/null 2>&1
|
||||
done
|
||||
sleep 0.5
|
||||
# Check whether the binary has stopped
|
||||
if ! pidof ${bin_name} >/dev/null 2>&1; then
|
||||
if ! busybox pidof ${bin_name} >/dev/null 2>&1; then
|
||||
log warn "done"
|
||||
fi
|
||||
fi
|
||||
@@ -462,7 +469,7 @@ case "$1" in
|
||||
clash) log debug "$(${bin_path} -v)";;
|
||||
*) log debug "$(${bin_path} version)";;
|
||||
esac
|
||||
[ $(pidof ${bin_name}) ] && \
|
||||
[ $(busybox pidof ${bin_name}) ] && \
|
||||
bin_usage || log warn "${bin_name} service is stopped"
|
||||
;;
|
||||
*)
|
||||
|
||||
@@ -86,7 +86,7 @@ network_check() {
|
||||
# Check if a binary is running by checking the pid file and cmdline
|
||||
probe_bin_alive() {
|
||||
if [ -f "${pid_file}" ]; then
|
||||
cmd_file="/proc/$(pidof "${bin_name}")/cmdline"
|
||||
cmd_file="/proc/$(busybox pidof "${bin_name}")/cmdline"
|
||||
if [ -f "${cmd_file}" ] && grep -q "${bin_name}" "${cmd_file}"; then
|
||||
return 0 # binary is alive
|
||||
else
|
||||
@@ -136,7 +136,7 @@ update_file() {
|
||||
if [ -f "${file}" ]; then
|
||||
mv "${file}" "${file_bak}" || return 1
|
||||
fi
|
||||
request="wget"
|
||||
request="busybox wget"
|
||||
request+=" --no-check-certificate"
|
||||
request+=" --user-agent ${user_agent}"
|
||||
request+=" -O ${file}"
|
||||
@@ -193,7 +193,7 @@ port_detection() {
|
||||
# Use 'command' function to check if 'ss' is available
|
||||
if command -v ss > /dev/null ; then
|
||||
# Use 'awk' with a regular expression to match the process ID
|
||||
ports=$(ss -antup | awk -v pid="$(pidof "${bin_name}")" '$7 ~ pid {print $5}' | awk -F ':' '{print $2}' | sort -u)
|
||||
ports=$(ss -antup | awk -v pid="$(busybox pidof "${bin_name}")" '$7 ~ pid {print $5}' | awk -F ':' '{print $2}' | sort -u)
|
||||
else
|
||||
# Log a warning message if 'ss' is not available
|
||||
log debug "Warning: 'ss' command not found, skipping port detection." >&2
|
||||
@@ -216,8 +216,8 @@ port_detection() {
|
||||
# kill bin
|
||||
kill_alive() {
|
||||
for list in "${bin_list[@]}" ; do
|
||||
if pidof "${list}" >/dev/null ; then
|
||||
pkill -15 "${list}" >/dev/null 2>&1 || killall -15 "${list}" >/dev/null 2>&1
|
||||
if busybox pidof "${list}" >/dev/null ; then
|
||||
busybox pkill -15 "${list}" >/dev/null 2>&1 || killall -15 "${list}" >/dev/null 2>&1
|
||||
fi
|
||||
done
|
||||
}
|
||||
@@ -238,9 +238,9 @@ update_kernel() {
|
||||
sing-box)
|
||||
url_down="https://github.com/SagerNet/sing-box/releases"
|
||||
if [ "${singbox_releases}" = "false" ]; then
|
||||
sing_box_version_temp=$(wget --no-check-certificate -qO- "${url_down}" | grep -oE '/tag/v[0-9]+\.[0-9]+-[a-z0-9]+' | head -1 | awk -F'/' '{print $3}')
|
||||
sing_box_version_temp=$(busybox wget --no-check-certificate -qO- "${url_down}" | grep -oE '/tag/v[0-9]+\.[0-9]+-[a-z0-9]+' | head -1 | awk -F'/' '{print $3}')
|
||||
else
|
||||
sing_box_version_temp=$(wget --no-check-certificate -qO- "${url_down}" | grep -oE '/tag/v[0-9]+\.[0-9]+\.[0-9]+' | head -1 | awk -F'/' '{print $3}')
|
||||
sing_box_version_temp=$(busybox wget --no-check-certificate -qO- "${url_down}" | grep -oE '/tag/v[0-9]+\.[0-9]+\.[0-9]+' | head -1 | awk -F'/' '{print $3}')
|
||||
fi
|
||||
sing_box_version=${sing_box_version_temp#v}
|
||||
download_link="${url_down}/download/${sing_box_version_temp}/sing-box-${sing_box_version}-${platform}-${arch}.tar.gz"
|
||||
@@ -252,9 +252,9 @@ update_kernel() {
|
||||
if [ "${meta}" = "true" ]; then
|
||||
# set download link and get the latest version
|
||||
download_link="https://github.com/MetaCubeX/Clash.Meta/releases"
|
||||
# tag=$(wget --no-check-certificate -qO- ${download_link} | grep -oE 'tag\/([^"]+)' | cut -d '/' -f 2 | head -1)
|
||||
# tag=$(busybox wget --no-check-certificate -qO- ${download_link} | grep -oE 'tag\/([^"]+)' | cut -d '/' -f 2 | head -1)
|
||||
tag="Prerelease-Alpha"
|
||||
latest_version=$(wget --no-check-certificate -qO- "${download_link}/expanded_assets/${tag}" | grep -oE "alpha-[0-9a-z]+" | head -1)
|
||||
latest_version=$(busybox wget --no-check-certificate -qO- "${download_link}/expanded_assets/${tag}" | grep -oE "alpha-[0-9a-z]+" | head -1)
|
||||
# set the filename based on platform and architecture
|
||||
filename="clash.meta-${platform}-${arch}"
|
||||
[ $(uname -m) != "aarch64" ] || filename+="-cgo"
|
||||
@@ -270,7 +270,7 @@ update_kernel() {
|
||||
update_file "${data_dir}/${file_kernel}.gz" "https://release.dreamacro.workers.dev/latest/clash-linux-${arch}-latest.gz"
|
||||
else
|
||||
# if dev flag is false, download latest premium version
|
||||
filename=$(wget --no-check-certificate -qO- "https://github.com/Dreamacro/clash/releases/expanded_assets/premium" | grep -oE "clash-linux-${arch}-[0-9]+.[0-9]+.[0-9]+" | head -1)
|
||||
filename=$(busybox wget --no-check-certificate -qO- "https://github.com/Dreamacro/clash/releases/expanded_assets/premium" | grep -oE "clash-linux-${arch}-[0-9]+.[0-9]+.[0-9]+" | head -1)
|
||||
log debug "download https://github.com/Dreamacro/clash/releases/download/premium/${filename}.gz"
|
||||
update_file "${data_dir}/${file_kernel}.gz" "https://github.com/Dreamacro/clash/releases/download/premium/${filename}.gz"
|
||||
fi
|
||||
@@ -280,7 +280,7 @@ update_kernel() {
|
||||
;;
|
||||
xray)
|
||||
# set download link and get the latest version
|
||||
latest_version=$(wget --no-check-certificate -qO- https://api.github.com/repos/XTLS/Xray-core/releases | grep "tag_name" | grep -o "v[0-9.]*" | head -1)
|
||||
latest_version=$(busybox wget --no-check-certificate -qO- https://api.github.com/repos/XTLS/Xray-core/releases | grep "tag_name" | grep -o "v[0-9.]*" | head -1)
|
||||
case $(uname -m) in
|
||||
"i386") download_file="Xray-linux-32.zip" ;;
|
||||
"x86_64") download_file="Xray-linux-64.zip" ;;
|
||||
@@ -297,7 +297,7 @@ update_kernel() {
|
||||
;;
|
||||
v2fly)
|
||||
# set download link and get the latest version
|
||||
latest_version=$(wget --no-check-certificate -qO- https://api.github.com/repos/v2fly/v2ray-core/releases | grep "tag_name" | grep -o "v[0-9.]*" | head -1)
|
||||
latest_version=$(busybox wget --no-check-certificate -qO- https://api.github.com/repos/v2fly/v2ray-core/releases | grep "tag_name" | grep -o "v[0-9.]*" | head -1)
|
||||
case $(uname -m) in
|
||||
"i386") download_file="v2ray-linux-32.zip" ;;
|
||||
"x86_64") download_file="v2ray-linux-64.zip" ;;
|
||||
@@ -320,7 +320,7 @@ update_kernel() {
|
||||
|
||||
case "${bin_name}" in
|
||||
clash)
|
||||
gunzip_command=$(command -v gunzip >/dev/null 2>&1 && echo "gunzip" || echo "${busybox_path} gunzip")
|
||||
gunzip_command=$(command -v gunzip >/dev/null 2>&1 && echo "gunzip" || echo "busybox gunzip")
|
||||
if ${gunzip_command} "${data_dir}/${file_kernel}.gz" >&2 && mv "${data_dir}/${file_kernel}" "${bin_kernel}/${bin_name}"; then
|
||||
[ -f "${pid_file}" ] && restart_box || log debug "${bin_name} does not need to be restarted"
|
||||
else
|
||||
@@ -328,7 +328,7 @@ update_kernel() {
|
||||
fi
|
||||
;;
|
||||
sing-box)
|
||||
tar_command=$(command -v tar >/dev/null 2>&1 && echo "tar" || echo "${busybox_path} tar")
|
||||
tar_command=$(command -v tar >/dev/null 2>&1 && echo "tar" || echo "busybox tar")
|
||||
if ${tar_command} -xf "${data_dir}/${file_kernel}.tar.gz" -C "${data_dir}/bin" >&2 && mv "${data_dir}/bin/sing-box-${sing_box_version}-${platform}-${arch}/sing-box" "${bin_kernel}/${bin_name}" && rm -r "${data_dir}/bin/sing-box-${sing_box_version}-${platform}-${arch}"; then
|
||||
[ -f "${pid_file}" ] && restart_box || log debug "${bin_name} does not need to be restarted"
|
||||
else
|
||||
@@ -337,7 +337,7 @@ update_kernel() {
|
||||
;;
|
||||
v2fly|xray)
|
||||
[ "${bin_name}" = "xray" ] && bin='xray' || bin='v2ray'
|
||||
unzip_command=$(command -v unzip >/dev/null 2>&1 && echo "unzip" || echo "${busybox_path} unzip")
|
||||
unzip_command=$(command -v unzip >/dev/null 2>&1 && echo "unzip" || echo "busybox unzip")
|
||||
if ${unzip_command} -o "${data_dir}/${file_kernel}.zip" "${bin}" -d "${bin_kernel}" >&2 ; then
|
||||
if mv "${bin_kernel}/${bin}" "${bin_kernel}/${bin_name}"; then
|
||||
[ -f "${pid_file}" ] && restart_box || log debug "${bin_name} does not need to be restarted"
|
||||
@@ -404,7 +404,7 @@ update_dashboard() {
|
||||
rm -rf "${data_dir}/${bin_name}/dashboard/dist"
|
||||
url="https://github.com/MetaCubeX/Yacd-meta/archive/refs/heads/gh-pages.zip"
|
||||
dir_name="Yacd-meta-gh-pages"
|
||||
wget --no-check-certificate "${url}" -O "${file_dashboard}" 2>&1
|
||||
busybox wget --no-check-certificate "${url}" -O "${file_dashboard}" 2>&1
|
||||
unzip -o "${file_dashboard}" "${dir_name}/*" -d "${data_dir}/${bin_name}/dashboard" >&2
|
||||
mv -f "${data_dir}/${bin_name}/dashboard/${dir_name}" "${data_dir}/${bin_name}/dashboard/dist"
|
||||
rm -f "${file_dashboard}"
|
||||
|
||||
16
uninstall.sh
16
uninstall.sh
@@ -2,8 +2,20 @@
|
||||
|
||||
box_data_dir="data/adb/box"
|
||||
rm_data() {
|
||||
rm -rf ${box_data_dir}
|
||||
rm -rf /data/adb/service.d/box_service.sh
|
||||
if [ ! -d "${box_data_dir}" ]; then
|
||||
exit 1
|
||||
else
|
||||
rm -rf "${box_data_dir}"
|
||||
fi
|
||||
|
||||
if [ -f "/data/adb/ksu/service.d/box_service.sh" ]; then
|
||||
rm -f "/data/adb/ksu/service.d/box_service.sh"
|
||||
fi
|
||||
|
||||
if [ -f "/data/adb/service.d/box_service.sh" ]; then
|
||||
rm -f "/data/adb/service.d/box_service.sh"
|
||||
fi
|
||||
|
||||
}
|
||||
|
||||
rm_data
|
||||
Reference in New Issue
Block a user