feat(脚本): 兼容宝塔多域名的情况,修复宝塔搭建失败问题

pull/656/head
mack-a 2023-05-08 15:08:48 +08:00
parent 7d1037b9c0
commit 072bc15146
1 changed files with 57 additions and 35 deletions

View File

@ -366,19 +366,35 @@ readInstallProtocolType() {
checkBTPanel() { checkBTPanel() {
if [[ -n $(pgrep -f "BT-Panel") ]]; then if [[ -n $(pgrep -f "BT-Panel") ]]; then
# 读取域名 # 读取域名
if [[ -d '/www/server/panel/vhost/cert/' ]]; then if [[ -d '/www/server/panel/vhost/cert/' && -n $(find /www/server/panel/vhost/cert/*/fullchain.pem) ]]; then
btDomain=$(find /www/server/panel/vhost/cert/* | head -1 | awk -F "[/]" '{print $7}')
domain=${btDomain}
if [[ ! -f "/etc/v2ray-agent/tls/${btDomain}.key" && ! -f "/etc/v2ray-agent/tls/${btDomain}.crt" && ! -L "/etc/v2ray-agent/tls/${btDomain}.key" && ! -L "/etc/v2ray-agent/tls/${btDomain}.crt" ]]; then
ln -s "/www/server/panel/vhost/cert/${btDomain}/privkey.pem" "/etc/v2ray-agent/tls/${btDomain}.key"
ln -s "/www/server/panel/vhost/cert/${btDomain}/fullchain.pem" "/etc/v2ray-agent/tls/${btDomain}.crt"
fi
nginxStaticPath="/www/wwwroot/${btDomain}/"
if [[ -f "/www/wwwroot/${btDomain}/.user.ini" ]]; then
chattr -i "/www/wwwroot/${btDomain}/.user.ini"
fi
nginxConfigPath="/www/server/panel/vhost/nginx/" echoContent skyBlue "\n读取宝塔配置\n"
find /www/server/panel/vhost/cert/*/fullchain.pem | awk -F "[/]" '{print $7}' | awk '{print NR""":"$0}'
read -r -p "请输入编号选择:" selectBTDomain
if [[ -n "${selectBTDomain}" ]]; then
btDomain=$(find /www/server/panel/vhost/cert/*/fullchain.pem | awk -F "[/]" '{print $7}' | awk '{print NR""":"$0}' | grep "${selectBTDomain}:" | cut -d ":" -f 2)
if [[ -z "${btDomain}" ]]; then
echoContent red " ---> 选择错误,请重新选择"
checkBTPanel
else
domain=${btDomain}
ln -s "/www/server/panel/vhost/cert/${btDomain}/fullchain.pem" "/etc/v2ray-agent/tls/${btDomain}.crt"
ln -s "/www/server/panel/vhost/cert/${btDomain}/privkey.pem" "/etc/v2ray-agent/tls/${btDomain}.key"
nginxStaticPath="/www/wwwroot/${btDomain}/"
if [[ -f "/www/wwwroot/${btDomain}/.user.ini" ]]; then
chattr -i "/www/wwwroot/${btDomain}/.user.ini"
fi
nginxConfigPath="/www/server/panel/vhost/nginx/"
fi
else
echoContent red " ---> 选择错误,请重新选择"
checkBTPanel
fi
fi fi
fi fi
} }
@ -670,7 +686,6 @@ readInstallProtocolType
readConfigHostPathUUID readConfigHostPathUUID
readInstallAlpn readInstallAlpn
readCustomPort readCustomPort
checkBTPanel
readXrayCoreRealityConfig readXrayCoreRealityConfig
# ------------------------------------------------------------- # -------------------------------------------------------------
@ -1050,8 +1065,9 @@ EOF
updateRedirectNginxConf() { updateRedirectNginxConf() {
local redirectDomain= local redirectDomain=
redirectDomain=${domain}:${port} redirectDomain=${domain}:${port}
if [[ -z "${btDomain}" ]]; then
checkPortOpen 80 "${domain}" >/dev/null checkPortOpen 80 "${domain}" >/dev/null
fi
cat <<EOF >${nginxConfigPath}alone.conf cat <<EOF >${nginxConfigPath}alone.conf
server { server {
@ -1370,7 +1386,11 @@ customPortFunction() {
echo echo
if [[ -n "${btDomain}" ]]; then if [[ -n "${btDomain}" ]]; then
echoContent yellow "请输入端口[不可与BT Panel端口相同]" echoContent yellow "请输入端口[不可与BT Panel端口相同回车随机]"
read -r -p "端口:" port
if [[ -z "${port}" ]]; then
port=$((RANDOM % 50001 + 10000))
fi
else else
checkPortOpen 80 "${domain}" checkPortOpen 80 "${domain}"
if [[ "${isPortOpen80}" == "true" ]]; then if [[ "${isPortOpen80}" == "true" ]]; then
@ -5782,6 +5802,7 @@ customV2RayInstall() {
fi fi
if [[ "${selectCustomInstallType}" =~ ^[0-5]+$ ]]; then if [[ "${selectCustomInstallType}" =~ ^[0-5]+$ ]]; then
cleanUp xrayClean cleanUp xrayClean
checkBTPanel
totalProgress=17 totalProgress=17
installTools 1 installTools 1
# 申请tls # 申请tls
@ -5836,8 +5857,8 @@ customXrayInstall() {
if ! echo "${selectCustomInstallType}" | grep -q "0"; then if ! echo "${selectCustomInstallType}" | grep -q "0"; then
selectCustomInstallType="0${selectCustomInstallType}" selectCustomInstallType="0${selectCustomInstallType}"
fi fi
cleanUp v2rayClean cleanUp v2rayClean
checkBTPanel
totalProgress=12 totalProgress=12
installTools 1 installTools 1
if [[ -n "${btDomain}" ]]; then if [[ -n "${btDomain}" ]]; then
@ -5860,14 +5881,14 @@ customXrayInstall() {
customCDNIP 5 customCDNIP 5
fi fi
if [[ -n "${btDomain}" ]]; then if [[ -n "${btDomain}" ]]; then
echoContent skyBlue "\n进度 6/${totalProgress} : 检测到宝塔面板,是否 安装/重新安装 伪装站点?" echoContent skyBlue "\n进度 6/${totalProgress} : 检测到宝塔面板,跳过伪装网站"
echoContent red "==============================================================" # echoContent red "=============================================================="
echoContent yellow "# 注意事项" # echoContent yellow "# 注意事项"
echoContent yellow "会清空当前安装网站下面的静态目录,如已自定义安装过请选择 [n]\n" # echoContent yellow "会清空当前安装网站下面的静态目录,如已自定义安装过请选择 [n]\n"
read -r -p "请选择[y/n]:" nginxBlogBTStatus # read -r -p "请选择[y/n]:" nginxBlogBTStatus
if [[ "${nginxBlogBTStatus}" == "y" ]]; then # if [[ "${nginxBlogBTStatus}" == "y" ]]; then
nginxBlog 6 # nginxBlog 6
fi # fi
else else
nginxBlog 6 nginxBlog 6
fi fi
@ -5934,6 +5955,7 @@ selectCoreInstall() {
# v2ray-core 安装 # v2ray-core 安装
v2rayCoreInstall() { v2rayCoreInstall() {
cleanUp xrayClean cleanUp xrayClean
checkBTPanel
selectCustomInstallType= selectCustomInstallType=
totalProgress=13 totalProgress=13
installTools 2 installTools 2
@ -5969,6 +5991,7 @@ v2rayCoreInstall() {
# xray-core 安装 # xray-core 安装
xrayCoreInstall() { xrayCoreInstall() {
cleanUp v2rayClean cleanUp v2rayClean
checkBTPanel
selectCustomInstallType= selectCustomInstallType=
totalProgress=13 totalProgress=13
installTools 2 installTools 2
@ -5995,18 +6018,17 @@ xrayCoreInstall() {
cleanUp v2rayDel cleanUp v2rayDel
installCronTLS 10 installCronTLS 10
if [[ -n "${btDomain}" ]]; then if [[ -n "${btDomain}" ]]; then
echoContent skyBlue "\n进度 11/${totalProgress} : 检测到宝塔面板,是否 安装/重新安装 伪装站点?" echoContent skyBlue "\n进度 11/${totalProgress} : 检测到宝塔面板,跳过伪装网站"
echoContent red "==============================================================" # echoContent red "=============================================================="
echoContent yellow "# 注意事项" # echoContent yellow "# 注意事项"
echoContent yellow "会清空当前安装网站下面的静态目录,如已自定义安装过请选择 [n]\n" # echoContent yellow "会清空当前安装网站下面的静态目录,如已自定义安装过请选择 [n]\n"
read -r -p "请选择[y/n]:" nginxBlogBTStatus # read -r -p "请选择[y/n]:" nginxBlogBTStatus
if [[ "${nginxBlogBTStatus}" == "y" ]]; then # if [[ "${nginxBlogBTStatus}" == "y" ]]; then
nginxBlog 11 # nginxBlog 11
fi # fi
else else
nginxBlog 11 nginxBlog 11
fi fi
updateRedirectNginxConf updateRedirectNginxConf
handleXray stop handleXray stop
sleep 2 sleep 2
@ -6896,7 +6918,7 @@ menu() {
cd "$HOME" || exit cd "$HOME" || exit
echoContent red "\n==============================================================" echoContent red "\n=============================================================="
echoContent green "作者mack-a" echoContent green "作者mack-a"
echoContent green "当前版本v2.8.15" echoContent green "当前版本v2.8.16"
echoContent green "Githubhttps://github.com/mack-a/v2ray-agent" echoContent green "Githubhttps://github.com/mack-a/v2ray-agent"
echoContent green "描述:八合一共存脚本\c" echoContent green "描述:八合一共存脚本\c"
showInstallStatus showInstallStatus