From 10fa0467dbf479af09845d882a6e62bf9501f2b2 Mon Sep 17 00:00:00 2001 From: powerAn <25736019+powerAn2020@users.noreply.github.com> Date: Tue, 16 May 2023 14:53:36 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A6=82=E6=9E=9C=E7=B3=BB=E7=BB=9F=E5=AD=98?= =?UTF-8?q?=E5=9C=A8yq=EF=BC=8C=E5=88=99=E4=BD=BF=E7=94=A8yq=E6=8F=90?= =?UTF-8?q?=E5=8F=96=E8=AE=A2=E9=98=85=E5=9C=B0=E5=9D=80=E4=B8=AD=E7=9A=84?= =?UTF-8?q?=E8=8A=82=E7=82=B9=E4=BF=A1=E6=81=AF=E5=88=B0domestic.yml?= =?UTF-8?q?=EF=BC=8C=E5=B0=BD=E9=87=8F=E4=B8=8D=E5=8A=A8config.yml?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- box/scripts/box.tool | 33 ++++++++++++++++++++++++++++----- box/settings.ini | 1 + 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/box/scripts/box.tool b/box/scripts/box.tool index f4ddcc4f..12f6d63b 100755 --- a/box/scripts/box.tool +++ b/box/scripts/box.tool @@ -148,9 +148,32 @@ update_subgeo() { log debug "Update geo $(date +"%F %R")" flag=false fi - if [ "${bin_name}" = "clash" ] && [ "${auto_update_subscription}" = "true" ] && update_file "${clash_config}" "${subscription_url}"; then + enhanced=false + update_file_name="${clash_config}" + yq_command="$(command -v yq >/dev/null 2>&1 ; echo $?)" + wc_command="$(command -v wc >/dev/null 2>&1 ; echo $?)" + if [ $yq_command -eq 0 ] && [ $wc_command -eq 0 ]; then + enhanced=true + update_file_name="${update_file_name}.subscription" + fi + if [ "${bin_name}" = "clash" ] && [ "${auto_update_subscription}" = "true" ] && update_file "${update_file_name}" "${subscription_url}"; then log debug "Downloading ${clash_config}" - flag=true + # If there is a yq command, extract the proxies information from yml and output it to the clash_domestic_config file + if [ "${enhanced}" = "true" ]; then + if [ $(cat ${update_file_name} | yq '.proxies' | wc -l) -gt 1 ];then + yq '.proxies' ${update_file_name} > ${clash_domestic_config} + yq -i '{"proxies": .}' ${clash_domestic_config} + log info "subscription success" + if [ -f "${update_file_name}.bak" ]; then + rm ${update_file_name}.bak + fi + flag=true + else + log error "subscription failed" + fi + else + flag=true + fi fi if [ -f "${pid_file}" ] && [ "${flag}" = "true" ]; then restart_box @@ -278,7 +301,7 @@ update_kernel() { gunzip_command="busybox gunzip" fi if ${gunzip_command} "${data_dir}/${file_kernel}.gz" >&2 && - mv "${data_dir}/${file_kernel}" "${bin_kernel}/${bin_name}"; then + mv "${data_dir}/${file_kernel}" "${bin_kernel}/${bin_name}"; then if [ -f "${pid_file}" ]; then restart_box else @@ -296,8 +319,8 @@ update_kernel() { tar_command="busybox tar" fi 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 + 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 if [ -f "${pid_file}" ]; then restart_box else diff --git a/box/settings.ini b/box/settings.ini index ab8bb8d3..20a6602d 100755 --- a/box/settings.ini +++ b/box/settings.ini @@ -64,6 +64,7 @@ uid_list=("/data/adb/box/run/appuid.list") # konfigurasi clash name_clash_config="config.yaml" clash_config="${data_dir}/clash/${name_clash_config}" +clash_domestic_config="${data_dir}/clash/provide/domestic.yml" # Mengatur variabel DNS, dokumentasi DNS ada di https://adguard-dns.io/kb/general/dns-providers/. # Variabel intervaldns harus dalam format cron. Misalnya "*/10 * * * *" untuk menjalankannya setiap 10 menit.