1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
| #!/bin/bash
# 这里写你的订阅连接, 转换成https://www.urlencoder.org/中的格式 url=""
function end { log+="\n" printf "%b" "$log" >> $LOG_FILE exit 0 }
CONFIG_DIR="/opt/mihomo" CONFIG_FILE="$CONFIG_DIR/config.yaml" LOG_FILE="$CONFIG_DIR/log.txt"
output="" # 保存生成的 config 内容 log="" # 保存日志内容
output+="mixed-port: 7890\n" output+="external-ui: /root/.config/mihomo/ui\n"
# 订阅文件更新 log+="[$(date -R)] \n\t订阅文件更新...\n\t" sub_response=$(curl -s --max-time 15 -w "%{http_code}" -o /tmp/mihomo_temp.yml "http://127.0.0.1:25500/sub?target=clash&url=$url") sub_exit_code=$?
if [ "$sub_exit_code" -ne 0 ]; then log+="Error❌️: 网络错误,退出码: $sub_exit_code\n\t" end elif [ "$sub_response" -ne 200 ]; then log+="Error❌️: 订阅文件更新失败,响应码: $sub_response\n\t" end fi
output+="$(awk 'NR>=3' /tmp/mihomo_temp.yml)""\n" printf "%b" "$output" > $CONFIG_FILE log+="订阅文件更新成功 ✅\n\t"
# 配置重新加载 log+="配置重新加载...\n\t" reload_response=$(curl -s --max-time 15 -w "%{http_code}" -X PUT "http://127.0.0.1:9090/configs?force=true" -H "Content-Type: application/json" -d '{"path":"","payload":""}') reload_exit_code=$?
if [ "$reload_exit_code" -ne 0 ]; then log+="Error❌️: 网络错误,退出码: $reload_exit_code\n\t" end elif [ "$reload_response" -ne 204 ]; then log+="Error❌️: 配置重新加载失败,响应码: $reload_response\n\t" end fi
log+="配置重新加载完成 ✅\n\t" end
|