Update warp-go.sh

dependabot/github_actions/actions/checkout-3.1.0
fscarmen 3 years ago committed by GitHub
parent 0d163a34ce
commit 3ac2f08fc5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 124
      warp-go.sh

@ -3,6 +3,7 @@ export LANG=en_US.UTF-8
# 当前脚本版本号和新增功能
VERSION=1.0.6
TOKEN_LENGTH=800
E[0]="Language:\n 1.English (default) \n 2.简体中文"
C[0]="${E[0]}"
@ -30,8 +31,8 @@ E[11]="Warp-go is not installed yet."
C[11]="还没有安装 warp-go"
E[12]="To install, press [y] and other keys to exit:"
C[12]="如需安装,请按[y],其他键退出:"
E[13]="\$(date +'%F %T') Try \${i}. Failed. IPv\$NF: \$WAN \$COUNTRY \$ASNORG. Retry after \${j} seconds. Brush ip runing time:\$DAY days \$HOUR hours \$MIN minutes \$SEC seconds"
C[13]="\$(date +'%F %T') 尝试第\${i}次,解锁失败,IPv\$NF: \$WAN \$COUNTRY \$ASNORG,\${j}秒后重新测试,刷 IP 运行时长: \$DAY 天 \$HOUR 时 \$MIN 分 \$SEC 秒"
E[13]="\$(date +'%F %T') Try \${i}. Failed. IPv\$NF: \$WAN \$COUNTRY \$ASNORG. Retry after \${l} seconds. Brush ip runing time:\$DAY days \$HOUR hours \$MIN minutes \$SEC seconds"
C[13]="\$(date +'%F %T') 尝试第\${i}次,解锁失败,IPv\$NF: \$WAN \$COUNTRY \$ASNORG,\${l}秒后重新测试,刷 IP 运行时长: \$DAY 天 \$HOUR 时 \$MIN 分 \$SEC 秒"
E[14]="1. Brush WARP IPv4 (default)\n 2. Brush WARP IPv6"
C[14]="1. 刷 WARP IPv4 (默认)\n 2. 刷 WARP IPv6"
E[15]="The current Netflix region is:\$REGION. To unlock the current region please press [y]. For other addresses please enter two regional abbreviations \(e.g. hk,sg, default:\$REGION\):"
@ -45,9 +46,9 @@ C[18]="成功!已同步最新脚本,版本号"
E[19]="New features"
C[19]="功能新增"
E[20]="Maximum \${j} attempts to get WARP IP..."
C[20]="后台获取 WARP IP 中,最大尝试\${j}次……"
E[21]="Try \${i}"
C[21]="第\${i}次尝试"
C[20]="后台获取 WARP IP 中, 最大尝试\${j}次……"
E[21]=""
C[21]=""
E[22]="Current Teams account is not available. Switch back to free account automatically."
C[22]="当前 Teams 账户不可用,自动切换回免费账户"
E[23]="Failed more than \${j} times, script aborted. Feedback: [https://github.com/fscarmen/warp/issues]"
@ -94,7 +95,7 @@ E[43]="License should be 26 characters, please re-enter WARP+ License. Otherwise
C[43]="License 应为26位字符,请重新输入 WARP+ License \(剩余\${i}次\): "
E[44]="Please enter the Teams Token (You can easily available at https://warp-team-api.herokuapp.com/. Or use the one provided by the script if left blank):"
C[44]="请输入 Teams Token (可通过 https://warp-team-api.herokuapp.com/ 轻松获取,如果留空,则使用脚本提供的):"
E[45]="Token error, please re-enter Teams token \(remaining \{i} times):"
E[45]="Token error, please re-enter Teams token \(remaining \${i} times\):"
C[45]="Token 错误,请重新输入 Teams token \(剩余\${i}次\):"
E[46]="Can't find the account file: /opt/warp-go/warp.conf.You can uninstall and reinstall it."
C[46]="找不到账户文件:/opt/warp-go/warp.conf,可以卸载后重装"
@ -104,8 +105,8 @@ E[48]="It is a Teams account already. Update is aborted."
C[48]="已经是 Teams 账户,不需要升级"
E[49]="1. Use WARP+ license to upgrade \n 2. Use Teams token to upgrade"
C[49]="1.使用 WARP+ license 升级\n 2.使用 Teams token 升级"
E[50]="Registration of teams account failed, script aborted. Feedback: [https://github.com/fscarmen/warp/issues]"
C[50]="注册 teams 账户失败,脚本中止,问题反馈: [https://github.com/fscarmen/warp/issues]"
E[50]="Registration of WARP\${k} account failed, script aborted. Feedback: [https://github.com/fscarmen/warp/issues]"
C[50]="注册 WARP\${k} 账户失败,脚本中止,问题反馈: [https://github.com/fscarmen/warp/issues]"
E[51]="Warp-go not yet installed. No account registered. Script aborted. Feedback: [https://github.com/fscarmen/warp/issues]"
C[51]="warp-go 还没有安装,没有注册账户,脚本中止,问题反馈: [https://github.com/fscarmen/warp/issues]"
E[52]="Path to wgcf.conf for this account: /opt/warp-go/wgcf.conf\n"
@ -120,10 +121,10 @@ E[56]="Download warp-go zip file unsuccessful. Script exits. Feedback: [https://
C[56]="下载 warp-go 压缩文件不成功,脚本退出,问题反馈: [https://github.com/fscarmen/warp/issues]"
E[57]="Warp-go file does not exist, script exits. Feedback: [https://github.com/fscarmen/warp/issues]"
C[57]="warp-go 文件不存在,脚本退出,问题反馈: [https://github.com/fscarmen/warp/issues]"
E[58]="Registration of teams account failed. Script aborted. Feedback: [https://github.com/fscarmen/warp/issues]"
C[58]="注册 teams 账户失败,脚本中止,问题反馈:[https://github.com/fscarmen/warp/issues]"
E[59]="Registration of free account failed. Script aborted. Feedback: [https://github.com/fscarmen/warp/issues]"
C[59]="注册 warp 账户失败,脚本中止,问题反馈: [https://github.com/fscarmen/warp/issues]"
E[58]="Maximum \${j} attempts to registe WARP\${k} account..."
C[58]="注册 WARP\${k} 账户中, 最大尝试\${j}次……"
E[59]="Try \${i}"
C[59]="第\${i}次尝试"
E[60]="Step 1/3: Install dependencies..."
C[60]="进度 2/3: 已安装 warp-go"
E[61]="Step 1/3: Install dependencies..."
@ -198,8 +199,8 @@ E[95]="Run again with warp-go [option] [lisence], such as"
C[95]="再次运行用 warp-go [option] [lisence],如"
E[96]="WARP Global dualstack"
C[96]="WARP 全局 双栈"
E[97]="The account type is Teams and does not support changing IP\n 1. Change to free (default)\n 2. Change to plus\n 3. Quit"
C[97]="账户类型为 Teams,不支持更换 IP\n 1. 更换为 free (默认)\n 2. 更换为 plus\n 3. 退出"
E[97]="The account type is Teams and does not support changing IP\n 1. Change to free (default)\n 2. Change to plus\n 3. Quit"
C[97]="账户类型为 Teams,不支持更换 IP\n 1. 更换为 free (默认)\n 2. 更换为 plus\n 3. 退出"
E[98]="Non-global"
C[98]="非全局"
E[99]="global"
@ -215,7 +216,6 @@ text() { eval echo "\${${L}[$*]}"; }
text_eval() { eval echo "\$(eval echo "\${${L}[$*]}")"; }
translate() { [ -n "$1" ] && curl -ksm8 "http://fanyi.youdao.com/translate?&doctype=json&type=AUTO&i=$1" | cut -d \" -f18 2>/dev/null; }
# 脚本当天及累计运行次数统计
statistics_of_run-times() {
COUNT=$(curl -4ksm1 "https://hits.seeyoufarm.com/api/count/incr/badge.svg?url=https%3A%2F%2Fraw.githubusercontent.com%2Ffscarmen%2Fwarp%2Fmain%2Fwarp-go.sh&count_bg=%2379C83D&title_bg=%23555555&icon=&icon_color=%23E7E7E7&title=hits&edge_flat=false" 2>&1 ||
@ -343,12 +343,12 @@ change_ip() {
warp_restart() {
warning " $(text_eval 13) "
cp -f /opt/warp-go/warp.conf{,.tmp1}
k=0
[ -e /opt/warp-go/License ] && k='+' || k=' free'
until [[ -e /opt/warp-go/warp.conf.tmp2 ]]; do
((k++)) || true
[[ $k = 11 ]] && rm -f /opt/warp-go/warp.conf.tmp* && error "$(text 59)"
((b++)) || true
[[ $b -gt $j ]] && rm -f /opt/warp-go/warp.conf.tmp* && error " $(text_eval 50) "
/opt/warp-go/warp-go --register --config=/opt/warp-go/warp.conf.tmp2 --license=$(cat /opt/warp-go/License 2>/dev/null) --device-name=$(cat /opt/warp-go/Device_Name 2>/dev/null) >/dev/null 2>&1
[[ $? != 0 ]] && sleep $l
[[ $? != 0 && $b -le $j ]] && sleep $l
done
sed -i '1,6!d' /opt/warp-go/warp.conf.tmp2
tail -n +7 /opt/warp-go/warp.conf.tmp1 >> /opt/warp-go/warp.conf.tmp2
@ -356,7 +356,7 @@ change_ip() {
/opt/warp-go/warp-go --config=/opt/warp-go/warp.conf.tmp1 --remove >/dev/null 2>&1
rm -f /opt/warp-go/warp.conf.tmp*
${SYSTEMCTL_RESTART[int]}
sleep $j
sleep $l
}
# 检测账户类型为 Team 的不能更换
@ -408,9 +408,10 @@ change_ip() {
[[ -z $EXPECT || $EXPECT = [Yy] ]] && EXPECT="$REGION"
fi
# 解锁检测程序。 i=尝试次数; j=重启服务后休息秒数; l=账户注册失败后等待重试时间
i=0; j=10; l=10
# 解锁检测程序。 i=尝试次数; b=当前账户注册次数; j=注册账户失败的最大次数; l=账户注册失败后等待重试时间
i=0; j=10; l=30
while true; do
b=0
(( i++ )) || true
ip_now=$(date +%s); RUNTIME=$((ip_now - ip_start)); DAY=$(( RUNTIME / 86400 )); HOUR=$(( (RUNTIME % 86400 ) / 3600 )); MIN=$(( (RUNTIME % 86400 % 3600) / 60 )); SEC=$(( RUNTIME % 86400 % 3600 % 60 ))
ip${NF}_info
@ -429,6 +430,10 @@ change_ip() {
# 关闭 WARP 网络接口,并删除 warp-go
uninstall() {
unset IP4 IP6 WAN4 WAN6 COUNTRY4 COUNTRY6 ASNORG4 ASNORG6 INTERFACE
# 如已安装 warp_unlock 项目,先行卸载
[ -e /etc/wireguard/warp_unlock.sh ] && bash <(curl -sSL https://raw.githubusercontent.com/fscarmen/warp_unlock/main/unlock.sh) -U -$L
# 卸载
systemctl disable --now warp-go >/dev/null 2>&1
kill -15 $(pgrep warp-go) >/dev/null 2>&1
@ -454,15 +459,15 @@ ver() {
# i=当前尝试次数,j=要尝试的次数
net() {
unset IP4 IP6 WAN4 WAN6 COUNTRY4 COUNTRY6 ASNORG4 ASNORG6 WARPSTATUS4 WARPSTATUS6
i=1;j=5;
i=1; j=5
grep -qE "^AllowedIPs[ ]+=.*0\.\0\/0|#AllowedIPs" /opt/warp-go/warp.conf && INTERFACE='--interface WARP'
hint " $(text_eval 20)\n $(text_eval 21) "
hint " $(text_eval 20)\n $(text_eval 59) "
${SYSTEMCTL_RESTART[int]}
sleep 5
ip4_info; ip6_info
until [[ $TRACE4$TRACE6 =~ on|plus ]]; do
(( i++ )) || true
hint " $(text_eval 21) "
hint " $(text_eval 59) "
${SYSTEMCTL_RESTART[int]}
sleep 5
ip4_info; ip6_info
@ -522,7 +527,7 @@ check_stack() {
# 判断用于检测 NAT VSP,以选择正确配置文件
if [ "$m" -le 3 ]; then
NAT=("0@1@" "1@0@1" "1@1@1" "@1@1")
NAT=("0@1@" "1@0@1" "1@1@1" "0@1@1")
for ((n=0;n<${#NAT[@]};n++)); do [ "$IPV4@$IPV6@$INET4" = "${NAT[n]}" ] && break; done
NATIVE=("IPv6 only" "IPv4 only" "$(text 94)" "NAT IPv4")
CONF1=("014" "104" "114" "11N4")
@ -571,7 +576,7 @@ stack_switch() {
TO="$T4$T6$SWITCHCHOOSE"
fi
else
[[ "$T4@$T6@$SWITCHCHOOSE" =~ '1@0@4'|'0@1@6'|'1@1@D' ]] && error "$(text 30)" || TO="$T4$T6$SWITCHCHOOSE"
[[ "$T4@$T6@$SWITCHCHOOSE" =~ '1@0@4'|'0@1@6'|'1@1@D' ]] && error " $(text 30) " || TO="$T4$T6$SWITCHCHOOSE"
fi
else
OPTION1="$(text_eval 31)"; OPTION2="$(text_eval 32)"
@ -637,22 +642,15 @@ EOF
fi
# 判断机器原生状态类型
IPV4=0; IPV6=0
LAN4=$(ip route get 192.168.193.10 2>/dev/null | grep -oP 'src \K\S+')
LAN6=$(ip route get 2606:4700:d0::a29f:c001 2>/dev/null | grep -oP 'src \K\S+')
[[ "$LAN4" =~ ^[0-9.]+$ ]] && INET4=1
[[ "$LAN6" != "::1" && "$LAN6" =~ ^[0-9a-z:]+$ ]] && INET6=1
if [[ "$STATUS" != 2 ]]; then
if [[ "$INET6" = 1 ]]; then
INET6=1 && ping6 -c2 -w10 2606:4700:d0::a29f:c001 >/dev/null 2>&1 && IPV6=1 && CDN=-6 && ip6_info
else
IPV6=0
fi
if [[ "$INET4" = 1 ]]; then
INET4=1 && ping -c2 -W3 162.159.193.10 >/dev/null 2>&1 && IPV4=1 && CDN=-4 && ip4_info
else
IPV4=0
fi
[[ "$INET6" = 1 ]] && ping6 -c2 -w10 2606:4700:d0::a29f:c001 >/dev/null 2>&1 && IPV6=1 && CDN=-6 && ip6_info
[[ "$INET4" = 1 ]] && ping -c2 -W3 162.159.193.10 >/dev/null 2>&1 && IPV4=1 && CDN=-4 && ip4_info
else
if grep -qE "^AllowedIPs.*\:\:\/0" /opt/warp-go/warp.conf || [[ "$INET6" = 1 ]]; then
IPV6=1 && CDN=-6 && ip6_info
@ -722,7 +720,7 @@ update_license() {
input_token() {
[[ -z $TOKEN ]] && reading " $(text 44) " TOKEN
i=5
until [[ -z $TOKEN || ${#TOKEN} -gt 1200 ]]; do
until [[ -z $TOKEN || "${#TOKEN}" -ge "$TOKEN_LENGTH" ]]; do
(( i-- )) || true
[[ $i = 0 ]] && error "$(text 39)" || reading " $(text_eval 45) " TOKEN
done
@ -745,9 +743,13 @@ update() {
if [[ -n $LICENSE ]]; then
cp -f /opt/warp-go/warp.conf{,.tmp1}
/opt/warp-go/warp-go --config=/opt/warp-go/warp.conf --remove >/dev/null 2>&1
i=0; j=5; k='+'
hint " $(text_eval 58) "
until [[ -e /opt/warp-go/warp.conf ]]; do
/opt/warp-go/warp-go --register --config=/opt/warp-go/warp.conf --license=$LICENSE --device-name=$NAME >/dev/null 2>&1
[[ $? != 0 ]] && sleep 10 || echo "$LICENSE" > /opt/warp-go/License
((i++)) || true
[[ $i -gt $j ]] && rm -f /opt/warp-go/warp.conf.tmp && error " $(text_eval 50) "
hint " $(text_eval 59) " && /opt/warp-go/warp-go --register --config=/opt/warp-go/warp.conf --license=$LICENSE --device-name=$NAME >/dev/null 2>&1
[[ $? != 0 && $i -lt $j ]] && sleep 30 || echo "$LICENSE" > /opt/warp-go/License
done
head -n +6 /opt/warp-go/warp.conf > /opt/warp-go/warp.conf.tmp2
tail -n +7 /opt/warp-go/warp.conf.tmp1 >> /opt/warp-go/warp.conf.tmp2
@ -759,11 +761,12 @@ update() {
2 ) input_token
if [[ -n $TOKEN ]]; then
i=0
i=0; j=5; k=' teams'
hint " $(text_eval 58) "
until [[ -e /opt/warp-go/warp.conf.tmp ]]; do
((i++)) || true
[[ $i = 11 ]] && rm -f /opt/warp-go/warp.conf.tmp && error "$(text 50)"
/opt/warp-go/warp-go --register --config=/opt/warp-go/warp.conf.tmp --team-config "$TOKEN" >/dev/null 2>&1
[[ $i -gt $j ]] && rm -f /opt/warp-go/warp.conf.tmp && error " $(text_eval 50) "
hint " $(text_eval 59) " && /opt/warp-go/warp-go --register --config=/opt/warp-go/warp.conf.tmp --team-config "$TOKEN" >/dev/null 2>&1
[[ $? != 0 ]] && sleep 10
done
for a in {2..5}; do sed -i "${a}s#.*#$(sed -ne ${a}p /opt/warp-go/warp.conf.tmp)#" /opt/warp-go/warp.conf; done
@ -826,7 +829,8 @@ install() {
# 安装 warp-go,尽量下载官方的最新版本,如官方 warp-go 下载不成功,将使用 githubusercontents 的 CDN,以更好的支持双栈。并添加执行权限
mkdir -p /opt/warp-go/ >/dev/null 2>&1
wget --no-check-certificate $CDN -O /opt/warp-go/warp-go_"$latest"_linux_"$ARCHITECTURE".tar.gz https://gitlab.com/ProjectWARP/warp-go/-/releases/v"$latest"/downloads/warp-go_"$latest"_linux_"$ARCHITECTURE".tar.gz
wget --no-check-certificate $CDN -O /opt/warp-go/warp-go_"$latest"_linux_"$ARCHITECTURE".tar.gz https://gitlab.com/ProjectWARP/warp-go/-/releases/v"$latest"/downloads/warp-go_"$latest"_linux_"$ARCHITECTURE".tar.gz ||
wget --no-check-certificate $CDN -O /opt/warp-go/warp-go_"$latest"_linux_"$ARCHITECTURE".tar.gz https://raw.githubusercontents.com/fscarmen/warp/main/warp-go/warp-go_"$latest"_linux_"$ARCHITECTURE".tar.gz
[[ ! -e /opt/warp-go/warp-go_"$latest"_linux_"$ARCHITECTURE".tar.gz ]] && error "$(text 56)"
tar xzf /opt/warp-go/warp-go_"$latest"_linux_"$ARCHITECTURE".tar.gz -C /opt/warp-go/ warp-go
[[ ! -e /opt/warp-go/warp-go ]] && error "$(text 57)" || chmod +x /opt/warp-go/warp-go
@ -835,12 +839,13 @@ install() {
# 注册用户自定义 token 的 Teams 账户
if [[ $LICENSETYPE = 2 ]]; then
if [[ -n $TOKEN ]]; then
i=0
i=0; j=5; k=' teams'
hint " $(text_eval 58) "
until [[ -e /opt/warp-go/warp.conf ]]; do
((i++)) || true
[[ $i = 11 ]] && error "$(text 58)"
/opt/warp-go/warp-go --register --config=/opt/warp-go/warp.conf --team-config "$TOKEN" >/dev/null 2>&1
[[ $? != 0 ]] && sleep 10
[[ $i -gt $j ]] && error " $(text_eval 50) "
hint " $(text_eval 59) " && /opt/warp-go/warp-go --register --config=/opt/warp-go/warp.conf --team-config "$TOKEN" >/dev/null 2>&1
[[ $? != 0 && $i -lt $j ]] && sleep 30
done
# 注册公用 token 的 Teams 账户
@ -866,12 +871,14 @@ EOF
# 注册免费和 Plus 账户
else
i=0
i=0; j=5
[ -n "$LICENSE" ] && k='+' || k=' free'
hint " $(text_eval 58) "
until [[ -e /opt/warp-go/warp.conf ]]; do
((i++)) || true
[[ $i = 11 ]] && error "$(text 59)"
/opt/warp-go/warp-go --register --config=/opt/warp-go/warp.conf --license=$LICENSE --device-name=$NAME >/dev/null 2>&1
[[ $? != 0 ]] && sleep 10
[[ $i -gt $j ]] && error " $(text_eval 50) "
hint " $(text_eval 59) " && /opt/warp-go/warp-go --register --config=/opt/warp-go/warp.conf --license=$LICENSE --device-name=$NAME >/dev/null 2>&1
[[ $? != 0 && $i -lt $j ]] && sleep 30
done
fi
@ -997,11 +1004,12 @@ EOF
# 查 WARP+ 余额流量接口
check_quota() {
ACCESS_TOKEN=$(grep 'Token' /opt/warp-go/warp.conf | cut -d= -f2 | sed 's# ##g')
DEVICE_ID=$(grep 'Device' /opt/warp-go/warp.conf | cut -d= -f2 | sed 's# ##g')
API=$(curl -s "https://api.cloudflareclient.com/v0a884/reg/$DEVICE_ID" -H "User-Agent: okhttp/3.12.1" -H "Authorization: Bearer $ACCESS_TOKEN")
QUOTA=$(grep -oP '"quota":\K\d+' <<< $API)
if [ -e /opt/warp-go/warp.conf ]; then
ACCESS_TOKEN=$(grep 'Token' /opt/warp-go/warp.conf | cut -d= -f2 | sed 's# ##g')
DEVICE_ID=$(grep 'Device' /opt/warp-go/warp.conf | cut -d= -f2 | sed 's# ##g')
API=$(curl -s "https://api.cloudflareclient.com/v0a884/reg/$DEVICE_ID" -H "User-Agent: okhttp/3.12.1" -H "Authorization: Bearer $ACCESS_TOKEN")
QUOTA=$(grep -oP '"quota":\K\d+' <<< $API)
fi
if type -p bc >/dev/null 2>&1; then
[[ $QUOTA -gt 10000000000000 ]] && QUOTA="$(echo "scale=2; $QUOTA/1000000000000" | bc) TB" || QUOTA="$(echo "scale=2; $QUOTA/1000000000" | bc) GB"
else
@ -1095,7 +1103,7 @@ menu() {
if [[ $2 != '[lisence]' ]]; then
if [[ $2 =~ ^[A-Z0-9a-z]{8}-[A-Z0-9a-z]{8}-[A-Z0-9a-z]{8}$ ]]; then
LICENSETYPE=1 && LICENSE=$2
elif [[ $2 =~ [A-Z0-9a-z]{1200,} ]]; then LICENSETYPE=2 && TOKEN=$2
elif [[ ${#2} -ge $TOKEN_LENGTH ]]; then LICENSETYPE=2 && TOKEN=$2
elif [[ $2 =~ ^[A-Za-z]{2}$ ]]; then EXPECT=$2
fi
fi

Loading…
Cancel
Save