Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env bash
- set -e
- TEMP_RULES_FILE="/tmp/clash-rules-temp.txt"
- CUSTOM_RULES_FILE="$HOME/.config/clash/custom-rules.txt"
- CONFIG_FILE="$HOME/.config/clash/config.yaml"
- CLASH_API_URL="http://127.0.0.1:9090/configs"
- CHINA_DOMAINS_URL="https://raw.githubusercontent.com/felixonmars/dnsmasq-china-list/master/accelerated-domains.china.conf"
- CHINA_IPS_URL="https://raw.githubusercontent.com/17mon/china_ip_list/master/china_ip_list.txt"
- GFWList_URL="https://raw.githubusercontent.com/gfwlist/gfwlist/master/gfwlist.txt"
- GOOGLE_URL="https://raw.githubusercontent.com/felixonmars/dnsmasq-china-list/master/google.china.conf"
- APPLE_URL="https://raw.githubusercontent.com/felixonmars/dnsmasq-china-list/master/apple.china.conf"
- echo "⚡️ 正在获取中国 DIRECT 域名列表……"
- curl -sSL $CHINA_DOMAINS_URL | awk -F '/' '{printf " - DOMAIN-SUFFIX,%s,DIRECT\n", $2}' > $TEMP_RULES_FILE
- echo "✅ 已生成中国 DIRECT 域名列表"
- echo "⚡️ 正在获取 Google PROXY 域名列表……"
- curl -sSL $GOOGLE_URL | awk -F '/' '{printf " - DOMAIN-SUFFIX,%s,PROXY\n", $2}' >> $TEMP_RULES_FILE
- echo "✅ 已生成 Google PROXY 域名列表"
- echo "⚡️ 正在获取 Apple PROXY 域名列表……"
- curl -sSL $APPLE_URL | awk -F '/' '{printf " - DOMAIN-SUFFIX,%s,PROXY\n", $2}' >> $TEMP_RULES_FILE
- echo "✅ 已生成 Apple PROXY 域名列表"
- echo "⚡️ 正在获取 GFWList 列表……"
- curl -sSL $GFWList_URL | \
- base64 -Dd | \
- grep -Eo '^(\|\||\.)(([0-9a-zA-Z-]+\.)+[0-9a-zA-Z-]+)' | \
- grep -Eo '([0-9a-zA-Z-]+\.)+[0-9a-zA-Z-]+' | \
- sort -su | \
- awk '{printf " - DOMAIN-SUFFIX,%s,PROXY\n", $0}' >> $TEMP_RULES_FILE
- echo "✅ 已生成 GFWList PROXY 域名列表并去重"
- echo "⚡️ 正在获取中国 DIRECT IP 列表……"
- curl -sSL $CHINA_IPS_URL | awk '{printf " - IP-CIDR,%s,DIRECT\n", $0}' >> $TEMP_RULES_FILE
- echo "✅ 已生成中国 DIRECT IP 列表"
- echo "------------附加内容-------------"
- cat $CUSTOM_RULES_FILE >> $TEMP_RULES_FILE
- cat $CUSTOM_RULES_FILE
- echo "------------插入完成-------------"
- # 在 Rule 后面新增行,作为查找删除内容的标志
- sed -i '' '/Rule:/a\
- This is a temp line' $CONFIG_FILE
- # 删除 This is a temp line 及后面所有内容
- sed -i '' '/^This\ is\ a\ temp\ line/,$d' $CONFIG_FILE
- echo "⚡️ 正在写入新路由规则……"
- # 将新规则插入在 Rule 之后
- sed -i '' "/Rule:/ r $TEMP_RULES_FILE" $CONFIG_FILE
- echo "✅ 已成功写入新路由规则"
- echo "⚡️ 正在重新载入 Clash 配置……"
- curl -X PUT -H 'Content-Type: application/json' -d "{'path':'$CONFIG_FILE'}" $CLASH_API_URL
- echo "✅ 成功啦!🍺🍟🍔"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement