Skip to content

Instantly share code, notes, and snippets.

@foru17
Created April 3, 2023 02:06
Show Gist options
  • Save foru17/61ce090da963bbcd1169527f34d35036 to your computer and use it in GitHub Desktop.
Save foru17/61ce090da963bbcd1169527f34d35036 to your computer and use it in GitHub Desktop.
批量更新节点订阅脚本
#!/bin/bash
# 配合定时脚本使用
# 订阅后台接口,建议自己搭建,参考 https://github.com/tindy2013/subconverter
SERVER_API_URL="https://any.sub.domain/subconver"
# 输出的目录位置, nginx 解析目录
OUTPUT_FOLDER="/www/wwwroot/sub.domain.com"
# bark 推动提醒地址
BARK_NOTIFY_URL="https://your.domain.com/bark"
# 节点信息 clash 和 quax
# 先用订阅工具生成一个订阅网址,把 &url 字段中后面的参数复出来
BASE_NODES_CONFIG="vmess%3A%2F%2FYXV<把引号内所有替换>balabala&config=https%3A%2F%2Fgist.githubusercontent.com%2Ftindy2013%2F1fa08640a9088ac8652dbd40c5d2715b%2Fraw%2Flhie1_dler.ini&emoji=true&list=false&tfo=false&scv=true&fdn=false"
# surge4 信息
SURGE_CONFIG="$BASE_NODES_CONFIG&sort=false"
function requestSubServer(){
local API_URL="$1"
local FILE_TYPE="$2"
echo $API_URL
response=$(curl -s -o /dev/null -w "%{http_code}" $API_URL)
if [ $response -eq 200 ]; then
echo "Request successful."
curl "$API_URL" -o $OUTPUT_FOLDER/$FILE_TYPE
curl "$BARK_NOTIFY_URL/订阅更新/$FILE_TYPE%20更新成功%0cCode:$response?icon=https://static.is26.com/share/icon-succes.png?ver=1"
else
echo "Request failed with response code: $response"
curl "$BARK_NOTIFY_URL/订阅更新/$FILE_TYPE%20更新失败%0cCode:$response?icon=https://static.is26.com/share/icon-error.png?ver=1"
fi
}
# 开始依次请求生成文件
# 生成 clash 订阅
requestSubServer "$SERVER_API_URL/sub?target=clash&&url=$BASE_NODES_CONFIG" "clash"
# 生成 quanx 订阅
requestSubServer "$SERVER_API_URL/sub?target=quanx&&url=$BASE_NODES_CONFIG" "quanx"
# 生成 surge4 订阅
requestSubServer "$SERVER_API_URL/sub?target=surge&ver=4&&url=$SURGE_CONFIG" "surge"
# 生成其他的订阅参考上面3个规则依次复制修改就好
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment