@@ -215,12 +215,12 @@ prepare_singbox() {
215
215
fi
216
216
217
217
# add exclude_package/include_package for tun
218
- # "${yq}" '(.inbounds[] | select(.type == "tun") | .include_package) = []' -i --output-format=json "${sing_config}"
219
- # "${yq}" '(.inbounds[] | select(.type == "tun") | .exclude_package) = []' -i --output-format=json "${sing_config}"
220
- # [ ${proxy_mode} = "blacklist" ] && local mode="exclude" || mode="include"
221
- # for package in "${packages_list[@]}"; do
222
- # "${yq}" eval '(.inbounds[] | select(.type == "tun") | .'${mode}'_package) += ["'${package}'"]' -i --output-format=json "${sing_config}"
223
- # done
218
+ " ${yq} " ' (.inbounds[] | select(.type == "tun") | .include_package) = []' -i --output-format=json " ${sing_config} "
219
+ " ${yq} " ' (.inbounds[] | select(.type == "tun") | .exclude_package) = []' -i --output-format=json " ${sing_config} "
220
+ [ ${proxy_mode} = " blacklist" ] && local mode=" exclude" || mode=" include"
221
+ for package in " ${packages_list[@]} " ; do
222
+ " ${yq} " eval ' (.inbounds[] | select(.type == "tun") | .' ${mode} ' _package) += ["' ${package} ' "]' -i --output-format=json " ${sing_config} "
223
+ done
224
224
225
225
# Add "redirect" configuration based on network_mode
226
226
if [[ " ${network_mode} " == @ (mixed| enhance| redirect) ]]; then
@@ -296,12 +296,13 @@ prepare_clash() {
296
296
' enable: true' \
297
297
' mtu: 9000' \
298
298
' device: utun' \
299
- ' stack: system # mixed / gvisor / system / lwip' \
299
+ ' stack: mixed # system / gvisor / system / lwip' \
300
300
' dns-hijack:' \
301
301
' - any:53' \
302
302
' - tcp://any:53' \
303
303
' auto-route: true' \
304
- ' strict-route: false' \
304
+ ' strict-route: true' \
305
+ ' auto-redirect: true' \
305
306
' auto-detect-interface: true' \
306
307
' include-android-user: [0, 10]' \
307
308
' exclude-package: []' \
@@ -312,17 +313,19 @@ prepare_clash() {
312
313
fi
313
314
314
315
# add exclude-package/include-package for tun
315
- # package=$(IFS=","; echo "${packages_list[*]}" | tr ' ' ',')
316
- # list_package="${package:-\"\"}"
317
- # if [ "${proxy_mode}" = "whitelist" ]; then
318
- # mode="include-package"
319
- # elif [ "${proxy_mode}" = "blacklist" ]; then
320
- # mode="exclude-package"
321
- # fi
322
- # sed -i "s/exclude-package:.*/exclude-package: []/g" "${clash_config}"
323
- # sed -i "s/include-package:.*/include-package: []/g" "${clash_config}"
324
- # sed -i "s/${mode}:.*/${mode}: [\"${list_package//,/\",\"}\"]/g" "${clash_config}"
325
-
316
+ package=$( IFS=" ," ; echo " ${packages_list[*]} " | tr ' ' ' ,' )
317
+ list_package=" ${package:- } "
318
+ if [ " ${proxy_mode} " = " whitelist" ]; then
319
+ mode=" include-package"
320
+ elif [ " ${proxy_mode} " = " blacklist" ]; then
321
+ mode=" exclude-package"
322
+ fi
323
+ sed -i " s/exclude-package:.*/exclude-package: []/g" " ${clash_config} "
324
+ sed -i " s/include-package:.*/include-package: []/g" " ${clash_config} "
325
+ # Add packages to the configuration if list_package is not empty
326
+ if [ -n " ${list_package} " ]; then
327
+ sed -i " s/${mode} :.*/${mode} : [\" ${list_package// ,/ \" ,\" } \" ]/g" " ${clash_config} "
328
+ fi
326
329
sed -i " /tun:/ {n;s/enable: false/enable: true/}" " ${clash_config} "
327
330
else
328
331
sed -i " /tun:/ {n;s/enable: true/enable: false/}" " ${clash_config} "
@@ -403,6 +406,7 @@ box_run_bin() {
403
406
404
407
# sync port
405
408
# sed -i "s/port = [0-9]*\.[0-9]*/port = ${tproxy_port}.0/" ${box_dir}/$bin_name/config.toml
409
+ ${box_dir} /bin/yq ' (.inbounds[] | select(.protocol == "dokodemo-door") | .port) = ' " ${tproxy_port} " -i --output-format=json " ${box_dir} /${bin_name} /config.json"
406
410
407
411
# check configuration file
408
412
if ! [ -f " ${box_dir} /${bin_name} /config.toml" ] && ! [ -f " ${box_dir} /${bin_name} /config.json" ]; then
@@ -435,6 +439,7 @@ box_run_bin() {
435
439
436
440
# sync port
437
441
# sed -i "s/port = [0-9]*\.[0-9]*/port = ${tproxy_port}.0/" ${box_dir}/$bin_name/config.toml
442
+ ${box_dir} /bin/yq ' (.inbounds[] | select(.protocol == "dokodemo-door") | .port) = ' " ${tproxy_port} " -i --output-format=json " ${box_dir} /${bin_name} /config.json"
438
443
439
444
# check configuration file
440
445
if ! [ -f " ${box_dir} /${bin_name} /config.toml" ] && ! [ -f " ${box_dir} /${bin_name} /config.json" ]; then
0 commit comments