From ab244fa247405b87287e87b260a6d81e33aa584b Mon Sep 17 00:00:00 2001 From: fscarmen <62703343+fscarmen@users.noreply.github.com> Date: Sat, 17 Dec 2022 17:29:33 +0800 Subject: [PATCH] Update warp-go.sh --- warp-go.sh | 619 +++++++++++++++++++++++++++++------------------------ 1 file changed, 345 insertions(+), 274 deletions(-) diff --git a/warp-go.sh b/warp-go.sh index da949a4..d5de2a0 100644 --- a/warp-go.sh +++ b/warp-go.sh @@ -2,15 +2,22 @@ export LANG=en_US.UTF-8 # 当前脚本版本号和新增功能 -VERSION=1.0.6 +VERSION=1.1.0 + +# 选择 IP API 服务商 +IP_API=https://api.ip.sb/geoip; ISP=isp +#IP_API=https://ifconfig.co/json; ISP=asn_org +#IP_API=https://ip.gs/json; ISP=asn_org + +# 判断 Teams token 最少字符数 TOKEN_LENGTH=800 E[0]="Language:\n 1.English (default) \n 2.简体中文" C[0]="${E[0]}" -E[1]="1.Fixed the bug that routing rules failed after restart in non-global mode; 2.Fixed the bug of not changing IP." -C[1]="1.解决了非全局模式重启后,路由规则失效的bug; 2.解决了更换不了IP的bug" -E[2]="warp-go h (help menu)\n warp-go o (temporary warp-go switch)\n warp-go u (uninstall WARP web interface and warp-go)\n warp-go v (sync script to latest version)\n warp-go i (replace IP with Netflix support)\n warp-go 4/6 ( WARP IPv4/IPv6 single-stack)\n warp-go d (WARP dual-stack)\n warp-go n (WARP IPv4 non-global)\n warp-go g (WARP global/non-global switching)\n warp-go e (output wireguard configuration file)" -C[2]="warp-go h (帮助菜单)\n warp-go o (临时 warp-go 开关)\n warp-go u (卸载 WARP 网络接口和 warp-go)\n warp-go v (同步脚本至最新版本)\n warp-go i (更换支持 Netflix 的IP)\n warp-go 4/6 (WARP IPv4/IPv6 单栈)\n warp-go d (WARP 双栈)\n warp-go n (WARP IPv4 非全局)\n warp-go g (WARP 全局 / 非全局相互切换)\n warp-go e (输出 wireguard 配置文件)" +E[1]="Support OpenWrt sysgtem." +C[1]="支持 OpenWrt 系统" +E[2]="warp-go h (help)\n warp-go o (temporary warp-go switch)\n warp-go u (uninstall WARP web interface and warp-go)\n warp-go v (sync script to latest version)\n warp-go i (replace IP with Netflix support)\n warp-go 4/6 ( WARP IPv4/IPv6 single-stack)\n warp-go d (WARP dual-stack)\n warp-go n (WARP IPv4 non-global)\n warp-go g (WARP global/non-global switching)\n warp-go e (output wireguard and sing-box configuration file)\n warp-go a (Change to Free, WARP+ or Teams account)" +C[2]="warp-go h (帮助)\n warp-go o (临时 warp-go 开关)\n warp-go u (卸载 WARP 网络接口和 warp-go)\n warp-go v (同步脚本至最新版本)\n warp-go i (更换支持 Netflix 的IP)\n warp-go 4/6 (WARP IPv4/IPv6 单栈)\n warp-go d (WARP 双栈)\n warp-go n (WARP IPv4 非全局)\n warp-go g (WARP 全局 / 非全局相互切换)\n warp-go e (输出 wireguard 和 sing-box 配置文件)\n warp-go a (更换到 Free,WARP+ 或 Teams 账户)" E[3]="This project is designed to add WARP network interface for VPS, using warp-go core, using various interfaces of CloudFlare-WARP, integrated wireguard-go, can completely replace WGCF. Save Hong Kong, Toronto and other VPS, can also get WARP IP. Thanks again @CoiaPrant and his team. Project address: https://gitlab.com/ProjectWARP/warp-go/-/tree/master/" C[3]="本项目专为 VPS 添加 WARP 网络接口,使用 wire-go 核心程序,利用CloudFlare-WARP 的各类接口,集成 wireguard-go,可以完全替代 WGCF。 救活了香港、多伦多等 VPS 也可以获取 WARP IP。再次感谢 @CoiaPrant 及其团队。项目地址: https://gitlab.com/ProjectWARP/warp-go/-/tree/master/" E[4]="Choose:" @@ -47,8 +54,8 @@ E[19]="New features" C[19]="功能新增" E[20]="Maximum \${j} attempts to get WARP IP..." C[20]="后台获取 WARP IP 中, 最大尝试\${j}次……" -E[21]="" -C[21]="" +E[21]="Can't find the account file: /opt/warp-go/warp.conf.You can uninstall and reinstall it." +C[21]="找不到账户文件:/opt/warp-go/warp.conf,可以卸载后重装" 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]" @@ -93,30 +100,30 @@ E[42]="Please Input WARP+ license:" C[42]="请输入WARP+ License:" E[43]="License should be 26 characters, please re-enter WARP+ License. Otherwise press Enter to continue. \(\${i} times remaining\): " 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[44]="Please enter the Teams Token (You can easily available at https://web--public--warp-team-api--coia-mfs4.code.run. Or use the one provided by the script if left blank):" +C[44]="请输入 Teams Token (可通过 https://web--public--warp-team-api--coia-mfs4.code.run 轻松获取,如果留空,则使用脚本提供的):" 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,可以卸载后重装" -E[47]="It is a WARP+ account already. Quota: \$QUOTA. Update is aborted." -C[47]="已经是 WARP+ 账户,剩余流量: \$QUOTA,不需要升级" -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[46]="Current account type is: \$ACCOUNT_TYPE\\\t \$PLUS_QUOTA\\\n \$CHANGE_TYPE" +C[46]="当前账户类型是: \$ACCOUNT_TYPE\\\t \$PLUS_QUOTA\\\n \$CHANGE_TYPE" +E[47]="1. Continue using the free account without changing.\n 2. Change to WARP+ account.\n 3. Change to Teams account. (You can easily available at https://web--public--warp-team-api--coia-mfs4.code.run. Or use the one provided by the script if left blank)\n 0. Return to the main menu." +C[47]="1. 继续使用 free 账户,不变更\n 2. 变更为 WARP+ 账户\n 3. 变更为 Teams 账户 (可通过 https://web--public--warp-team-api--coia-mfs4.code.run 轻松获取,如果留空,则使用脚本提供的)\n 0. 返回主菜单" +E[48]="1. Change to free account.\n 2. Change to WARP+ account.\n 3. Change to another WARP Teams account. (You can easily available at https://web--public--warp-team-api--coia-mfs4.code.run. Or use the one provided by the script if left blank)\n 0. Return to the main menu." +C[48]="1. 变更为 free 账户\n 2. 变更为 WARP+ 账户\n 3. 更换为另一个 Teams 账户 (可通过 https://web--public--warp-team-api--coia-mfs4.code.run 轻松获取,如果留空,则使用脚本提供的)\n 0. 返回主菜单" +E[49]="1. Change to free account.\n 2. Change to another WARP+ account.\n 3. Change to Teams account. (You can easily available at https://web--public--warp-team-api--coia-mfs4.code.run. Or use the one provided by the script if left blank)\n 0. Return to the main menu." +C[49]="1. 变更为 free 账户\n 2. 变更为另一个 WARP+ 账户\n 3. 变更为 Teams 账户 (可通过 https://web--public--warp-team-api--coia-mfs4.code.run 轻松获取,如果留空,则使用脚本提供的)\n 0. 返回主菜单" 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" -C[52]="该账户的 wgcf.conf 路径: /opt/warp-go/wgcf.conf\n" +E[52]="Wireguard configuration file: /opt/warp-go/wgcf.conf\n" +C[52]="Wireguard 配置文件: /opt/warp-go/wgcf.conf\n" E[53]="Warp-go installed. Script aborted. Feedback: [https://github.com/fscarmen/warp/issues]" C[53]="warp-go 已安装,脚本中止,问题反馈: [https://github.com/fscarmen/warp/issues]" -E[54]="Is there a WARP+ or Teams account?\n 1. WARP+\n 2. Teams\n 3. use free account (default)" +E[54]="Is there a WARP+ or Teams account?\n 1. WARP+\n 2. Teams\n 3. Use free account (default)" C[54]="如有 WARP+ 或 Teams 账户请选择\n 1. WARP+\n 2. Teams\n 3. 使用免费账户 (默认)" -E[55]="Please choose the priority:\n 1. IPv4 (default)\n 2. IPv6\n 3. Use initial settings" -C[55]="请选择优先级别:\n 1. IPv4 (默认)\n 2. IPv6\n 3. 使用 VPS 初始设置" +E[55]="Please choose the priority:\n 1. IPv4\n 2. IPv6\n 3. Use initial settings (default)" +C[55]="请选择优先级别:\n 1. IPv4\n 2. IPv6\n 3. 使用 VPS 初始设置 (默认)" E[56]="Download warp-go zip file unsuccessful. Script exits. Feedback: [https://github.com/fscarmen/warp/issues]" 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]" @@ -159,12 +166,12 @@ E[75]="\${WARP_BEFORE[m]} switch to \${WARP_AFTER2[m]} \${SHORTCUT2[m]}" C[75]="\${WARP_BEFORE[m]} 转为 \${WARP_AFTER2[m]} \${SHORTCUT2[m]}" E[76]="Switch to WARP \${GLOBAL_AFTER}global network interface \(warp-go g\)" C[76]="转为 WARP \${GLOBAL_AFTER}全局 网络接口 \(warp-go g\)" -E[77]="Upgrade to WARP+ or Teams account \(warp-go a\)" -C[77]="升级为 WARP+ 或 Teams 账户 \(warp-go a\)" +E[77]="Change to Free, WARP+ or Teams account \(warp-go a\)" +C[77]="更换为 Free,WARP+ 或 Teams 账户 \(warp-go a\)" E[78]="Change the WARP IP to support Netflix (warp-go i)" C[78]="更换支持 Netflix 的 IP (warp-go i)" -E[79]="Export wgcf configuration file (warp-go e)" -C[79]="输出 wgcf 配置文件 (warp-go e)" +E[79]="Export wireguard and sing-box configuration file (warp-go e)" +C[79]="输出 wireguard 和 sing-box 配置文件 (warp-go e)" E[80]="Uninstall the WARP interface and warp-go (warp-go u)" C[80]="卸载 WARP 网络接口和 warp-go (warp-go u)" E[81]="Exit" @@ -205,6 +212,12 @@ E[98]="Non-global" C[98]="非全局" E[99]="global" C[99]="全局" +E[100]="IPv\$PRIO priority" +C[100]="IPv\$PRIO 优先" +E[101]="Sing-box configuration file: /opt/warp-go/singbox.json\n" +C[101]="Sing-box 配置文件: /opt/warp-go/singbox.json\n" +E[102]="WAN interface network protocol must be [static] on OpenWrt." +C[102]="OpenWrt 系统的 WAN 接口的网络传输协议必须为 [静态地址]" # 自定义字体彩色,read 函数,友道翻译函数 warning() { echo -e "\033[31m\033[01m$*\033[0m"; } @@ -226,26 +239,26 @@ statistics_of_run-times() { # 选择语言,先判断 /opt/warp-go/language 里的语言选择,没有的话再让用户选择,默认英语 select_language() { case $(cat /opt/warp-go/language 2>&1) in - E ) L=E;; - C ) L=C;; - * ) L=E && [[ -z $OPTION || $OPTION = [aclehdpbviw46] ]] && hint "\n $(text 0) \n" && reading " $(text 4) " LANGUAGE - [[ $LANGUAGE = 2 ]] && L=C;; + E ) L=E ;; + C ) L=C ;; + * ) L=E && [[ -z "$OPTION" || "$OPTION" = [ahvi46d] ]] && hint "\n $(text 0) \n" && reading " $(text 4) " LANGUAGE + [ "$LANGUAGE" = 2 ] && L=C ;; esac } # 必须以root运行脚本 check_root_virt() { - [[ $(id -u) != 0 ]] && error " $(text 5) " + [ "$(id -u)" != 0 ] && error " $(text 5) " # 判断虚拟化,选择 Wireguard内核模块 还是 Wireguard-Go - VIRT=$(systemd-detect-virt 2>/dev/null | tr '[:upper:]' '[:lower:]') - [[ -z $VIRT ]] && VIRT=$(hostnamectl 2>/dev/null | tr '[:upper:]' '[:lower:]' | grep virtualization | sed "s/.*://g") + VIRT=$(systemd-detect-virt 2>/dev/null | tr 'A-Z' 'a-z') + [ -z "$VIRT" ] && VIRT=$(hostnamectl 2>/dev/null | tr 'A-Z' 'a-z' | grep virtualization | sed "s/.*://g") } # 检测 warp-go 的安装状态。 0-未安装; 1-已安装未启动; 2-已安装启动中; 3-脚本安装中 check_install() { - if [[ -e /opt/warp-go/warp.conf ]]; then - [[ $(ip a) =~ ": WARP:" ]] && STATUS=2 || STATUS=1 + if [ -e /opt/warp-go/warp.conf ]; then + [[ "$(ip a)" =~ ": WARP:" ]] && STATUS=2 || STATUS=1 else STATUS=0 fi @@ -262,88 +275,117 @@ check_operating_system() { ) for i in "${CMD[@]}"; do - SYS="$i" && [[ -n $SYS ]] && break + SYS="$i" && [ -n "$SYS" ] && break done # 自定义 Alpine 系统若干函数 alpine_warp_restart() { kill -15 $(pgrep warp-go) 2>/dev/null; /opt/warp-go/warp-go --config=/opt/warp-go/warp.conf; } alpine_wgcf_enable() { echo -e "/opt/warp-go/tun.sh\n/opt/warp-go/warp-go --config=/opt/warp-go/warp.conf" > /etc/local.d/warp-go.start; chmod +x /etc/local.d/warp-go.start; rc-update add local; } + openwrt_wgcf_enable() { echo -e "@reboot /opt/warp-go/warp-go --config=/opt/warp-go/warp.conf" >> /etc/crontabs/root; } - REGEX=("debian" "ubuntu" "centos|red hat|kernel|oracle linux|alma|rocky|amazon linux" "alpine" "arch linux") - RELEASE=("Debian" "Ubuntu" "CentOS" "Alpine" "Arch") + REGEX=("debian" "ubuntu" "centos|red hat|kernel|oracle linux|alma|rocky|amazon linux" "alpine" "arch linux" "openwrt") + RELEASE=("Debian" "Ubuntu" "CentOS" "Alpine" "Arch" "OpenWrt") EXCLUDE=("bookworm") - MAJOR=("9" "16" "7" "3" "") - PACKAGE_UPDATE=("apt -y update" "apt -y update" "yum -y update" "apk update -f" "pacman -Sy") - PACKAGE_INSTALL=("apt -y install" "apt -y install" "yum -y install" "apk add -f" "pacman -S --noconfirm") - PACKAGE_UNINSTALL=("apt -y autoremove" "apt -y autoremove" "yum -y autoremove" "apk del -f" "pacman -Rcnsu --noconfirm") - SYSTEMCTL_START=("systemctl start warp-go" "systemctl start warp-go" "systemctl start warp-go" "/opt/warp-go/warp-go --config=/opt/warp-go/warp.conf" "systemctl start warp-go") - SYSTEMCTL_STOP=("systemctl stop warp-go" "systemctl stop warp-go" "systemctl stop warp-go" "kill -15 $(pgrep warp-go)" "systemctl stop warp-go") - SYSTEMCTL_RESTART=("systemctl restart warp-go" "systemctl restart warp-go" "systemctl restart warp-go" "alpine_warp_restart" "systemctl restart wg-quick@wgcf") + MAJOR=("9" "16" "7" "3" "" "") + PACKAGE_UPDATE=("apt -y update" "apt -y update" "yum -y update" "apk update -f" "pacman -Sy" "opkg update") + PACKAGE_INSTALL=("apt -y install" "apt -y install" "yum -y install" "apk add -f" "pacman -S --noconfirm" "opkg install") + PACKAGE_UNINSTALL=("apt -y autoremove" "apt -y autoremove" "yum -y autoremove" "apk del -f" "pacman -Rcnsu --noconfirm" "opkg remove --force-depends") + SYSTEMCTL_START=("systemctl start warp-go" "systemctl start warp-go" "systemctl start warp-go" "/opt/warp-go/warp-go --config=/opt/warp-go/warp.conf" "systemctl start warp-go" "/opt/warp-go/warp-go --config=/opt/warp-go/warp.conf") + SYSTEMCTL_STOP=("systemctl stop warp-go" "systemctl stop warp-go" "systemctl stop warp-go" "kill -15 $(pgrep warp-go)" "systemctl stop warp-go" "kill -15 $(pgrep warp-go)") + SYSTEMCTL_RESTART=("systemctl restart warp-go" "systemctl restart warp-go" "systemctl restart warp-go" "alpine_warp_restart" "systemctl restart wg-quick@wgcf" "alpine_warp_restart") SYSTEMCTL_ENABLE=("systemctl enable --now warp-go" "systemctl enable --now warp-go" "systemctl enable --now warp-go" "alpine_wgcf_enable" "systemctl enable --now warp-go") for ((int=0; int<${#REGEX[@]}; int++)); do - [[ $(echo "$SYS" | tr '[:upper:]' '[:lower:]') =~ ${REGEX[int]} ]] && SYSTEM="${RELEASE[int]}" && COMPANY="${COMPANY[int]}" && [[ -n $SYSTEM ]] && break + [[ $(echo "$SYS" | tr 'A-Z' 'a-z') =~ ${REGEX[int]} ]] && SYSTEM="${RELEASE[int]}" && COMPANY="${COMPANY[int]}" && [ -n "$SYSTEM" ] && break done - [[ -z $SYSTEM ]] && error "$(text 6)" + [ -z "$SYSTEM" ] && error "$(text 6)" + [ "$SYSTEM" = OpenWrt ] && [ $(uci show network.wan.proto | cut -d \' -f2) != 'static' ] && error "$(text 102)" # 先排除 EXCLUDE 里包括的特定系统,其他系统需要作大发行版本的比较 - for ex in "${EXCLUDE[@]}"; do [[ ! $(echo "$SYS" | tr '[:upper:]' '[:lower:]') =~ $ex ]]; done && - [[ $(echo $SYS | sed "s/[^0-9.]//g" | cut -d. -f1) -lt "${MAJOR[int]}" ]] && error " $(text_eval 7) " + for ex in "${EXCLUDE[@]}"; do [[ ! $(echo "$SYS" | tr 'A-Z' 'a-z') =~ $ex ]]; done && + [[ "$(echo "$SYS" | sed "s/[^0-9.]//g" | cut -d. -f1)" -lt "${MAJOR[int]}" ]] && error " $(text_eval 7) " } -# 安装 curl +# 安装系统依赖及定义 ping 指令 check_dependencies() { - # 对于 alpine 系统,升级库并重新安装依赖 - if [ $SYSTEM = Alpine ]; then + # 对于 Alpine 和 OpenWrt 系统,升级库并重新安装依赖 + if echo "$SYSTEM" | grep -qE "Alpine|OpenWrt"; then [ ! -e /opt/warp-go/warp-go ] && ( ${PACKAGE_UPDATE[int]}; ${PACKAGE_INSTALL[int]} curl wget grep bash ) else DEPS_CHECK=("ping" "wget" "curl" "systemctl" "ip") - DEPS_INSTALL=(" inetutils-ping" " wget" " curl" " systemctl" " iproute2") - for ((c=0;c<${#DEPS_CHECK[@]};c++)); do ! type -p ${DEPS_CHECK[c]} >/dev/null 2>&1 && DEPS+=${DEPS_INSTALL[c]}; done + DEPS_INSTALL=(" iputils-ping" " wget" " curl" " systemctl" " iproute2") + for ((c=0;c<${#DEPS_CHECK[@]};c++)); do [[ ! $(type -p ${DEPS_CHECK[c]}) ]] && DEPS+=${DEPS_INSTALL[c]}; done if [ -n "$DEPS" ]; then info "\n $(text 8) $DEPS \n" - ${PACKAGE_UPDATE[int]} - ${PACKAGE_INSTALL[int]} $DEPS + ${PACKAGE_UPDATE[int]} >/dev/null 2>&1 + ${PACKAGE_INSTALL[int]} $DEPS >/dev/null 2>&1 else info "\n $(text 9) \n" fi fi + PING6='ping -6' && [ $(type -p ping6) ] && PING6='ping6' } # 检测 IPv4 IPv6 信息,WARP Ineterface 开启,普通还是 Plus账户 和 IP 信息 ip4_info() { unset IP4 COUNTRY4 ASNORG4 TRACE4 PLUS4 WARPSTATUS4 - IP4=$(curl -ks4m8 https://ip.gs/json $INTERFACE) - WAN4=$(expr "$IP4" : '.*ip\":\"\([^"]*\).*') - COUNTRY4=$(expr "$IP4" : '.*country\":\"\([^"]*\).*') - ASNORG4=$(expr "$IP4" : '.*asn_org\":\"\([^"]*\).*') + IP4=$(curl -ks4m8 -A Mozilla $IP_API $INTERFACE) + WAN4=$(expr "$IP4" : '.*ip\":[ ]*\"\([^"]*\).*') + COUNTRY4=$(expr "$IP4" : '.*country\":[ ]*\"\([^"]*\).*') + ASNORG4=$(expr "$IP4" : '.*'$ISP'\":[ ]*\"\([^"]*\).*') TRACE4=$(curl -ks4m8 https://www.cloudflare.com/cdn-cgi/trace $INTERFACE | grep warp | sed "s/warp=//g") } ip6_info() { unset IP6 COUNTRY6 ASNORG6 TRACE6 PLUS6 WARPSTATUS6 - IP6=$(curl -ks6m8 https://ip.gs/json) - WAN6=$(expr "$IP6" : '.*ip\":\"\([^"]*\).*') - COUNTRY6=$(expr "$IP6" : '.*country\":\"\([^"]*\).*') - ASNORG6=$(expr "$IP6" : '.*asn_org\":\"\([^"]*\).*') + IP6=$(curl -ks6m8 -A Mozilla $IP_API) + WAN6=$(expr "$IP6" : '.*ip\":[ ]*\"\([^"]*\).*') + COUNTRY6=$(expr "$IP6" : '.*country\":[ ]*\"\([^"]*\).*') + ASNORG6=$(expr "$IP6" : '.*'$ISP'\":[ ]*\"\([^"]*\).*') TRACE6=$(curl -ks6m8 https://www.cloudflare.com/cdn-cgi/trace | grep warp | sed "s/warp=//g") } # 帮助说明 help() { hint " $(text 2) "; } -# IPv4 / IPv6 优先 +# IPv4 / IPv6 优先设置 stack_priority() { - [[ -e /etc/gai.conf ]] && sed -i '/^precedence \:\:ffff\:0\:0/d;/^label 2002\:\:\/16/d' /etc/gai.conf - case "$PRIORITY" in - 2 ) echo "label 2002::/16 2" >> /etc/gai.conf;; - 3 ) ;; - * ) echo "precedence ::ffff:0:0/96 100" >> /etc/gai.conf;; + if [ "$SYSTEM" != OpenWrt ]; then + [ "$OPTION" = s ] && case "$PRIORITY_SWITCH" in + 4 ) PRIORITY=1 ;; + 6 ) PRIORITY=2 ;; + d ) : ;; + * ) hint "\n $(text 55) \n" && reading " $(text 4) " PRIORITY ;; + esac + + [ -e /etc/gai.conf ] && sed -i '/^precedence \:\:ffff\:0\:0/d;/^label 2002\:\:\/16/d' /etc/gai.conf + case "$PRIORITY" in + 1 ) echo "precedence ::ffff:0:0/96 100" >> /etc/gai.conf ;; + 2 ) echo "label 2002::/16 2" >> /etc/gai.conf ;; + esac + fi +} + +# IPv4 / IPv6 优先结果 +result_priority() { + PRIO=(0 0) + if [ -e /etc/gai.conf ]; then + grep -qsE "^precedence[ ]+::ffff:0:0/96[ ]+100" /etc/gai.conf && PRIO[0]=1 + grep -qsE "^label[ ]+2002::/16[ ]+2" /etc/gai.conf && PRIO[1]=1 + fi + case "${PRIO[*]}" in + '1 0' ) PRIO=4 ;; + '0 1' ) PRIO=6 ;; + * ) [[ "$(curl -ksm8 -A Mozilla $IP_API | grep '"ip"' | sed 's/.*ip\":[ ]*\"\([^"]*\).*/\1/g')" =~ ^([0-9]{1,3}\.){3} ]] && PRIO=4 || PRIO=6 ;; esac + PRIORITY_NOW=$(text_eval 100) + + # 如是快捷方式切换优先级别的话,显示结果 + [ "$OPTION" = s ] && hint "\n $PRIORITY_NOW \n" } need_install() { - [[ $STATUS = 0 ]] && warning " $(text 11) " && reading " $(text 12) " TO_INSTALL + [ "$STATUS" = 0 ] && warning " $(text 11) " && reading " $(text 12) " TO_INSTALL [[ $TO_INSTALL = [Yy] ]] && install } @@ -354,11 +396,11 @@ change_ip() { warning " $(text_eval 13) " cp -f /opt/warp-go/warp.conf{,.tmp1} [ -e /opt/warp-go/License ] && k='+' || k=' free' - until [[ -e /opt/warp-go/warp.conf.tmp2 ]]; do + until [ -e /opt/warp-go/warp.conf.tmp2 ]; do ((b++)) || true - [[ $b -gt $j ]] && rm -f /opt/warp-go/warp.conf.tmp* && error " $(text_eval 50) " + [ "$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 && $b -le $j ]] && 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 @@ -382,14 +424,14 @@ change_ip() { # 设置时区,让时间戳时间准确,显示脚本运行时长,中文为 GMT+8,英文为 UTC; 设置 UA ip_start=$(date +%s) - [[ $SYSTEM != Alpine ]] && ( [[ $L = C ]] && timedatectl set-timezone Asia/Shanghai || timedatectl set-timezone UTC ) + echo "$SYSTEM" | grep -qE "Alpine" && ( [ "$L" = C ] && timedatectl set-timezone Asia/Shanghai || timedatectl set-timezone UTC ) UA_Browser="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.87 Safari/537.36" # 根据 lmc999 脚本检测 Netflix Title,如获取不到,使用兜底默认值 - LMC999=$(curl -sSLm4 https://raw.githubusercontent.com/lmc999/RegionRestrictionCheck/main/check.sh) - RESULT_TITLE=$(echo "$LMC999" | grep "result.*netflix.com/title/" | sed "s/.*title\/\([^\"]*\).*/\1/") - REGION_TITLE=$(echo "$LMC999" | grep "region.*netflix.com/title/" | sed "s/.*title\/\([^\"]*\).*/\1/") - RESULT_TITLE=${RESULT_TITLE:-'81215567'}; REGION_TITLE=${REGION_TITLE:-'80018499'} + #LMC999=$(curl -sSLm4 https://raw.githubusercontent.com/lmc999/RegionRestrictionCheck/main/check.sh) + #RESULT_TITLE=$(echo "$LMC999" | grep "result.*netflix.com/title/" | sed "s/.*title\/\([^\"]*\).*/\1/") + #REGION_TITLE=$(echo "$LMC999" | grep "region.*netflix.com/title/" | sed "s/.*title\/\([^\"]*\).*/\1/") + RESULT_TITLE=${RESULT_TITLE:-'80062035'}; REGION_TITLE=${REGION_TITLE:-'80062035'} # 检测 WARP 单双栈服务 unset T4 T6 @@ -404,18 +446,18 @@ change_ip() { 01 ) NF='6';; 10 ) NF='4';; 11 ) hint "\n $(text 14) \n" && reading " $(text 4) " NETFLIX - NF='4' && [[ $NETFLIX = 2 ]] && NF='6';; + NF='4' && [ "$NETFLIX" = 2 ] && NF='6';; esac # 输入解锁区域 - if [[ -z "$EXPECT" ]]; then - [[ -n "$NF" ]] && REGION=$(tr '[:lower:]' '[:upper:]' <<< $(curl --user-agent "${UA_Browser}" $INTERFACE -$NF -fs --max-time 10 --write-out %{redirect_url} --output /dev/null "https://www.netflix.com/title/$REGION_TITLE" | sed 's/.*com\/\([^-/]\{1,\}\).*/\1/g')) + if [ -z "$EXPECT" ]; then + [ -n "$NF" ] && REGION=$(tr 'a-z' 'A-Z' <<< "$(curl --user-agent "${UA_Browser}" $INTERFACE -$NF -fs --max-time 10 --write-out %{redirect_url} --output /dev/null "https://www.netflix.com/title/$REGION_TITLE" | sed 's/.*com\/\([^-/]\{1,\}\).*/\1/g')") REGION=${REGION:-'US'} reading " $(text_eval 15) " EXPECT - until [[ -z $EXPECT || $EXPECT = [Yy] || $EXPECT =~ ^[A-Za-z]{2}$ ]]; do + until [[ -z "$EXPECT" || "$EXPECT" = [Yy] || "$EXPECT" =~ ^[A-Za-z]{2}$ ]]; do reading " $(text_eval 15) " EXPECT done - [[ -z $EXPECT || $EXPECT = [Yy] ]] && EXPECT="$REGION" + [[ -z "$EXPECT" || "$EXPECT" = [Yy] ]] && EXPECT="$REGION" fi # 解锁检测程序。 i=尝试次数; b=当前账户注册次数; j=注册账户失败的最大次数; l=账户注册失败后等待重试时间 @@ -426,10 +468,10 @@ change_ip() { 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 WAN=$(eval echo \$WAN$NF) && ASNORG=$(eval echo \$ASNORG$NF) - [[ $L = C ]] && COUNTRY=$(translate "$(eval echo \$COUNTRY$NF)") || COUNTRY=$(eval echo \$COUNTRY$NF) + [ "$L" = C ] && COUNTRY=$(translate "$(eval echo \$COUNTRY$NF)") || COUNTRY=$(eval echo \$COUNTRY$NF) RESULT=$(curl --user-agent "${UA_Browser}" $INTERFACE -$NF -fsL --write-out %{http_code} --output /dev/null --max-time 10 "https://www.netflix.com/title/$RESULT_TITLE" 2>&1) - if [[ $RESULT = 200 ]]; then - REGION=$(tr '[:lower:]' '[:upper:]' <<< $(curl --user-agent "${UA_Browser}" $INTERFACE -$NF -fs --max-time 10 --write-out %{redirect_url} --output /dev/null "https://www.netflix.com/title/$REGION_TITLE" | sed 's/.*com\/\([^-/]\{1,\}\).*/\1/g')) + if [ "$RESULT" = 200 ]; then + REGION=$(tr 'a-z' 'A-Z' <<< "$(curl --user-agent "${UA_Browser}" $INTERFACE -$NF -fs --max-time 10 --write-out %{redirect_url} --output /dev/null "https://www.netflix.com/title/$REGION_TITLE" | sed 's/.*com\/\([^-/]\{1,\}\).*/\1/g')") REGION=${REGION:-'US'} echo "$REGION" | grep -qi "$EXPECT" && info " $(text_eval 16) " && rm -f /opt/warp-go/warp.conf.tmp1 && i=0 && sleep 1h || warp_restart else warp_restart @@ -449,11 +491,11 @@ uninstall() { kill -15 $(pgrep warp-go) >/dev/null 2>&1 /opt/warp-go/warp-go --config=/opt/warp-go/warp.conf --remove >/dev/null 2>&1 rm -rf /opt/warp-go /lib/systemd/system/warp-go.service /usr/bin/warp-go - [[ -e /opt/warp-go/tun.sh ]] && rm -f /opt/warp-go/tun.sh && sed -i '/tun.sh/d' /etc/crontab + [ -e /opt/warp-go/tun.sh ] && rm -f /opt/warp-go/tun.sh && sed -i '/tun.sh/d' /etc/crontab # 显示卸载结果 - ip4_info; [[ $L = C && -n "$COUNTRY4" ]] && COUNTRY4=$(translate "$COUNTRY4") - ip6_info; [[ $L = C && -n "$COUNTRY6" ]] && COUNTRY6=$(translate "$COUNTRY6") + ip4_info; [[ "$L" = C && -n "$COUNTRY4" ]] && COUNTRY4=$(translate "$COUNTRY4") + ip6_info; [[ "$L" = C && -n "$COUNTRY6" ]] && COUNTRY6=$(translate "$COUNTRY6") info " $(text 17)\n IPv4: $WAN4 $COUNTRY4 $ASNORG4\n IPv6: $WAN6 $COUNTRY6 $ASNORG6 " } @@ -472,17 +514,17 @@ net() { 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 59) " - ${SYSTEMCTL_RESTART[int]} - sleep 5 + [ "$KEEP_FREE" != 1 ] && ${SYSTEMCTL_RESTART[int]} + sleep 1 ip4_info; ip6_info - until [[ $TRACE4$TRACE6 =~ on|plus ]]; do + until [[ "$TRACE4$TRACE6" =~ on|plus ]]; do (( i++ )) || true hint " $(text_eval 59) " ${SYSTEMCTL_RESTART[int]} - sleep 5 + sleep 1 ip4_info; ip6_info - if [[ $i = "$j" ]]; then - if [[ -e /opt/warp-go/warp.conf.tmp1 ]]; then + if [[ "$i" = "$j" ]]; then + if [ -e /opt/warp-go/warp.conf.tmp1 ]; then i=0 && info " $(text 22) " && mv -f /opt/warp-go/warp.conf.tmp1 /opt/warp-go/warp.conf else @@ -493,28 +535,28 @@ net() { done ACCOUNT_TYPE=$(grep "Type" /opt/warp-go/warp.conf | cut -d= -f2 | sed "s# ##g") - [[ $ACCOUNT_TYPE = 'plus' ]] && check_quota - [[ $WARP_STACK = 4 ]] || grep -q '#AllowedIPs' /opt/warp-go/warp.conf && GLOBAL_TYPE="$(text 24)" + [ "$ACCOUNT_TYPE" = 'plus' ] && check_quota + [ "$WARP_STACK" = 4 ] || grep -q '#AllowedIPs' /opt/warp-go/warp.conf && GLOBAL_TYPE="$(text 24)" info " $(text_eval 25) " - [[ $L = C ]] && COUNTRY4=$(translate "$COUNTRY4") - [[ $L = C ]] && COUNTRY6=$(translate "$COUNTRY6") - [[ $OPTION = o ]] && info " IPv4: $WAN4 $WARPSTATUS4 $COUNTRY4 $ASNORG4\n IPv6: $WAN6 $WARPSTATUS6 $COUNTRY6 $ASNORG6 " - [[ -n "$QUOTA" ]] && info " $(text 26): $QUOTA " + [ "$L" = C ] && COUNTRY4=$(translate "$COUNTRY4") + [ "$L" = C ] && COUNTRY6=$(translate "$COUNTRY6") + [ "$OPTION" = o ] && info " IPv4: $WAN4 $WARPSTATUS4 $COUNTRY4 $ASNORG4\n IPv6: $WAN6 $WARPSTATUS6 $COUNTRY6 $ASNORG6 " + [ -n "$QUOTA" ] && info " $(text 26): $QUOTA " } # WARP 开关,先检查是否已安装,再根据当前状态转向相反状态 onoff() { case "$STATUS" in - 0 ) need_install;; - 1 ) net;; - 2 ) ${SYSTEMCTL_STOP[int]}; info " $(text 27) ";; + 0 ) need_install ;; + 1 ) net ;; + 2 ) ${SYSTEMCTL_STOP[int]}; info " $(text 27) " ;; esac } # 检查系统 WARP 单双栈情况。为了速度,先检查 warp-go 配置文件里的情况,再判断 trace check_stack() { - if [[ -e /opt/warp-go/warp.conf ]]; then + if [ -e /opt/warp-go/warp.conf ]; then if grep -q "^#AllowedIPs" /opt/warp-go/warp.conf; then T4=2 else @@ -526,7 +568,7 @@ check_stack() { case "$TRACE6" in off ) T6='0';; 'on'|'plus' ) T6='1';; esac fi CASE=("@0" "0@" "0@0" "@1" "0@1" "1@" "1@0" "1@1" "2@") - for ((m=0;m<${#CASE[@]};m++)); do [[ $T4@$T6 = ${CASE[m]} ]] && break; done + for ((m=0;m<${#CASE[@]};m++)); do [[ "$T4@$T6" = "${CASE[m]}" ]] && break; done WARP_BEFORE=("" "" "" "WARP $(text 99) IPv6 only" "WARP $(text 99) IPv6" "WARP $(text 99) IPv4 only" "WARP $(text 99) IPv4" "$(text 96)" "WARP $(text 98) IPv4") WARP_AFTER1=("" "" "" "WARP $(text 99) IPv4" "WARP $(text 99) IPv4" "WARP $(text 99) IPv6" "WARP $(text 99) IPv6" "WARP $(text 99) IPv4" "WARP $(text 99) IPv4") WARP_AFTER2=("" "" "" "$(text 96)" "$(text 96)" "$(text 96)" "$(text 96)" "WARP $(text 99) IPv6" "$(text 96)") @@ -548,17 +590,17 @@ check_stack() { # 检查全局状态 check_global() { - [[ -e /opt/warp-go/warp.conf ]] && grep -q '#AllowedIPs' /opt/warp-go/warp.conf && NON_GLOBAL=1 + [ -e /opt/warp-go/warp.conf ] && grep -q '#AllowedIPs' /opt/warp-go/warp.conf && NON_GLOBAL=1 } # 单双栈在线互换。先看菜单是否有选择,再看传参数值,再没有显示2个可选项 stack_switch() { need_install check_global - if [[ $NON_GLOBAL = 1 ]]; then - if [[ $CHOOSE != [12] ]]; then + if [ "$NON_GLOBAL" = 1 ]; then + if [[ "$CHOOSE" != [12] ]]; then warning " $(text 28) " && reading " $(text 29) " TO_GLOBAL - [[ $TO_GLOBAL != [Yy] ]] && exit 0 || global_switch + [[ "$TO_GLOBAL" != [Yy] ]] && exit 0 || global_switch else global_switch fi @@ -574,10 +616,10 @@ stack_switch() { check_stack - if [[ $CHOOSE = [12] ]]; then + if [[ "$CHOOSE" = [12] ]]; then TO=$(eval echo \${TO$CHOOSE[m]}) - elif [[ $SWITCHCHOOSE = [46D] ]]; then - if [[ $TO_GLOBAL = [Yy] ]]; then + elif [[ "$SWITCHCHOOSE" = [46D] ]]; then + if [[ "$TO_GLOBAL" = [Yy] ]]; then if [[ "$T4@$T6@$SWITCHCHOOSE" =~ '1@0@4'|'0@1@6'|'1@1@D' ]]; then grep -q "^AllowedIPs.*0\.\0\/0" /opt/warp-go/warp.conf || unset INTERFACE OPTION=o && net @@ -600,7 +642,7 @@ stack_switch() { fi [ "${#TO}" != 3 ] && error " $(text 10) " || sh -c "$(eval echo "\$SWITCH$TO")" - ${SYSTEMCTL_RESTART[int]} + ${SYSTEMCTL_RESTART[int]}; sleep 1 grep -q "^AllowedIPs.*0\.\0\/0" /opt/warp-go/warp.conf || unset INTERFACE OPTION=o && net } @@ -608,7 +650,7 @@ stack_switch() { # 全局 / 非全局在线互换 global_switch() { # 如状态不是安装中,则检测是否已安装 warp-go,如已安装,则停止 systemd - if [ $STATUS != 3 ]; then + if [ "$STATUS" != 3 ]; then need_install ${SYSTEMCTL_STOP[int]} fi @@ -621,7 +663,7 @@ global_switch() { fi # 如状态不是安装中,不是非全局转换到全局时的快捷或菜单选择情况。则开始 systemd, - if [[ $STATUS != 3 && $TO_GLOBAL != [Yy] && $CHOOSE != [12] ]]; then + if [[ "$STATUS" != 3 && "$TO_GLOBAL" != [Yy] && "$CHOOSE" != [12] ]]; then ${SYSTEMCTL_START[int]} OPTION=o && net fi @@ -632,8 +674,8 @@ check_system_info() { info " $(text 35) " # 必须加载 TUN 模块,先尝试在线打开 TUN。尝试成功放到启动项,失败作提示并退出脚本 - TUN=$(cat /dev/net/tun 2>&1 | tr '[:upper:]' '[:lower:]') - if [[ ! $TUN =~ 'in bad state' ]] && [[ ! $TUN =~ '处于错误状态' ]] && [[ ! $TUN =~ 'Die Dateizugriffsnummer ist in schlechter Verfassung' ]]; then + TUN=$(cat /dev/net/tun 2>&1 | tr 'A-Z' 'a-z') + if [[ ! "$TUN" =~ 'in bad state' ]] && [[ ! "$TUN" =~ '处于错误状态' ]] && [[ ! "$TUN" =~ 'Die Dateizugriffsnummer ist in schlechter Verfassung' ]]; then mkdir -p /opt/warp-go/ >/dev/null 2>&1 cat >/opt/warp-go/tun.sh << EOF #!/usr/bin/env bash @@ -642,178 +684,200 @@ mknod /dev/net/tun c 10 200 chmod 0666 /dev/net/tun EOF bash /opt/warp-go/tun.sh - TUN=$(cat /dev/net/tun 2>&1 | tr '[:upper:]' '[:lower:]') - if [[ ! $TUN =~ 'in bad state' ]] && [[ ! $TUN =~ '处于错误状态' ]] && [[ ! $TUN =~ 'Die Dateizugriffsnummer ist in schlechter Verfassung' ]]; then + TUN=$(cat /dev/net/tun 2>&1 | tr 'A-Z' 'a-z') + if [[ ! "$TUN" =~ 'in bad state' ]] && [[ ! "$TUN" =~ '处于错误状态' ]] && [[ ! "$TUN" =~ 'Die Dateizugriffsnummer ist in schlechter Verfassung' ]]; then rm -f /usr/bin/tun.sh && error "$(text 36)" else chmod +x /opt/warp-go/tun.sh - [ $SYSTEM != Alpine ] && echo "@reboot root bash /opt/warp-go/tun.sh" >> /etc/crontab + echo "$SYSTEM" | grep -qvE "Alpine|OpenWrt" && echo "@reboot root bash /opt/warp-go/tun.sh" >> /etc/crontab fi 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 - [[ "$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 + LAN4=$(ip route get 192.168.193.10 2>/dev/null | awk '{for (i=0; i/dev/null | awk '{for (i=0; i/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 + if grep -qE "^AllowedIPs.*\:\:\/0" /opt/warp-go/warp.conf || [ "$INET6" = 1 ]; then IPV6=1 && CDN=-6 && ip6_info else IPV6=0 fi if grep -qE "^AllowedIPs.*0\.\0\/0|^#AllowedIPs" /opt/warp-go/warp.conf; then INTERFACE='--interface WARP' && IPV4=1 && CDN=-4 && ip4_info - elif [[ "$INET4" = 1 ]]; then + elif [ "$INET4" = 1 ]; then IPV4=1 && CDN=-4 && ip4_info else IPV4=0 fi fi - [[ $L = C && -n "$COUNTRY4" ]] && COUNTRY4=$(translate "$COUNTRY4") - [[ $L = C && -n "$COUNTRY6" ]] && COUNTRY6=$(translate "$COUNTRY6") + [[ "$L" = C && -n "$COUNTRY4" ]] && COUNTRY4=$(translate "$COUNTRY4") + [[ "$L" = C && -n "$COUNTRY6" ]] && COUNTRY6=$(translate "$COUNTRY6") # 判断处理器架构 case $(uname -m) in - aarch64 ) ARCHITECTURE=arm64;; - x86) ARCHITECTURE=386;; + aarch64 ) ARCHITECTURE=arm64 ;; + x86) ARCHITECTURE=386 ;; x86_64 ) CPU_FLAGS=$(cat /proc/cpuinfo | grep flags | head -n 1 | cut -d: -f2) case "$CPU_FLAGS" in - *avx512* ) ARCHITECTURE=amd64v4;; - *avx2* ) ARCHITECTURE=amd64v3;; - *sse3* ) ARCHITECTURE=amd64v2;; - * ) ARCHITECTURE=amd64;; - esac;; - s390x ) ARCHITECTURE=s390x;; - * ) error " $(text_eval 37) ";; + *avx512* ) ARCHITECTURE=amd64v4 ;; + *avx2* ) ARCHITECTURE=amd64v3 ;; + *sse3* ) ARCHITECTURE=amd64v2 ;; + * ) ARCHITECTURE=amd64 ;; + esac ;; + s390x ) ARCHITECTURE=s390x ;; + * ) error " $(text_eval 37) " ;; esac # 判断当前 IPv4 与 IPv6 ,IP归属 - [[ $STATUS = 2 ]] && grep -qE "^AllowedIPs[ ]+=.*0\.\0\/0|#AllowedIPs" /opt/warp-go/warp.conf && INTERFACE='--interface WARP' - [[ $IPV4 = 1 ]] && ip4_info - [[ $IPV6 = 1 ]] && ip6_info - [[ $L = C && -n "$COUNTRY4" ]] && COUNTRY4=$(translate "$COUNTRY4") - [[ $L = C && -n "$COUNTRY6" ]] && COUNTRY6=$(translate "$COUNTRY6") + [ "$STATUS" = 2 ] && grep -qE "^AllowedIPs[ ]+=.*0\.\0\/0|#AllowedIPs" /opt/warp-go/warp.conf && INTERFACE='--interface WARP' + [ "$IPV4" = 1 ] && ip4_info + [ "$IPV6" = 1 ] && ip6_info + [[ "$L" = C && -n "$COUNTRY4" ]] && COUNTRY4=$(translate "$COUNTRY4") + [[ "$L" = C && -n "$COUNTRY6" ]] && COUNTRY6=$(translate "$COUNTRY6") } # 输入 WARP+ 账户(如有),限制位数为空或者26位以防输入错误 input_license() { - [[ -z $LICENSE ]] && reading " $(text 38) " LICENSE + [ -z "$LICENSE" ] && reading " $(text 38) " LICENSE i=5 - until [[ -z $LICENSE || $LICENSE =~ ^[A-Z0-9a-z]{8}-[A-Z0-9a-z]{8}-[A-Z0-9a-z]{8}$ ]]; do + until [[ -z "$LICENSE" || "$LICENSE" =~ ^[A-Z0-9a-z]{8}-[A-Z0-9a-z]{8}-[A-Z0-9a-z]{8}$ ]]; do (( i-- )) || true - [[ $i = 0 ]] && error "$(text 39)" || reading " $(text_eval 40) " LICENSE + [ "$i" = 0 ] && error "$(text 39)" || reading " $(text_eval 40) " LICENSE done - [[ -n $LICENSE && -z $NAME ]] && reading " $(text 41) " NAME - [[ -n $NAME ]] && NAME="${NAME//[[:space:]]/_}" || NAME=${NAME:-'warp-go'} + [[ -n "$LICENSE" && -z "$NAME" ]] && reading " $(text 41) " NAME + [ -n "$NAME" ] && NAME="${NAME//[[:space:]]/_}" || NAME="${NAME:-'warp-go'}" } # 升级 WARP+ 账户(如有),限制位数为空或者26位以防输入错误,WARP interface 可以自定义设备名(不允许字符串间有空格,如遇到将会以_代替) update_license() { - [[ -z $LICENSE ]] && reading " $(text 42) " LICENSE + [ -z "$LICENSE" ] && reading " $(text 42) " LICENSE i=5 - until [[ $LICENSE =~ ^[A-Z0-9a-z]{8}-[A-Z0-9a-z]{8}-[A-Z0-9a-z]{8}$ ]]; do + until [[ "$LICENSE" =~ ^[A-Z0-9a-z]{8}-[A-Z0-9a-z]{8}-[A-Z0-9a-z]{8}$ ]]; do (( i-- )) || true - [[ $i = 0 ]] && error "$(text 39)" || reading " $(text_eval 43) " LICENSE + [ "$i" = 0 ] && error "$(text 39)" || reading " $(text_eval 43) " LICENSE done - [[ -n $LICENSE && -z $NAME ]] && reading " $(text 41) " NAME - [[ -n $NAME ]] && NAME="${NAME//[[:space:]]/_}" || NAME=${NAME:-'warp-go'} + [[ -n "$LICENSE" && -z "$NAME" ]] && reading " $(text 41) " NAME + [ -n "$NAME" ] && NAME="${NAME//[[:space:]]/_}" || NAME="${NAME:-'warp-go'}" } # 输入 Teams 账户 token(如有),如果 TOKEN 以 com.cloudflare.warp 开头,将自动删除多余部分 input_token() { - [[ -z $TOKEN ]] && reading " $(text 44) " TOKEN + [ -z "$TOKEN" ] && reading " $(text 44) " TOKEN i=5 - until [[ -z $TOKEN || "${#TOKEN}" -ge "$TOKEN_LENGTH" ]]; do + until [[ -z "$TOKEN" || "${#TOKEN}" -ge "$TOKEN_LENGTH" ]]; do (( i-- )) || true - [[ $i = 0 ]] && error "$(text 39)" || reading " $(text_eval 45) " TOKEN + [ "$i" = 0 ] && error "$(text 39)" || reading " $(text_eval 45) " TOKEN done } # 免费 WARP 账户升级 WARP+ 或 Teams 账户 update() { need_install - [[ ! -e /opt/warp-go/warp.conf ]] && error "$(text 46)" + [ ! -e /opt/warp-go/warp.conf ] && error "$(text 21)" ACCOUNT_TYPE=$(grep "Type" /opt/warp-go/warp.conf | cut -d= -f2 | sed "s# ##g") case "$ACCOUNT_TYPE" in - plus ) check_quota && error " $(text_eval 47) ";; - team ) error " $(text_eval 48) ";; + free ) CHANGE_TYPE=$(text 47) ;; + team ) CHANGE_TYPE=$(text 48) ;; + plus ) CHANGE_TYPE=$(text 49) + check_quota + [[ "$QUOTA" =~ '.' ]] && PLUS_QUOTA="\\n $(text 26): $QUOTA" ;; esac - [[ -z $LICENSETYPE ]] && hint "\n $(text 49) \n" && reading " $(text 4) " LICENSETYPE - case $LICENSETYPE in - 1 ) update_license - if [[ -n $LICENSE ]]; then + [ -z "$LICENSETYPE" ] && hint "\n $(text_eval 46) \n" && reading " $(text 4) " LICENSETYPE + case "$LICENSETYPE" in + 1|2 ) unset QUOTA + case "$LICENSETYPE" in + 1 ) k=' free' + [ "$ACCOUNT_TYPE" = free ] && KEEP_FREE='1' + [ -e /opt/warp-go/Device_Name ] && rm -f /opt/warp-go/Device_Name + if [ "$ACCOUNT_TYPE" = free ]; then + OPTION=o && net + exit 0 + fi + ;; + 2 ) k='+' + update_license + ;; + esac 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='+' + [ -e /opt/warp-go/warp.conf ] && rm -f /opt/warp-go/warp.conf + i=0; j=5 hint " $(text_eval 58) " - until [[ -e /opt/warp-go/warp.conf ]]; do + until [ -e /opt/warp-go/warp.conf ]; do ((i++)) || true - [[ $i -gt $j ]] && rm -f /opt/warp-go/warp.conf.tmp && error " $(text_eval 50) " + [ "$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 + [[ "$?" != 0 && "$i" -lt "$j" ]] && sleep 30 || + ( [ -n "$LICENSE" ] && 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 + rm -f /opt/warp-go/warp.conf.tmp1 mv -f /opt/warp-go/warp.conf.tmp2 /opt/warp-go/warp.conf - grep -qE 'Type[ ]+=[ ]+plus' /opt/warp-go/warp.conf && echo $NAME > /opt/warp-go/Device_Name - check_quota + grep -qE 'Type[ ]+=[ ]+plus' /opt/warp-go/warp.conf && echo "$NAME" > /opt/warp-go/Device_Name OPTION=o && net - fi;; - - 2 ) input_token - if [[ -n $TOKEN ]]; then + ;; + 3 ) unset QUOTA + input_token + if [ -n "$TOKEN" ]; then i=0; j=5; k=' teams' hint " $(text_eval 58) " - until [[ -e /opt/warp-go/warp.conf.tmp ]]; do + until [ -e /opt/warp-go/warp.conf.tmp ]; do ((i++)) || true - [[ $i -gt $j ]] && rm -f /opt/warp-go/warp.conf.tmp && error " $(text_eval 50) " + [ "$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 + [ "$?" != 0 ] && sleep 30 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 rm -f /opt/warp-go/warp.conf.tmp else - sed -i "s#.*Device.*#Device = FSCARMEN-WARP-SHARE-TEAM#g; s#.*PrivateKey.*#PrivateKey = SHVqHEGI7k2+OQ/oWMmWY2EQObbRQjRBdDPimh0h1WY=#g; s#.*Token.*#Token = SB-KKKYG-YGKKK-SB#g; s#.*Type.*#Type = team#g" /opt/warp-go/warp.conf + sed -i "s#.*Device.*#Device = FSCARMEN-WARP-SHARE-TEAM#g; s#.*PrivateKey.*#PrivateKey = SHVqHEGI7k2+OQ/oWMmWY2EQObbRQjRBdDPimh0h1WY=#g; s#.*Token.*#Token = SB-MISAKANO-ZZY-SB#g; s#.*Type.*#Type = team#g" /opt/warp-go/warp.conf fi - OPTION=o && net;; - - * ) warning " $(text 34) [1-2] "; sleep 1; unset LICENSETYPE; update;; + OPTION=o && net + ;; + 0 ) unset LICENSETYPE + menu + ;; + * ) warning " $(text 34) [0-3] "; sleep 1; unset LICENSETYPE; update;; esac } -# 输出 wgcf 配置文件 -export_wireguard() { - if [[ ! -e /opt/warp-go/wgcf.conf ]]; then - if [[ -e /opt/warp-go/warp-go ]]; then - if [[ -e /opt/warp-go/warp.conf ]]; then - /opt/warp-go/warp-go --config=/opt/warp-go/warp.conf --export-wireguard=/opt/warp-go/wgcf.conf >/dev/null 2>&1 - else - /opt/warp-go/warp-go --register --config=/opt/warp-go/warp.conf --team-config "$TOKEN" >/dev/null 2>&1 - /opt/warp-go/warp-go --config=/opt/warp-go/warp.conf --export-wireguard=/opt/warp-go/wgcf.conf >/dev/null 2>&1 - fi - else - error "$(text 51)" - fi +# 输出 wireguard 和 sing-box 配置文件 +export_file() { + if [ -e /opt/warp-go/warp-go ]; then + PY=("python3" "python" "python2") + for g in "${PY[@]}"; do [ $(type -p $g) ] && PYTHON=$g && break; done + [ -z "$PYTHON" ] && PYTHON=python3 && ${PACKAGE_INSTALL[int]} $PYTHON + [ ! -e /opt/warp-go/warp.conf ] && /opt/warp-go/warp-go --register --config=/opt/warp-go/warp.conf --team-config "$TOKEN" >/dev/null 2>&1 + /opt/warp-go/warp-go --config=/opt/warp-go/warp.conf --export-wireguard=/opt/warp-go/wgcf.conf >/dev/null 2>&1 + /opt/warp-go/warp-go --config=/opt/warp-go/warp.conf --export-singbox=/opt/warp-go/singbox.json >/dev/null 2>&1 + else + error "$(text 51)" fi - info " $(text 52) " + info "\n $(text 52) " cat /opt/warp-go/wgcf.conf echo -e "\n\n" + + info " $(text 101) " + cat /opt/warp-go/singbox.json | $PYTHON -m json.tool + echo -e "\n\n" } # warp-go 安装 install() { # 已经状态码不为 0, 即已安装, 脚本退出 - [[ $STATUS != 0 ]] && error "$(text 53)" + [ "$STATUS" != 0 ] && error "$(text 53)" # CONF 参数如果不是3位或4位, 即检测不出正确的配置参数, 脚本退出 [[ "${#CONF}" != [34] ]] && error " $(text 10) " @@ -822,43 +886,44 @@ install() { rm -rf /opt/warp-go/warp-go /opt/warp-go/warp.conf # 询问是否有 WARP+ 或 Teams 账户 - [[ -z $LICENSETYPE ]] && hint "\n $(text 54) \n" && reading " $(text 4) " LICENSETYPE - case $LICENSETYPE in - 1 ) input_license;; - 2 ) input_token;; + [ -z "$LICENSETYPE" ] && hint "\n $(text 54) \n" && reading " $(text 4) " LICENSETYPE + case "$LICENSETYPE" in + 1 ) input_license ;; + 2 ) input_token ;; esac # 选择优先使用 IPv4 /IPv6 网络 - [[ -z $PRIORITY ]] && hint "\n $(text 55) \n" && reading " $(text 4) " PRIORITY + [ -z "$PRIORITY" ] && hint "\n $(text 55) \n" && reading " $(text 4) " PRIORITY # 脚本开始时间 start=$(date +%s) # 注册 WARP 账户 (将生成 warp 文件保存账户信息) - # 判断 warp-go 的最新版本,如因 gitlab 接口问题未能获取,默认 v1.0.5 + # 判断 warp-go 的最新版本,如因 gitlab 接口问题未能获取,默认 v1.0.6 { - latest=$(wget -qO- -T1 -t1 https://gitlab.com/api/v4/projects/ProjectWARP%2Fwarp-go/releases | grep -oP '"tag_name":"v\K[^\"]+' | head -n 1) - latest=${latest:-'1.0.5'} + latest=$(wget -qO- -T1 -t1 https://gitlab.com/api/v4/projects/ProjectWARP%2Fwarp-go/releases | awk -F '"' '{for (i=0; i/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://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)" + wget -T20 -t1 --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 -T20 -t2 --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)" + [ $(type -p tar) ] || ${PACKAGE_INSTALL[int]} tar 2>/dev/null || ( ${PACKAGE_UPDATE[int]}; ${PACKAGE_INSTALL[int]} tar 2>/dev/null ) 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 + [ ! -e /opt/warp-go/warp-go ] && error "$(text 57)" || chmod +x /opt/warp-go/warp-go rm -f /opt/warp-go/warp-go_"$latest"_linux_"$ARCHITECTURE".tar.gz # 注册用户自定义 token 的 Teams 账户 - if [[ $LICENSETYPE = 2 ]]; then - if [[ -n $TOKEN ]]; then + if [ "$LICENSETYPE" = 2 ]; then + if [ -n "$TOKEN" ]; then i=0; j=5; k=' teams' hint " $(text_eval 58) " - until [[ -e /opt/warp-go/warp.conf ]]; do + until [ -e /opt/warp-go/warp.conf ]; do ((i++)) || true - [[ $i -gt $j ]] && error " $(text_eval 50) " + [ "$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 + [[ "$?" != 0 && "$i" -lt "$j" ]] && sleep 30 done # 注册公用 token 的 Teams 账户 @@ -867,7 +932,7 @@ install() { [Account] Device = FSCARMEN-WARP-SHARE-TEAM PrivateKey = SHVqHEGI7k2+OQ/oWMmWY2EQObbRQjRBdDPimh0h1WY= -Token = SB-KKKYG-YGKKK-SB +Token = SB-MISAKANO-ZZY-SB Type = team [Peer] @@ -887,11 +952,11 @@ EOF i=0; j=5 [ -n "$LICENSE" ] && k='+' || k=' free' hint " $(text_eval 58) " - until [[ -e /opt/warp-go/warp.conf ]]; do + until [ -e /opt/warp-go/warp.conf ]; do ((i++)) || true - [[ $i -gt $j ]] && error " $(text_eval 50) " + [ "$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 + [[ "$?" != 0 && "$i" -lt "$j" ]] && sleep 30 done fi @@ -918,7 +983,7 @@ EOF # 对于 IPv4 only VPS 开启 IPv6 支持 { - [[ $IPV4$IPV6 = 10 ]] && [[ $(sysctl -a 2>/dev/null | grep 'disable_ipv6.*=.*1') || $(grep -s "disable_ipv6.*=.*1" /etc/sysctl.{conf,d/*} ) ]] && + [ "$IPV4$IPV6" = 10 ] && [[ $(sysctl -a 2>/dev/null | grep 'disable_ipv6.*=.*1') || $(grep -s "disable_ipv6.*=.*1" /etc/sysctl.{conf,d/*} ) ]] && (sed -i '/disable_ipv6/d' /etc/sysctl.{conf,d/*} echo 'net.ipv6.conf.all.disable_ipv6 = 0' >/etc/sysctl.d/ipv6.conf sysctl -w net.ipv6.conf.all.disable_ipv6=0) @@ -930,17 +995,10 @@ EOF # 根据系统选择需要安装的依赖, 安装一些必要的网络工具包 info "\n $(text 61) \n" - Debian() { :; } - - Ubuntu() { :; } - - CentOS() { :; } - - Alpine() { ${PACKAGE_INSTALL[int]} openrc; } - - Arch() { ${PACKAGE_INSTALL[int]} openresolv; } - - $SYSTEM + case "$SYSTEM" in + Alpine ) ${PACKAGE_INSTALL[int]} openrc ;; + Arch ) ${PACKAGE_INSTALL[int]} openresolv ;; + esac wait @@ -964,10 +1022,10 @@ EOF sh -c "$(eval echo "\$MODIFY$CONF")" # 如为 WARP IPv4 非全局,修改配置文件,在路由表插入规则 - [[ $WARP_STACK = 4 || $OPTION = n ]] && STATUS=3 && global_switch + [[ "$WARP_STACK" = 4 || "$OPTION" = n ]] && STATUS=3 && global_switch # 创建 warp-go systemd 进程守护(Alpine 系统除外) - if [[ $SYSTEM != Alpine ]]; then + if echo "$SYSTEM" | grep -qvE "Alpine|OpenWrt"; then cat > /lib/systemd/system/warp-go.service << EOF [Unit] Description=warp-go service @@ -999,19 +1057,22 @@ EOF ln -sf /opt/warp-go/warp-go.sh /usr/bin/warp-go echo "$L" > /opt/warp-go/language - # 结果提示,脚本运行时间,次数统计 + # 结果提示,脚本运行时间,次数统计,IPv4 / IPv6 优先级别 + [ "$(curl -ksm8 https://$IP_API)" = "$WAN6" ] && PRIO=6 || PRIO=4 end=$(date +%s) ACCOUNT_TYPE=$(grep "Type" /opt/warp-go/warp.conf | cut -d= -f2 | sed "s# ##g") - [[ $ACCOUNT_TYPE = 'plus' ]] && check_quota + [ "$ACCOUNT_TYPE" = 'plus' ] && check_quota + result_priority echo -e "\n==============================================================\n" info " IPv4: $WAN4 $WARPSTATUS4 $COUNTRY4 $ASNORG4 " info " IPv6: $WAN6 $WARPSTATUS6 $COUNTRY6 $ASNORG6 " info " $(text_eval 62) " [[ -n "$QUOTA" ]] && info " $(text 26): $QUOTA " + info " $PRIORITY_NOW " echo -e "\n==============================================================\n" hint " $(text 95)\n " && help - [[ $TRACE4$TRACE6 = offoff ]] && warning " $(text 63) " + [ "$TRACE4$TRACE6" = offoff ] && warning " $(text 63) " exit } @@ -1021,18 +1082,26 @@ 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) + QUOTA=$(sed 's/.*quota":\([^,]\+\).*/\1/g' <<< $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 - [[ $QUOTA -gt 10000000000000 ]] && QUOTA="$((QUOTA/1000000000000)) TB" || QUOTA="$((QUOTA/1000000000)) GB" + + # 部分系统没有依赖 bc,所以两个小数不能用 $(echo "scale=2; $QUOTA/1000000000000000" | bc),改为从右往左数字符数的方法 + if [[ "$QUOTA" != 0 && "$QUOTA" =~ ^[0-9]+$ && "$QUOTA" -ge 1000000000 ]]; then + CONVERSION=("1000000000000000000" "1000000000000000" "1000000000000" "1000000000") + UNIT=("EB" "PB" "TB" "GB") + for ((o=0; o<${#CONVERSION[*]}; o++)); do + [[ "$QUOTA" -ge "${CONVERSION[o]}" ]] && break + done + + QUOTA_INTEGER=$(( $QUOTA / ${CONVERSION[o]} )) + QUOTA_DECIMALS=${QUOTA:0-$(( ${#CONVERSION[o]} - 1 )):2} + QUOTA="$QUOTA_INTEGER.$QUOTA_DECIMALS ${UNIT[o]}" fi } # 判断当前 WARP 网络接口及 Client 的运行状态,并对应的给菜单和动作赋值 menu_setting() { - if [[ $STATUS = 0 ]]; then + if [ "$STATUS" = 0 ]; then OPTION1="$(text_eval 64)" OPTION2="$(text_eval 65)" OPTION3="$(text_eval 66)" @@ -1050,8 +1119,8 @@ menu_setting() { ACTION7() { CONF=${CONF3[n]}; PRIORITY=1; WARP_STACK=4; install; } ACTION8() { CONF=${CONF3[n]}; PRIORITY=2; WARP_STACK=4; install; } else - [[ $NON_GLOBAL = 1 ]] || GLOBAL_AFTER="$(text 24)" - [[ $STATUS = 2 ]] && ON_OFF="$(text 72)" || ON_OFF="$(text 73)" + [ "$NON_GLOBAL" = 1 ] || GLOBAL_AFTER="$(text 24)" + [ "$STATUS" = 2 ] && ON_OFF="$(text 72)" || ON_OFF="$(text 73)" OPTION1="$(text_eval 74)" OPTION2="$(text_eval 75)" OPTION3="$(text_eval 76)" @@ -1067,7 +1136,7 @@ menu_setting() { ACTION4() { OPTION=o; onoff; } ACTION5() { update; } ACTION6() { change_ip; } - ACTION7() { export_wireguard; } + ACTION7() { export_file; } ACTION8() { uninstall; } fi @@ -1076,8 +1145,8 @@ menu_setting() { ACTION0() { exit; } ACTION9() { ver; } - [[ -e /opt/warp-go/warp.conf ]] && TYPE=$(grep "Type" /opt/warp-go/warp.conf | cut -d= -f2 | sed "s# ##g") && - [[ $TYPE = plus ]] && check_quota && PLUSINFO="$(text 83): $(cat /opt/warp-go/Device_Name)\t $(text 26): $QUOTA" + [ -e /opt/warp-go/warp.conf ] && TYPE=$(grep "Type" /opt/warp-go/warp.conf | cut -d= -f2 | sed "s# ##g") && + [ "$TYPE" = plus ] && check_quota && PLUSINFO="$(text 83): $(cat /opt/warp-go/Device_Name)\t $(text 26): $QUOTA" } # 显示菜单 @@ -1088,21 +1157,21 @@ menu() { info " $(text 84): $VERSION\t $(text 85): $(text 1)\n $(text 86):\n\t $(text 87): $SYS\n\t $(text 88): $(uname -r)\n\t $(text 89): $ARCHITECTURE\n\t $(text 90): $VIRT " info "\t IPv4: $WAN4 $WARPSTATUS4 $COUNTRY4 $ASNORG4 " info "\t IPv6: $WAN6 $WARPSTATUS6 $COUNTRY6 $ASNORG6 " - if [[ $STATUS = 2 ]]; then + if [ "$STATUS" = 2 ]; then info "\t $(text_eval 91) " grep -q '#AllowedIPs' /opt/warp-go/warp.conf && GLOBAL_TYPE="$(text 24)" info "\t $(text_eval 92) " else info "\t $(text 93) " fi - [[ -n "$PLUSINFO" ]] && info "\t $PLUSINFO " + [ -n "$PLUSINFO" ] && info "\t $PLUSINFO " echo -e "\n======================================================================================================================\n" info " 1. $OPTION1\n 2. $OPTION2\n 3. $OPTION3\n 4. $OPTION4\n 5. $OPTION5\n 6. $OPTION6\n 7. $OPTION7\n 8. $OPTION8\n 9. $OPTION9 \n 0. $OPTION0\n " reading " $(text 4) " CHOOSE # 输入必须是数字且少于等于最大可选项 MAX_CHOOSE=9 - if grep -qE "^[0-9]$" <<< $CHOOSE && [ $CHOOSE -le $MAX_CHOOSE ]; then + if grep -qE "^[0-9]$" <<< "$CHOOSE" && [ "$CHOOSE" -le "$MAX_CHOOSE" ]; then ACTION$CHOOSE else warning " $(text 34) [0-$MAX_CHOOSE] " && sleep 1 && menu @@ -1110,19 +1179,20 @@ menu() { } # 传参选项 OPTION:1=为 IPv4 或者 IPv6 补全另一栈WARP; 2=安装双栈 WARP; u=卸载 WARP -[[ $1 != '[option]' ]] && OPTION=$(tr '[:upper:]' '[:lower:]' <<< "$1") +[ "$1" != '[option]' ] && OPTION=$(tr 'A-Z' 'a-z' <<< "$1") # 参数选项 URL 或 License 或转换 WARP 单双栈 -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} -ge $TOKEN_LENGTH ]]; then LICENSETYPE=2 && TOKEN=$2 - elif [[ $2 =~ ^[A-Za-z]{2}$ ]]; then EXPECT=$2 +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}" -ge "$TOKEN_LENGTH" ]]; then LICENSETYPE=2 && TOKEN="$2" + elif [[ "$2" =~ ^[A-Za-z]{2}$ ]]; then EXPECT="$2" + elif [[ "$1" = s && "$2" = [46Dd] ]]; then PRIORITY_SWITCH=$(tr 'A-Z' 'a-z' <<< "$2") fi fi # 自定义 WARP+ 设备名 -NAME=$3 +NAME="$3" # 主程序运行 1/3 statistics_of_run-times @@ -1132,9 +1202,10 @@ check_operating_system # 设置部分后缀 1/3 case "$OPTION" in - h ) help; exit 0;; - i ) change_ip; exit 0;; - e ) export_wireguard; exit 0;; + h ) help; exit 0 ;; + i ) change_ip; exit 0 ;; + e ) export_file; exit 0 ;; + s ) stack_priority; result_priority; exit 0 ;; esac # 主程序运行 2/3 @@ -1142,10 +1213,10 @@ check_root_virt # 设置部分后缀 2/3 case "$OPTION" in - u ) uninstall; exit 0;; - v ) ver; exit 0;; - o ) onoff; exit 0;; - g ) global_switch; exit 0;; + u ) uninstall; exit 0 ;; + v ) ver; exit 0 ;; + o ) onoff; exit 0 ;; + g ) global_switch; exit 0 ;; esac # 主程序运行 3/3 @@ -1159,18 +1230,18 @@ menu_setting case "$OPTION" in [46dn] ) if [[ $STATUS != 0 ]]; then - SWITCHCHOOSE="$(tr '[:lower:]' '[:upper:]' <<< "$OPTION")" + SWITCHCHOOSE="$(tr 'a-z' 'A-Z' <<< "$OPTION")" stack_switch else case "$OPTION" in - 4 ) CONF=${CONF1[n]};; - 6 ) CONF=${CONF2[n]};; - d|n ) CONF=${CONF3[n]};; + 4 ) CONF=${CONF1[n]} ;; + 6 ) CONF=${CONF2[n]} ;; + d|n ) CONF=${CONF3[n]} ;; esac install - fi;; - - a ) update;; + fi + ;; + a ) update ;; - * ) menu;; + * ) menu ;; esac