passwall 自动切换节点

#! /bin/bash

conf=/etc/config/passwall
# 获取所有节点
function getNodes(){
    f=$1;
    ret=`cat $f | grep "config nodes" | awk '{print $3}' | sed -r "s/'//g"`;
    echo $ret | tr " " " ";
}
# 移动旧的自动切换节点
function removeAutoSwitchNode(){
    f=$1;
	p=1;
	stp=0;
	while IFS= read -r line; do
	    if [[ $stp == "1" ]]; then
			ret=`echo "$line" | grep 'list tcp_node'`;
		    if [[ $ret != "" ]]; then
	        	continue;
		    fi
	    	stp=0;
	    fi

	    echo $line >> "$f.$p";
	    ret=`echo "$line" | grep 'config auto_switch'`;
	    if [[ $ret != "" ]]; then
	    	p=$((p+1));
	    	stp=1;
	    fi
	done < "$f"
	mv $f "$f.bak"
	cat "$f.1" > "$f";
	rm "$f.1" -rf;
	cat "$f.2" >> "$f";
	rm "$f.2" -rf;
}
# 添加自动切换节点
function addAutoSwitchNode(){
	f="$1";
	n="$2";
	mv $f "$f.bak1";
	cat "$f.bak1" | sed -r "s/(config auto_switch)/\1\n list tcp_node '$n'/g" > $f;
	rm "$f.bak1" -rf;
}
# 主入口程序
function main(){
	f=$1;
	nodes=$(getNodes "$f");
	removeAutoSwitchNode "$f";
	for n in ${nodes[@]}; do
		addAutoSwitchNode "$f" "$n";
	done
	sh /usr/share/passwall/app.sh stop;
    lua /usr/share/passwall/subscribe.lua start
    sh /usr/share/passwall/app.sh start;
}

main "$conf"

将脚本上传到openwrt服务器上。然后通过corntab -e 定时启动

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值