From 5e39f2612f9e3fa7082531d7184ecf0c4e406a1d Mon Sep 17 00:00:00 2001 From: Sving1024 Date: Sat, 28 Dec 2024 19:02:31 +0800 Subject: [PATCH 1/2] add scripts to auto update config file for dnsmasq --- script/cfst_dnsmasq.sh | 45 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100755 script/cfst_dnsmasq.sh diff --git a/script/cfst_dnsmasq.sh b/script/cfst_dnsmasq.sh new file mode 100755 index 0000000..8327f5e --- /dev/null +++ b/script/cfst_dnsmasq.sh @@ -0,0 +1,45 @@ +#!/usr/bin/env bash +PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin +export PATH +# -------------------------------------------------------------- +# 项目: CloudflareSpeedTest 自动更新 dnsmasq 配置文件 +# 版本: 1.0.4 +# 作者: XIU2,Sving1024 +# 项目: https://github.com/XIU2/CloudflareSpeedTest +# -------------------------------------------------------------- + +_UPDATE() { + echo -e "开始测速..." + + # 这里可以自己添加、修改 CloudflareST 的运行参数 + ./CloudflareST -o "result_hosts.txt" + + # 如果需要 "找不到满足条件的 IP 就一直循环测速下去",那么可以将下面的两个 exit 0 改为 _UPDATE 即可 + [[ ! -e "result_hosts.txt" ]] && echo "CloudflareST 测速结果 IP 数量为 0,跳过下面步骤..." && exit 0 + + # 下面这行代码是 "找不到满足条件的 IP 就一直循环测速下去" 才需要的代码 + # 考虑到当指定了下载速度下限,但一个满足全部条件的 IP 都没找到时,CloudflareST 就会输出所有 IP 结果 + # 因此当你指定 -sl 参数时,需要移除下面这段代码开头的 # 井号注释符,来做文件行数判断(比如下载测速数量:10 个,那么下面的值就设在为 11) + #[[ $(cat result_hosts.txt|wc -l) > 11 ]] && echo "CloudflareST 测速结果没有找到一个完全满足条件的 IP,重新测速..." && _UPDATE + + BESTIP=$(sed -n "2,1p" result_hosts.txt | awk -F, '{print $1}') + if [[ -z "${BESTIP}" ]]; then + echo "CloudflareST 测速结果 IP 数量为 0,跳过下面步骤..." + exit 0 + fi + echo ${BESTIP} > nowip_hosts.txt + echo -e "最优 IP 为 ${BESTIP}\n" + + [[ -f cloudflare.conf ]] && rm cloudflare.conf + + cat site.conf | while read domain + do + [[ ${domain:0:1} != "#" && ${domain} != "" ]] && echo "address=/${domain}/${BESTIP}" >> "cloudflare.conf" + done + + [[ -f /etc/dnsmasq.d/cloudflare.conf ]] && rm /etc/dnsmasq.d/cloudflare.conf + cp cloudflare.conf /etc/dnsmasq.d/cloudflare.conf + systemctl restart dnsmasq.service +} + +_UPDATE \ No newline at end of file From 25fc2921e22c2b79ce8600af659c471bc143e046 Mon Sep 17 00:00:00 2001 From: Sving1024 Date: Sat, 28 Dec 2024 19:30:36 +0800 Subject: [PATCH 2/2] reset version --- script/cfst_dnsmasq.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/script/cfst_dnsmasq.sh b/script/cfst_dnsmasq.sh index 8327f5e..c1d5212 100755 --- a/script/cfst_dnsmasq.sh +++ b/script/cfst_dnsmasq.sh @@ -3,7 +3,7 @@ PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin export PATH # -------------------------------------------------------------- # 项目: CloudflareSpeedTest 自动更新 dnsmasq 配置文件 -# 版本: 1.0.4 +# 版本: 1.0.0 # 作者: XIU2,Sving1024 # 项目: https://github.com/XIU2/CloudflareSpeedTest # --------------------------------------------------------------