From 795eb7a8f802dea3adeb962a12f46915864afcb9 Mon Sep 17 00:00:00 2001 From: mack-a <57424792+mack-a@users.noreply.github.com> Date: Fri, 27 Sep 2024 16:53:28 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E8=84=9A=E6=9C=AC):=20=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E5=BF=AB=E6=8D=B7=E9=87=8D=E6=96=B0=E5=AE=89=E8=A3=85=EF=BC=88?= =?UTF-8?q?=E8=AF=BB=E5=8F=96=E4=B8=8A=E6=AC=A1=E9=85=8D=E7=BD=AE=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- install.sh | 194 ++++++++++++++++++++++++++++++++++------------------- 1 file changed, 125 insertions(+), 69 deletions(-) diff --git a/install.sh b/install.sh index d726287..95b13e5 100644 --- a/install.sh +++ b/install.sh @@ -321,6 +321,9 @@ initVar() { addressWarpReg= secretKeyWarpReg= + # 上次安装配置状态 + lastInstallationConfig= + } # 读取tls证书详情 @@ -484,6 +487,7 @@ readInstallProtocolType() { currentInstallProtocolType="${currentInstallProtocolType}7," if [[ "${coreInstallType}" == "1" ]]; then xrayVLESSRealityServerName=$(jq -r .inbounds[0].streamSettings.realitySettings.serverNames[0] "${row}.json") + realityServerName=${xrayVLESSRealityServerName} xrayVLESSRealityPort=$(jq -r .inbounds[0].port "${row}.json") # xrayVLESSRealityPrivateKey=$(jq -r .inbounds[0].streamSettings.realitySettings.privateKey "${row}.json") # xrayVLESSRealityPublicKey=$(jq -r .inbounds[0].streamSettings.realitySettings.publicKey "${row}.json") @@ -494,6 +498,7 @@ readInstallProtocolType() { frontingTypeReality=07_VLESS_vision_reality_inbounds singBoxVLESSRealityVisionPort=$(jq -r .inbounds[0].listen_port "${row}.json") singBoxVLESSRealityVisionServerName=$(jq -r .inbounds[0].tls.server_name "${row}.json") + realityServerName=${singBoxVLESSRealityVisionServerName} if [[ -f "${configPath}reality_key" ]]; then singBoxVLESSRealityPublicKey=$(grep "publicKey" <"${configPath}reality_key" | awk -F "[:]" '{print $2}') @@ -754,6 +759,15 @@ readSingBoxConfig() { fi } +# 读取上次安装的配置 +readLastInstallationConfig() { + if [[ -n "${configPath}" ]]; then + read -r -p "读取到上次安装的配置,是否使用 ?[y/n]:" lastInstallationConfigStatus + if [[ "${lastInstallationConfigStatus}" == "y" ]]; then + lastInstallationConfig=true + fi + fi +} # 卸载 sing-box unInstallSingBox() { local type=$1 @@ -970,10 +984,10 @@ cleanUp() { initVar "$1" checkSystem checkCPUVendor + readInstallType readInstallProtocolType readConfigHostPathUUID -#readInstallAlpn readCustomPort readSingBoxConfig # ------------------------------------------------------------- @@ -1378,7 +1392,7 @@ EOF initTLSNginxConfig() { handleNginx stop echoContent skyBlue "\n进度 $1/${totalProgress} : 初始化Nginx申请证书配置" - if [[ -n "${currentHost}" ]]; then + if [[ -n "${currentHost}" && -z "${lastInstallationConfig}" ]]; then echo read -r -p "读取到上次安装记录,是否使用上次安装时的域名 ?[y/n]:" historyDomainStatus if [[ "${historyDomainStatus}" == "y" ]]; then @@ -1389,6 +1403,8 @@ initTLSNginxConfig() { echoContent yellow "请输入要配置的域名 例: www.v2ray-agent.com --->" read -r -p "域名:" domain fi + elif [[ -n "${currentHost}" && -n "${lastInstallationConfig}" ]]; then + domain=${currentHost} else echo echoContent yellow "请输入要配置的域名 例: www.v2ray-agent.com --->" @@ -1808,10 +1824,14 @@ customPortFunction() { local historyCustomPortStatus= if [[ -n "${customPort}" || -n "${currentPort}" ]]; then echo - read -r -p "读取到上次安装时的端口,是否使用上次安装时的端口?[y/n]:" historyCustomPortStatus - if [[ "${historyCustomPortStatus}" == "y" ]]; then + if [[ -z "${lastInstallationConfig}" ]]; then + read -r -p "读取到上次安装时的端口,是否使用上次安装时的端口?[y/n]:" historyCustomPortStatus + if [[ "${historyCustomPortStatus}" == "y" ]]; then + port=${currentPort} + echoContent yellow "\n ---> 端口: ${port}" + fi + elif [[ -n "${lastInstallationConfig}" ]]; then port=${currentPort} - echoContent yellow "\n ---> 端口: ${port}" fi fi if [[ -z "${currentPort}" ]] || [[ "${historyCustomPortStatus}" == "n" ]]; then @@ -1884,11 +1904,13 @@ installTLS() { else if [[ -d "$HOME/.acme.sh/${tlsDomain}_ecc" && -f "$HOME/.acme.sh/${tlsDomain}_ecc/${tlsDomain}.key" && -f "$HOME/.acme.sh/${tlsDomain}_ecc/${tlsDomain}.cer" ]] || [[ "${installedDNSAPIStatus}" == "true" ]]; then - echoContent yellow " ---> 如未过期或者自定义证书请选择[n]\n" - read -r -p "是否重新安装?[y/n]:" reInstallStatus - if [[ "${reInstallStatus}" == "y" ]]; then - rm -rf /etc/v2ray-agent/tls/* - installTLS "$1" + if [[ -z "${lastInstallationConfig}" ]]; then + echoContent yellow " ---> 如未过期或者自定义证书请选择[n]\n" + read -r -p "是否重新安装?[y/n]:" reInstallStatus + if [[ "${reInstallStatus}" == "y" ]]; then + rm -rf /etc/v2ray-agent/tls/* + installTLS "$1" + fi fi fi fi @@ -1957,10 +1979,12 @@ randomPathFunction() { echoContent skyBlue "生成随机路径" fi - if [[ -n "${currentPath}" ]]; then + if [[ -n "${currentPath}" && -z "${lastInstallationConfig}" ]]; then echo read -r -p "读取到上次安装记录,是否使用上次安装时的path路径 ?[y/n]:" historyPathStatus echo + elif [[ -n "${currentPath}" && -n "${lastInstallationConfig}" ]]; then + historyPathStatus="y" fi if [[ "${historyPathStatus}" == "y" ]]; then @@ -2005,7 +2029,12 @@ nginxBlog() { if [[ -d "${nginxStaticPath}" && -f "${nginxStaticPath}/check" ]]; then echo - read -r -p "检测到安装伪装站点,是否需要重新安装[y/n]:" nginxBlogInstallStatus + if [[ -z "${lastInstallationConfig}" ]]; then + read -r -p "检测到安装伪装站点,是否需要重新安装[y/n]:" nginxBlogInstallStatus + else + nginxBlogInstallStatus="n" + fi + if [[ "${nginxBlogInstallStatus}" == "y" ]]; then rm -rf "${nginxStaticPath}*" # randomNum=$((RANDOM % 6 + 1)) @@ -2288,10 +2317,12 @@ installSingBox() { fi else echoContent green " ---> sing-box版本:v$(/etc/v2ray-agent/sing-box/sing-box version | grep "sing-box version" | awk '{print $3}')" - read -r -p "是否更新、升级?[y/n]:" reInstallSingBoxStatus - if [[ "${reInstallSingBoxStatus}" == "y" ]]; then - rm -f /etc/v2ray-agent/sing-box/sing-box - installSingBox "$1" + if [[ -z "${lastInstallationConfig}" ]]; then + read -r -p "是否更新、升级?[y/n]:" reInstallSingBoxStatus + if [[ "${reInstallSingBoxStatus}" == "y" ]]; then + rm -f /etc/v2ray-agent/sing-box/sing-box + installSingBox "$1" + fi fi fi @@ -2318,7 +2349,6 @@ installXray() { if [[ ! -f "/etc/v2ray-agent/xray/xray" ]]; then version=$(curl -s "https://api.github.com/repos/XTLS/Xray-core/releases?per_page=5" | jq -r ".[]|select (.prerelease==${prereleaseStatus})|.tag_name" | head -1) - echoContent green " ---> Xray-core版本:${version}" if [[ "${release}" == "alpine" ]]; then wget -c -q -P /etc/v2ray-agent/xray/ "https://github.com/XTLS/Xray-core/releases/download/${version}/${xrayCoreCPUVendor}.zip" @@ -2351,11 +2381,13 @@ installXray() { chmod 655 /etc/v2ray-agent/xray/xray fi else - echoContent green " ---> Xray-core版本:$(/etc/v2ray-agent/xray/xray --version | awk '{print $2}' | head -1)" - read -r -p "是否更新、升级?[y/n]:" reInstallXrayStatus - if [[ "${reInstallXrayStatus}" == "y" ]]; then - rm -f /etc/v2ray-agent/xray/xray - installXray "$1" "$2" + if [[ -z "${lastInstallationConfig}" ]]; then + echoContent green " ---> Xray-core版本:$(/etc/v2ray-agent/xray/xray --version | awk '{print $2}' | head -1)" + read -r -p "是否更新、升级?[y/n]:" reInstallXrayStatus + if [[ "${reInstallXrayStatus}" == "y" ]]; then + rm -f /etc/v2ray-agent/xray/xray + installXray "$1" "$2" + fi fi fi } @@ -3975,13 +4007,15 @@ initXrayFrontingConfig() { # 初始化sing-box端口 initSingBoxPort() { local port=$1 - if [[ -n "${port}" ]]; then + if [[ -n "${port}" && -z "${lastInstallationConfig}" ]]; then read -r -p "读取到上次使用的端口,是否使用 ?[y/n]:" historyPort if [[ "${historyPort}" != "y" ]]; then port= else echo "${port}" fi + elif [[ -n "${port}" && -n "${lastInstallationConfig}" ]]; then + echo "${port}" fi if [[ -z "${port}" ]]; then read -r -p '请输入自定义端口[需合法],端口不可重复,[回车]随机端口:' port @@ -4005,12 +4039,14 @@ initXrayConfig() { echo local uuid= local addClientsStatus= - if [[ -n "${currentUUID}" ]]; then + if [[ -n "${currentUUID}" && -z "${lastInstallationConfig}" ]]; then read -r -p "读取到上次用户配置,是否使用上次安装的配置 ?[y/n]:" historyUUIDStatus if [[ "${historyUUIDStatus}" == "y" ]]; then addClientsStatus=true echoContent green "\n ---> 使用成功" fi + elif [[ -n "${currentUUID}" && -n "${lastInstallationConfig}" ]]; then + addClientsStatus=true fi if [[ -z "${addClientsStatus}" ]]; then @@ -4351,6 +4387,7 @@ EOF # VLESS_TCP/reality if echo "${selectCustomInstallType}" | grep -q ",7," || [[ "$1" == "all" ]]; then echoContent skyBlue "\n===================== 配置VLESS+Reality =====================\n" + initXrayRealityPort initRealityClientServersName initRealityKey @@ -4466,12 +4503,14 @@ initSingBoxConfig() { elif [[ -n "${currentHost}" ]]; then sslDomain="${currentHost}" fi - if [[ -n "${currentUUID}" ]]; then + if [[ -n "${currentUUID}" && -z "${lastInstallationConfig}" ]]; then read -r -p "读取到上次用户配置,是否使用上次安装的配置 ?[y/n]:" historyUUIDStatus if [[ "${historyUUIDStatus}" == "y" ]]; then addClientsStatus=true echoContent green "\n ---> 使用成功" fi + elif [[ -n "${currentUUID}" && -n "${lastInstallationConfig}" ]]; then + addClientsStatus=true fi if [[ -z "${addClientsStatus}" ]]; then @@ -8028,6 +8067,7 @@ customSingBoxInstall() { fi if [[ "${selectCustomInstallType//,/}" =~ ^[0-9]+$ ]]; then + readLastInstallationConfig totalProgress=9 installTools 1 # 申请tls @@ -8098,6 +8138,7 @@ customXrayInstall() { selectCustomInstallType=",${selectCustomInstallType}," fi if [[ "${selectCustomInstallType//,/}" =~ ^[0-7]+$ ]]; then + readLastInstallationConfig unInstallSubscribe checkBTPanel check1Panel @@ -8156,7 +8197,7 @@ customXrayInstall() { fi } -# 选择核心安装---v2ray-core、xray-core +# 选择核心安装sing-box、xray-core selectCoreInstall() { echoContent skyBlue "\n功能 1/${totalProgress} : 选择核心安装" echoContent red "\n==============================================================" @@ -8188,6 +8229,7 @@ selectCoreInstall() { # xray-core 安装 xrayCoreInstall() { + readLastInstallationConfig unInstallSubscribe checkBTPanel check1Panel @@ -8233,17 +8275,12 @@ xrayCoreInstall() { # sing-box 全部安装 singBoxInstall() { + readLastInstallationConfig checkBTPanel check1Panel selectCustomInstallType= totalProgress=8 installTools 2 - # if [[ -n "${btDomain}" ]]; then - # echoContent skyBlue "\n进度 3/${totalProgress} : 检测到宝塔面板,跳过申请TLS步骤" - # handleXray stop - # customPortFunction - # else - # 申请tls if [[ -n "${btDomain}" ]]; then echoContent skyBlue "\n进度 3/${totalProgress} : 检测到宝塔面板/1Panel,跳过申请TLS步骤" @@ -8261,6 +8298,7 @@ singBoxInstall() { installSingBox 5 installSingBoxService 6 initSingBoxConfig all 7 + cleanUp xrayDel installCronTLS 8 @@ -9183,12 +9221,15 @@ switchAlpn() { # 初始化realityKey initRealityKey() { echoContent skyBlue "\n生成Reality key\n" - if [[ -n "${currentRealityPublicKey}" ]]; then + if [[ -n "${currentRealityPublicKey}" && -z "${lastInstallationConfig}" ]]; then read -r -p "读取到上次安装记录,是否使用上次安装时的PublicKey/PrivateKey ?[y/n]:" historyKeyStatus if [[ "${historyKeyStatus}" == "y" ]]; then realityPrivateKey=${currentRealityPrivateKey} realityPublicKey=${currentRealityPublicKey} fi + elif [[ -n "${currentRealityPublicKey}" && -n "${lastInstallationConfig}" ]]; then + realityPrivateKey=${currentRealityPrivateKey} + realityPublicKey=${currentRealityPublicKey} fi if [[ -z "${realityPrivateKey}" ]]; then if [[ "${selectCoreType}" == "2" || "${coreInstallType}" == "2" ]]; then @@ -9247,47 +9288,58 @@ initRealityDest() { } # 初始化客户端可用的ServersName initRealityClientServersName() { - realityServerName= - if [[ -n "${domain}" ]]; then - echo - read -r -p "是否使用 ${domain} 此域名作为Reality目标域名 ?[y/n]:" realityServerNameCurrentDomainStatus - if [[ "${realityServerNameCurrentDomainStatus}" == "y" ]]; then - realityServerName="${domain}" - if [[ "${selectCoreType}" == "1" ]]; then - # if [[ -n "${port}" ]]; then - # realityDomainPort="${port}" - if [[ -z "${subscribePort}" ]]; then + + if [[ -n "${realityServerName}" && -z "${lastInstallationConfig}" ]]; then + read -r -p "读取到上次安装设置的Reality域名,是否使用?[y/n]:" realityServerNameStatus + if [[ "${realityServerNameStatus}" != "y" ]]; then + realityServerName= + fi + elif [[ -z "${lastInstallationConfig}" ]]; then + realityServerName= + fi + if [[ -n "${realityServerName}" ]] && [[ "${realityServerName}" != "${domain}" ]]; then + realityDomainPort=443 + fi + + if [[ -z "${realityServerName}" ]]; then + if [[ -n "${domain}" ]]; then + echo + read -r -p "是否使用 ${domain} 此域名作为Reality目标域名 ?[y/n]:" realityServerNameCurrentDomainStatus + if [[ "${realityServerNameCurrentDomainStatus}" == "y" ]]; then + realityServerName="${domain}" + if [[ "${selectCoreType}" == "1" ]]; then + if [[ -z "${subscribePort}" ]]; then + echo + installSubscribe + readNginxSubscribe + realityDomainPort="${subscribePort}" + fi + fi + + if [[ "${selectCoreType}" == "2" && -z "${subscribePort}" ]]; then echo installSubscribe readNginxSubscribe realityDomainPort="${subscribePort}" fi fi - - if [[ "${selectCoreType}" == "2" && -z "${subscribePort}" ]]; then - echo - installSubscribe - readNginxSubscribe - realityDomainPort="${subscribePort}" - fi fi - fi - if [[ -z "${realityServerName}" ]]; then - local realityDestDomainList="gateway.icloud.com,itunes.apple.com,swdist.apple.com,swcdn.apple.com,updates.cdn-apple.com,mensura.cdn-apple.com,osxapps.itunes.apple.com,aod.itunes.apple.com,download-installer.cdn.mozilla.net,addons.mozilla.org,s0.awsstatic.com,d1.awsstatic.com,images-na.ssl-images-amazon.com,m.media-amazon.com,player.live-video.net,one-piece.com,lol.secure.dyn.riotcdn.net,www.lovelive-anime.jp,www.swift.com,academy.nvidia.com,www.cisco.com,www.asus.com,www.samsung.com,www.amd.com,cdn-dynmedia-1.microsoft.com,software.download.prss.microsoft.com,dl.google.com,www.google-analytics.com" - realityDomainPort=443 - echoContent skyBlue "\n================ 配置客户端可用的serverNames ===============\n" - echoContent yellow "#注意事项" - echoContent green "Reality目标可用域名列表:https://www.v2ray-agent.com/archives/1689439383686#heading-3\n" - echoContent yellow "录入示例:addons.mozilla.org:443\n" - read -r -p "请输入目标域名,[回车]随机域名,默认端口443:" realityServerName if [[ -z "${realityServerName}" ]]; then - # randomNum=$((RANDOM % 27 + 1)) - randomNum=$(randomNum 1 27) - realityServerName=$(echo "${realityDestDomainList}" | awk -F ',' -v randomNum="$randomNum" '{print $randomNum}') - fi - if echo "${realityServerName}" | grep -q ":"; then - realityDomainPort=$(echo "${realityServerName}" | awk -F "[:]" '{print $2}') - realityServerName=$(echo "${realityServerName}" | awk -F "[:]" '{print $1}') + local realityDestDomainList="gateway.icloud.com,itunes.apple.com,swdist.apple.com,swcdn.apple.com,updates.cdn-apple.com,mensura.cdn-apple.com,osxapps.itunes.apple.com,aod.itunes.apple.com,download-installer.cdn.mozilla.net,addons.mozilla.org,s0.awsstatic.com,d1.awsstatic.com,images-na.ssl-images-amazon.com,m.media-amazon.com,player.live-video.net,one-piece.com,lol.secure.dyn.riotcdn.net,www.lovelive-anime.jp,www.swift.com,academy.nvidia.com,www.cisco.com,www.asus.com,www.samsung.com,www.amd.com,cdn-dynmedia-1.microsoft.com,software.download.prss.microsoft.com,dl.google.com,www.google-analytics.com" + realityDomainPort=443 + echoContent skyBlue "\n================ 配置客户端可用的serverNames ===============\n" + echoContent yellow "#注意事项" + echoContent green "Reality目标可用域名列表:https://www.v2ray-agent.com/archives/1689439383686#heading-3\n" + echoContent yellow "录入示例:addons.mozilla.org:443\n" + read -r -p "请输入目标域名,[回车]随机域名,默认端口443:" realityServerName + if [[ -z "${realityServerName}" ]]; then + randomNum=$(randomNum 1 27) + realityServerName=$(echo "${realityDestDomainList}" | awk -F ',' -v randomNum="$randomNum" '{print $randomNum}') + fi + if echo "${realityServerName}" | grep -q ":"; then + realityDomainPort=$(echo "${realityServerName}" | awk -F "[:]" '{print $2}') + realityServerName=$(echo "${realityServerName}" | awk -F "[:]" '{print $1}') + fi fi fi @@ -9295,11 +9347,13 @@ initRealityClientServersName() { } # 初始化reality端口 initXrayRealityPort() { - if [[ -n "${xrayVLESSRealityPort}" ]]; then + if [[ -n "${xrayVLESSRealityPort}" && -z "${lastInstallationConfig}" ]]; then read -r -p "读取到上次安装记录,是否使用上次安装时的端口 ?[y/n]:" historyRealityPortStatus if [[ "${historyRealityPortStatus}" == "y" ]]; then realityPort=${xrayVLESSRealityPort} fi + elif [[ -n "${xrayVLESSRealityPort}" && -n "${lastInstallationConfig}" ]]; then + realityPort=${xrayVLESSRealityPort} fi if [[ -z "${realityPort}" ]]; then @@ -9332,11 +9386,13 @@ initXrayRealityPort() { } # 初始化SplitHTTP端口 initXraySplitPort() { - if [[ -n "${xrayVLESSSplitHTTPort}" ]]; then + if [[ -n "${xrayVLESSSplitHTTPort}" && -z "${lastInstallationConfig}" ]]; then read -r -p "读取到上次安装记录,是否使用上次安装时的端口 ?[y/n]:" historySplitHTTPortStatus if [[ "${historySplitHTTPortStatus}" == "y" ]]; then splitHTTPort=${xrayVLESSSplitHTTPort} fi + elif [[ -n "${xrayVLESSSplitHTTPort}" && -n "${lastInstallationConfig}" ]]; then + splitHTTPort=${xrayVLESSSplitHTTPort} fi if [[ -z "${splitHTTPort}" ]]; then @@ -9629,7 +9685,7 @@ menu() { cd "$HOME" || exit echoContent red "\n==============================================================" echoContent green "作者:mack-a" - echoContent green "当前版本:v3.3.18" + echoContent green "当前版本:v3.3.19" echoContent green "Github:https://github.com/mack-a/v2ray-agent" echoContent green "描述:八合一共存脚本\c" showInstallStatus