@ -66,8 +66,8 @@ E[29]="Input errors up to 5 times.The script is aborted."
C[ 29] = "输入错误达5次,脚本退出"
E[ 30] = "License should be 26 characters, please re-enter WARP+ License. Otherwise press Enter to continue. \(\${i} times remaining\):"
C[ 30] = "License 应为26位字符,请重新输入 WARP+ License,没有可回车继续\(剩余\${i}次\):"
E[ 31] = "The new license is the same as the one currently in use. Does not need to be replaced."
C[ 31] = "新输入的 License 与现使用中的一样,不需要更换。"
E[ 31] = "The new \$KEY_LICENSE is the same as the one currently in use. Does not need to be replaced."
C[ 31] = "新输入的 \$KEY_LICENSE 与现使用中的一样,不需要更换。"
E[ 32] = "Step 1/3: Install dependencies..."
C[ 32] = "进度 1/3: 安装系统依赖……"
E[ 33] = "Step 2/3: WGCF is ready"
@ -606,11 +606,11 @@ change_ip() {
client_restart( ) {
[ [ $( warp-cli --accept-tos settings) = ~ WarpProxy ] ] && CLIENT_PROXY = 1
warning " $( text_eval 126) " && warp-cli --accept-tos delete >/dev/null 2>& 1
[ " $CLIENT_PROXY " != 1 ] && ( ip -4 rule delete from 172.16.0.2/32 lookup 51820; ip -4 rule delete table main suppress_prefixlength 0 )
[ " $CLIENT_PROXY " != 1 ] && rule_del >/dev/null 2>& 1
warp-cli --accept-tos register >/dev/null 2>& 1 &&
[ -e /etc/wireguard/license ] && warp-cli --accept-tos set-license $( cat /etc/wireguard/license) >/dev/null 2>& 1
sleep $j
[ " $CLIENT_PROXY " != 1 ] && ( ip -4 rule add from 172.16.0.2 lookup 51820; ip -4 route add default dev CloudflareWARP table 51820; ip -4 rule add table main suppress_prefixlength 0 )
[ " $CLIENT_PROXY " != 1 ] && rule_add >/dev/null 2>& 1
}
if [ [ $( warp-cli --accept-tos settings) = ~ WarpProxy ] ] ; then
@ -751,8 +751,7 @@ uninstall() {
warp-cli --accept-tos disconnect >/dev/null 2>& 1
warp-cli --accept-tos disable-always-on >/dev/null 2>& 1
warp-cli --accept-tos delete >/dev/null 2>& 1
ip -4 rule delete from 172.16.0.2/32 lookup 51820 >/dev/nulll 2>& 1
ip -4 rule delete table main suppress_prefixlength 0 >/dev/nulll 2>& 1
rule_del >/dev/null 2>& 1
${ PACKAGE_UNINSTALL [int] } cloudflare-warp 2>/dev/null
systemctl disable --now warp-svc >/dev/null 2>& 1
rm -rf /usr/bin/wgcf /etc/wireguard /usr/bin/wireguard-go /usr/bin/warp
@ -852,7 +851,7 @@ onoff() {
proxy_onoff( ) {
! type -p warp-cli >/dev/null 2>& 1 && error " $( text 93) "
if systemctl is-active warp-svc >/dev/null 2>& 1; then
[ [ ! " $( warp-cli --accept-tos settings) " = ~ WarpProxy ] ] && ( ip -4 rule delete from 172.16.0.2/32 lookup 51820; ip -4 rule delete table main suppress_prefixlength 0 )
[ [ ! " $( warp-cli --accept-tos settings) " = ~ WarpProxy ] ] && rule_del >/dev/null 2>& 1
systemctl stop warp-svc
info " $( text 91) " && exit 0
@ -866,7 +865,7 @@ proxy_onoff() {
exit 0
else INTERFACE = '--interface CloudflareWARP'
ip -4 rule add from 172.16.0.2 lookup 51820; ip -4 route add default dev CloudflareWARP table 51820; ip -4 rule add table main suppress_prefixlength 0
rule_add >/dev/null 2>& 1
ip4_info
[ [ " $L " = C && -n " $COUNTRY4 " ] ] && COUNTRY4 = $( translate " $COUNTRY4 " )
ACCOUNT = $( warp-cli --accept-tos account 2>/dev/null)
@ -1023,6 +1022,16 @@ EOF
fi
}
rule_add( ) {
ip -4 rule add from 172.16.0.2 lookup 51820
ip -4 route add default dev CloudflareWARP table 51820
ip -4 rule add table main suppress_prefixlength 0
}
rule_del( ) {
ip -4 rule delete from 172.16.0.2 lookup 51820
ip -4 rule delete table main suppress_prefixlength 0
}
# 替换为 Teams 账户信息
teams_change( ) {
sed -i " s#PrivateKey.*#PrivateKey = $PRIVATEKEY #g;s#Address.*32#Address = ${ ADDRESS4 } /32#g;s#Address.*128#Address = ${ ADDRESS6 } /128#g;s#PublicKey.*#PublicKey = $PUBLICKEY #g " /etc/wireguard/wgcf.conf
@ -1300,8 +1309,12 @@ install() {
fi
# 生成 Wire-Guard 配置文件 (wgcf.conf)
[ -e /etc/wireguard/wgcf-account.toml ] && wgcf generate --config /etc/wireguard/wgcf-account.toml --profile /etc/wireguard/wgcf.conf >/dev/null 2>& 1
if [ -e /etc/wireguard/wgcf-account.toml ] ; then
until [ -e /etc/wireguard/wgcf.conf ] ; do
wgcf generate --config /etc/wireguard/wgcf-account.toml --profile /etc/wireguard/wgcf.conf >/dev/null 2>& 1
done
info " \n $( text 33) \n "
fi
# 反复测试最佳 MTU。 Wireguard Header:IPv4=60 bytes,IPv6=80 bytes,1280 ≤ MTU ≤ 1420。 ping = 8(ICMP回显示请求和回显应答报文格式长度) + 20(IP首部) 。
# 详细说明:<[WireGuard] Header / MTU sizes for Wireguard>:https://lists.zx2c4.com/pipermail/wireguard/2017-December/002201.html
@ -1592,30 +1605,24 @@ proxy() {
warp-cli --accept-tos connect >/dev/null 2>& 1
warp-cli --accept-tos enable-always-on >/dev/null 2>& 1
sleep 5
ip -4 rule add from 172.16.0.2 lookup 51820
ip -4 route add default dev CloudflareWARP table 51820
ip -4 rule add table main suppress_prefixlength 0
rule_add >/dev/null 2>& 1
ip4_info
until [ -n " $IP4 " ] ; do
( ( i++ ) ) || true
hint " $( text_eval 12) "
warp-cli --accept-tos disconnect >/dev/null 2>& 1
warp-cli --accept-tos disable-always-on >/dev/null 2>& 1
ip -4 rule delete from 172.16.0.2 lookup 51820
ip -4 rule delete table main suppress_prefixlength 0
rule_del >/dev/null 2>& 1
sleep 2
warp-cli --accept-tos connect >/dev/null 2>& 1
warp-cli --accept-tos enable-always-on >/dev/null 2>& 1
sleep 5
ip -4 rule add from 172.16.0.2 lookup 51820
ip -4 route add default dev CloudflareWARP table 51820
ip -4 rule add table main suppress_prefixlength 0
rule_add >/dev/null 2>& 1
ip4_info
if [ " $i " = " $j " ] ; then
warp-cli --accept-tos disconnect >/dev/null 2>& 1
warp-cli --accept-tos disable-always-on >/dev/null 2>& 1
ip -4 rule delete from 172.16.0.2 lookup 51820
ip -4 rule delete table main suppress_prefixlength 0
rule_del >/dev/null 2>& 1
error " $( text_eval 13) "
fi
done
@ -1771,39 +1778,44 @@ check_quota() {
QUOTA = $( grep -oP '"quota":\K\d+' <<< $API )
fi
if type -p bc >/dev/null 2>& 1; then
if [ [ " $QUOTA " -gt 10000000000000000 ] ] ; then
QUOTA = " $( echo " scale=2; $QUOTA /10000000000000000 " | bc) PB "
elif [ [ " $QUOTA " -gt 10000000000000 ] ] ; then
QUOTA = " $( echo " scale=2; $QUOTA /1000000000000 " | bc) TB "
# 部分系统没有依赖 bc,所以两个小数不能用 $(echo "scale=2; $QUOTA/1000000000000000" | bc),改为从右往左数字符数的方法
if [ [ " $QUOTA " -gt 1000000000000000000 ] ] ; then
QUOTA_INTEGER = " $(( $QUOTA / 1000000000000000000 )) "
QUOTA_DECIMALS = ${ QUOTA : 0 -18 : 2 }
QUOTA = " $QUOTA_INTEGER . $QUOTA_DECIMALS EB "
elif [ [ " $QUOTA " -gt 1000000000000000 ] ] ; then
QUOTA_INTEGER = " $(( $QUOTA / 1000000000000000 )) "
QUOTA_DECIMALS = ${ QUOTA : 0 -15 : 2 }
QUOTA = " $QUOTA_INTEGER . $QUOTA_DECIMALS PB "
elif [ [ " $QUOTA " -gt 1000000000000 ] ] ; then
QUOTA_INTEGER = " $(( $QUOTA / 1000000000000 )) "
QUOTA_DECIMALS = ${ QUOTA : 0 -12 : 2 }
QUOTA = " $QUOTA_INTEGER . $QUOTA_DECIMALS TB "
else
QUOTA = " $( echo " scale=2; $QUOTA /1000000000 " | bc) GB "
fi
else
if [ [ " $QUOTA " -gt 10000000000000000 ] ] ; then
QUOTA = " $(( QUOTA/10000000000000000)) PB "
elif [ [ " $QUOTA " -gt 10000000000000 ] ] ; then
QUOTA = " $(( QUOTA/1000000000000)) TB "
else
QUOTA = " $(( QUOTA/1000000000)) GB "
fi
QUOTA_INTEGER = " $(( $QUOTA / 1000000000 )) "
QUOTA_DECIMALS = ${ QUOTA : 0 -9 : 2 }
QUOTA = " $QUOTA_INTEGER . $QUOTA_DECIMALS GB "
fi
}
# 更换为免费账户
change_to_free( ) {
if [ " $UPDATE_ACCOUNT " = client ] ; then
if [ " $ACCOUNT_TYPE " = + ] ; then
[ [ $( warp-cli --accept-tos settings) = ~ WarpProxy ] ] && CLIENT_PROXY = 1
warp-cli --accept-tos delete >/dev/null 2>& 1
[ " $CLIENT_PROXY " != 1 ] && ( ip -4 rule delete from 172.16.0.2/32 lookup 51820; ip -4 rule delete table main suppress_prefixlength 0 )
[ " $CLIENT_PROXY " != 1 ] && rule_del >/dev/null 2>& 1
warp-cli --accept-tos register >/dev/null 2>& 1
rm -f /etc/wireguard/license
sleep 5
[ " $CLIENT_PROXY " != 1 ] && ( ip -4 rule add from 172.16.0.2 lookup 51820; ip -4 route add default dev CloudflareWARP table 51820; ip -4 rule add table main suppress_prefixlength 0 )
fi
AC3 = ' free' && proxy_info
unset AC && AC3 = ' free' && rm -f /etc/wireguard/license
sleep 2
if [ " $CLIENT_PROXY " != 1 ] ; then
rule_add >/dev/null 2>& 1
INTERFACE = '--interface CloudflareWARP' && ip4_info
[ " $L " = C ] && COUNTRY4 = $( translate " $COUNTRY4 " )
info " $( text_eval 169) \n $( text_eval 62) "
else
proxy_info
info " $( text_eval 27) \n $( text_eval 62) "
fi
exit 0
else
if [ " $ACCOUNT_TYPE " = free ] ; then
@ -1813,8 +1825,12 @@ change_to_free() {
until [ -e /etc/wireguard/account-temp.toml ] >/dev/null 2>& 1; do
/usr/bin/wgcf register --accept-tos --config /etc/wireguard/account-temp.toml >/dev/null 2>& 1 && break
done
[ -e /etc/wireguard/account-temp.toml ] && /usr/bin/wgcf generate --config /etc/wireguard/account-temp.toml --profile /etc/wireguard/profile-temp.conf >/dev/null 2>& 1
[ -e /etc/wireguard/profile-temp.conf ] && sed -i " 2s#.*# $( sed -ne 2p /etc/wireguard/profile-temp.conf) #; 3s#.*# $( sed -ne 3p /etc/wireguard/profile-temp.conf) #; 4s#.*# $( sed -ne 4p /etc/wireguard/profile-temp.conf) # " /etc/wireguard/wgcf.conf
if [ -e /etc/wireguard/account-temp.toml ] ; then
until [ -e /etc/wireguard/profile-temp.conf ] ; do
/usr/bin/wgcf generate --config /etc/wireguard/account-temp.toml --profile /etc/wireguard/profile-temp.conf >/dev/null 2>& 1
done
fi
sed -i " 2s#.*# $( sed -ne 2p /etc/wireguard/profile-temp.conf) #; 3s#.*# $( sed -ne 3p /etc/wireguard/profile-temp.conf) #; 4s#.*# $( sed -ne 4p /etc/wireguard/profile-temp.conf) # " /etc/wireguard/wgcf.conf
rm -f /etc/wireguard/account-temp.toml /etc/wireguard/profile-temp.conf /etc/wireguard/info.log
if [ " $UPDATE_ACCOUNT " = wgcf ] ; then
wg-quick down wgcf >/dev/null 2>& 1
@ -1833,10 +1849,11 @@ change_to_free() {
change_to_plus( ) {
update_license
if [ " $UPDATE_ACCOUNT " = client ] ; then
[ [ " $ACCOUNT " = ~ " $LICENSE " ] ] && error " $( text 31) "
[ [ " $ACCOUNT " = ~ " $LICENSE " ] ] && KEY_LICENSE = 'License' && error " $( text_eval 31) "
[ [ $( warp-cli --accept-tos settings) = ~ WarpProxy ] ] && CLIENT_PROXY = 1
hint " \n $( text 35) \n "
warp-cli --accept-tos delete >/dev/null 2>& 1
[ " $CLIENT_PROXY " != 1 ] && ( ip -4 rule delete from 172.16.0.2/32 lookup 51820; ip -4 rule delete table main suppress_prefixlength 0 )
[ " $CLIENT_PROXY " != 1 ] && rule_del >/dev/null 2>& 1
warp-cli --accept-tos register >/dev/null 2>& 1 &&
[ -n " $LICENSE " ] && warp-cli --accept-tos set-license " $LICENSE " >/dev/null 2>& 1 && sleep 1 &&
ACCOUNT = $( warp-cli --accept-tos account 2>/dev/null) &&
@ -1844,10 +1861,9 @@ change_to_plus() {
CHECK_TYPE = 1 && check_quota
sleep 3
if [ " $CLIENT_PROXY " != 1 ] ; then
ip -4 rule add from 172.16.0.2 lookup 51820
ip -4 route add default dev CloudflareWARP table 51820
ip -4 rule add table main suppress_prefixlength 0
rule_add >/dev/null 2>& 1
INTERFACE = '--interface CloudflareWARP' && ip4_info
[ " $L " = C ] && COUNTRY4 = $( translate " $COUNTRY4 " )
info " $( text_eval 169) \n $( text_eval 62) \n $( text 63) : $QUOTA \n "
else
proxy_info
@ -1855,7 +1871,7 @@ change_to_plus() {
fi
else
# 如现正使用着 WARP+ 账户,并且新输入的 License 也与现一样的话,脚本退出
[ " $ACCOUNT_TYPE " = + ] && grep -q " $LICENSE " /etc/wireguard/wgcf-account.toml && error " $( text 31) "
[ " $ACCOUNT_TYPE " = + ] && grep -q " $LICENSE " /etc/wireguard/wgcf-account.toml && KEY_LICENSE = 'License' && error " $( text_eval 31) "
hint " \n $( text 35) \n "
cp -f /etc/wireguard/wgcf-account.toml /etc/wireguard/account-temp.toml || exit 1
sed -i " s#license_key.*#license_key = \' $LICENSE \'#g " /etc/wireguard/account-temp.toml
@ -1869,7 +1885,11 @@ change_to_plus() {
warning " $( text_eval 36) " && OPTION = n && net
exit 1
fi
if [ -e /etc/wireguard/account-temp.toml ] ; then
until [ -e /etc/wireguard/profile-temp.conf ] ; do
wgcf generate --config /etc/wireguard/account-temp.toml --profile /etc/wireguard/profile-temp.conf >/dev/null 2>& 1
done
fi
sed -i " 2s#.*# $( sed -ne 2p /etc/wireguard/profile-temp.conf) #; 3s#.*# $( sed -ne 3p /etc/wireguard/profile-temp.conf) #; 4s#.*# $( sed -ne 4p /etc/wireguard/profile-temp.conf) # " /etc/wireguard/wgcf.conf
rm -f /etc/wireguard/account-temp.toml /etc/wireguard/profile-temp.conf
if [ " $UPDATE_ACCOUNT " = wgcf ] ; then
@ -1889,6 +1909,7 @@ change_to_plus() {
# 更换为 Teams 账户
change_to_teams( ) {
input_url
grep -q " $PRIVATEKEY " /etc/wireguard/wgcf.conf && KEY_LICENSE = 'Private key' && error " $( text_eval 31) "
if grep -qiw "y" <<< " $CONFIRM " ; then
cp -f /etc/wireguard/wgcf.conf{ ,.bak}
echo " $TEAMS " > /etc/wireguard/info.log 2>& 1
@ -1896,12 +1917,12 @@ change_to_teams() {
teams_change
wg-quick down wgcf >/dev/null 2>& 1
OPTION = n && net
[ [ $( curl -ks4 https://www.cloudflare.com/cdn-cgi/trace | grep warp | sed "s/warp=//g" ) = plus || $( curl -ks6 https://www.cloudflare.com/cdn-cgi/trace | grep warp | sed "s/warp=//g" ) = plus ] ] && rm -f /etc/wireguard/wgcf.conf.bak && AC3 = ' teams' && info " $( text 62) "
[ [ $( curl -ks4 https://www.cloudflare.com/cdn-cgi/trace | grep warp | sed "s/warp=//g" ) = plus || $( curl -ks6 https://www.cloudflare.com/cdn-cgi/trace | grep warp | sed "s/warp=//g" ) = plus ] ] && rm -f /etc/wireguard/wgcf.conf.bak && AC3 = ' teams' && info " $( text_eval 62) "
else
sed -i " s#PrivateKey.*#PrivateKey = $PRIVATEKEY #g " /etc/wireguard/proxy.conf
systemctl stop wireproxy; sleep 2
wireproxy_onoff
[ [ $( eval echo " \$(curl -sx socks5h://localhost: $( ss -nltp | grep wireproxy | grep -oP '127.0*\S+' | cut -d: -f2) https://www.cloudflare.com/cdn-cgi/trace) " ) = ~ plus ] ] && rm -f /etc/wireguard/wgcf.conf.bak && AC3 = ' teams' && info " $( text 62) "
[ [ $( eval echo " \$(curl -sx socks5h://localhost: $( ss -nltp | grep wireproxy | grep -oP '127.0*\S+' | cut -d: -f2) https://www.cloudflare.com/cdn-cgi/trace) " ) = ~ plus ] ] && rm -f /etc/wireguard/wgcf.conf.bak && AC3 = ' teams' && info " $( text_eval 62) "
fi
fi
}
@ -1920,7 +1941,7 @@ update() {
# 判断现 WGCF 账户类型: free, plus, teams,如果是 plus,查 WARP+ 余额流量
[ -z " $ACCOUNT_TYPE " ] && ACCOUNT_TYPE = free && CHANGE_TYPE = $( text 174) &&
[ -e /etc/wireguard/info.log ] && ACCOUNT_TYPE = teams && CHANGE_TYPE = $( text 175) &&
grep -q 'Device name' /etc/wireguard/info.log && ACCOUNT_TYPE = '+' && CHANGE_TYPE = $( text 176) && check_quota && PLUS_QUOTA = " $( text 63) : $QUOTA "
grep -q 'Device name' /etc/wireguard/info.log && ACCOUNT_TYPE = '+' && CHANGE_TYPE = $( text 176) && check_quota && PLUS_QUOTA = " \\n $( text 63) : $QUOTA "
[ -z " $CHOOSE_TYPE " ] && hint " \n $( text_eval 173) \n " && reading " $( text 50) " CHOOSE_TYPE
# 输入必须是数字且少于等于3