Skip to content

Commit 8d74c59

Browse files
committed
box: switch sing-box to single config file
- Add log_backup flag (default: false) for optional log backup - Include Android user 999 in tun config - Use -c "${sing_config}" instead of -C for sing-box check/run
1 parent f17ba92 commit 8d74c59

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

box/scripts/box.service

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,22 @@ scripts_dir="${0%/*}"
99
source /data/adb/box/settings.ini
1010

1111
PROPFILE="/data/adb/modules/box_for_root/module.prop"
12+
log_backup="false"
1213

1314
box_check_logs() {
1415
ts=$(date '+%Y-%m-%d_%H-%M-%S')
1516
log Info "Cleaning and backing up logs"
1617

1718
# Backup logs for each bin in bin_list
18-
for bin in "${bin_name}"; do
19-
log_file="${box_run}/${bin}.log"
20-
if [ -f "${log_file}" ]; then
21-
mv "${log_file}" "${box_run}/${bin}_$ts.log.bak"
22-
log Info "Backup: ${bin}.log → ${bin}_${ts}.log.bak"
23-
fi
24-
done
19+
if [ "${log_backup}" = "true" ]; then
20+
for bin in "${bin_name}"; do
21+
log_file="${box_run}/${bin}.log"
22+
if [ -f "${log_file}" ]; then
23+
mv "${log_file}" "${box_run}/${bin}_$ts.log.bak"
24+
log Info "Backup: ${bin}.log → ${bin}_${ts}.log.bak"
25+
fi
26+
done
27+
fi
2528

2629
# Remove specific unnecessary files
2730
find "${box_run}" -maxdepth 1 -type f \( -name "root" -o -name "*.list" -o -name "*.inotify.log" \) -exec rm -f {} +
@@ -208,7 +211,7 @@ prepare_singbox() {
208211
"auto_route": true,
209212
"strict_route": true,
210213
"auto_redirect": true,
211-
"include_android_user": [0,10],
214+
"include_android_user": [0,10,999],
212215
"include_package": [],
213216
"exclude_package": []
214217
}]' -i --output-format=json "${sing_config}"
@@ -334,7 +337,7 @@ prepare_clash() {
334337
' strict-route: true' \
335338
' auto-redirect: true' \
336339
' auto-detect-interface: true' \
337-
' include-android-user: [0, 10]' \
340+
' include-android-user: [0, 10, 999]' \
338341
' exclude-package: []' \
339342
' include-package: []' \ >> "${clash_config}"
340343
log Debug "[tun] configuration has been added to ${clash_config}"
@@ -440,8 +443,8 @@ box_run_bin() {
440443
;;
441444
sing-box)
442445
prepare_singbox
443-
if ${bin_path} check -D "${box_dir}/${bin_name}" -C "${box_dir}/${bin_name}" > "${box_run}/${bin_name}.log" 2>&1; then
444-
nohup busybox setuidgid "${box_user_group}" "${bin_path}" run -D "${box_dir}/${bin_name}" -C "${box_dir}/${bin_name}" > "${bin_log}" 2>&1 &
446+
if ${bin_path} check -D "${box_dir}/${bin_name}" -c "${sing_config}" > "${box_run}/${bin_name}.log" 2>&1; then
447+
nohup busybox setuidgid "${box_user_group}" "${bin_path}" run -D "${box_dir}/${bin_name}" -c "${sing_config}" > "${bin_log}" 2>&1 &
445448
PID=$!
446449
echo -n $PID > "${box_pid}"
447450
sleep 1

box/scripts/box.tool

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ check() {
8989

9090
case "${bin_name}" in
9191
sing-box)
92-
if ${bin_path} check -D "${box_dir}/${bin_name}" --config-directory "${box_dir}/sing-box" >/dev/null; then
92+
if ${bin_path} check -D "${box_dir}/${bin_name}" -c "${sing_config}" >/dev/null; then
9393
log Info "${sing_config} passed"
9494
else
9595
log Error "Configuration check failed for sing-box"

0 commit comments

Comments
 (0)