docker.sh 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763
  1. #!/bin/bash
  2. export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/sbin:/bin
  3. export LANG=en_US.UTF-8
  4. # 当前脚本版本号和新增功能
  5. VERSION=1.0
  6. # 选择 IP API 服务商
  7. IP_API=https://api.ip.sb/geoip; ISP=isp
  8. #IP_API=https://ifconfig.co/json; ISP=asn_org
  9. #IP_API=https://ip.gs/json; ISP=asn_org
  10. # 自定义字体彩色,read 函数
  11. red(){ echo -e "\033[31m\033[01m$1\033[0m"; }
  12. green(){ echo -e "\033[32m\033[01m$1\033[0m"; }
  13. yellow(){ echo -e "\033[33m\033[01m$1\033[0m"; }
  14. reading(){ read -rp "$(green "$1")" "$2"; }
  15. # 自定义友道或谷歌翻译函数
  16. # translate() { [ -n "$1" ] && curl -ksm8 "http://fanyi.youdao.com/translate?&doctype=json&type=EN2ZH_CN&i=${1//[[:space:]]/}" | cut -d \" -f18 2>/dev/null; }
  17. translate() {
  18. [ -n "$@" ] && EN="$@"
  19. ZH=$(curl -km8 -sSL "https://translate.google.com/translate_a/t?client=any_client_id_works&sl=en&tl=zh&q=${EN//[[:space:]]/}")
  20. [[ "$ZH" =~ ^\[\".+\"\]$ ]] && cut -d \" -f2 <<< "$ZH"
  21. }
  22. # 传参选项 OPTION:1=为 IPv4 或者 IPv6 补全另一栈 WARP; u=卸载 WARP; o=WARP开关; 其他或空值=菜单界面
  23. [[ $1 != '[option]' ]] && OPTION=$(tr '[:upper:]' '[:lower:]' <<< "$1")
  24. # 参数选项 URL 或 License
  25. if [[ $2 != '[lisence]' ]]; then
  26. if [[ $2 =~ 'http' ]]; then
  27. LICENSETYPE=2 && URL=$2
  28. elif [[ $2 =~ ^[A-Z0-9a-z]{8}-[A-Z0-9a-z]{8}-[A-Z0-9a-z]{8}$ ]]; then
  29. LICENSETYPE=1 && LICENSE=$2
  30. fi
  31. fi
  32. # 自定义 WARP+ 设备名
  33. NAME=$3
  34. declare -A T
  35. T[E0]="\n Language:\n 1.English (default) \n 2.简体中文\n"
  36. T[C0]="${T[E0]}"
  37. T[E1]="wgcf on docker"
  38. T[C1]="docker 的 wgcf 为宿主机服务"
  39. T[E2]="The script must be run as root, you can enter sudo -i and then download and run again. Feedback: [https://github.com/fscarmen/warp/issues]"
  40. T[C2]="必须以root方式运行脚本,可以输入 sudo -i 后重新下载运行,问题反馈:[https://github.com/fscarmen/warp/issues]"
  41. T[E3]="The TUN module is not loaded. You should turn it on in the control panel. Ask the supplier for more help. Feedback: [https://github.com/fscarmen/warp/issues]"
  42. T[C3]="没有加载 TUN 模块,请在管理后台开启或联系供应商了解如何开启,问题反馈:[https://github.com/fscarmen/warp/issues]"
  43. T[E4]="The WARP server cannot be connected. It may be a China Mainland VPS. You can manually ping 162.159.192.1 or ping6 2606:4700:d0::a29f:c001.You can run the script again if the connect is successful. Feedback: [https://github.com/fscarmen/warp/issues]"
  44. T[C4]="与 WARP 的服务器不能连接,可能是大陆 VPS,可手动 ping 162.159.192.1 或 ping6 2606:4700:d0::a29f:c001,如能连通可再次运行脚本,问题反馈:[https://github.com/fscarmen/warp/issues]"
  45. T[E5]="The script supports Debian, Ubuntu, CentOS or Alpine systems only. Feedback: [https://github.com/fscarmen/warp/issues]"
  46. T[C5]="本脚本只支持 Debian、Ubuntu、CentOS 或 Alpine 系统,问题反馈:[https://github.com/fscarmen/warp/issues]"
  47. T[E6]="warp h (help)\n warp o (Turn off WARP temporarily)\n warp u (Turn off and uninstall WARP docker)\n warp d (Upgrade to WARP+ account)\n warp d N5670ljg-sS9jD334-6o6g4M9F (Upgrade to WARP+ account with the license)\n warp d http://gist.github.com/teams.xml (Upgrade to Teams account with the URL)\n warp v (Sync the latest version)\n warp 1 (Add WARP IPv6 interface to native IPv4 VPS or WARP IPv4 interface to native IPv6 VPS)\n warp 1 N5670ljg-sS9jD334-6o6g4M9F Goodluck (Add IPv4 or IPV6 WARP+ interface with the license and named Goodluck)\n"
  48. T[C6]="warp h (帮助菜单)\n warp o (临时warp开关)\n warp u (卸载 WARP 网络接口和 Socks5 Client)\n warp d (免费 WARP 账户升级 WARP+)\n warp d N5670ljg-sS9jD334-6o6g4M9F (指定 License 升级 WARP+)\n warp d http://gist.github.com/teams.xml (指定 URL 升级 Teams)\n warp v (同步脚本至最新版本)\n warp 1 (Warp单栈)\n warp 1 N5670ljg-sS9jD334-6o6g4M9F Goodluck (指定 WARP+ License Warp 单栈,设备名为 Goodluck)\n"
  49. T[C7]="安装curl中……"
  50. T[E8]="It is necessary to upgrade the latest package library before install curl.It will take a little time,please be patiently..."
  51. T[C8]="先升级软件库才能继续安装 curl,时间较长,请耐心等待……"
  52. T[E9]="Failed to install curl. The script is aborted. Feedback: [https://github.com/fscarmen/warp/issues]"
  53. T[C9]="安装 curl 失败,脚本中止,问题反馈:[https://github.com/fscarmen/warp/issues]"
  54. T[E10]="WireGuard tools are not installed or the configuration file wgcf.conf cannot be found, please reinstall."
  55. T[C10]="没有安装 WireGuard tools 或者找不到配置文件 wgcf.conf,请重新安装。"
  56. T[E11]="Maximum \$j attempts to get WARP IP..."
  57. T[C11]="后台获取 WARP IP 中,最大尝试\$j次……"
  58. T[E12]="Try \$i"
  59. T[C12]="第\$i次尝试"
  60. T[E13]="There have been more than \$j failures. The script is aborted. Feedback: [https://github.com/fscarmen/warp/issues]"
  61. T[C13]="失败已超过\$j次,脚本中止,问题反馈:[https://github.com/fscarmen/warp/issues]"
  62. T[E14]="Got the WARP IP successfully."
  63. T[C14]="已成功获取 WARP 网络"
  64. T[E15]="WARP is turned off. It could be turned on again by [warp o]"
  65. T[C15]="已暂停 WARP,再次开启可以用 warp o"
  66. T[E16]=""
  67. T[C16]=""
  68. T[E17]="Version"
  69. T[C17]="脚本版本"
  70. T[E18]="New features"
  71. T[C18]="功能新增"
  72. T[E19]="System infomation"
  73. T[C19]="系统信息"
  74. T[E20]="Operating System"
  75. T[C20]="当前操作系统"
  76. T[E21]="Kernel"
  77. T[C21]="内核"
  78. T[E22]="Architecture"
  79. T[C22]="处理器架构"
  80. T[E23]="Virtualization"
  81. T[C23]="虚拟化"
  82. T[E24]=""
  83. T[C24]=""
  84. T[E25]="Device name"
  85. T[C25]="设备名"
  86. T[E26]="Curren operating system is \$SYS.\\\n The system lower than \$SYSTEM \${MAJOR[int]} is not supported. Feedback: [https://github.com/fscarmen/warp/issues]"
  87. T[C26]="当前操作是 \$SYS\\\n 不支持 \$SYSTEM \${MAJOR[int]} 以下系统,问题反馈:[https://github.com/fscarmen/warp/issues]"
  88. T[E27]=""
  89. T[C27]=""
  90. T[E28]="If there is a WARP+ License, please enter it, otherwise press Enter to continue:"
  91. T[C28]="如有 WARP+ License 请输入,没有可回车继续:"
  92. T[E29]="Input errors up to 5 times.The script is aborted."
  93. T[C29]="输入错误达5次,脚本退出"
  94. T[E30]="License should be 26 characters, please re-enter WARP+ License. Otherwise press Enter to continue. \(\$i times remaining\):"
  95. T[C30]="License 应为26位字符,请重新输入 WARP+ License,没有可回车继续\(剩余\$i次\):"
  96. T[E31]="\n 1.Update with WARP+ license\n 2.Update with Teams (You need upload the Teams file to a private storage space before. For example: gist.github.com)\n"
  97. T[C31]="\n 1.使用 WARP+ license 升级\n 2.使用 Teams 升级 (你须事前把 Teams 文件上传到私密存储空间,比如:gist.github.com )\n"
  98. T[E32]="Step 1/3: Install docker..."
  99. T[C32]="进度 1/3:安装 docker……"
  100. T[E33]="Step 2/3: WGCF is ready"
  101. T[C33]="进度 2/3:已安装 WGCF"
  102. T[E34]=""
  103. T[C34]=""
  104. T[E35]="Update WARP+ account..."
  105. T[C35]="升级 WARP+ 账户中……"
  106. T[E36]="The upgrade failed, WARP+ account error or more than 5 devices have been activated. Free WARP account to continu."
  107. T[C36]="升级失败,WARP+ 账户错误或者已激活超过5台设备,自动更换免费 WARP 账户继续"
  108. T[E37]="Checking VPS infomation..."
  109. T[C37]="检查环境中……"
  110. T[E38]="Create shortcut [warp] successfully"
  111. T[C38]="创建快捷 warp 指令成功"
  112. T[E39]="Running WARP"
  113. T[C39]="运行 WARP"
  114. T[E40]=""
  115. T[C40]=""
  116. T[E41]="Congratulations! WARP\$TYPE is turned on. Spend time:\$(( end - start )) seconds.\\\n The script runs today: \$TODAY. Total:\$TOTAL"
  117. T[C41]="恭喜!WARP\$TYPE 已开启,总耗时:\$(( end - start ))秒, 脚本当天运行次数:\$TODAY,累计运行次数:\$TOTAL"
  118. T[E42]="Congratulations! WARP is turned on. Spend time:\$(( end - start )) seconds.\\\n The script runs on today: \$TODAY. Total:\$TOTAL"
  119. T[C42]="恭喜!WARP 已开启,总耗时:\$(( end - start ))秒, 脚本当天运行次数:\$TODAY,累计运行次数:\$TOTAL"
  120. T[E43]="Turn on WGCF: [docker exec -it wgcf sh] and [wg-quick up wgcf; exit]. Turn off WGCF: [docker exec -it wgcf sh] and [wg-quick down wgcf; exit]"
  121. T[C43]="运行 WGCF: [docker exec -it wgcf sh], 然后 [wg-quick up wgcf; exit]; 关闭 WGCF:[docker exec -it wgcf sh], 然后 [wg-quick down wgcf; exit]"
  122. T[E44]="WARP installation failed. Feedback: [https://github.com/fscarmen/warp/issues]"
  123. T[C44]="WARP 安装失败,问题反馈:[https://github.com/fscarmen/warp/issues]"
  124. T[E45]="WARP docker have been completely deleted!"
  125. T[C45]="WARP docker 已彻底删除!"
  126. T[E46]=""
  127. T[C46]=""
  128. T[E47]=""
  129. T[C47]=""
  130. T[E48]=""
  131. T[C48]=""
  132. T[E49]=""
  133. T[C49]=""
  134. T[E50]="Choose:"
  135. T[C50]="请选择:"
  136. T[E51]="Please enter the correct number"
  137. T[C51]="请输入正确数字"
  138. T[E52]=""
  139. T[C52]=""
  140. T[E53]=""
  141. T[C53]=""
  142. T[E54]=""
  143. T[C54]=""
  144. T[E55]=""
  145. T[C55]=""
  146. T[E56]=""
  147. T[C56]=""
  148. T[E57]=""
  149. T[C57]=""
  150. T[E58]="WARP+ or Teams account is working now. No need to upgrade."
  151. T[C58]="已经是 WARP+ 或者 Teams 账户,不需要升级"
  152. T[E59]="Cannot find the account file: /etc/wireguard/wgcf-account.toml, you can reinstall with the WARP+ License"
  153. T[C59]="找不到账户文件:/etc/wireguard/wgcf-account.toml,可以卸载后重装,输入 WARP+ License"
  154. T[E60]="Cannot find the configuration file: /etc/wireguard/wgcf.conf, you can reinstall with the WARP+ License"
  155. T[C60]="找不到配置文件: /etc/wireguard/wgcf.conf,可以卸载后重装,输入 WARP+ License"
  156. T[E61]="Please Input WARP+ license:"
  157. T[C61]="请输入WARP+ License:"
  158. T[E62]="Successfully upgraded to a WARP+ account"
  159. T[C62]="已升级为 WARP+ 账户"
  160. T[E63]="WARP+ quota"
  161. T[C63]="剩余流量"
  162. T[E64]="Successfully synchronized the latest version"
  163. T[C64]="成功!已同步最新脚本,版本号"
  164. T[E65]="Upgrade failed. Feedback:[https://github.com/fscarmen/warp/issues]"
  165. T[C65]="升级失败,问题反馈:[https://github.com/fscarmen/warp/issues]"
  166. T[E66]="Add WARP IPv4 interface to IPv6 only VPS"
  167. T[C66]="为 IPv6 only 添加 IPv4 网络接口"
  168. T[E67]="Add WARP IPv6 interface to IPv4 only VPS"
  169. T[C67]="为 IPv4 only 添加 IPv6 网络接口"
  170. T[E68]="Add WARP dualstack interface to IPv6 only VPS"
  171. T[C68]="为 IPv6 only 添加双栈网络接口"
  172. T[E69]="Add WARP dualstack interface to IPv4 only VPS"
  173. T[C69]="为 IPv4 only 添加双栈网络接口"
  174. T[E70]="Add WARP dualstack interface to native dualstack"
  175. T[C70]="为 原生双栈 添加 WARP 双栈 网络接口"
  176. T[E71]="Turn on WARP"
  177. T[C71]="打开 WARP"
  178. T[E72]="Turn off, uninstall WARP docker"
  179. T[C72]="永久关闭 WARP 网络接口,并删除 WARP docker"
  180. T[E73]=""
  181. T[C73]=""
  182. T[E74]=""
  183. T[C74]=""
  184. T[E75]="Sync the latest version"
  185. T[C75]="同步最新版本"
  186. T[E76]="Exit"
  187. T[C76]="退出脚本"
  188. T[E77]="Turn off WARP"
  189. T[C77]="暂时关闭 WARP"
  190. T[E78]="Upgrade to WARP+ or Teams account"
  191. T[C78]="升级为 WARP+ 或 Teams 账户"
  192. T[E79]=""
  193. T[C79]=""
  194. T[E80]=""
  195. T[C80]=""
  196. T[E81]="Step 3/3: Searching for the best MTU value is ready."
  197. T[C81]="进度 3/3:寻找 MTU 最优值已完成"
  198. T[E82]=""
  199. T[C82]=""
  200. T[E83]=""
  201. T[C83]=""
  202. T[E84]=""
  203. T[C84]=""
  204. T[E85]=""
  205. T[C85]=""
  206. T[E86]=""
  207. T[C86]=""
  208. T[E87]=""
  209. T[C87]=""
  210. T[E88]=""
  211. T[C88]=""
  212. T[E89]=""
  213. T[C89]=""
  214. T[E90]=""
  215. T[C90]=""
  216. T[E91]=""
  217. T[C91]=""
  218. T[E92]=""
  219. T[C92]=""
  220. T[E93]=""
  221. T[C93]=""
  222. T[E94]=""
  223. T[C94]=""
  224. T[E95]=""
  225. T[C95]=""
  226. T[E96]=""
  227. T[C96]=""
  228. T[E97]="It is a WARP+ account already. Update is aborted."
  229. T[C97]="已经是 WARP+ 账户,不需要升级"
  230. T[E98]=""
  231. T[C98]=""
  232. T[E99]=""
  233. T[C99]=""
  234. T[E100]="License should be 26 characters, please re-enter WARP+ License. Otherwise press Enter to continue. \(\$i times remaining\): "
  235. T[C100]="License 应为26位字符,请重新输入 WARP+ License \(剩余\$i次\): "
  236. T[E101]=""
  237. T[C101]=""
  238. T[E102]="Please customize the WARP+ device name (Default is [WARP] if left blank):"
  239. T[C102]="请自定义 WARP+ 设备名 (如果不输入,默认为 [WARP]):"
  240. T[E103]=""
  241. T[C103]=""
  242. T[E104]=""
  243. T[C104]=""
  244. T[E105]="\n Please choose the priority:\n 1.IPv4 (default)\n 2.IPv6\n 3.Use initial settings\n"
  245. T[C105]="\n 请选择优先级别:\n 1.IPv4 (默认)\n 2.IPv6\n 3.使用 VPS 初始设置\n"
  246. T[E106]="IPv6 priority"
  247. T[C106]="IPv6 优先"
  248. T[E107]="IPv4 priority"
  249. T[C107]="IPv4 优先"
  250. T[E108]=""
  251. T[C108]=""
  252. T[E109]=""
  253. T[C109]=""
  254. T[E110]=""
  255. T[C110]=""
  256. T[E111]=""
  257. T[C111]=""
  258. T[E112]=""
  259. T[C112]=""
  260. T[E113]=""
  261. T[C113]=""
  262. T[E114]="WARP\$TYPE Interface is on"
  263. T[C114]="WARP\$TYPE 网络接口已开启"
  264. T[E115]="WARP Interface is on"
  265. T[C115]="WARP 网络接口已开启"
  266. T[E116]="WARP Interface is off"
  267. T[C116]="WARP 网络接口未开启"
  268. T[E117]="Uninstall WARP Interface was complete."
  269. T[C117]="WARP 网络接口卸载成功"
  270. T[E118]="Uninstall WARP Interface was fail."
  271. T[C118]="WARP 网络接口卸载失败"
  272. T[E119]=""
  273. T[C119]=""
  274. T[E120]=""
  275. T[C120]=""
  276. T[E121]=""
  277. T[C121]=""
  278. T[E122]=""
  279. T[C122]=""
  280. T[E123]=""
  281. T[C123]=""
  282. T[E124]=""
  283. T[C124]=""
  284. T[E125]=""
  285. T[C125]=""
  286. T[E126]=""
  287. T[C126]=""
  288. T[E127]="Please input Teams file URL (To use the one provided by the script if left blank):"
  289. T[C127]="请输入 Teams 文件 URL (如果留空,则使用脚本提供的):"
  290. T[E128]="Successfully upgraded to a WARP Teams account"
  291. T[C128]="已升级为 WARP Teams 账户"
  292. T[E129]="The current Teams account is unavailable, automatically switch back to the free account"
  293. T[C129]="当前 Teams 账户不可用,自动切换回免费账户"
  294. T[E130]="\\\n Please confirm\\\n Private key : \$PRIVATEKEY \$MATCH1\\\n Public key : \$PUBLICKEY \$MATCH2\\\n Address IPv4 : \$ADDRESS4/32 \$MATCH3\\\n Address IPv6 : \$ADDRESS6/128 \$MATCH4\\\n"
  295. T[C130]="\\\n 请确认Teams 信息\\\n Private key : \$PRIVATEKEY \$MATCH1\\\n Public key : \$PUBLICKEY \$MATCH2\\\n Address IPv4 : \$ADDRESS4/32 \$MATCH3\\\n Address IPv6 : \$ADDRESS6/128 \$MATCH4\\\n"
  296. T[E131]="comfirm please enter [y] , and other keys to use free account:"
  297. T[C131]="确认请按 y ,其他按键则使用免费账户:"
  298. T[E132]="\n Is there a WARP+ or Teams account?\n 1. WARP+\n 2. Teams\n 3. use free account (default)\n"
  299. T[C132]="\n 如有 WARP+ 或 Teams 账户请选择\n 1. WARP+\n 2. Teams\n 3. 使用免费账户 (默认)\n"
  300. T[E133]="Device name:\$(grep -s 'Device name' /etc/wireguard/info.log | awk '{ print \$NF }')\\\n Quota:\$(grep -s Quota /etc/wireguard/info.log | awk '{ print \$(NF-1), \$NF }')"
  301. T[C133]="设备名:\$(grep -s 'Device name' /etc/wireguard/info.log | awk '{ print \$NF }')\\\n 剩余流量:\$(grep -s Quota /etc/wireguard/info.log | awk '{ print \$(NF-1), \$NF }')"
  302. T[E134]="Curren architecture \$(arch) is not supported. Feedback: [https://github.com/fscarmen/warp/issues]"
  303. T[C134]="当前架构 \$(arch) 暂不支持,问题反馈:[https://github.com/fscarmen/warp/issues]"
  304. T[E135]="( match √ )"
  305. T[C135]="( 符合 √ )"
  306. T[E136]="( mismatch X )"
  307. T[C136]="( 不符合 X )"
  308. # 脚本当天及累计运行次数统计
  309. COUNT=$(curl --retry 2 -ksm2 "https://hits.seeyoufarm.com/api/count/incr/badge.svg?url=https%3A%2F%2Fcdn.jsdelivr.net%2Fgh%2Ffscarmen%2Fwarp%2Fdocker.sh&count_bg=%2379C83D&title_bg=%23555555&icon=&icon_color=%23E7E7E7&title=&edge_flat=true" 2>&1 | grep -m1 -oE "[0-9]+[ ]+/[ ]+[0-9]+") &&
  310. TODAY=$(cut -d " " -f1 <<< "$COUNT") && TOTAL=$(cut -d " " -f3 <<< "$COUNT")
  311. # 选择语言,先判断 /etc/wireguard/language 里的语言选择,没有的话再让用户选择,默认英语
  312. case $(cat /etc/wireguard/language-docker 2>&1) in
  313. E ) L=E;; C ) L=C;;
  314. * ) L=E && [[ -z $OPTION || $OPTION = [hdv1] ]] && yellow " ${T[${L}0]} " && reading " ${T[${L}50]} " LANGUAGE
  315. [[ $LANGUAGE = 2 ]] && L=C;;
  316. esac
  317. # 多方式判断操作系统,试到有值为止。只支持 Debian 10/11、Ubuntu 18.04/20.04 或 CentOS 7/8 ,如非上述操作系统,退出脚本
  318. # 感谢猫大的技术指导优化重复的命令。https://github.com/Oreomeow
  319. if [ -s /etc/os-release ]; then
  320. SYS="$(grep -i pretty_name /etc/os-release | cut -d \" -f2)"
  321. elif [ $(type -p hostnamectl) ]; then
  322. SYS="$(hostnamectl | grep -i system | cut -d : -f2)"
  323. elif [ $(type -p lsb_release) ]; then
  324. SYS="$(lsb_release -sd)"
  325. elif [ -s /etc/lsb-release ]; then
  326. SYS="$(grep -i description /etc/lsb-release | cut -d \" -f2)"
  327. elif [ -s /etc/redhat-release ]; then
  328. SYS="$(grep . /etc/redhat-release)"
  329. elif [ -s /etc/issue ]; then
  330. SYS="$(grep . /etc/issue | cut -d '\' -f1 | sed '/^[ ]*$/d')"
  331. fi
  332. # 自定义 Alpine 系统若干函数
  333. alpine_wgcf_restart(){ wg-quick down wgcf >/dev/null 2>&1; wg-quick up wgcf >/dev/null 2>&1; }
  334. alpine_wgcf_enable(){ echo 'nohup wg-quick up wgcf &' > /etc/local.d/wgcf.start; chmod +x /etc/local.d/wgcf.start; rc-update add local; }
  335. REGEX=("debian" "ubuntu" "centos|red hat|kernel|oracle linux|alma|rocky" "'amazon linux'" "alpine")
  336. RELEASE=("Debian" "Ubuntu" "CentOS" "CentOS" "Alpine")
  337. PACKAGE_UPDATE=("apt -y update" "apt -y update" "yum -y update" "yum -y update" "apk update -f")
  338. PACKAGE_INSTALL=("apt -y install" "apt -y install" "yum -y install" "yum -y install" "apk add -f")
  339. PACKAGE_UNINSTALL=("apt -y autoremove" "apt -y autoremove" "yum -y autoremove" "yum -y autoremove" "apk del -f")
  340. for ((int=0; int<${#REGEX[@]}; int++)); do
  341. [[ $(echo "$SYS" | tr '[:upper:]' '[:lower:]') =~ ${REGEX[int]} ]] && SYSTEM="${RELEASE[int]}" && COMPANY="${COMPANY[int]}" && [[ -n $SYSTEM ]] && break
  342. done
  343. [[ -z $SYSTEM ]] && red " ${T[${L}5]} " && exit 1
  344. [[ $SYSTEM = Alpine ]] && ! type -P curl >/dev/null 2>&1 && ${PACKAGE_UPDATE[int]} && ${PACKAGE_INSTALL[int]} curl wget grep
  345. # 检测 IPv4 IPv6 信息,WARP Ineterface 开启,普通还是 Plus账户 和 IP 信息
  346. ip4_info(){
  347. IP4=$(curl -ks4m8 -A Mozilla $IP_API $INTERFACE)
  348. LAN4=$(ip route get 162.159.192.1 2>/dev/null | grep -oP 'src \K\S+')
  349. WAN4=$(expr "$IP4" : '.*ip\":[ ]*\"\([^"]*\).*')
  350. COUNTRY4=$(expr "$IP4" : '.*country\":[ ]*\"\([^"]*\).*')
  351. ASNORG4=$(expr "$IP4" : '.*'$ISP'\":[ ]*\"\([^"]*\).*')
  352. TRACE4=$(curl -ks4m8 https://www.cloudflare.com/cdn-cgi/trace | grep warp | sed "s/warp=//g")
  353. if [[ $TRACE4 = plus ]]; then
  354. grep -sq 'Device name' /etc/wireguard/info.log && PLUS4='+' || PLUS4=' Teams'
  355. fi
  356. [[ $TRACE4 = on || $TRACE4 = plus ]] && WARPSTATUS4="( WARP$PLUS4 IPv4 )"
  357. }
  358. ip6_info(){
  359. IP6=$(curl -ks6m8 -A Mozilla $IP_API)
  360. LAN6=$(ip route get 2606:4700:d0::a29f:c001 2>/dev/null | grep -oP 'src \K\S+')
  361. WAN6=$(expr "$IP6" : '.*ip\":[ ]*\"\([^"]*\).*')
  362. COUNTRY6=$(expr "$IP6" : '.*country\":[ ]*\"\([^"]*\).*')
  363. ASNORG6=$(expr "$IP6" : '.*'$ISP'\":[ ]*\"\([^"]*\).*')
  364. TRACE6=$(curl -ks6m8 https://www.cloudflare.com/cdn-cgi/trace | grep warp | sed "s/warp=//g")
  365. if [[ $TRACE6 = plus ]]; then
  366. grep -sq 'Device name' /etc/wireguard/info.log && PLUS6='+' || PLUS6=' Teams'
  367. fi
  368. [[ $TRACE6 = on || $TRACE6 = plus ]] && WARPSTATUS6="( WARP$PLUS6 IPv6 )"
  369. }
  370. green " ${T[${L}37]} "
  371. # 必须以root运行脚本
  372. [[ $(id -u) != 0 ]] && red " ${T[${L}2]} " && exit 1
  373. # 判断虚拟化
  374. VIRT=$(systemd-detect-virt 2>/dev/null | tr '[:upper:]' '[:lower:]')
  375. [[ -n $VIRT ]] || VIRT=$(hostnamectl 2>/dev/null | tr '[:upper:]' '[:lower:]' | grep virtualization | sed "s/.*://g")
  376. # 必须加载 TUN 模块
  377. TUN=$(cat /dev/net/tun 2>&1 | tr '[:upper:]' '[:lower:]')
  378. [[ ! $TUN =~ 'in bad state' ]] && [[ ! $TUN =~ '处于错误状态' ]] && red " ${T[${L}3]} " && exit 1
  379. help(){ yellow " ${T[${L}6]} "; }
  380. # WGCF docker 卸载
  381. uninstall(){
  382. unset IP4 IP6 WAN4 WAN6 COUNTRY4 COUNTRY6 ASNORG4 ASNORG6
  383. docker exec -it wgcf wg-quick down wgcf
  384. # 停止及删除容器
  385. docker stop wgcf
  386. docker rm wgcf
  387. # 删除镜像
  388. docker rmi -f $(docker images | grep wgcf | awk '{print $3}')
  389. # 删除文件
  390. rm -rf /usr/local/bin/wgcf /etc/wireguard wgcf-account.toml wgcf-profile.conf /usr/bin/warp
  391. # 显示卸载结果
  392. ip4_info; [[ $L = C && -n "$COUNTRY4" ]] && COUNTRY4=$(translate "$COUNTRY4")
  393. ip6_info; [[ $L = C && -n "$COUNTRY6" ]] && COUNTRY6=$(translate "$COUNTRY6")
  394. green " ${T[${L}45]}\n IPv4:$WAN4 $COUNTRY4 $ASNORG4\n IPv6:$WAN6 $COUNTRY6 $ASNORG6 "
  395. }
  396. # 同步脚本至最新版本
  397. ver(){
  398. wget -N -P /etc/wireguard https://raw.githubusercontent.com/fscarmen/warp/main/docker.sh || wget -N -P /etc/wireguard https://cdn.jsdelivr.net/gh/fscarmen/warp/docker.sh
  399. chmod +x /etc/wireguard/docker.sh
  400. ln -sf /etc/wireguard/docker.sh /usr/bin/warp
  401. green " ${T[${L}64]}:$(grep ^VERSION /etc/wireguard/docker.sh | sed "s/.*=//g") ${T[${L}18]}:$(grep "T\[${L}1]" /etc/wireguard/docker.sh | cut -d \" -f2) " || red " ${T[${L}65]} "
  402. exit
  403. }
  404. # 由于warp bug,有时候获取不了ip地址,加入刷网络脚本手动运行,并在定时任务加设置 VPS 重启后自动运行,i=当前尝试次数,j=要尝试的次数
  405. net(){
  406. i=1;j=10
  407. yellow " $(eval echo "${T[${L}11]}")\n $(eval echo "${T[${L}12]}") "
  408. docker exec -it wgcf wg-quick up wgcf >/dev/null 2>&1
  409. ip4_info
  410. [[ -n $IP4 ]] && ip6_info
  411. until [[ -n $IP4 && -n $IP6 && $TRACE4$TRACE6 =~ on|plus ]]
  412. do (( i++ )) || true
  413. yellow " $(eval echo "${T[${L}12]}") "
  414. docker exec -it wgcf wg-quick down wgcf >/dev/null 2>&1
  415. docker exec -it wgcf wg-quick up wgcf >/dev/null 2>&1
  416. ip4_info
  417. [[ -n $IP4 ]] && ip6_info
  418. if [[ $i = "$j" ]]; then
  419. if [[ $LICENSETYPE = 2 ]]; then
  420. unset LICENSETYPE && i=0 && green " ${T[${L}129]} " &&
  421. cp -f /etc/wireguard/wgcf-profile.conf /etc/wireguard/wgcf.conf
  422. else
  423. docker exec -it wgcf wg-quick down wgcf >/dev/null 2>&1
  424. red " $(eval echo "${T[${L}13]}") " && exit 1
  425. fi
  426. fi
  427. done
  428. green " ${T[${L}14]} "
  429. [[ $L = C ]] && COUNTRY4=$(translate "$COUNTRY4")
  430. [[ $L = C ]] && COUNTRY6=$(translate "$COUNTRY6")
  431. [[ $OPTION = [on] ]] && green " IPv4:$WAN4 $WARPSTATUS4 $COUNTRY4 $ASNORG4\n IPv6:$WAN6 $WARPSTATUS6 $COUNTRY6 $ASNORG6 "
  432. }
  433. # WARP 开关
  434. onoff(){ [[ -n $(docker exec -it wgcf wg 2>/dev/null) ]] && (docker exec -it wgcf wg-quick down wgcf >/dev/null 2>&1; green " ${T[${L}15]} ") || net; }
  435. # 设置部分后缀 1/2
  436. case "$OPTION" in
  437. h ) help; exit 0;;
  438. u ) uninstall; exit 0;;
  439. v ) ver; exit 0;;
  440. n ) net; exit 0;;
  441. o ) onoff; exit 0;;
  442. esac
  443. # 判断是否大陆 VPS。先尝试连接 CloudFlare WARP 服务的 Endpoint IP,如遇到 WARP 断网则先关闭、杀进程后重试一次,仍然不通则 WARP 项目不可用。
  444. ping6 -c2 -w8 2606:4700:d0::a29f:c001 >/dev/null 2>&1 && IPV6=1 && CDN=-6 || IPV6=0
  445. ping -c2 -W8 162.159.192.1 >/dev/null 2>&1 && IPV4=1 && CDN=-4 || IPV4=0
  446. if [[ $IPV4$IPV6 = 00 && -n $(wg) ]]; then
  447. wg-quick down wgcf >/dev/null 2>&1
  448. kill -9 $(pgrep -f wireguard 2>/dev/null)
  449. ping6 -c2 -w10 2606:4700:d0::a29f:c001 >/dev/null 2>&1 && IPV6=1 && CDN=-6
  450. ping -c2 -W10 162.159.192.1 >/dev/null 2>&1 && IPV4=1 && CDN=-4
  451. fi
  452. [[ $IPV4$IPV6 = 00 ]] && red " ${T[${L}4]} " && exit 1
  453. # 安装 curl
  454. type -P curl >/dev/null 2>&1 || (yellow " ${T[${L}7]} " && ${PACKAGE_INSTALL[int]} curl) || (yellow " ${T[${L}8]} " && ${PACKAGE_UPDATE[int]} && ${PACKAGE_INSTALL[int]} curl)
  455. ! type -P curl >/dev/null 2>&1 && yellow " ${T[${L}9]} " && exit 1
  456. # 判断处理器架构
  457. case $(tr '[:upper:]' '[:lower:]' <<< "$(arch)") in
  458. aarch64 ) ARCHITECTURE=arm64;; x86_64 ) ARCHITECTURE=amd64;; s390x ) ARCHITECTURE=s390x;; * ) red " $(eval echo "${T[${L}134]}") " && exit 1;;
  459. esac
  460. # 判断当前 IPv4 与 IPv6 ,IP归属 及 WARP, Linux Client 是否开启
  461. [[ $IPV4 = 1 ]] && ip4_info
  462. [[ $IPV6 = 1 ]] && ip6_info
  463. # 判断当前 WARP 状态,决定变量 PLAN,变量 PLAN 含义:1=单栈 2=双栈 3=WARP已开启
  464. [[ $TRACE4 = plus || $TRACE4 = on || $TRACE6 = plus || $TRACE6 = on ]] && PLAN=3 || PLAN=$((IPV4+IPV6))
  465. # WGCF 配置修改,其中用到的 162.159.192.1 和 2606:4700:d0::a29f:c001 均是 engage.cloudflareclient.com 的IP
  466. MODIFYS01='sed -i "s/1.1.1.1/2606:4700:4700::1111,2001:4860:4860::8888,2001:4860:4860::8844,1.1.1.1,8.8.8.8,8.8.4.4/g;/\:\:\/0/d;s/engage.cloudflareclient.com/[2606:4700:d0::a29f:c001]/g" wgcf-profile.conf'
  467. MODIFYD01='sed -i "s/1.1.1.1/2606:4700:4700::1111,2001:4860:4860::8888,2001:4860:4860::8844,1.1.1.1,8.8.8.8,8.8.4.4/g;7 s/^/PostDown = ip -6 rule delete from '$LAN6' lookup main\n/;7 s/^/PostUp = ip -6 rule add from '$LAN6' lookup main\n/;s/engage.cloudflareclient.com/[2606:4700:d0::a29f:c001]/g" wgcf-profile.conf'
  468. MODIFYS10='sed -i "s/1.1.1.1/1.1.1.1,8.8.8.8,8.8.4.4,2606:4700:4700::1111,2001:4860:4860::8888,2001:4860:4860::8844/g;/0\.\0\/0/d;s/engage.cloudflareclient.com/162.159.192.1/g" wgcf-profile.conf'
  469. MODIFYD10='sed -i "s/1.1.1.1/1.1.1.1,8.8.8.8,8.8.4.4,2606:4700:4700::1111,2001:4860:4860::8888,2001:4860:4860::8844/g;7 s/^/PostDown = ip -4 rule delete from '$LAN4' lookup main\n/;7 s/^/PostUp = ip -4 rule add from '$LAN4' lookup main\n/;s/engage.cloudflareclient.com/162.159.192.1/g" wgcf-profile.conf'
  470. MODIFYD11='sed -i "s/1.1.1.1/1.1.1.1,8.8.8.8,8.8.4.4,2606:4700:4700::1111,2001:4860:4860::8888,2001:4860:4860::8844/g;7 s/^/PostDown = ip -6 rule delete from '$LAN6' lookup main\n/;7 s/^/PostUp = ip -6 rule add from '$LAN6' lookup main\n/;7 s/^/PostDown = ip -4 rule delete from '$LAN4' lookup main\n/;7 s/^/PostUp = ip -4 rule add from '$LAN4' lookup main\n/" wgcf-profile.conf'
  471. # 替换为 Teams 账户信息
  472. teams_change(){
  473. 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
  474. case $IPV4$IPV6 in
  475. 01 ) sed -i "s#Endpoint.*#Endpoint = $(expr "$TEAMS" : '.*v6&quot;:&quot;\(\[[^&]*\).*')#g" /etc/wireguard/wgcf.conf;;
  476. 10 ) sed -i "s#Endpoint.*#Endpoint = $(expr "$TEAMS" : '.*endpoint&quot;:{&quot;v4&quot;:&quot;\([^&]*\).*')#g" /etc/wireguard/wgcf.conf;;
  477. esac
  478. }
  479. # 输入 WARP+ 账户(如有),限制位数为空或者26位以防输入错误
  480. input_license(){
  481. [[ -z $LICENSE ]] && reading " ${T[${L}28]} " LICENSE
  482. i=5
  483. until [[ -z $LICENSE || $LICENSE =~ ^[A-Z0-9a-z]{8}-[A-Z0-9a-z]{8}-[A-Z0-9a-z]{8}$ ]]
  484. do (( i-- )) || true
  485. [[ $i = 0 ]] && red " ${T[${L}29]} " && exit 1 || reading " $(eval echo "${T[${L}30]}") " LICENSE
  486. done
  487. if [[ $INPUT_LICENSE = 1 ]]; then
  488. [[ -n $LICENSE && -z $NAME ]] && reading " ${T[${L}102]} " NAME
  489. [[ -n $NAME ]] && NAME="${NAME//[[:space:]]/_}" || NAME=${NAME:-'WARP'}
  490. fi
  491. }
  492. # 输入 Teams 账户 URL(如有)
  493. input_url(){
  494. [[ -z $URL ]] && reading " ${T[${L}127]} " URL
  495. URL=${URL:-'https://gist.githubusercontent.com/fscarmen/56aaf02d743551737c9973b8be7a3496/raw/16cf34edf5fb28be00f53bb1c510e95a35491032/com.cloudflare.onedotonedotonedotone_preferences.xml'}
  496. TEAMS=$(curl -sSL "$URL" | sed "s/\"/\&quot;/g")
  497. PRIVATEKEY=$(expr "$TEAMS" : '.*private_key&quot;>\([^<]*\).*')
  498. PUBLICKEY=$(expr "$TEAMS" : '.*public_key&quot;:&quot;\([^&]*\).*')
  499. ADDRESS4=$(expr "$TEAMS" : '.*v4&quot;:&quot;\(172[^&]*\).*')
  500. ADDRESS6=$(expr "$TEAMS" : '.*v6&quot;:&quot;\([^[&]*\).*')
  501. [[ $PRIVATEKEY =~ ^[A-Z0-9a-z/+]{43}=$ ]] && MATCH1=${T[${L}135]} || MATCH1=${T[${L}136]}
  502. [[ $PUBLICKEY =~ ^[A-Z0-9a-z/+]{43}=$ ]] && MATCH2=${T[${L}135]} || MATCH2=${T[${L}136]}
  503. [[ $ADDRESS4 =~ ^172.16.[01].[0-9]{1,3}$ ]] && MATCH3=${T[${L}135]} || MATCH3=${T[${L}136]}
  504. [[ $ADDRESS6 =~ ^fd01(:[0-9a-f]{0,4}){7}$ ]] && MATCH4=${T[${L}135]} || MATCH4=${T[${L}136]}
  505. yellow " $(eval echo "${T[${L}130]}") " && reading " ${T[${L}131]} " CONFIRM
  506. }
  507. # 升级 WARP+ 账户(如有),限制位数为空或者26位以防输入错误,WARP interface 可以自定义设备名(不允许字符串间有空格,如遇到将会以_代替)
  508. update_license(){
  509. [[ -z $LICENSE ]] && reading " ${T[${L}61]} " LICENSE
  510. i=5
  511. until [[ $LICENSE =~ ^[A-Z0-9a-z]{8}-[A-Z0-9a-z]{8}-[A-Z0-9a-z]{8}$ ]]
  512. do (( i-- )) || true
  513. [[ $i = 0 ]] && red " ${T[${L}29]} " && exit 1 || reading " $(eval echo "${T[${L}100]}") " LICENSE
  514. done
  515. [[ $UPDATE_LICENSE = 1 && -n $LICENSE && -z $NAME ]] && reading " ${T[${L}102]} " NAME
  516. [[ -n $NAME ]] && NAME="${NAME//[[:space:]]/_}" || NAME=${NAME:-'WARP'}
  517. }
  518. # IPv4, IPv6 优先
  519. stack_priority(){
  520. [[ -e /etc/gai.conf ]] && sed -i '/^precedence \:\:ffff\:0\:0/d;/^label 2002\:\:\/16/d' /etc/gai.conf
  521. case "$PRIORITY" in
  522. 2 ) echo "label 2002::/16 2" >> /etc/gai.conf;;
  523. 3 ) ;;
  524. * ) echo "precedence ::ffff:0:0/96 100" >> /etc/gai.conf;;
  525. esac
  526. }
  527. # 免费 WARP 账户升级 WARP+ 账户
  528. update(){
  529. [[ $TRACE4 = plus || $TRACE6 = plus ]] && red " ${T[${L}58]} " && exit 1
  530. [[ ! -e /etc/wireguard/wgcf-account.toml ]] && red " ${T[${L}59]} " && exit 1
  531. [[ ! -e /etc/wireguard/wgcf.conf ]] && red " ${T[${L}60]} " && exit 1
  532. [[ -z $LICENSETYPE ]] && yellow " ${T[${L}31]}" && reading " ${T[${L}50]} " LICENSETYPE
  533. case $LICENSETYPE in
  534. 1 ) UPDATE_LICENSE=1 && update_license
  535. cd /etc/wireguard || exit
  536. sed -i "s#license_key.*#license_key = \"$LICENSE\"#g" wgcf-account.toml &&
  537. if wgcf update --name "$NAME" > /etc/wireguard/info.log 2>&1; then
  538. wgcf generate >/dev/null 2>&1
  539. sed -i "2s#.*#$(sed -ne 2p wgcf-profile.conf)#;3s#.*#$(sed -ne 3p wgcf-profile.conf)#;4s#.*#$(sed -ne 4p wgcf-profile.conf)#" wgcf.conf
  540. docker exec -it wgcf wg-quick down wgcf >/dev/null 2>&1
  541. net
  542. green " ${T[${L}62]}\n ${T[${L}25]}:$(grep 'Device name' /etc/wireguard/info.log | awk '{ print $NF }')\n ${T[${L}63]}:$(grep Quota /etc/wireguard/info.log | awk '{ print $(NF-1), $NF }')"
  543. else red " ${T[${L}36]} "
  544. fi;;
  545. 2 ) input_url
  546. [[ $CONFIRM = [Yy] ]] && (echo "$TEAMS" > /etc/wireguard/info.log 2>&1
  547. teams_change
  548. docker exec -it wgcf wg-quick down wgcf >/dev/null 2>&1
  549. net
  550. [[ $(curl -s4 https://www.cloudflare.com/cdn-cgi/trace | grep warp | sed "s/warp=//g") = plus || $(curl -s6 https://www.cloudflare.com/cdn-cgi/trace | grep warp | sed "s/warp=//g") = plus ]] && green " ${T[${L}128]} ");;
  551. * ) red " ${T[${L}51]} [1-2] "; sleep 1; update;;
  552. esac
  553. }
  554. # WGCF docker 安装
  555. install(){
  556. # 先删除之前安装,可能导致失败的文件
  557. rm -rf /usr/local/bin/wgcf /usr/bin/wireguard-go wgcf-account.toml wgcf-profile.conf
  558. # 询问是否有 WARP+ 或 Teams 账户
  559. [[ -z $LICENSETYPE ]] && yellow " ${T[${L}132]}" && reading " ${T[${L}50]} " LICENSETYPE
  560. case $LICENSETYPE in
  561. 1 ) INPUT_LICENSE=1 && input_license;;
  562. 2 ) input_url;;
  563. esac
  564. # 选择优先使用 IPv4 /IPv6 网络
  565. yellow " ${T[${L}105]} " && reading " ${T[${L}50]} " PRIORITY
  566. # 脚本开始时间
  567. start=$(date +%s)
  568. # 安装 docker, 拉取镜像+创建容器
  569. { green " \n${T[${L}32]}\n " && ! systemctl is-active docker >/dev/null 2>&1 && curl -sSL get.docker.com | sh
  570. docker run -dit --restart=always --network=host --name wgcf --device /dev/net/tun --privileged --cap-add net_admin --cap-add sys_module -v /etc/wireguard:/etc/wireguard -v /lib/modules:/lib/modules fscarmen/wgcf:"$ARCHITECTURE"
  571. }&
  572. # 注册 WARP 账户 (将生成 wgcf-account.toml 文件保存账户信息)
  573. # 判断 wgcf 的最新版本,如因 github 接口问题未能获取,默认 v2.2.18
  574. {
  575. latest=$(wget --no-check-certificate -qO- -T1 -t1 $CDN "https://api.github.com/repos/ViRb3/wgcf/releases/latest" | grep "tag_name" | head -n 1 | cut -d : -f2 | sed 's/[ \"v,]//g')
  576. latest=${latest:-'2.2.18'}
  577. # 安装 wgcf,尽量下载官方的最新版本,如官方 wgcf 下载不成功,将使用 jsDelivr ,以更好的支持双栈。并添加执行权限
  578. wget --no-check-certificate -T1 -t1 $CDN -O /usr/local/bin/wgcf https://github.com/ViRb3/wgcf/releases/download/v"$latest"/wgcf_"$latest"_linux_$ARCHITECTURE ||
  579. wget --no-check-certificate $CDN -O /usr/local/bin/wgcf https://cdn.jsdelivr.net/gh/fscarmen/warp/wgcf_"$latest"_linux_$ARCHITECTURE
  580. chmod +x /usr/local/bin/wgcf
  581. # 注册 WARP 账户 (将生成 wgcf-account.toml 文件保存账户信息)
  582. until [[ -e wgcf-account.toml ]] >/dev/null 2>&1; do
  583. wgcf register --accept-tos >/dev/null 2>&1 && break
  584. done
  585. # 如有 WARP+ 账户,修改 license 并升级,并把设备名等信息保存到 /etc/wireguard/info.log
  586. mkdir -p /etc/wireguard/ >/dev/null 2>&1
  587. [[ -n $LICENSE ]] && yellow " \n${T[${L}35]}\n " && sed -i "s/license_key.*/license_key = \"$LICENSE\"/g" wgcf-account.toml &&
  588. ( wgcf update --name "$NAME" > /etc/wireguard/info.log 2>&1 &&
  589. green " ${T[${L}62]}\n ${T[${L}25]}:$(grep 'Device name' /etc/wireguard/info.log | awk '{ print $NF }')\n ${T[${L}63]}:$(grep Quota /etc/wireguard/info.log | awk '{ print $(NF-1), $NF }')" || red " ${T[${L}36]} " )
  590. # 生成 Wire-Guard 配置文件 (wgcf-profile.conf)
  591. [[ -e wgcf-account.toml ]] && wgcf generate >/dev/null 2>&1
  592. green "\n ${T[${L}33]}\n "
  593. # 反复测试最佳 MTU。 Wireguard Header:IPv4=60 bytes,IPv6=80 bytes,1280 ≤1 MTU ≤ 1420。 ping = 8(ICMP回显示请求和回显应答报文格式长度) + 20(IP首部) 。
  594. # 详细说明:<[WireGuard] Header / MTU sizes for Wireguard>:https://lists.zx2c4.com/pipermail/wireguard/2017-December/002201.html
  595. MTU=$((1500-28))
  596. [[ $IPV4$IPV6 = 01 ]] && ping6 -c1 -W1 -s $MTU -Mdo 2606:4700:d0::a29f:c001 >/dev/null 2>&1 || ping -c1 -W1 -s $MTU -Mdo 162.159.192.1 >/dev/null 2>&1
  597. until [[ $? = 0 || $MTU -le $((1280+80-28)) ]]
  598. do
  599. MTU=$((MTU-10))
  600. [[ $IPV4$IPV6 = 01 ]] && ping6 -c1 -W1 -s $MTU -Mdo 2606:4700:d0::a29f:c001 >/dev/null 2>&1 || ping -c1 -W1 -s $MTU -Mdo 162.159.192.1 >/dev/null 2>&1
  601. done
  602. if [[ $MTU -eq $((1500-28)) ]]; then MTU=$MTU
  603. elif [[ $MTU -le $((1280+80-28)) ]]; then MTU=$((1280+80-28))
  604. else
  605. for ((i=0; i<9; i++)); do
  606. (( MTU++ ))
  607. ( [[ $IPV4$IPV6 = 01 ]] && ping6 -c1 -W1 -s $MTU -Mdo 2606:4700:d0::a29f:c001 >/dev/null 2>&1 || ping -c1 -W1 -s $MTU -Mdo 162.159.192.1 >/dev/null 2>&1 ) || break
  608. done
  609. (( MTU-- ))
  610. fi
  611. MTU=$((MTU+28-80))
  612. [[ -e wgcf-profile.conf ]] && sed -i "s/MTU.*/MTU = $MTU/g" wgcf-profile.conf && green "\n ${T[${L}81]}\n "
  613. }&
  614. # 优先使用 IPv4 /IPv6 网络
  615. { stack_priority; }&
  616. # 对于 IPv4 only VPS 开启 IPv6 支持
  617. # 感谢 P3terx 大神项目这块的技术指导。项目:https://github.com/P3TERX/warp.sh/blob/main/warp.sh
  618. {
  619. [[ $IPV4$IPV6 = 10 ]] && [[ $(sysctl -a 2>/dev/null | grep 'disable_ipv6.*=.*1') || $(grep -s "disable_ipv6.*=.*1" /etc/sysctl.{conf,d/*} ) ]] &&
  620. (sed -i '/disable_ipv6/d' /etc/sysctl.{conf,d/*}
  621. echo 'net.ipv6.conf.all.disable_ipv6 = 0' >/etc/sysctl.d/ipv6.conf
  622. sysctl -w net.ipv6.conf.all.disable_ipv6=0)
  623. }&
  624. wait
  625. echo "$MODIFY" | sh
  626. # 把 wgcf-profile.conf 复制到/etc/wireguard/ 并命名为 wgcf.conf, 如有 Teams,改为 Teams 账户信息
  627. cp -f wgcf-profile.conf /etc/wireguard/wgcf.conf >/dev/null 2>&1
  628. # 保存好配置文件
  629. mv -f wgcf-account.toml wgcf-profile.conf docker.sh /etc/wireguard >/dev/null 2>&1
  630. # 创建再次执行的软链接快捷方式,再次运行可以用 warp 指令,设置默认语言
  631. chmod +x /etc/wireguard/docker.sh >/dev/null 2>&1
  632. ln -sf /etc/wireguard/docker.sh /usr/bin/warp && green " ${T[${L}38]} "
  633. echo "$L" >/etc/wireguard/language-docker
  634. [[ $CONFIRM = [Yy] ]] && teams_change && echo "$TEAMS" > /etc/wireguard/info.log 2>&1
  635. # 运行 WGCF
  636. unset IP4 IP6 WAN4 WAN6 COUNTRY4 COUNTRY6 ASNORG4 ASNORG6 TRACE4 TRACE6 PLUS4 PLUS6 WARPSTATUS4 WARPSTATUS6
  637. net
  638. [[ "$(curl -ksm8 -A Mozilla $IP_API | grep '"ip"' | sed 's/.*ip\":[ ]*\"\([^"]*\).*/\1/g')" =~ ^([0-9]{1,3}\.){3} ]] && PRIORITY=${T[${L}107]} || PRIORITY=${T[${L}106]}
  639. # 结果提示,脚本运行时间,次数统计
  640. ip4_info; [[ $L = C && -n "$COUNTRY4" ]] && COUNTRY4=$(translate "$COUNTRY4")
  641. ip6_info; [[ $L = C && -n "$COUNTRY6" ]] && COUNTRY6=$(translate "$COUNTRY6")
  642. end=$(date +%s)
  643. red "\n==============================================================\n"
  644. green " IPv4:$WAN4 $WARPSTATUS4 $COUNTRY4 $ASNORG4 "
  645. green " IPv6:$WAN6 $WARPSTATUS6 $COUNTRY6 $ASNORG6 "
  646. grep -sq 'Device name' /etc/wireguard/info.log 2>/dev/null && TYPE='+' || TYPE=' Teams'
  647. [[ $TRACE4 = plus || $TRACE6 = plus ]] && green " $(eval echo "${T[${L}41]}") " && grep -sq 'Device name' /etc/wireguard/info.log && green " $(eval echo "${T[${L}133]}") "
  648. [[ $TRACE4 = on || $TRACE6 = on ]] && green " $(eval echo "${T[${L}42]}") "
  649. green " $PRIORITY "
  650. red "\n==============================================================\n"
  651. }
  652. # 显示菜单
  653. menu(){
  654. if [[ $PLAN != 3 ]]; then
  655. case $IPV4$IPV6 in
  656. 01 ) OPTION1=${T[${L}66]} && OPTION2=${T[${L}71]};;
  657. 10 ) OPTION1=${T[${L}67]} && OPTION2=${T[${L}71]};;
  658. 11 ) OPTION1=${T[${L}70]} && OPTION2=${T[${L}71]};;
  659. esac
  660. else OPTION1=${T[${L}77]} && OPTION2=${T[${L}78]}
  661. fi
  662. grep -sq 'Device name' /etc/wireguard/info.log 2>/dev/null && TYPE='+' && PLUSINFO="${T[${L}25]}:$(grep 'Device name' /etc/wireguard/info.log 2>/dev/null | awk '{ print $NF }')" || TYPE=' Teams'
  663. clear
  664. yellow " ${T[${L}16]} "
  665. red "======================================================================================================================\n"
  666. green " ${T[${L}17]}:$VERSION ${T[${L}18]}:${T[${L}1]}\n ${T[${L}19]}:\n ${T[${L}20]}:$SYS\n ${T[${L}21]}:$(uname -r)\n ${T[${L}22]}:$ARCHITECTURE\n ${T[${L}23]}:$VIRT "
  667. green " IPv4:$WAN4 $WARPSTATUS4 $COUNTRY4 $ASNORG4 "
  668. green " IPv6:$WAN6 $WARPSTATUS6 $COUNTRY6 $ASNORG6 "
  669. [[ $TRACE4 = plus || $TRACE6 = plus ]] && green " $(eval echo "${T[${L}114]}") $PLUSINFO "
  670. [[ $TRACE4 = on || $TRACE6 = on ]] && green " ${T[${L}115]} "
  671. [[ $PLAN != 3 ]] && green " ${T[${L}116]} "
  672. red "\n======================================================================================================================\n"
  673. green " 1. $OPTION1\n 2. $OPTION2\n 3. ${T[${L}72]}\n 0. ${T[${L}76]}\n "
  674. reading " ${T[${L}50]} " CHOOSE1
  675. case "$CHOOSE1" in
  676. 1 ) [[ $OPTION1 = ${T[${L}66]} || $OPTION1 = ${T[${L}67]} ]] && MODIFY=$(eval echo \$MODIFYS$IPV4$IPV6) && install
  677. [[ $OPTION1 = ${T[${L}70]} ]] && MODIFY=$MODIFYD11 && install
  678. [[ $OPTION1 = ${T[${L}77]} ]] && onoff;;
  679. 2 ) [[ $OPTION2 = ${T[${L}71]} ]] && OPTION=o && onoff
  680. [[ $OPTION2 = ${T[${L}78]} ]] && update;;
  681. 3 ) uninstall;;
  682. 0 ) exit;;
  683. * ) red " ${T[${L}51]} [0-3] "; sleep 1; menu;;
  684. esac
  685. }
  686. # 设置部分后缀 2/2
  687. case "$OPTION" in
  688. 1|2 ) [[ $IPV4$IPV6 != 11 ]] && MODIFY=$(eval echo \$MODIFYS$IPV4$IPV6) || MODIFY=$MODIFYD11
  689. install;;
  690. d ) update;;
  691. * ) menu;;
  692. esac