更新脚本变量

This commit is contained in:
CallMeR
2023-12-09 21:17:31 +08:00
parent 0d091d93c1
commit 906db9eac4
+10 -10
View File
@@ -2,9 +2,9 @@
set -e set -e
WORKDIR="$(mktemp -d)" WORKDIR="$(mktemp -d)"
CONFIG_DIR="/etc/smartdns.d" CONFDIR="/etc/smartdns.d"
SERVERS=(223.5.5.5 119.29.29.29 114.114.114.114 114.114.115.115) SERVERS=(223.5.5.5 119.29.29.29 114.114.114.114 114.114.115.115)
SERVERS_GROUP=(accelerate) GROUP=(accelerate)
# Others: 223.6.6.6 119.28.28.28 # Others: 223.6.6.6 119.28.28.28
# Not using best possible CDN pop: 1.2.4.8 210.2.4.8 # Not using best possible CDN pop: 1.2.4.8 210.2.4.8
# Broken?: 180.76.76.76 # Broken?: 180.76.76.76
@@ -14,8 +14,8 @@ CONF_WITH_GROUP=(server-group.china)
CONF_SIMPLE=(bogus-nxdomain.china) CONF_SIMPLE=(bogus-nxdomain.china)
echo "Checking whether the configuration folder exists..." echo "Checking whether the configuration folder exists..."
if [ ! -d "$CONFIG_DIR" ]; then if [ ! -d "$CONFDIR" ]; then
mkdir -p "$CONFIG_DIR" mkdir -p "$CONFDIR"
fi fi
echo "Downloading latest configurations..." echo "Downloading latest configurations..."
@@ -30,27 +30,27 @@ git clone --depth=1 https://gitee.com/felixonmars/dnsmasq-china-list.git "$WORKD
echo "Removing old configurations..." echo "Removing old configurations..."
for _conf in "${CONF_WITH_SERVERS[@]}" "${CONF_WITH_GROUP[@]}" "${CONF_SIMPLE[@]}"; do for _conf in "${CONF_WITH_SERVERS[@]}" "${CONF_WITH_GROUP[@]}" "${CONF_SIMPLE[@]}"; do
rm -f "$CONFIG_DIR/$_conf"*.conf rm -f "$CONFDIR/$_conf"*.conf
done done
echo "Installing new configurations..." echo "Installing new configurations..."
for _conf in "${CONF_WITH_SERVERS[@]}" "${CONF_WITH_GROUP[@]}" "${CONF_SIMPLE[@]}"; do for _conf in "${CONF_WITH_SERVERS[@]}" "${CONF_WITH_GROUP[@]}" "${CONF_SIMPLE[@]}"; do
if [[ "${CONF_WITH_SERVERS[@]}" =~ $_conf ]]; then if [[ "${CONF_WITH_SERVERS[@]}" =~ $_conf ]]; then
sed -En 's|^server=/([^/]*)/114.114.114.114$|\1|p' "$WORKDIR/$_conf.conf" | grep -Ev '^#' > "$WORKDIR/$_conf.step1.raw" sed -En 's|^server=/([^/]*)/114.114.114.114$|\1|p' "$WORKDIR/$_conf.conf" | grep -Ev '^#' > "$WORKDIR/$_conf.step1.raw"
sed -En "s/(.*)/nameserver \\/\\1\\/${SERVERS_GROUP[@]}/p" "$WORKDIR/$_conf.step1.raw" > "$WORKDIR/$_conf.step2.raw" sed -En "s/(.*)/nameserver \\/\\1\\/${GROUP[@]}/p" "$WORKDIR/$_conf.step1.raw" > "$WORKDIR/$_conf.step2.raw"
cp "$WORKDIR/$_conf.step2.raw" "$CONFIG_DIR/$_conf.${SERVERS_GROUP[@]}.conf" cp "$WORKDIR/$_conf.step2.raw" "$CONFDIR/$_conf.${GROUP[@]}.conf"
fi fi
if [[ "${CONF_WITH_GROUP[@]}" =~ $_conf ]]; then if [[ "${CONF_WITH_GROUP[@]}" =~ $_conf ]]; then
for _server in "${SERVERS[@]}"; do for _server in "${SERVERS[@]}"; do
echo "server $_server -group ${SERVERS_GROUP[@]} -exclude-default-group" >> "$WORKDIR/$_conf.raw" echo "server $_server -group ${GROUP[@]} -exclude-default-group" >> "$WORKDIR/$_conf.raw"
done done
cp "$WORKDIR/$_conf.raw" "$CONFIG_DIR/${CONF_WITH_GROUP[@]}.${SERVERS_GROUP[@]}.conf" cp "$WORKDIR/$_conf.raw" "$CONFDIR/${CONF_WITH_GROUP[@]}.${GROUP[@]}.conf"
fi fi
if [[ "${CONF_SIMPLE[@]}" =~ $_conf ]]; then if [[ "${CONF_SIMPLE[@]}" =~ $_conf ]]; then
sed -e "s|=| |" "$WORKDIR/$_conf.conf" > "$WORKDIR/$_conf.raw" sed -e "s|=| |" "$WORKDIR/$_conf.conf" > "$WORKDIR/$_conf.raw"
cp "$WORKDIR/$_conf.raw" "$CONFIG_DIR/$_conf.${SERVERS_GROUP[@]}.conf" cp "$WORKDIR/$_conf.raw" "$CONFDIR/$_conf.${GROUP[@]}.conf"
fi fi
done done