WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
如题。经常遇到切换节点后本项目功能虽然显示绿色(启用状态),但客户端无法被劫持(安卓客户端版本是网易云音乐改版90.40,更高版本和原版君无法使用)。
于是用AI写了个脚本,放在启动项的本地脚本内(不知道是不是应该放在这里?)。
测试是SSH后直接输入的,貌似成功。希望大家测试并提出修改意见🙏🏻
以下是脚本:
写入监控脚本
cat > /usr/bin/unblock-node-watch.sh <<'EOF'
#!/bin/sh
/usr/bin/unblock-node-watch.sh
监测 default route 和 /etc/config/passwall 修改时间。
若检测到变化,延时 8 秒后重启 UnblockNeteaseMusic(并记录日志)。
WATCH_INTERVAL=2 # 检测间隔(秒)
DEBOUNCE_SEC=8 # 发现变化后等待多少秒再重启
STATE_FILE="/var/run/unblock-watch.state"
LOG_TAG="unblock-watch"
helper: 获取默认路由
get_route_key() {
ip route show default 2>/dev/null | tr -s ' ' | sed -n '1p'
|| ip route get 1.1.1.1 2>/dev/null | tr -s ' ' | sed -n '1p'
|| echo "no-route"
}
helper: 获取 passwall 配置文件的 mtime
get_passwall_mtime() {
if [ -f /etc/config/passwall ]; then
stat -c %Y /etc/config/passwall 2>/dev/null || echo 0
else
echo 0
fi
}
初始化上次值
if [ -f "$STATE_FILE" ]; then
LAST_ROUTE="$(sed -n '1p' $STATE_FILE 2>/dev/null || echo "")"
LAST_PW_MTIME="$(sed -n '2p' $STATE_FILE 2>/dev/null || echo "0")"
else
LAST_ROUTE="$(get_route_key)"
LAST_PW_MTIME="$(get_passwall_mtime)"
mkdir -p "$(dirname $STATE_FILE)"
printf "%s\n%s\n" "$LAST_ROUTE" "$LAST_PW_MTIME" > "$STATE_FILE"
fi
logger -t "$LOG_TAG" "watcher started: interval=${WATCH_INTERVAL}s debounce=${DEBOUNCE_SEC}s"
while true; do
CUR_ROUTE="$(get_route_key)"
CUR_PW_MTIME="$(get_passwall_mtime)"
if [ "$CUR_ROUTE" != "$LAST_ROUTE" ] || [ "$CUR_PW_MTIME" != "$LAST_PW_MTIME" ]; then
logger -t "$LOG_TAG" "detected change"
printf "%s\n%s\n" "$CUR_ROUTE" "$CUR_PW_MTIME" > "$STATE_FILE"
fi
sleep "$WATCH_INTERVAL"
done
EOF
chmod +x /usr/bin/unblock-node-watch.sh
写入 init 脚本
cat > /etc/init.d/unblock-watch <<'EOF'
#!/bin/sh /etc/rc.common
/etc/init.d/unblock-watch
START=95
STOP=10
USE_PROCD=1
start() {
procd_open_instance
procd_set_param command /usr/bin/unblock-node-watch.sh
procd_set_param respawn
procd_close_instance
}
EOF
chmod +x /etc/init.d/unblock-watch
启用并启动
/etc/init.d/unblock-watch enable
/etc/init.d/unblock-watch start
Beta Was this translation helpful? Give feedback.
All reactions