Skip to content

Commit

Permalink
Fix add busybox to PATH
Browse files Browse the repository at this point in the history
  • Loading branch information
CHIZI-0618 committed Mar 28, 2023
1 parent d04e8de commit a2e5a5a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 14 deletions.
18 changes: 8 additions & 10 deletions box/scripts/box.service
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#!/system/bin/sh

magisk_path=$(magisk --path 2>> /dev/null)
export PATH=${magisk_path}/.magisk/busybox:$PATH:/data/data/com.termux/files/usr/bin
busybox_path="/data/adb/ksu/bin/busybox"
export PATH="/data/adb/magisk:/data/adb/ksu/bin:$PATH:/data/data/com.termux/files/usr/bin"

scripts=$(realpath $0)
scripts_dir=$(dirname ${scripts})
Expand Down Expand Up @@ -90,7 +88,7 @@ start_bin() {
sing-box)
if ${bin_path} check -D ${box_path}/${bin_name} > ${run_path}/check.log 2>&1 ; then
log Info "starting ${bin_name} service."
nohup ${busybox_path} setuidgid ${box_user_group} ${bin_path} run -D ${box_path}/${bin_name} > /dev/null 2> ${run_path}/error_${bin_name}.log &
nohup busybox setuidgid ${box_user_group} ${bin_path} run -D ${box_path}/${bin_name} > /dev/null 2> ${run_path}/error_${bin_name}.log &
echo -n $! > ${pid_file}
return 0
else
Expand All @@ -101,7 +99,7 @@ start_bin() {
clash)
if ${bin_path} -t -d ${box_path}/${bin_name} > ${run_path}/check.log 2>&1 ; then
log Info "starting ${bin_name} service."
nohup ${busybox_path} setuidgid ${box_user_group} ${bin_path} -d ${box_path}/${bin_name} > ${box_path}/${bin_name}/${bin_name}_$(date +%Y%m%d%H%M).log 2> ${run_path}/error_${bin_name}.log &
nohup busybox setuidgid ${box_user_group} ${bin_path} -d ${box_path}/${bin_name} > ${box_path}/${bin_name}/${bin_name}_$(date +%Y%m%d%H%M).log 2> ${run_path}/error_${bin_name}.log &
echo -n $! > ${pid_file}
return 0
else
Expand All @@ -112,7 +110,7 @@ start_bin() {
xray)
if ${bin_path} -test -confdir ${box_path}/${bin_name} > ${run_path}/check.log 2>&1 ; then
log Info "starting ${bin_name} service."
nohup ${busybox_path} setuidgid ${box_user_group} ${bin_path} -confdir ${box_path}/${bin_name} > /dev/null 2> ${run_path}/error_${bin_name}.log &
nohup busybox setuidgid ${box_user_group} ${bin_path} -confdir ${box_path}/${bin_name} > /dev/null 2> ${run_path}/error_${bin_name}.log &
echo -n $! > ${pid_file}
return 0
else
Expand All @@ -123,7 +121,7 @@ start_bin() {
v2ray)
if ${bin_path} test -d ${box_path}/${bin_name} > ${run_path}/check.log 2>&1 ; then
log Info "starting ${bin_name} service."
nohup ${busybox_path} setuidgid ${box_user_group} ${bin_path} run -d ${box_path}/${bin_name} > /dev/null 2> ${run_path}/error_${bin_name}.log &
nohup busybox setuidgid ${box_user_group} ${bin_path} run -d ${box_path}/${bin_name} > /dev/null 2> ${run_path}/error_${bin_name}.log &
echo -n $! > ${pid_file}
return 0
else
Expand All @@ -146,7 +144,7 @@ find_netstat_path() {

wait_bin_listen() {
wait_count=0
bin_pid=$(${busybox_path} pidof ${bin_name})
bin_pid=$(busybox pidof ${bin_name})
find_netstat_path && \
check_bin_cmd="netstat -tnulp | grep -q ${bin_name}" || \
check_bin_cmd="ls -lh /proc/${bin_pid}/fd | grep -q socket"
Expand All @@ -161,12 +159,12 @@ wait_bin_listen() {
}

display_bin_status() {
if bin_pid=$(${busybox_path} pidof ${bin_name}) ; then
if bin_pid=$(busybox pidof ${bin_name}) ; then
log Info "${bin_name} has started with the $(stat -c %U:%G /proc/${bin_pid}) user group."
log Info "${bin_name} service is running. ( PID: ${bin_pid} )"
log Info "${bin_name} memory usage: $(cat /proc/${bin_pid}/status | grep -w VmRSS | awk '{print $2$3}')"
log Info "${bin_name} cpu usage: $((/system/bin/ps -eo %CPU,NAME | grep ${bin_name} | awk '{print $1"%"}') 2> /dev/null || dumpsys cpuinfo | grep ${bin_name} | awk '{print $1}')"
log Info "${bin_name} running time: $(${busybox_path} ps -o comm,etime | grep ${bin_name} | awk '{print $2}')"
log Info "${bin_name} running time: $(busybox ps -o comm,etime | grep ${bin_name} | awk '{print $2}')"
echo -n ${bin_pid} > ${pid_file}
return 0
else
Expand Down
6 changes: 2 additions & 4 deletions box/scripts/box.tproxy
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#!/system/bin/sh

magisk_path=$(magisk --path 2>> /dev/null)
export PATH=${magisk_path}/.magisk/busybox:$PATH:/data/data/com.termux/files/usr/bin
busybox_path="/data/adb/ksu/bin/busybox"
export PATH="/data/adb/magisk:/data/adb/ksu/bin:$PATH:/data/data/com.termux/files/usr/bin"

scripts=$(realpath $0)
scripts_dir=$(dirname ${scripts})
Expand Down Expand Up @@ -40,7 +38,7 @@ find_packages_uid() {
}

probe_user_group() {
if bin_pid=$(${busybox_path} 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
Expand Down

0 comments on commit a2e5a5a

Please sign in to comment.