Update unlock.sh

dependabot/github_actions/actions/checkout-3.1.0
fscarmen 4 years ago committed by GitHub
parent 891b3c9015
commit f0a927b70e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 103
      unlock.sh

@ -50,8 +50,8 @@ T[E17]="Version"
T[C17]="脚本版本"
T[E18]="New features"
T[C18]="功能新增"
T[E19]="\\\n Stream media unlock daemon is running in \${UNLOCK_MODE_NOW[f]}.\\\n 1. Change the streame media that needs to be unlocked\\\n 2. Switch to \${UNLOCK_MODE_AFTER1[f]}\\\n 3. Switch to \${UNLOCK_MODE_AFTER2[f]}\\\n 4. Uninstall\\\n 0. Exit\\\n"
T[C19]="\\\n 流媒体解锁守护正在以 \${UNLOCK_MODE_NOW[f]} 运行中\\\n 1. 更换需要解锁的流媒体\\\n 2. 切换至\${UNLOCK_MODE_AFTER1[f]}\\\n 3. 切换至\${UNLOCK_MODE_AFTER2[f]}\\\n 4. 卸载\\\n 0. 退出\\\n"
T[E19]="\\\n Stream media unlock daemon is running in \$UNLOCK_MODE_NOW.\\\n"
T[C19]="\\\n 流媒体解锁守护正在以 \$UNLOCK_MODE_NOW 运行中\\\n"
T[E20]="Media unlock daemon installed successfully. A session window u has been created, enter [screen -Udr u] and close [screen -SX u quit]. The VPS restart will still take effect. The running log of the scheduled task will be saved in /root/result.log\n"
T[C20]="\n 媒体解锁守护进程已安装成功,已创建一个会话窗口 u ,进入 [screen -Udr u],关闭 [screen -SX u quit],VPS 重启仍生效。进入任务运行日志将保存在 /root/result.log\n"
T[E21]="Media unlock daemon installed successfully. A jobs has been created, check [pgrep -laf warp_unlock] and close [kill -9 \$(pgrep -f warp_unlock)]. The VPS restart will still take effect. The running log of the scheduled task will be saved in /root/result.log\n"
@ -142,64 +142,13 @@ done
# 检查解锁是否已运行,如果是则判断模式,以前给更换模式赋值
check_unlock_running(){
switch_1_1(){ true; }
switch_1_2(){ TASK="sed -i '/warp_unlock.sh/d' /etc/crontab && echo \"@reboot root screen -USdm u bash /etc/wireguard/warp_unlock.sh\" >> /etc/crontab"
MODE2=("while true; do" "sleep 1h; done")
check_dependencies screen
}
switch_1_3(){ TASK="sed -i '/warp_unlock.sh/d' /etc/crontab && echo \"@reboot root nohup bash /etc/wireguard/warp_unlock.sh &\" >> /etc/crontab"
MODE2=("while true; do" "sleep 1h; done")
}
switch_2_1(){ TASK="sed -i '/warp_unlock.sh/d' /etc/crontab && echo \"*/5 * * * * root bash /etc/wireguard/warp_unlock.sh\" >> /etc/crontab"; }
switch_2_2(){ MODE2=("while true; do" "sleep 1h; done"); }
switch_2_3(){ TASK="sed -i '/warp_unlock.sh/d' /etc/crontab && echo \"@reboot root nohup bash /etc/wireguard/warp_unlock.sh &\" >> /etc/crontab"
MODE2=("while true; do" "sleep 1h; done")
}
switch_3_1(){ TASK="sed -i '/warp_unlock.sh/d' /etc/crontab && echo \"*/5 * * * * root bash /etc/wireguard/warp_unlock.sh\" >> /etc/crontab"; }
switch_3_2(){ TASK="sed -i '/warp_unlock.sh/d' /etc/crontab && echo \"@reboot root screen -USdm u bash /etc/wireguard/warp_unlock.sh\" >> /etc/crontab"
MODE2=("while true; do" "sleep 1h; done")
check_dependencies screen
}
switch_3_3(){ MODE2=("while true; do" "sleep 1h; done"); }
run_1_1(){ kill -9 $(pgrep -f warp_unlock.sh) >/dev/null 2>&1; }
run_1_2(){ kill -9 $(pgrep -f warp_unlock.sh) >/dev/null 2>&1
screen -USdm u bash /etc/wireguard/warp_unlock.sh
}
run_1_3(){ kill -9 $(pgrep -f warp_unlock.sh) >/dev/null 2>&1
nohup bash /etc/wireguard/warp_unlock.sh >/dev/null 2>&1 &
}
run_2_1(){ screen -SX u quit >/dev/null 2>&1 && screen -wipe >/dev/null 2>&1; }
run_2_2(){ screen -SX u quit >/dev/null 2>&1 && screen -wipe >/dev/null 2>&1
screen -USdm u bash /etc/wireguard/warp_unlock.sh
}
run_2_3(){ screen -SX u quit >/dev/null 2>&1 && screen -wipe >/dev/null 2>&1
nohup bash /etc/wireguard/warp_unlock.sh >/dev/null 2>&1 &
}
run_3_1(){ kill -9 $(pgrep -f warp_unlock.sh) >/dev/null 2>&1; }
run_3_2(){ kill -9 $(pgrep -f warp_unlock.sh) >/dev/null 2>&1
screen -USdm u bash /etc/wireguard/warp_unlock.sh
}
run_3_3(){ kill -9 $(pgrep -f warp_unlock.sh) >/dev/null 2>&1
nohup bash /etc/wireguard/warp_unlock.sh >/dev/null 2>&1 &
}
UNLOCK_MODE_NOW=$(grep -s "MODE=" /etc/wireguard/warp_unlock.sh | cut -d \" -f2)
EXPECT=$(grep -s "EXPECT=" /etc/wireguard/warp_unlock.sh | cut -d \" -f2)
TOKEN=$(grep -s "TOKEN=" /etc/wireguard/warp_unlock.sh | cut -d \" -f2)
USERID=$(grep -s "USERID=" /etc/wireguard/warp_unlock.sh | cut -d \" -f2)
CUSTOM=$(grep -s "CUSTOM=" /etc/wireguard/warp_unlock.sh | cut -d \" -f2)
NIC=$(grep -s "NIC=" /etc/wireguard/warp_unlock.sh | cut -d \" -f2)
RESTART=$(grep -s "RESTART=" /etc/wireguard/warp_unlock.sh | cut -d \" -f2)
check_crontab=("^\*.*warp_unlock" "screen.*warp_unlock" "nohup.*warp_unlock")
for ((f=0; f<"$UNLOCK_NUM"; f++)); do
grep -qE "${check_crontab[f]}" /etc/crontab && break; done
UNLOCK_MODE_NOW=("${T[${L}40]}" "${T[${L}41]}" "${T[${L}42]}")
UNLOCK_MODE_AFTER1=("${T[${L}41]}" "${T[${L}40]}" "${T[${L}40]}")
UNLOCK_MODE_AFTER2=("${T[${L}42]}" "${T[${L}42]}" "${T[${L}41]}")
SWITCH_MODE1=( "switch_1_1" "switch_2_2" "switch_3_3" )
SWITCH_MODE2=( "switch_1_2" "switch_2_1" "switch_3_1" )
SWITCH_MODE3=( "switch_1_3" "switch_2_3" "switch_3_2" )
RUN_AFTER_SWITCH1=( "run_1_1" "run_2_2" "run_3_3" )
RUN_AFTER_SWITCH2=( "run_1_2" "run_2_1" "run_3_1" )
RUN_AFTER_SWITCH3=( "run_1_3" "run_2_3" "run_3_2" )
}
# 判断是否已经安装 WARP 网络接口或者 Socks5 代理,如已经安装组件尝试启动。再分情况作相应处理
@ -294,6 +243,7 @@ sh -c "$TASK"
# 感谢以下两位作者: lmc999 [https://github.com/lmc999/RegionRestrictionCheck] 和 luoxue-bot [https://github.com/luoxue-bot/warp_auto_change_ip]
cat <<EOF >/etc/wireguard/warp_unlock.sh
#!/bin/bash
MODE="$CHOOSE1"
EXPECT="$EXPECT"
TOKEN="$TOKEN"
USERID="$USERID"
@ -398,18 +348,17 @@ green " $RESULT_OUTPUT "
green " $(eval echo "${T[${L}22]}") "
}
# 卸载
uninstall(){
screen -QX u quit >/dev/null 2>&1 && screen -wipe >/dev/null 2>&1
type -P wg-quick >/dev/null 2>&1 && wg-quick down wgcf >/dev/null 2>&1
type -P warp-cli >/dev/null 2>&1 && warp-cli --accept-tos delete >/dev/null 2>&1 && sleep 1
type -P wg-quick >/dev/null 2>&1 && systemctl restart wgcf >/dev/null 2>&1
type -P warp-cli >/dev/null 2>&1 && ( warp-cli --accept-tos delete >/dev/null 2>&1; sleep 1; warp-cli --accept-tos register >/dev/null 2>&1 )
sed -i '/warp_unlock.sh/d' /etc/crontab
kill -9 $(pgrep -f warp_unlock.sh) >/dev/null 2>&1
rm -f /etc/wireguard/warp_unlock.sh /root/result.log /etc/wireguard/status.log /etc/systemd/system/warp_unlock.service
systemctl disable --now warp_unlock >/dev/null 2>&1
pm2 delete warp_unlock >/dev/null 2>&1
pm2 unstartup systemd >/dev/null 2>&1
type -P wg-quick >/dev/null 2>&1 && wg-quick up wgcf >/dev/null 2>&1
type -P warp-cli >/dev/null 2>&1 && warp-cli --accept-tos register >/dev/null 2>&1
# 输出执行结果
green " ${T[${L}11]} "
@ -455,37 +404,19 @@ done
check_system_info
check_unlock_running
check_dependencies curl
if [[ "$f" -lt "$UNLOCK_NUM" ]]; then
MENU_SHOW="$(eval echo "${T[${L}19]}")"
action1(){
"${SWITCH_MODE1[f]}"
export_unlock_file
"${RUN_AFTER_SWITCH1[f]}"
}
action2(){
"${SWITCH_MODE2[f]}"
export_unlock_file
"${RUN_AFTER_SWITCH2[f]}"
}
action3(){
"${SWITCH_MODE3[f]}"
export_unlock_file
"${RUN_AFTER_SWITCH3[f]}"
}
action4(){ uninstall; }
action0(){ exit 0; }
else
MENU_SHOW="${T[${L}12]}"
check_warp
MODE2=("while true; do" "sleep 1h; done")
[ -n "$UNLOCK_MODE_NOW" ] && MENU_SHOW="$(eval echo "${T[${L}19]}")${T[${L}12]}" || MENU_SHOW="${T[${L}12]}"
action1(){
unset MODE2
[ -n "$UNLOCK_MODE_NOW" ] && uninstall
TASK="sed -i '/warp_unlock.sh/d' /etc/crontab && echo \"*/5 * * * * root bash /etc/wireguard/warp_unlock.sh\" >> /etc/crontab"
RESULT_OUTPUT="${T[${L}10]}"
export_unlock_file
result_output
}
action2(){
MODE2=("while true; do" "sleep 1h; done")
[ -n "$UNLOCK_MODE_NOW" ] && uninstall
TASK="sed -i '/warp_unlock.sh/d' /etc/crontab && echo \"@reboot root screen -USdm u bash /etc/wireguard/warp_unlock.sh\" >> /etc/crontab"
RESULT_OUTPUT="${T[${L}20]}"
check_dependencies screen
@ -495,8 +426,7 @@ result_output
}
action3(){
MODE2[0]="while true; do"
MODE2[1]="sleep 1h; done"
[ -n "$UNLOCK_MODE_NOW" ] && uninstall
TASK="sed -i '/warp_unlock.sh/d' /etc/crontab && echo \"@reboot root nohup bash /etc/wireguard/warp_unlock.sh &\" >> /etc/crontab"
RESULT_OUTPUT="${T[${L}21]}"
export_unlock_file
@ -505,8 +435,7 @@ result_output
}
action4(){
MODE2[0]="while true; do"
MODE2[1]="sleep 1h; done"
[ -n "$UNLOCK_MODE_NOW" ] && uninstall
TASK="cat <<EOF > /etc/systemd/system/warp_unlock.service
[Unit]
Description = WARP unlock
@ -527,7 +456,7 @@ result_output
}
action5(){
MODE2=("while true; do" "sleep 1h; done")
[ -n "$UNLOCK_MODE_NOW" ] && uninstall
TASK=""
RESULT_OUTPUT="${T[${L}44]}"
check_dependencies npm nodejs
@ -537,8 +466,8 @@ pm2 start /etc/wireguard/warp_unlock.sh
pm2 save; pm2 startup
result_output
}
action0(){ exit 0; }
fi
# 菜单显示
menu(){

Loading…
Cancel
Save