hysteria.sh 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594
  1. #!/bin/bash
  2. export LANG=en_US.UTF-8
  3. RED="\033[31m"
  4. GREEN="\033[32m"
  5. YELLOW="\033[33m"
  6. PLAIN="\033[0m"
  7. red(){
  8. echo -e "\033[31m\033[01m$1\033[0m"
  9. }
  10. green(){
  11. echo -e "\033[32m\033[01m$1\033[0m"
  12. }
  13. yellow(){
  14. echo -e "\033[33m\033[01m$1\033[0m"
  15. }
  16. # 判断系统及定义系统安装依赖方式
  17. REGEX=("debian" "ubuntu" "centos|red hat|kernel|oracle linux|alma|rocky" "'amazon linux'" "fedora")
  18. RELEASE=("Debian" "Ubuntu" "CentOS" "CentOS" "Fedora")
  19. PACKAGE_UPDATE=("apt-get update" "apt-get update" "yum -y update" "yum -y update" "yum -y update")
  20. PACKAGE_INSTALL=("apt -y install" "apt -y install" "yum -y install" "yum -y install" "yum -y install")
  21. PACKAGE_REMOVE=("apt -y remove" "apt -y remove" "yum -y remove" "yum -y remove" "yum -y remove")
  22. PACKAGE_UNINSTALL=("apt -y autoremove" "apt -y autoremove" "yum -y autoremove" "yum -y autoremove" "yum -y autoremove")
  23. [[ $EUID -ne 0 ]] && red "注意: 请在root用户下运行脚本" && exit 1
  24. CMD=("$(grep -i pretty_name /etc/os-release 2>/dev/null | cut -d \" -f2)" "$(hostnamectl 2>/dev/null | grep -i system | cut -d : -f2)" "$(lsb_release -sd 2>/dev/null)" "$(grep -i description /etc/lsb-release 2>/dev/null | cut -d \" -f2)" "$(grep . /etc/redhat-release 2>/dev/null)" "$(grep . /etc/issue 2>/dev/null | cut -d \\ -f1 | sed '/^[ ]*$/d')")
  25. for i in "${CMD[@]}"; do
  26. SYS="$i" && [[ -n $SYS ]] && break
  27. done
  28. for ((int = 0; int < ${#REGEX[@]}; int++)); do
  29. [[ $(echo "$SYS" | tr '[:upper:]' '[:lower:]') =~ ${REGEX[int]} ]] && SYSTEM="${RELEASE[int]}" && [[ -n $SYSTEM ]] && break
  30. done
  31. [[ -z $SYSTEM ]] && red "目前暂不支持你的VPS的操作系统!" && exit 1
  32. if [[ -z $(type -P curl) ]]; then
  33. if [[ ! $SYSTEM == "CentOS" ]]; then
  34. ${PACKAGE_UPDATE[int]}
  35. fi
  36. ${PACKAGE_INSTALL[int]} curl
  37. fi
  38. realip(){
  39. ip=$(curl -s4m8 ip.gs -k) || ip=$(curl -s6m8 ip.gs -k)
  40. }
  41. inst_cert(){
  42. green "Hysteria 2 协议证书申请方式如下:"
  43. echo ""
  44. echo -e " ${GREEN}1.${PLAIN} 必应自签证书 ${YELLOW}(默认)${PLAIN}"
  45. echo -e " ${GREEN}2.${PLAIN} Acme 脚本自动申请"
  46. echo -e " ${GREEN}3.${PLAIN} 自定义证书路径"
  47. echo ""
  48. read -rp "请输入选项 [1-3]: " certInput
  49. if [[ $certInput == 2 ]]; then
  50. cert_path="/root/cert.crt"
  51. key_path="/root/private.key"
  52. chmod -R 777 /root
  53. chmod +rw /root/cert.crt
  54. chmod +rw /root/private.key
  55. if [[ -f /root/cert.crt && -f /root/private.key ]] && [[ -s /root/cert.crt && -s /root/private.key ]] && [[ -f /root/ca.log ]]; then
  56. domain=$(cat /root/ca.log)
  57. green "检测到原有域名:$domain 的证书,正在应用"
  58. hy_domain=$domain
  59. else
  60. WARPv4Status=$(curl -s4m8 https://www.cloudflare.com/cdn-cgi/trace -k | grep warp | cut -d= -f2)
  61. WARPv6Status=$(curl -s6m8 https://www.cloudflare.com/cdn-cgi/trace -k | grep warp | cut -d= -f2)
  62. if [[ $WARPv4Status =~ on|plus ]] || [[ $WARPv6Status =~ on|plus ]]; then
  63. wg-quick down wgcf >/dev/null 2>&1
  64. systemctl stop warp-go >/dev/null 2>&1
  65. realip
  66. wg-quick up wgcf >/dev/null 2>&1
  67. systemctl start warp-go >/dev/null 2>&1
  68. else
  69. realip
  70. fi
  71. read -p "请输入需要申请证书的域名:" domain
  72. [[ -z $domain ]] && red "未输入域名,无法执行操作!" && exit 1
  73. green "已输入的域名:$domain" && sleep 1
  74. domainIP=$(dig @8.8.8.8 +time=2 +short "$domain" 2>/dev/null)
  75. if echo $domainIP | grep -q "network unreachable\|timed out" || [[ -z $domainIP ]]; then
  76. domainIP=$(dig @2001:4860:4860::8888 +time=2 aaaa +short "$domain" 2>/dev/null)
  77. fi
  78. if echo $domainIP | grep -q "network unreachable\|timed out" || [[ -z $domainIP ]] ; then
  79. red "未解析出 IP,请检查域名是否输入有误"
  80. yellow "是否尝试强行匹配?"
  81. green "1. 是,将使用强行匹配"
  82. green "2. 否,退出脚本"
  83. read -p "请输入选项 [1-2]:" ipChoice
  84. if [[ $ipChoice == 1 ]]; then
  85. yellow "将尝试强行匹配以申请域名证书"
  86. else
  87. red "将退出脚本"
  88. exit 1
  89. fi
  90. fi
  91. if [[ $domainIP == $ip ]]; then
  92. ${PACKAGE_INSTALL[int]} curl wget sudo socat openssl
  93. if [[ $SYSTEM == "CentOS" ]]; then
  94. ${PACKAGE_INSTALL[int]} cronie
  95. systemctl start crond
  96. systemctl enable crond
  97. else
  98. ${PACKAGE_INSTALL[int]} cron
  99. systemctl start cron
  100. systemctl enable cron
  101. fi
  102. curl https://get.acme.sh | sh -s email=$(date +%s%N | md5sum | cut -c 1-16)@gmail.com
  103. source ~/.bashrc
  104. bash ~/.acme.sh/acme.sh --upgrade --auto-upgrade
  105. bash ~/.acme.sh/acme.sh --set-default-ca --server letsencrypt
  106. if [[ -n $(echo $ip | grep ":") ]]; then
  107. bash ~/.acme.sh/acme.sh --issue -d ${domain} --standalone -k ec-256 --listen-v6 --insecure
  108. else
  109. bash ~/.acme.sh/acme.sh --issue -d ${domain} --standalone -k ec-256 --insecure
  110. fi
  111. bash ~/.acme.sh/acme.sh --install-cert -d ${domain} --key-file /root/private.key --fullchain-file /root/cert.crt --ecc
  112. if [[ -f /root/cert.crt && -f /root/private.key ]] && [[ -s /root/cert.crt && -s /root/private.key ]]; then
  113. echo $domain > /root/ca.log
  114. sed -i '/--cron/d' /etc/crontab >/dev/null 2>&1
  115. echo "0 0 * * * root bash /root/.acme.sh/acme.sh --cron -f >/dev/null 2>&1" >> /etc/crontab
  116. green "证书申请成功! 脚本申请到的证书 (cert.crt) 和私钥 (private.key) 文件已保存到 /root 文件夹下"
  117. yellow "证书crt文件路径如下: /root/cert.crt"
  118. yellow "私钥key文件路径如下: /root/private.key"
  119. hy_domain=$domain
  120. fi
  121. else
  122. red "当前域名解析的IP与当前VPS使用的真实IP不匹配"
  123. green "建议如下:"
  124. yellow "1. 请确保CloudFlare小云朵为关闭状态(仅限DNS), 其他域名解析或CDN网站设置同理"
  125. yellow "2. 请检查DNS解析设置的IP是否为VPS的真实IP"
  126. yellow "3. 脚本可能跟不上时代, 建议截图发布到GitHub Issues、GitLab Issues、论坛或TG群询问"
  127. exit 1
  128. fi
  129. fi
  130. elif [[ $certInput == 3 ]]; then
  131. read -p "请输入公钥文件 crt 的路径:" cert_path
  132. yellow "公钥文件 crt 的路径:$cert_path "
  133. read -p "请输入密钥文件 key 的路径:" key_path
  134. yellow "密钥文件 key 的路径:$key_path "
  135. read -p "请输入证书的域名:" domain
  136. yellow "证书域名:$domain"
  137. hy_domain=$domain
  138. chmod +rw $cert_path
  139. chmod +rw $key_path
  140. else
  141. green "将使用必应自签证书作为 Hysteria 2 的节点证书"
  142. cert_path="/etc/hysteria/cert.crt"
  143. key_path="/etc/hysteria/private.key"
  144. openssl ecparam -genkey -name prime256v1 -out /etc/hysteria/private.key
  145. openssl req -new -x509 -days 36500 -key /etc/hysteria/private.key -out /etc/hysteria/cert.crt -subj "/CN=www.bing.com"
  146. chmod 777 /etc/hysteria/cert.crt
  147. chmod 777 /etc/hysteria/private.key
  148. hy_domain="www.bing.com"
  149. domain="www.bing.com"
  150. fi
  151. }
  152. inst_port(){
  153. iptables -t nat -F PREROUTING >/dev/null 2>&1
  154. read -p "设置 Hysteria 2 端口 [1-65535](回车则随机分配端口):" port
  155. [[ -z $port ]] && port=$(shuf -i 2000-65535 -n 1)
  156. until [[ -z $(ss -tunlp | grep -w udp | awk '{print $5}' | sed 's/.*://g' | grep -w "$port") ]]; do
  157. if [[ -n $(ss -tunlp | grep -w udp | awk '{print $5}' | sed 's/.*://g' | grep -w "$port") ]]; then
  158. echo -e "${RED} $port ${PLAIN} 端口已经被其他程序占用,请更换端口重试!"
  159. read -p "设置 Hysteria 2 端口 [1-65535](回车则随机分配端口):" port
  160. [[ -z $port ]] && port=$(shuf -i 2000-65535 -n 1)
  161. fi
  162. done
  163. yellow "将在 Hysteria 2 节点使用的端口是:$port"
  164. inst_jump
  165. }
  166. inst_jump(){
  167. green "Hysteria 2 端口使用模式如下:"
  168. echo ""
  169. echo -e " ${GREEN}1.${PLAIN} 单端口 ${YELLOW}(默认)${PLAIN}"
  170. echo -e " ${GREEN}2.${PLAIN} 端口跳跃"
  171. echo ""
  172. read -rp "请输入选项 [1-2]: " jumpInput
  173. if [[ $jumpInput == 2 ]]; then
  174. read -p "设置范围端口的起始端口 (建议10000-65535之间):" firstport
  175. read -p "设置一个范围端口的末尾端口 (建议10000-65535之间,一定要比上面起始端口大):" endport
  176. if [[ $firstport -ge $endport ]]; then
  177. until [[ $firstport -le $endport ]]; do
  178. if [[ $firstport -ge $endport ]]; then
  179. red "你设置的起始端口小于末尾端口,请重新输入起始和末尾端口"
  180. read -p "设置范围端口的起始端口 (建议10000-65535之间):" firstport
  181. read -p "设置一个范围端口的末尾端口 (建议10000-65535之间,一定要比上面起始端口大):" endport
  182. fi
  183. done
  184. fi
  185. iptables -t nat -A PREROUTING -p udp --dport $firstport:$endport -j DNAT --to-destination :$port
  186. ip6tables -t nat -A PREROUTING -p udp --dport $firstport:$endport -j DNAT --to-destination :$port
  187. netfilter-persistent save >/dev/null 2>&1
  188. else
  189. red "将继续使用单端口模式"
  190. fi
  191. }
  192. inst_pwd(){
  193. read -p "设置 Hysteria 2 密码(回车跳过为随机字符):" auth_pwd
  194. [[ -z $auth_pwd ]] && auth_pwd=$(date +%s%N | md5sum | cut -c 1-8)
  195. yellow "使用在 Hysteria 2 节点的密码为:$auth_pwd"
  196. }
  197. inst_site(){
  198. read -rp "请输入 Hysteria 2 的伪装网站地址 (去除https://) [回车世嘉maimai日本网站]:" proxysite
  199. [[ -z $proxysite ]] && proxysite="maimai.sega.jp"
  200. yellow "使用在 Hysteria 2 节点的伪装网站为:$proxysite"
  201. }
  202. insthysteria(){
  203. warpv6=$(curl -s6m8 https://www.cloudflare.com/cdn-cgi/trace -k | grep warp | cut -d= -f2)
  204. warpv4=$(curl -s4m8 https://www.cloudflare.com/cdn-cgi/trace -k | grep warp | cut -d= -f2)
  205. if [[ $warpv4 =~ on|plus || $warpv6 =~ on|plus ]]; then
  206. wg-quick down wgcf >/dev/null 2>&1
  207. systemctl stop warp-go >/dev/null 2>&1
  208. realip
  209. systemctl start warp-go >/dev/null 2>&1
  210. wg-quick up wgcf >/dev/null 2>&1
  211. else
  212. realip
  213. fi
  214. if [[ ! ${SYSTEM} == "CentOS" ]]; then
  215. ${PACKAGE_UPDATE}
  216. fi
  217. ${PACKAGE_INSTALL} curl wget sudo qrencode procps iptables-persistent netfilter-persistent
  218. wget -N https://raw.githubusercontent.com/Misaka-blog/hysteria-install/main/hy2/install_server.sh
  219. bash install_server.sh
  220. rm -f install_server.sh
  221. if [[ -f "/usr/local/bin/hysteria" ]]; then
  222. green "Hysteria 2 安装成功!"
  223. else
  224. red "Hysteria 2 安装失败!"
  225. exit 1
  226. fi
  227. # 询问用户 Hysteria 配置
  228. inst_cert
  229. inst_port
  230. inst_pwd
  231. inst_site
  232. # 设置 Hysteria 配置文件
  233. cat << EOF > /etc/hysteria/config.yaml
  234. listen: :$port
  235. tls:
  236. cert: $cert_path
  237. key: $key_path
  238. quic:
  239. initStreamReceiveWindow: 16777216
  240. maxStreamReceiveWindow: 16777216
  241. initConnReceiveWindow: 33554432
  242. maxConnReceiveWindow: 33554432
  243. auth:
  244. type: password
  245. password: $auth_pwd
  246. masquerade:
  247. type: proxy
  248. proxy:
  249. url: https://$proxysite
  250. rewriteHost: true
  251. EOF
  252. # 确定最终入站端口范围
  253. if [[ -n $firstport ]]; then
  254. last_port="$port,$firstport-$endport"
  255. else
  256. last_port=$port
  257. fi
  258. # 给 IPv6 地址加中括号
  259. if [[ -n $(echo $ip | grep ":") ]]; then
  260. last_ip="[$ip]"
  261. else
  262. last_ip=$ip
  263. fi
  264. mkdir /root/hy
  265. cat << EOF > /root/hy/hy-client.yaml
  266. server: $last_ip:$last_port
  267. auth: $auth_pwd
  268. tls:
  269. sni: $hy_domain
  270. insecure: true
  271. quic:
  272. initStreamReceiveWindow: 16777216
  273. maxStreamReceiveWindow: 16777216
  274. initConnReceiveWindow: 33554432
  275. maxConnReceiveWindow: 33554432
  276. fastOpen: true
  277. socks5:
  278. listen: 127.0.0.1:5080
  279. transport:
  280. udp:
  281. hopInterval: 30s
  282. EOF
  283. cat << EOF > /root/hy/hy-client.json
  284. {
  285. "server": "$last_ip:$last_port",
  286. "auth": "$auth_pwd",
  287. "tls": {
  288. "sni": "$hy_domain",
  289. "insecure": true
  290. },
  291. "quic": {
  292. "initStreamReceiveWindow": 16777216,
  293. "maxStreamReceiveWindow": 16777216,
  294. "initConnReceiveWindow": 33554432,
  295. "maxConnReceiveWindow": 33554432
  296. },
  297. "fastOpen": true,
  298. "socks5": {
  299. "listen": "127.0.0.1:5080"
  300. },
  301. "transport": {
  302. "udp": {
  303. "hopInterval": "30s"
  304. }
  305. }
  306. }
  307. EOF
  308. cat <<EOF > /root/hy/clash-meta.yaml
  309. mixed-port: 7890
  310. external-controller: 127.0.0.1:9090
  311. allow-lan: false
  312. mode: rule
  313. log-level: debug
  314. ipv6: true
  315. dns:
  316. enable: true
  317. listen: 0.0.0.0:53
  318. enhanced-mode: fake-ip
  319. nameserver:
  320. - 8.8.8.8
  321. - 1.1.1.1
  322. - 114.114.114.114
  323. proxies:
  324. - name: Misaka-Hysteria2
  325. type: hysteria2
  326. server: $last_ip
  327. port: $port
  328. password: $auth_pwd
  329. sni: $hy_domain
  330. skip-cert-verify: true
  331. proxy-groups:
  332. - name: Proxy
  333. type: select
  334. proxies:
  335. - Misaka-Hysteria2
  336. rules:
  337. - GEOIP,CN,DIRECT
  338. - MATCH,Proxy
  339. EOF
  340. url="hysteria2://$auth_pwd@$last_ip:$last_port/?insecure=1&sni=$hy_domain#Misaka-Hysteria2"
  341. echo $url > /root/hy/url.txt
  342. nohopurl="hysteria2://$auth_pwd@$last_ip:$port/?insecure=1&sni=$hy_domain#Misaka-Hysteria2"
  343. echo $nohopurl > /root/hy/url-nohop.txt
  344. systemctl daemon-reload
  345. systemctl enable hysteria-server
  346. systemctl start hysteria-server
  347. if [[ -n $(systemctl status hysteria-server 2>/dev/null | grep -w active) && -f '/etc/hysteria/config.yaml' ]]; then
  348. green "Hysteria 2 服务启动成功"
  349. else
  350. red "Hysteria 2 服务启动失败,请运行 systemctl status hysteria-server 查看服务状态并反馈,脚本退出" && exit 1
  351. fi
  352. red "======================================================================================"
  353. green "Hysteria 2 代理服务安装完成"
  354. yellow "Hysteria 2 客户端 YAML 配置文件 hy-client.yaml 内容如下,并保存到 /root/hy/hy-client.yaml"
  355. red "$(cat /root/hy/hy-client.yaml)"
  356. yellow "Hysteria 2 客户端 JSON 配置文件 hy-client.json 内容如下,并保存到 /root/hy/hy-client.json"
  357. red "$(cat /root/hy/hy-client.json)"
  358. yellow "Clash Meta 客户端配置文件已保存到 /root/hy/clash-meta.yaml"
  359. yellow "Hysteria 2 节点分享链接如下,并保存到 /root/hy/url.txt"
  360. red "$(cat /root/hy/url.txt)"
  361. yellow "Hysteria 2 节点单端口的分享链接如下,并保存到 /root/hy/url.txt"
  362. red "$(cat /root/hy/url-nohop.txt)"
  363. }
  364. unsthysteria(){
  365. systemctl stop hysteria-server.service >/dev/null 2>&1
  366. systemctl disable hysteria-server.service >/dev/null 2>&1
  367. rm -f /lib/systemd/system/hysteria-server.service /lib/systemd/system/hysteria-server@.service
  368. rm -rf /usr/local/bin/hysteria /etc/hysteria /root/hy /root/hysteria.sh
  369. iptables -t nat -F PREROUTING >/dev/null 2>&1
  370. netfilter-persistent save >/dev/null 2>&1
  371. green "Hysteria 2 已彻底卸载完成!"
  372. }
  373. starthysteria(){
  374. systemctl start hysteria-server
  375. systemctl enable hysteria-server >/dev/null 2>&1
  376. }
  377. stophysteria(){
  378. systemctl stop hysteria-server
  379. systemctl disable hysteria-server >/dev/null 2>&1
  380. }
  381. hysteriaswitch(){
  382. yellow "请选择你需要的操作:"
  383. echo ""
  384. echo -e " ${GREEN}1.${PLAIN} 启动 Hysteria 2"
  385. echo -e " ${GREEN}2.${PLAIN} 关闭 Hysteria 2"
  386. echo -e " ${GREEN}3.${PLAIN} 重启 Hysteria 2"
  387. echo ""
  388. read -rp "请输入选项 [0-3]: " switchInput
  389. case $switchInput in
  390. 1 ) starthysteria ;;
  391. 2 ) stophysteria ;;
  392. 3 ) stophysteria && starthysteria ;;
  393. * ) exit 1 ;;
  394. esac
  395. }
  396. changeport(){
  397. oldport=$(cat /etc/hysteria/config.yaml 2>/dev/null | sed -n 1p | awk '{print $2}' | awk -F ":" '{print $2}')
  398. read -p "设置 Hysteria 2 端口[1-65535](回车则随机分配端口):" port
  399. [[ -z $port ]] && port=$(shuf -i 2000-65535 -n 1)
  400. until [[ -z $(ss -tunlp | grep -w udp | awk '{print $5}' | sed 's/.*://g' | grep -w "$port") ]]; do
  401. if [[ -n $(ss -tunlp | grep -w udp | awk '{print $5}' | sed 's/.*://g' | grep -w "$port") ]]; then
  402. echo -e "${RED} $port ${PLAIN} 端口已经被其他程序占用,请更换端口重试!"
  403. read -p "设置 Hysteria 2 端口 [1-65535](回车则随机分配端口):" port
  404. [[ -z $port ]] && port=$(shuf -i 2000-65535 -n 1)
  405. fi
  406. done
  407. sed -i "1s#$oldport#$port#g" /etc/hysteria/config.yaml
  408. sed -i "1s#$oldport#$port#g" /root/hy/hy-client.yaml
  409. sed -i "2s#$oldport#$port#g" /root/hy/hy-client.json
  410. stophysteria && starthysteria
  411. green "Hysteria 2 端口已成功修改为:$port"
  412. yellow "请手动更新客户端配置文件以使用节点"
  413. showconf
  414. }
  415. changepasswd(){
  416. oldpasswd=$(cat /etc/hysteria/config.yaml 2>/dev/null | sed -n 15p | awk '{print $2}')
  417. read -p "设置 Hysteria 2 密码(回车跳过为随机字符):" passwd
  418. [[ -z $passwd ]] && passwd=$(date +%s%N | md5sum | cut -c 1-8)
  419. sed -i "1s#$oldpasswd#$passwd#g" /etc/hysteria/config.yaml
  420. sed -i "1s#$oldpasswd#$passwd#g" /root/hy/hy-client.yaml
  421. sed -i "3s#$oldpasswd#$passwd#g" /root/hy/hy-client.json
  422. stophysteria && starthysteria
  423. green "Hysteria 2 节点密码已成功修改为:$passwd"
  424. yellow "请手动更新客户端配置文件以使用节点"
  425. showconf
  426. }
  427. change_cert(){
  428. old_cert=$(cat /etc/hysteria/config.yaml | grep cert | awk -F " " '{print $2}')
  429. old_key=$(cat /etc/hysteria/config.yaml | grep key | awk -F " " '{print $2}')
  430. old_hydomain=$(cat /root/hy/hy-client.yaml | grep sni | awk '{print $2}')
  431. inst_cert
  432. sed -i "s!$old_cert!$cert_path!g" /etc/hysteria/config.yaml
  433. sed -i "s!$old_key!$key_path!g" /etc/hysteria/config.yaml
  434. sed -i "6s/$old_hydomain/$hy_domain/g" /root/hy/hy-client.yaml
  435. sed -i "5s/$old_hydomain/$hy_domain/g" /root/hy/hy-client.json
  436. stophysteria && starthysteria
  437. green "Hysteria 2 节点证书类型已成功修改"
  438. yellow "请手动更新客户端配置文件以使用节点"
  439. showconf
  440. }
  441. changeproxysite(){
  442. oldproxysite=$(cat /etc/hysteria/config.yaml | grep url | awk -F " " '{print $2}' | awk -F "https://" '{print $2}')
  443. inst_site
  444. sed -i "s#$oldproxysite#$proxysite#g" /etc/caddy/Caddyfile
  445. stophysteria && starthysteria
  446. green "Hysteria 2 节点伪装网站已成功修改为:$proxysite"
  447. }
  448. changeconf(){
  449. green "Hysteria 2 配置变更选择如下:"
  450. echo -e " ${GREEN}1.${PLAIN} 修改端口"
  451. echo -e " ${GREEN}2.${PLAIN} 修改密码"
  452. echo -e " ${GREEN}3.${PLAIN} 修改证书类型"
  453. echo -e " ${GREEN}4.${PLAIN} 修改伪装网站"
  454. echo ""
  455. read -p " 请选择操作 [1-4]:" confAnswer
  456. case $confAnswer in
  457. 1 ) changeport ;;
  458. 2 ) changepasswd ;;
  459. 3 ) change_cert ;;
  460. 4 ) changeproxysite ;;
  461. * ) exit 1 ;;
  462. esac
  463. }
  464. showconf(){
  465. yellow "Hysteria 2 客户端 YAML 配置文件 hy-client.yaml 内容如下,并保存到 /root/hy/hy-client.yaml"
  466. red "$(cat /root/hy/hy-client.yaml)"
  467. yellow "Hysteria 2 客户端 JSON 配置文件 hy-client.json 内容如下,并保存到 /root/hy/hy-client.json"
  468. red "$(cat /root/hy/hy-client.json)"
  469. yellow "Clash Meta 客户端配置文件已保存到 /root/hy/clash-meta.yaml"
  470. yellow "Hysteria 2 节点分享链接如下,并保存到 /root/hy/url.txt"
  471. red "$(cat /root/hy/url.txt)"
  472. yellow "Hysteria 2 节点单端口的分享链接如下,并保存到 /root/hy/url.txt"
  473. red "$(cat /root/hy/url-nohop.txt)"
  474. }
  475. update_core(){
  476. wget -N https://raw.githubusercontent.com/Misaka-blog/hysteria-install/main/hy2/install_server.sh
  477. bash install_server.sh
  478. rm -f install_server.sh
  479. }
  480. menu() {
  481. clear
  482. echo "#############################################################"
  483. echo -e "# ${RED}Hysteria 2 一键安装脚本${PLAIN} #"
  484. echo -e "# ${GREEN}作者${PLAIN}: MisakaNo の 小破站 #"
  485. echo -e "# ${GREEN}博客${PLAIN}: https://blog.misaka.cyou #"
  486. echo -e "# ${GREEN}GitHub 项目${PLAIN}: https://github.com/Misaka-blog #"
  487. echo -e "# ${GREEN}GitLab 项目${PLAIN}: https://gitlab.com/Misaka-blog #"
  488. echo -e "# ${GREEN}Telegram 频道${PLAIN}: https://t.me/misakanocchannel #"
  489. echo -e "# ${GREEN}Telegram 群组${PLAIN}: https://t.me/misakanoc #"
  490. echo -e "# ${GREEN}YouTube 频道${PLAIN}: https://www.youtube.com/@misaka-blog #"
  491. echo "#############################################################"
  492. echo ""
  493. echo -e " ${GREEN}1.${PLAIN} 安装 Hysteria 2"
  494. echo -e " ${GREEN}2.${PLAIN} ${RED}卸载 Hysteria 2${PLAIN}"
  495. echo " -------------"
  496. echo -e " ${GREEN}3.${PLAIN} 关闭、开启、重启 Hysteria 2"
  497. echo -e " ${GREEN}4.${PLAIN} 修改 Hysteria 2 配置"
  498. echo -e " ${GREEN}5.${PLAIN} 显示 Hysteria 2 配置文件"
  499. echo " -------------"
  500. echo -e " ${GREEN}6.${PLAIN} 更新 Hysteria 2 内核"
  501. echo " -------------"
  502. echo -e " ${GREEN}0.${PLAIN} 退出脚本"
  503. echo ""
  504. read -rp "请输入选项 [0-5]: " menuInput
  505. case $menuInput in
  506. 1 ) insthysteria ;;
  507. 2 ) unsthysteria ;;
  508. 3 ) hysteriaswitch ;;
  509. 4 ) changeconf ;;
  510. 5 ) showconf ;;
  511. 6 ) update_core ;;
  512. * ) exit 1 ;;
  513. esac
  514. }
  515. menu