feat(脚本): 完善REALITY(兼容配置)、修改卸载(不删除acme)

dev
mack-a 2023-03-11 23:44:16 +08:00
parent 9c464ccbf1
commit 61a5ce59ae
1 changed files with 70 additions and 59 deletions

View File

@ -284,12 +284,12 @@ readInstallType() {
if [[ -d "/etc/v2ray-agent/xray" && -f "/etc/v2ray-agent/xray/xray" ]]; then if [[ -d "/etc/v2ray-agent/xray" && -f "/etc/v2ray-agent/xray/xray" ]]; then
# 这里检测xray-core # 这里检测xray-core
if [[ -d "/etc/v2ray-agent/xray/conf" ]] && [[ -f "/etc/v2ray-agent/xray/conf/02_VLESS_TCP_inbounds.json" || -f "/etc/v2ray-agent/xray/conf/02_trojan_TCP_inbounds.json" || -f "/etc/v2ray-agent/xray/conf/02_VLESS_reality_inbounds.json" ]]; then if [[ -d "/etc/v2ray-agent/xray/conf" ]] && [[ -f "/etc/v2ray-agent/xray/conf/02_VLESS_TCP_inbounds.json" || -f "/etc/v2ray-agent/xray/conf/02_trojan_TCP_inbounds.json" || -f "/etc/v2ray-agent/xray/conf/07_VLESS_reality_inbounds.json" ]]; then
# xray-core # xray-core
configPath=/etc/v2ray-agent/xray/conf/ configPath=/etc/v2ray-agent/xray/conf/
ctlPath=/etc/v2ray-agent/xray/xray ctlPath=/etc/v2ray-agent/xray/xray
coreInstallType=1 coreInstallType=1
if [[ -f "${configPath}02_VLESS_reality_inbounds.json" ]]; then if [[ -f "${configPath}07_VLESS_reality_inbounds.json" ]]; then
realityStatus=1 realityStatus=1
fi fi
fi fi
@ -462,9 +462,9 @@ readHysteriaConfig() {
# 读取xray reality配置 # 读取xray reality配置
readXrayCoreRealityConfig() { readXrayCoreRealityConfig() {
if [[ -n "${realityStatus}" ]]; then if [[ -n "${realityStatus}" ]]; then
currentRealityServerNames=$(jq -r .inbounds[0].streamSettings.realitySettings.serverNames "${configPath}02_VLESS_reality_inbounds.json") currentRealityServerNames=$(jq -r .inbounds[0].streamSettings.realitySettings.serverNames "${configPath}07_VLESS_reality_inbounds.json")
currentRealityPublicKey=$(jq -r .inbounds[0].streamSettings.realitySettings.publicKey "${configPath}02_VLESS_reality_inbounds.json") currentRealityPublicKey=$(jq -r .inbounds[0].streamSettings.realitySettings.publicKey "${configPath}07_VLESS_reality_inbounds.json")
currentRealityPort=$(jq -r .inbounds[0].port "${configPath}02_VLESS_reality_inbounds.json") currentRealityPort=$(jq -r .inbounds[0].port "${configPath}07_VLESS_reality_inbounds.json")
fi fi
} }
@ -516,9 +516,16 @@ readConfigHostPathUUID() {
fi fi
if [[ -n "${configPath}" ]]; then
if [[ -z "${realityStatus}" ]]; then
currentUUID=$(jq -r .inbounds[0].settings.clients[0].id ${configPath}${frontingType}.json)
else
currentUUID=$(jq -r .inbounds[0].settings.clients[0].id ${configPath}07_VLESS_reality_inbounds.json)
fi
fi
if [[ "${coreInstallType}" == "1" && -n "${configPath}" && -z "${realityStatus}" ]]; then if [[ "${coreInstallType}" == "1" && -n "${configPath}" && -z "${realityStatus}" ]]; then
currentHost=$(jq -r .inbounds[0].streamSettings.tlsSettings.certificates[0].certificateFile ${configPath}${frontingType}.json | awk -F '[t][l][s][/]' '{print $2}' | awk -F '[.][c][r][t]' '{print $1}') currentHost=$(jq -r .inbounds[0].streamSettings.tlsSettings.certificates[0].certificateFile ${configPath}${frontingType}.json | awk -F '[t][l][s][/]' '{print $2}' | awk -F '[.][c][r][t]' '{print $1}')
currentUUID=$(jq -r .inbounds[0].settings.clients[0].id ${configPath}${frontingType}.json)
currentAdd=$(jq -r .inbounds[0].settings.clients[0].add ${configPath}${frontingType}.json) currentAdd=$(jq -r .inbounds[0].settings.clients[0].add ${configPath}${frontingType}.json)
if [[ "${currentAdd}" == "null" ]]; then if [[ "${currentAdd}" == "null" ]]; then
currentAdd=${currentHost} currentAdd=${currentHost}
@ -540,14 +547,14 @@ readConfigHostPathUUID() {
showInstallStatus() { showInstallStatus() {
if [[ -n "${coreInstallType}" ]]; then if [[ -n "${coreInstallType}" ]]; then
if [[ "${coreInstallType}" == 1 ]]; then if [[ "${coreInstallType}" == 1 ]]; then
if [[ -n $(pgrep -f xray/xray) ]]; then if [[ -n $(pgrep -f "xray/xray") ]]; then
echoContent yellow "\n核心: Xray-core[运行中]" echoContent yellow "\n核心: Xray-core[运行中]"
else else
echoContent yellow "\n核心: Xray-core[未运行]" echoContent yellow "\n核心: Xray-core[未运行]"
fi fi
elif [[ "${coreInstallType}" == 2 || "${coreInstallType}" == 3 ]]; then elif [[ "${coreInstallType}" == 2 || "${coreInstallType}" == 3 ]]; then
if [[ -n $(pgrep -f v2ray/v2ray) ]]; then if [[ -n $(pgrep -f "v2ray/v2ray") ]]; then
echoContent yellow "\n核心: v2ray-core[运行中]" echoContent yellow "\n核心: v2ray-core[运行中]"
else else
echoContent yellow "\n核心: v2ray-core[未运行]" echoContent yellow "\n核心: v2ray-core[未运行]"
@ -1308,6 +1315,8 @@ customPortFunction() {
exit exit
fi fi
else else
allowPort 80
allowPort 443
customPort= customPort=
echoContent yellow "\n ---> 端口: 443" echoContent yellow "\n ---> 端口: 443"
fi fi
@ -1514,7 +1523,7 @@ handleNginx() {
sleep 0.5 sleep 0.5
if [[ -z $(pgrep -f nginx) ]]; then if [[ -z $(pgrep -f "nginx") ]]; then
echoContent red " ---> Nginx启动失败" echoContent red " ---> Nginx启动失败"
echoContent red " ---> 请手动尝试安装nginx后再次执行脚本" echoContent red " ---> 请手动尝试安装nginx后再次执行脚本"
@ -1999,9 +2008,9 @@ updateXray() {
checkGFWStatue() { checkGFWStatue() {
readInstallType readInstallType
echoContent skyBlue "\n进度 $1/${totalProgress} : 验证服务启动状态" echoContent skyBlue "\n进度 $1/${totalProgress} : 验证服务启动状态"
if [[ "${coreInstallType}" == "1" ]] && [[ -n $(pgrep -f xray/xray) ]]; then if [[ "${coreInstallType}" == "1" ]] && [[ -n $(pgrep -f "xray/xray") ]]; then
echoContent green " ---> 服务启动成功" echoContent green " ---> 服务启动成功"
elif [[ "${coreInstallType}" == "2" ]] && [[ -n $(pgrep -f v2ray/v2ray) ]]; then elif [[ "${coreInstallType}" == "2" ]] && [[ -n $(pgrep -f "v2ray/v2ray") ]]; then
echoContent green " ---> 服务启动成功" echoContent green " ---> 服务启动成功"
else else
echoContent red " ---> 服务启动失败,请检查终端是否有日志打印" echoContent red " ---> 服务启动失败,请检查终端是否有日志打印"
@ -2789,11 +2798,10 @@ initXrayFrontingConfig() {
# 移动上次配置文件至临时文件 # 移动上次配置文件至临时文件
movePreviousConfig() { movePreviousConfig() {
if [[ -n "${configPath}" ]] && [[ -f "${configPath}02_VLESS_TCP_inbounds.json" ]]; then if [[ -n "${configPath}" && -z "${realityStatus}" ]]; then
rm -rf ${configPath}../tmp/* rm -rf "${configPath}../tmp/*"
mv ${configPath}* ${configPath}../tmp/ mv ${configPath}[0][2-6]* ${configPath}../tmp/
fi fi
} }
# 初始化Xray 配置文件 # 初始化Xray 配置文件
@ -2834,6 +2842,8 @@ initXrayConfig() {
movePreviousConfig movePreviousConfig
# log # log
if [[ ! -f "/etc/v2ray-agent/xray/conf/00_log.json" ]]; then
cat <<EOF >/etc/v2ray-agent/xray/conf/00_log.json cat <<EOF >/etc/v2ray-agent/xray/conf/00_log.json
{ {
"log": { "log": {
@ -2842,8 +2852,10 @@ initXrayConfig() {
} }
} }
EOF EOF
fi
# outbounds # outbounds
if [[ ! -f "/etc/v2ray-agent/xray/conf/10_ipv6_outbounds.json" ]]; then
if [[ -n "${pingIPv6}" ]]; then if [[ -n "${pingIPv6}" ]]; then
cat <<EOF >/etc/v2ray-agent/xray/conf/10_ipv6_outbounds.json cat <<EOF >/etc/v2ray-agent/xray/conf/10_ipv6_outbounds.json
{ {
@ -2888,8 +2900,10 @@ EOF
} }
EOF EOF
fi fi
fi
# dns # dns
if [[ ! -f "/etc/v2ray-agent/xray/conf/11_dns.json" ]]; then
cat <<EOF >/etc/v2ray-agent/xray/conf/11_dns.json cat <<EOF >/etc/v2ray-agent/xray/conf/11_dns.json
{ {
"dns": { "dns": {
@ -2899,7 +2913,9 @@ EOF
} }
} }
EOF EOF
fi
# routing # routing
if [[ ! -f "/etc/v2ray-agent/xray/conf/09_routing.json" ]]; then
cat <<EOF >/etc/v2ray-agent/xray/conf/09_routing.json cat <<EOF >/etc/v2ray-agent/xray/conf/09_routing.json
{ {
"routing": { "routing": {
@ -2915,6 +2931,7 @@ EOF
} }
} }
EOF EOF
fi
# VLESS_TCP_TLS_Vision # VLESS_TCP_TLS_Vision
# 回落nginx # 回落nginx
local fallbacksList='{"dest":31300,"xver":0},{"alpn":"h2","dest":31302,"xver":0}' local fallbacksList='{"dest":31300,"xver":0},{"alpn":"h2","dest":31302,"xver":0}'
@ -3111,11 +3128,11 @@ EOF
defaultPort=${customPort} defaultPort=${customPort}
fi fi
cat <<EOF >/etc/v2ray-agent/xray/conf/02_VLESS_reality_inbounds.json cat <<EOF >/etc/v2ray-agent/xray/conf/07_VLESS_reality_inbounds.json
{ {
"inbounds": [ "inbounds": [
{ {
"port": ${defaultPort}, "port": ${realityPort},
"protocol": "vless", "protocol": "vless",
"tag": "VLESSReality", "tag": "VLESSReality",
"settings": { "settings": {
@ -3133,7 +3150,7 @@ EOF
"network": "tcp", "network": "tcp",
"security": "reality", "security": "reality",
"realitySettings": { "realitySettings": {
"show": false, "show": true,
"dest": "${realityDestDomain}", "dest": "${realityDestDomain}",
"xver": 0, "xver": 0,
"serverNames": [ "serverNames": [
@ -3141,7 +3158,7 @@ EOF
], ],
"privateKey": "${realityPrivateKey}", "privateKey": "${realityPrivateKey}",
"publicKey": "${realityPublicKey}", "publicKey": "${realityPublicKey}",
"maxTimeDiff": 0, "maxTimeDiff": 70000,
"shortIds": [ "shortIds": [
"" ""
] ]
@ -3518,10 +3535,11 @@ showAccounts() {
done done
fi fi
# VLESS reality
if echo ${currentInstallProtocolType} | grep -q 7; then if echo ${currentInstallProtocolType} | grep -q 7; then
show=1 show=1
echoContent skyBlue "================================ VLESS reality =================================\n" echoContent skyBlue "================================ VLESS reality =================================\n"
jq .inbounds[0].settings.clients ${configPath}02_VLESS_reality_inbounds.json | jq -c '.[]' | while read -r user; do jq .inbounds[0].settings.clients ${configPath}07_VLESS_reality_inbounds.json | jq -c '.[]' | while read -r user; do
local email= local email=
email=$(echo "${user}" | jq -r .email) email=$(echo "${user}" | jq -r .email)
@ -3633,7 +3651,7 @@ updateNginxBlog() {
addNginx302 "${redirectDomain}" addNginx302 "${redirectDomain}"
handleNginx stop handleNginx stop
handleNginx start handleNginx start
if [[ -z $(pgrep -f nginx) ]]; then if [[ -z $(pgrep -f "nginx") ]]; then
backupNginxConfig restoreBackup backupNginxConfig restoreBackup
handleNginx start handleNginx start
exit 0 exit 0
@ -3791,7 +3809,7 @@ unInstall() {
menu menu
exit 0 exit 0
fi fi
echoContent red " ---> 脚本不会删除acme相关配置删除请手动执行 [rm -rf /root/.acme.sh]"
handleNginx stop handleNginx stop
if [[ -z $(pgrep -f "nginx") ]]; then if [[ -z $(pgrep -f "nginx") ]]; then
echoContent green " ---> 停止Nginx成功" echoContent green " ---> 停止Nginx成功"
@ -3816,19 +3834,18 @@ unInstall() {
echoContent green " ---> 删除Hysteria开机自启完成" echoContent green " ---> 删除Hysteria开机自启完成"
fi fi
if [[ -f "/root/.acme.sh/acme.sh.env" ]] && grep -q 'acme.sh.env' </root/.bashrc; then # if [[ -f "/root/.acme.sh/acme.sh.env" ]] && grep -q 'acme.sh.env' </root/.bashrc; then
sed -i 's/. "\/root\/.acme.sh\/acme.sh.env"//g' "$(grep '. "/root/.acme.sh/acme.sh.env"' -rl /root/.bashrc)" # sed -i 's/. "\/root\/.acme.sh\/acme.sh.env"//g' "$(grep '. "/root/.acme.sh/acme.sh.env"' -rl /root/.bashrc)"
fi # fi
rm -rf /root/.acme.sh # rm -rf /root/.acme.sh
echoContent green " ---> 删除acme.sh完成"
rm -rf /tmp/v2ray-agent-tls/* # rm -rf /tmp/v2ray-agent-tls/*
if [[ -d "/etc/v2ray-agent/tls" ]] && [[ -n $(find /etc/v2ray-agent/tls/ -name "*.key") ]] && [[ -n $(find /etc/v2ray-agent/tls/ -name "*.crt") ]]; then # if [[ -d "/etc/v2ray-agent/tls" ]] && [[ -n $(find /etc/v2ray-agent/tls/ -name "*.key") ]] && [[ -n $(find /etc/v2ray-agent/tls/ -name "*.crt") ]]; then
mv /etc/v2ray-agent/tls /tmp/v2ray-agent-tls # mv /etc/v2ray-agent/tls /tmp/v2ray-agent-tls
if [[ -n $(find /tmp/v2ray-agent-tls -name '*.key') ]]; then # if [[ -n $(find /tmp/v2ray-agent-tls -name '*.key') ]]; then
echoContent yellow " ---> 备份证书成功,请注意留存。[/tmp/v2ray-agent-tls]" # echoContent yellow " ---> 备份证书成功,请注意留存。[/tmp/v2ray-agent-tls]"
fi # fi
fi # fi
rm -rf /etc/v2ray-agent rm -rf /etc/v2ray-agent
rm -rf ${nginxConfigPath}alone.conf rm -rf ${nginxConfigPath}alone.conf
@ -5492,7 +5509,7 @@ unInstallXrayCoreReality() {
echoContent yellow "# 仅删除VLESS Reality相关配置不会删除其他内容。" echoContent yellow "# 仅删除VLESS Reality相关配置不会删除其他内容。"
echoContent yellow "# 如果需要卸载其他内容,请卸载脚本功能" echoContent yellow "# 如果需要卸载其他内容,请卸载脚本功能"
handleXray stop handleXray stop
rm -rf /etc/v2ray-agent/xray/conf/02_VLESS_reality_inbounds.json rm -rf /etc/v2ray-agent/xray/conf/07_VLESS_reality_inbounds.json
echoContent yellow " >卸载完成" echoContent yellow " >卸载完成"
} }
@ -5631,29 +5648,23 @@ initXrayRealityConfig() {
read -r -p "端口:" realityPort read -r -p "端口:" realityPort
checkCustomPort "${realityPort}" checkCustomPort "${realityPort}"
allowPort "${realityPort}"
echoContent skyBlue "\n --- reality key\n" echoContent skyBlue "\n --->生成key\n"
realityX25519Key=$(/etc/v2ray-agent/xray/xray x25519) realityX25519Key=$(/etc/v2ray-agent/xray/xray x25519)
realityPrivateKey=$(echo "${realityX25519Key}" | head -1 | awk '{print $3}') realityPrivateKey=$(echo "${realityX25519Key}" | head -1 | awk '{print $3}')
realityPublicKey=$(echo "${realityX25519Key}" | tail -n 1 | awk '{print $3}') realityPublicKey=$(echo "${realityX25519Key}" | tail -n 1 | awk '{print $3}')
echoContent skyBlue "\n --- \ echoContent green "\n privateKey:${realityPrivateKey}"
\ echoContent green "\n publicKey:${realityPublicKey}"
\
--- >生成 \ echoContent skyBlue "\n --->生成配置回落的域名 例如:[addons.mozilla.org:443]\n"
> \
\
\
\
\
配置回落的域名\n"
read -r -p "请输入:" realityDestDomain read -r -p "请输入:" realityDestDomain
echoContent skyBlue "\n >配置客户端可用的serverNames\n" echoContent skyBlue "\n >配置客户端可用的serverNames\n"
echoContent red "\n==============================================================" echoContent red "\n=============================================================="
echoContent yellow " # 注意事项\n" echoContent yellow " # 注意事项\n"
echoContent yellow "录入示例:bing.com,www.bing.com\n" echoContent yellow "录入示例:addons.mozilla.org\n"
read -r -p "请输入:" realityServerNames read -r -p "请输入:" realityServerNames
realityServerNames=\"${realityServerNames//,/\",\"}\" realityServerNames=\"${realityServerNames//,/\",\"}\"
} }
@ -5762,14 +5773,14 @@ menu() {
cd "$HOME" || exit cd "$HOME" || exit
echoContent red "\n==============================================================" echoContent red "\n=============================================================="
echoContent green "作者mack-a" echoContent green "作者mack-a"
echoContent green "当前版本v2.7.13" echoContent green "当前版本v2.7.13_reality_beta"
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
echoContent red "\n==============================================================" echoContent red "\n=========================== 推广区============================"
echoContent red " 推广区 " echoContent red " "
echoContent green "推广请联系TG@mackaff\n" echoContent green "推广请联系TG@mackaff\n"
echoContent green "AFF捐赠https://github.com/mack-a/v2ray-agent/blob/master/documents/donation_aff.md\n" echoContent green "AFF捐赠https://github.com/mack-a/v2ray-agent/blob/master/documents/donation_aff.md"
echoContent red "==============================================================" echoContent red "=============================================================="
if [[ -n "${coreInstallType}" ]]; then if [[ -n "${coreInstallType}" ]]; then
echoContent yellow "1.重新安装" echoContent yellow "1.重新安装"