From d2096d0895e335ec8bc6df0ab2641a2cdba30861 Mon Sep 17 00:00:00 2001 From: mack-a <57424792+mack-a@users.noreply.github.com> Date: Wed, 11 Oct 2023 16:15:45 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E8=84=9A=E6=9C=AC):=20hysteria2=E6=9B=BF?= =?UTF-8?q?=E6=8D=A2=E4=B8=BAsingbox=E6=A0=B8=E5=BF=83=EF=BC=8C=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0tuic=E3=80=81hysteria2=E8=AE=A2=E9=98=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- install.sh | 356 ++++++++++++++++++++++++++++++----------------------- 1 file changed, 204 insertions(+), 152 deletions(-) diff --git a/install.sh b/install.sh index 1d62120..780948c 100644 --- a/install.sh +++ b/install.sh @@ -349,12 +349,12 @@ readInstallType() { hysteriaConfigPath=/etc/v2ray-agent/hysteria/conf/ fi fi - # - # if [[ -d "/etc/v2ray-agent/tuic" && -f "/etc/v2ray-agent/tuic/tuic" ]]; then - # if [[ -d "/etc/v2ray-agent/tuic/conf" ]] && [[ -f "/etc/v2ray-agent/tuic/conf/config.json" ]]; then - # tuicConfigPath=/etc/v2ray-agent/tuic/conf/ - # fi - # fi + + if [[ -d "/etc/v2ray-agent/tuic" && -f "/etc/v2ray-agent/tuic/tuic" ]]; then + if [[ -d "/etc/v2ray-agent/tuic/conf" ]] && [[ -f "/etc/v2ray-agent/tuic/conf/config.json" ]]; then + tuicConfigPath=/etc/v2ray-agent/tuic/conf/ + fi + fi if [[ -d "/etc/v2ray-agent/sing-box" && -f "/etc/v2ray-agent/sing-box/sing-box" ]]; then if [[ -d "/etc/v2ray-agent/sing-box/conf" ]] && [[ -f "/etc/v2ray-agent/sing-box/conf/config.json" ]]; then @@ -402,8 +402,8 @@ readInstallProtocolType() { done < <(find ${configPath} -name "*inbounds.json" | awk -F "[.]" '{print $1}') - if [[ -n "${hysteriaConfigPath}" ]]; then - # if [[ -n "${singBoxConfigPath}" ]] && [[ -f "/etc/v2ray-agent/sing-box/conf/config.json" ]] && grep -q 'hysteria' 删除sing-box tuic配置成功" + fi + + if grep -q 'hysteria2' 删除sing-box hysteria2配置成功" + fi + singBoxMergeConfig + fi + + readInstallType + + if [[ -n "${singBoxConfigPath}" ]]; then + echoContent yellow " ---> 检测到有其他配置,保留sing-box核心" + handleSingBox stop + handleSingBox start + else + handleSingBox stop + rm /etc/systemd/system/sing-box.service + rm -rf /etc/v2ray-agent/sing-box/* + echoContent green " ---> sing-box 卸载完成" fi } # 读取xray reality配置 @@ -2345,7 +2378,7 @@ checkGFWStatue() { # fi #} -安装hysteria开机自启 +# 安装hysteria开机自启 installHysteriaService() { echoContent skyBlue "\n进度 $1/${totalProgress} : 配置Hysteria开机自启" if [[ -n $(find /bin /usr/bin -name "systemctl") ]]; then @@ -2527,35 +2560,35 @@ handleHysteria() { } # 操作Tuic -#handleTuic() { -# # shellcheck disable=SC2010 -# if find /bin /usr/bin | grep -q systemctl && ls /etc/systemd/system/ | grep -q tuic.service; then -# if [[ -z $(pgrep -f "tuic/tuic") ]] && [[ "$1" == "start" ]]; then -# systemctl start tuic.service -# elif [[ -n $(pgrep -f "tuic/tuic") ]] && [[ "$1" == "stop" ]]; then -# systemctl stop tuic.service -# fi -# fi -# sleep 0.8 -# -# if [[ "$1" == "start" ]]; then -# if [[ -n $(pgrep -f "tuic/tuic") ]]; then -# echoContent green " ---> Tuic启动成功" -# else -# echoContent red "Tuic启动失败" -# echoContent red "请手动执行【/etc/v2ray-agent/tuic/tuic -c /etc/v2ray-agent/tuic/conf/config.json】,查看错误日志" -# exit 0 -# fi -# elif [[ "$1" == "stop" ]]; then -# if [[ -z $(pgrep -f "tuic/tuic") ]]; then -# echoContent green " ---> Tuic关闭成功" -# else -# echoContent red "Tuic关闭失败" -# echoContent red "请手动执行【ps -ef|grep -v grep|grep tuic|awk '{print \$2}'|xargs kill -9】" -# exit 0 -# fi -# fi -#} +handleTuic() { + # shellcheck disable=SC2010 + if find /bin /usr/bin | grep -q systemctl && ls /etc/systemd/system/ | grep -q tuic.service; then + if [[ -z $(pgrep -f "tuic/tuic") ]] && [[ "$1" == "start" ]]; then + systemctl start tuic.service + elif [[ -n $(pgrep -f "tuic/tuic") ]] && [[ "$1" == "stop" ]]; then + systemctl stop tuic.service + fi + fi + sleep 0.8 + + if [[ "$1" == "start" ]]; then + if [[ -n $(pgrep -f "tuic/tuic") ]]; then + echoContent green " ---> Tuic启动成功" + else + echoContent red "Tuic启动失败" + echoContent red "请手动执行【/etc/v2ray-agent/tuic/tuic -c /etc/v2ray-agent/tuic/conf/config.json】,查看错误日志" + exit 0 + fi + elif [[ "$1" == "stop" ]]; then + if [[ -z $(pgrep -f "tuic/tuic") ]]; then + echoContent green " ---> Tuic关闭成功" + else + echoContent red "Tuic关闭失败" + echoContent red "请手动执行【ps -ef|grep -v grep|grep tuic|awk '{print \$2}'|xargs kill -9】" + exit 0 + fi + fi +} # 操作sing-box handleSingBox() { @@ -2571,17 +2604,17 @@ handleSingBox() { if [[ "$1" == "start" ]]; then if [[ -n $(pgrep -f "sing-box") ]]; then - echoContent green " ---> sing-box 启动成功" + echoContent green " ---> sing-box启动成功" else - echoContent red "sing-box 启动失败" + echoContent red "sing-box启动失败" echoContent red "请手动执行【/etc/v2ray-agent/sing-box/sing-box run -c /etc/v2ray-agent/sing-box/conf/config.json】,查看错误日志" exit 0 fi elif [[ "$1" == "stop" ]]; then if [[ -z $(pgrep -f "sing-box") ]]; then - echoContent green " ---> sing-box 关闭成功" + echoContent green " ---> sing-box关闭成功" else - echoContent red "sing-box 关闭失败" + echoContent red " ---> sing-box关闭失败" echoContent red "请手动执行【ps -ef|grep -v grep|grep sing-box|awk '{print \$2}'|xargs kill -9】" exit 0 fi @@ -2631,11 +2664,6 @@ initXrayClients() { fi local users= users=[] - # if [[ "${type}" == "9" ]]; then - # users={} - # else - # users=[] - # fi while read -r user; do uuid=$(echo "${user}" | jq -r .id) email=$(echo "${user}" | jq -r .email | awk -F "[-]" '{print $1}') @@ -2678,7 +2706,9 @@ initXrayClients() { # hysteria if echo "${type}" | grep -q "6"; then - users=$(echo "${users}" | jq -r ". +=[\"${uuid}\"]") + currentUser="{\"password\":\"${uuid}\",\"name\":\"${email}-singbox_hysteria2\"}" + + users=$(echo "${users}" | jq -r ". +=[${currentUser}]") fi # vless reality vision @@ -2752,7 +2782,7 @@ addClientsHysteria() { # 初始化hysteria端口 initHysteriaPort() { - readHysteriaConfig + readSingBoxConfig if [[ -n "${hysteriaPort}" ]]; then read -r -p "读取到上次安装时的端口,是否使用上次安装时的端口?[y/n]:" historyHysteriaPortStatus if [[ "${historyHysteriaPortStatus}" == "y" ]]; then @@ -3015,7 +3045,7 @@ EOF # 初始化tuic端口 initTuicPort() { - readTuicConfig + readSingBoxConfig if [[ -n "${tuicPort}" ]]; then read -r -p "读取到上次安装时的端口,是否使用上次安装时的端口?[y/n]:" historyTuicPortStatus if [[ "${historyTuicPortStatus}" == "y" ]]; then @@ -3119,8 +3149,35 @@ initSingBoxTuicConfig() { EOF } -# singBox Tuic安装 -# todo 123 +# 初始化 sing-box Hysteria2 配置 +initSingBoxHysteria2Config() { + echoContent skyBlue "\n进度 $1/${totalProgress} : 初始化Hysteria2配置" + + initHysteriaPort + # todo 123123 + cat </etc/v2ray-agent/sing-box/conf/config/hysteria2.json +{ + "inbounds": [ + { + "type": "hysteria2", + "listen": "::", + "listen_port": ${hysteriaPort}, + "users": $(initXrayClients 6), + "tls": { + "enabled": true, + "alpn": [ + "h3" + ], + "certificate_path": "/etc/v2ray-agent/tls/${currentHost}.crt", + "key_path": "/etc/v2ray-agent/tls/${currentHost}.key" + } + } + ] +} +EOF +} + +# sing-box Tuic安装 singBoxTuicInstall() { if ! echo "${currentInstallProtocolType}" | grep -q "0" || [[ -z "${coreInstallType}" ]]; then echoContent red "\n ---> 由于证书环境依赖,如安装Tuic,请先安装Xray-core的VLESS_TCP_TLS_Vision" @@ -3136,6 +3193,21 @@ singBoxTuicInstall() { showAccounts 4 } +# sing-box hy2安装 +singBoxHysteria2Install() { + if ! echo "${currentInstallProtocolType}" | grep -q "0" || [[ -z "${coreInstallType}" ]]; then + echoContent red "\n ---> 由于证书环境依赖,如安装Hysteria2,请先安装Xray-core的VLESS_TCP_TLS_Vision" + exit 0 + fi + totalProgress=5 + installSingBox 1 + initSingBoxHysteria2Config 2 + singBoxMergeConfig + installSingBoxService 3 + reloadCore + showAccounts 4 +} + # 合并config singBoxMergeConfig() { rm /etc/v2ray-agent/sing-box/conf/config.json >/dev/null 2>&1 @@ -4220,39 +4292,26 @@ EOF echoContent green " https://api.qrserver.com/v1/create-qr-code/?size=400x400&data=trojan%3a%2f%2f${id}%40${add}%3a${currentDefaultPort}%3Fencryption%3Dnone%26fp%3Dchrome%26security%3Dtls%26peer%3d${currentHost}%26type%3Dgrpc%26sni%3d${currentHost}%26path%3D${currentPath}trojangrpc%26alpn%3Dh2%26serviceName%3D${currentPath}trojangrpc%23${email}\n" elif [[ "${type}" == "hysteria" ]]; then - # local hysteriaEmail= - # hysteriaEmail=$(echo "${email}" | awk -F "[-]" '{print $1}')_hysteria echoContent yellow " ---> Hysteria(TLS)" - echoContent green " hysteria2://${id}@${currentHost}:${hysteriaPort}?peer=${currentHost}&insecure=0&sni=${currentHost}&alpn=h3#hysteria2\n" - # cat <>"/etc/v2ray-agent/subscribe_local/default/${user}" - #hysteria2://${id}@${currentHost}:${hysteriaPort}?peer=${currentHost}&insecure=0&sni=${currentHost}&alpn=h3#hysteria2 - #EOF - echoContent yellow " ---> v2rayN(hysteria+TLS)" - cat <"/etc/v2ray-agent/hysteria/conf/client.json" -{ - "server": "${currentHost}:${hysteriaPort}", - "socks5": { "listen": "127.0.0.1:10808", "timeout": 300}, - "auth":"${id}", - "tls":{ - "sni":"${currentHost}" - } -} + echoContent green " hysteria2://${id}@${currentHost}:${hysteriaPort}?peer=${currentHost}&insecure=0&sni=${currentHost}&alpn=h3#${email}\n" + cat <>"/etc/v2ray-agent/subscribe_local/default/${user}" +hysteria2://${id}@${currentHost}:${hysteriaPort}?peer=${currentHost}&insecure=0&sni=${currentHost}&alpn=h3#${email} EOF - local v2rayNConf= - v2rayNConf="$(cat /etc/v2ray-agent/hysteria/conf/client.json)" - echoContent green "${v2rayNConf}\n" + echoContent yellow " ---> v2rayN(hysteria+TLS)" + echo "{\"server\": \"${currentHost}:${hysteriaPort}\",\"socks5\": { \"listen\": \"127.0.0.1:10808\", \"timeout\": 300},\"auth\":\"${id}\",\"tls\":{\"sni\":\"${currentHost}\"}}" | jq - # cat <>"/etc/v2ray-agent/subscribe_local/clashMeta/${user}" - # - name: hysteria2 - # type: hysteria2 - # server: ${currentHost} - # port: ${hysteriaPort} - # password: ${id} - # sni: ${currentHost} - #EOF + cat <>"/etc/v2ray-agent/subscribe_local/clashMeta/${user}" + - name: "${email}" + type: hysteria2 + server: ${currentHost} + port: ${hysteriaPort} + password: ${id} + sni: ${currentHost} +EOF echoContent yellow " ---> 二维码 Hysteria(TLS)" - echoContent green " https://api.qrserver.com/v1/create-qr-code/?size=400x400&data=hysteria2%3A%2F%2F${id}%40${currentHost}%3A${hysteriaPort}%3Fpeer%3D${currentHost}%26insecure%3D0%26sni%3D${currentHost}%26alpn%3Dh3%23hysteria2\n" + echoContent green " https://api.qrserver.com/v1/create-qr-code/?size=400x400&data=hysteria2%3A%2F%2F${id}%40${currentHost}%3A${hysteriaPort}%3Fpeer%3D${currentHost}%26insecure%3D0%26sni%3D${currentHost}%26alpn%3Dh3%23${email}\n" + elif [[ "${type}" == "vlessReality" ]]; then echoContent yellow " ---> 通用格式(VLESS+reality+uTLS+Vision)" echoContent green " vless://${id}@$(getPublicIP):${currentRealityPort}?encryption=none&security=reality&type=tcp&sni=${currentRealityServerNames}&fp=chrome&pbk=${currentRealityPublicKey}&sid=6ba85179e30d4fc2&flow=xtls-rprx-vision#${email}\n" @@ -4319,6 +4378,9 @@ EOF echoContent yellow " ---> 格式化明文(Tuic+TLS)" echoContent green " 协议类型:Tuic,地址:${currentHost},端口:${tuicPort},uuid:${id},password:${id},congestion-controller:${tuicAlgorithm},alpn: h3,账户名:${email}\n" + cat <>"/etc/v2ray-agent/subscribe_local/default/${user}" +tuic://${id}@${currentHost}:${tuicPort}?peer=${currentHost}&congestion_control=${tuicAlgorithm}&password=${id}&insecure=0&sni=${currentHost}&alpn=h3#${email} +EOF echoContent yellow " ---> v2rayN(Tuic+TLS)" echo "{\"relay\": {\"server\": \"${currentHost}:${tuicPort}\",\"uuid\": \"${id}\",\"password\": \"${id}\",\"ip\": \"$(getPublicIP)\",\"congestion_control\": \"${tuicAlgorithm}\",\"alpn\": [\"h3\"]},\"local\": {\"server\": \"127.0.0.1:7798\"},\"log_level\": \"warn\"}" | jq @@ -4345,10 +4407,11 @@ showAccounts() { readInstallType readInstallProtocolType readConfigHostPathUUID - readHysteriaConfig + # readHysteriaConfig + readSingBoxConfig readXrayCoreRealityConfig - readHysteriaPortHopping - readTuicConfig + # readHysteriaPortHopping + echo echoContent skyBlue "\n进度 $1/${totalProgress} : 账号" local show @@ -4473,14 +4536,10 @@ showAccounts() { fi if echo ${currentInstallProtocolType} | grep -q 6; then echoContent skyBlue "\n================================ Hysteria TLS ================================\n" - jq -r .auth.password "${hysteriaConfigPath}config.json" | while read -r user; do - - if [[ -n ${user} ]]; then - echoContent skyBlue "\n ---> 账号:hysteria2" - echo - defaultBase64Code hysteria hysteria2 "${user}" - fi - + jq -r -c '.inbounds[]|select(.type=="hysteria2")|.users[]' "${singBoxConfigPath}config.json" | while read -r user; do + echoContent skyBlue "\n ---> 账号:$(echo "${user}" | jq -r .name)" + echo + defaultBase64Code hysteria "$(echo "${user}" | jq -r .name)" "$(echo "${user}" | jq -r .password)" done fi @@ -4799,27 +4858,26 @@ unInstall() { handleXray stop rm -rf /etc/systemd/system/xray.service echoContent green " ---> 删除Xray开机自启完成" - - # elif [[ "${coreInstallType}" == "2" ]]; then - # - # handleV2Ray stop - # rm -rf /etc/systemd/system/v2ray.service - # echoContent green " ---> 删除V2Ray开机自启完成" - fi - if [[ -z "${hysteriaConfigPath}" ]]; then + if [[ -n "${hysteriaConfigPath}" ]]; then handleHysteria stop rm -rf /etc/systemd/system/hysteria.service echoContent green " ---> 删除Hysteria开机自启完成" fi - if [[ -z "${tuicConfigPath}" ]]; then + if [[ -n "${tuicConfigPath}" ]]; then handleTuic stop rm -rf /etc/systemd/system/tuic.service echoContent green " ---> 删除Tuic开机自启完成" fi + if [[ -n "${singBoxConfigPath}" ]]; then + handleSingBox stop + rm -rf /etc/systemd/system/sing-box.service + echoContent green " ---> 删除sing-box开机自启完成" + fi + # if [[ -f "/root/.acme.sh/acme.sh.env" ]] && grep -q 'acme.sh.env' 新版本依赖sing-box,检测到旧版本hysteria,执行卸载操作" - if [[ -z "${hysteriaConfigPath}" ]]; then - echoContent red "\n ---> 未安装" - exit 0 + deleteHysteriaPortHoppingRules + handleHysteria stop + rm -rf /etc/v2ray-agent/hysteria/* + rm ${configPath}02_socks_inbounds_hysteria.json + rm -rf /etc/systemd/system/hysteria.service + echoContent green " ---> 卸载完成" fi - deleteHysteriaPortHoppingRules - handleHysteria stop - rm -rf /etc/v2ray-agent/hysteria/* - rm ${configPath}02_socks_inbounds_hysteria.json - rm -rf /etc/systemd/system/hysteria.service - echoContent green " ---> 卸载完成" } + # 卸载Tuic unInstallTuicCore() { - if [[ -z "${tuicConfigPath}" ]]; then - echoContent red "\n ---> 未安装" - exit 0 + if [[ -n "${tuicConfigPath}" ]]; then + echoContent yellow " ---> 新版本依赖sing-box,检测到旧版本Tuic,执行卸载操作" + + handleTuic stop + rm -rf /etc/v2ray-agent/tuic/* + rm -rf /etc/systemd/system/tuic.service + echoContent green " ---> 卸载完成" fi - handleTuic stop - rm -rf /etc/v2ray-agent/tuic/* - rm -rf /etc/systemd/system/tuic.service - echoContent green " ---> 卸载完成" + } unInstallXrayCoreReality() { @@ -7871,32 +7927,28 @@ manageReality() { # hysteria管理 manageHysteria() { - echoContent skyBlue "\n进度 1/1 : Hysteria管理" + echoContent skyBlue "\n进度 1/1 : Hysteria2 管理" echoContent red "\n==============================================================" - local hysteriaStatus= - if [[ -n "${hysteriaConfigPath}" ]]; then + local hysteria2Status= + if [[ -n "${singBoxConfigPath}" ]] && [[ -f "/etc/v2ray-agent/sing-box/conf/config.json" ]] && grep -q 'hysteria2'