feat(脚本): 完善个性化安装、修改升级v2ray-core逻辑、添加安装时读取上一次配置的path

pull/534/merge
mack-a 2020-11-23 17:40:20 +08:00
parent d2227e55dc
commit 008c1a688c
1 changed files with 88 additions and 60 deletions

View File

@ -10,7 +10,7 @@ coreType=
domain= domain=
add= add=
globalType= globalType=
customPath=alone customPath=
centosVersion=0 centosVersion=0
totalProgress=1 totalProgress=1
iplc=$1 iplc=$1
@ -66,7 +66,7 @@ mkdirTools(){
mkdir -p /etc/v2ray-agent/trojan mkdir -p /etc/v2ray-agent/trojan
mkdir -p /etc/systemd/system/ mkdir -p /etc/systemd/system/
mkdir -p /tmp/v2ray-agent-tls/ mkdir -p /tmp/v2ray-agent-tls/
echoContent red ${coreType} # echoContent red ${coreType}
} }
# 创建基础的文件目录 # 创建基础的文件目录
mkdirBaseDIR(){ mkdirBaseDIR(){
@ -346,12 +346,62 @@ EOF
# 自定义/随机路径 # 自定义/随机路径
randomPathFunction(){ randomPathFunction(){
echoContent skyBlue "\n进度 $1/${totalProgress} : 生成随机路径" echoContent skyBlue "\n进度 $1/${totalProgress} : 生成随机路径"
echoContent yellow "请输入自定义路径[例: alone],不需要斜杠,[回车]随机路径" filePath=
read -p '路径:' customPath if [[ ! -z "${customInstallType}" ]]
if [[ -z "${customPath}" ]]
then then
customPath=`head -n 50 /dev/urandom|sed 's/[^a-z]//g'|strings -n 4|tr 'A-Z' 'a-z'|head -1` filePath=/etc/v2ray-agent/v2ray/conf/02_VLESS_TCP_inbounds.json
elif [[ -f "/etc/v2ray-agent/v2ray/config_full.json" ]]
then
filePath=/etc/v2ray-agent/v2ray/config_full.json
fi
customPath=
if [[ ! -z "${filePath}" ]]
then
cat ${filePath}|jq .inbounds[0].settings.fallbacks|jq -c '.[]'|while read row
do
if [[ ! -z `echo ${row}|grep 31299` ]]
then
# vmess ws
path=`echo ${row}|awk -F '["]' '{print $4}'`
customPath=${path:1:4}
echo ${customPath} > /tmp/v2rayagentcustomPath
fi
if [[ ! -z `echo ${row}|grep 31298` ]]
then
path=`echo ${row}|awk -F '["]' '{print $4}'`
customPath=${path:1:4}
echo ${customPath} > /tmp/v2rayagentcustomPath
fi
if [[ ! -z `echo ${row}|grep 31297` ]]
then
# vless ws
path=`echo ${row}|awk -F '["]' '{print $4}'`
customPath=${path:1:4}
echo ${customPath} > /tmp/v2rayagentcustomPath
fi
done
customPath=`cat /tmp/v2rayagentcustomPath`
rm -f /tmp/v2rayagentcustomPath
fi
if [[ ! -z "${customPath}" ]]
then
echo
read -p "读取到上次安装记录是否使用上次安装时的path路径 [y/n]:" historyPathStatus
echo
fi
if [[ "${historyPathStatus}" = "y" ]]
then
echoContent green " ---> 使用成功\n"
else
echoContent yellow "请输入自定义路径[例: alone],不需要斜杠,[回车]随机路径"
read -p '路径:' customPath
if [[ -z "${customPath}" ]]
then
customPath=`head -n 50 /dev/urandom|sed 's/[^a-z]//g'|strings -n 4|tr 'A-Z' 'a-z'|head -1`
fi
fi fi
echoContent yellow "path${customPath}" echoContent yellow "path${customPath}"
} }
@ -1600,8 +1650,8 @@ EOF
}, },
"streamSettings": { "streamSettings": {
"network": "tcp", "network": "tcp",
"security": "xtls", "security": "tls",
"xtlsSettings": { "tlsSettings": {
"alpn": [ "alpn": [
"http/1.1" "http/1.1"
], ],
@ -1781,7 +1831,7 @@ defaultBase64Code(){
echo " vmess://${qrCodeBase64Default}" >> /etc/v2ray-agent/v2ray/usersv2ray.conf echo " vmess://${qrCodeBase64Default}" >> /etc/v2ray-agent/v2ray/usersv2ray.conf
echoContent yellow " ---> 通用json(VLESS+TCP+TLS)" echoContent yellow " ---> 通用json(VLESS+TCP+TLS)"
echoContent green ' {"port":"'${port}'","ps":"'${ps}'","tls":"tls","id":'"${id}"',"host":"'${host}'","type":"none","net":"tcp","add":"'${host}'","allowInsecure":0,"method":"none","peer":""}\n' echoContent green ' {"port":"'${port}'","ps":"'${ps}'","tls":"tls","id":'"${id}"',"host":"'${host}'","type":"none","net":"tcp","add":"'${host}'","allowInsecure":0,"method":"none","peer":""}\n'
echoContent green ' V2Ray v4.27.4+ 目前无通用订阅需要手动配置VLESS TCP、XTLS和TCP大部分一样其余内容不变请注意手动输入的流控flow类型\n' echoContent green ' V2Ray v4.27.4+ 目前无通用订阅需要手动配置VLESS TCP、XTLS和TCP大部分一样其余内容不变请注意手动输入的流控flow类型v4.32.1之后不支持XTLS\n'
elif [[ "${type}" = "vmessws" ]] elif [[ "${type}" = "vmessws" ]]
then then
@ -1966,10 +2016,10 @@ showAccounts(){
# XTLS Direct # XTLS Direct
local tcpIDirect=`echo ${tcp}|jq .settings.clients[1].id` local tcpIDirect=`echo ${tcp}|jq .settings.clients[1].id`
local tcpDirectEmail="`echo ${tcp}|jq .settings.clients[1].email|awk -F '["]' '{print $2}'`" local tcpDirectEmail="`echo ${tcp}|jq .settings.clients[1].email|awk -F '["]' '{print $2}'`"
host=`echo ${tcp}|jq .streamSettings.xtlsSettings.certificates[0].certificateFile|awk -F '[t][l][s][/]' '{print $2}'|awk -F '["]' '{print $1}'|awk -F '[.][c][r][t]' '{print $1}'`
if [[ "${coreType}" = "3" ]] if [[ "${coreType}" = "3" ]]
then then
host=`echo ${tcp}|jq .streamSettings.xtlsSettings.certificates[0].certificateFile|awk -F '[t][l][s][/]' '{print $2}'|awk -F '["]' '{print $1}'|awk -F '[.][c][r][t]' '{print $1}'`
echoContent skyBlue "\n============================ VLESS TCP TLS/XTLS-origin ===========================" echoContent skyBlue "\n============================ VLESS TCP TLS/XTLS-origin ==========================="
defaultBase64Code vlesstcp ${tcpEmail} "${tcpID}" "${host}:${port}" ${add} defaultBase64Code vlesstcp ${tcpEmail} "${tcpID}" "${host}:${port}" ${add}
@ -1978,6 +2028,7 @@ showAccounts(){
elif [[ "${coreType}" = "2" ]] elif [[ "${coreType}" = "2" ]]
then then
host=`echo ${tcp}|jq .streamSettings.tlsSettings.certificates[0].certificateFile|awk -F '[t][l][s][/]' '{print $2}'|awk -F '["]' '{print $1}'|awk -F '[.][c][r][t]' '{print $1}'`
echoContent skyBlue "\n============================ VLESS TCP TLS =======================================" echoContent skyBlue "\n============================ VLESS TCP TLS ======================================="
defaultBase64Code vlesstcp ${tcpEmail} "${tcpID}" "${host}:${port}" ${add} defaultBase64Code vlesstcp ${tcpEmail} "${tcpID}" "${host}:${port}" ${add}
fi fi
@ -2435,12 +2486,12 @@ menu(){
cd cd
echoContent red "\n==============================================================" echoContent red "\n=============================================================="
echoContent green "作者mack-a" echoContent green "作者mack-a"
echoContent green "当前版本v2.1.9" echoContent green "当前版本v2.1.10"
echoContent green "Githubhttps://github.com/mack-a/v2ray-agent" echoContent green "Githubhttps://github.com/mack-a/v2ray-agent"
echoContent green "描述:七合一共存脚本" echoContent green "描述:七合一共存脚本"
echoContent red "==============================================================" echoContent red "=============================================================="
echoContent yellow "1.安装" echoContent yellow "1.安装"
echoContent yellow "2.任意组合安装[临时屏蔽]" echoContent yellow "2.任意组合安装"
echoContent skyBlue "-------------------------工具管理-----------------------------" echoContent skyBlue "-------------------------工具管理-----------------------------"
echoContent yellow "3.查看账号" echoContent yellow "3.查看账号"
echoContent yellow "4.自动排错 [仅V2Ray]" echoContent yellow "4.自动排错 [仅V2Ray]"
@ -2465,11 +2516,11 @@ menu(){
case ${selectInstallType} in case ${selectInstallType} in
1) 1)
selectCoreInstall selectCoreInstall
v2rayCoreInstall
;; ;;
2) 2)
echoContent red " ---> 临时屏蔽,请等待更新" selectCoreInstall
exit 0; customInstall
# customInstall
;; ;;
3) 3)
showAccounts 1 showAccounts 1
@ -2597,24 +2648,36 @@ aliasInstall(){
echoContent green "快捷方式创建成功,可执行[vasma]重新打开脚本" echoContent green "快捷方式创建成功,可执行[vasma]重新打开脚本"
fi fi
} }
# 如果v2ray-core核心低于4.33则不允许升级v2ray-core # 判断配置文件是否支持XTLS不支持XTLS则允许升级v2ray-core
judgeCoreType(){ judgeCoreType(){
if [[ -d '/etc/v2ray-agent' ]] && [[ -d '/etc/v2ray-agent/v2ray' ]] && [[ -f '/etc/v2ray-agent/v2ray/v2ray' ]] && [[ -f '/etc/v2ray-agent/v2ray/v2ctl' ]] if [[ -d '/etc/v2ray-agent' ]] && [[ -d '/etc/v2ray-agent/v2ray' ]] && [[ -f '/etc/v2ray-agent/v2ray/v2ray' ]] && [[ -f '/etc/v2ray-agent/v2ray/v2ctl' ]]
then then
# 所属v2ray-core # 所属v2ray-core
local version=`/etc/v2ray-agent/v2ray/v2ray --version|awk '{print $2}'|awk -F "[.]" '{print $2}'|head -1` local version=`/etc/v2ray-agent/v2ray/v2ray --version|awk '{print $2}'|awk -F "[.]" '{print $2}'|head -1`
if [[ ${version} -lt 33 ]] if [[ -f "/etc/v2ray-agent/v2ray/config_full.json" ]]
then then
coreType=3; if [[ ! -z `cat /etc/v2ray-agent/v2ray/config_full.json|grep xtls` ]]
v2rayCoreVersion=v4.32.1 then
else coreType=3;
coreType=2; v2rayCoreVersion=v4.32.1
else
coreType=2;
fi
elif [[ -d "/etc/v2ray-agent/v2ray/conf" ]] && [[ -f "/etc/v2ray-agent/v2ray/conf/02_VLESS_TCP_inbounds.json" ]]
then
if [[ ! -z `cat /etc/v2ray-agent/v2ray/conf/02_VLESS_TCP_inbounds.json|grep xtls` ]]
then
coreType=3;
v2rayCoreVersion=v4.32.1
else
coreType=2;
fi
fi fi
elif [[ -d '/etc/v2ray-agent' ]] && [[ -d '/etc/v2ray-agent/xray' ]] && [[ -f '/etc/v2ray-agent/xray/xray' ]] elif [[ -d '/etc/v2ray-agent' ]] && [[ -d '/etc/v2ray-agent/xray' ]] && [[ -f '/etc/v2ray-agent/xray/xray' ]]
then then
coreType=0 coreType=0
fi fi
# echoContent red "${coreType}" echoContent red "debug log:${coreType}--${v2rayCoreVersion}"
} }
# v2ray-core 安装 # v2ray-core 安装
v2rayCoreInstall(){ v2rayCoreInstall(){
@ -2650,40 +2713,6 @@ v2rayCoreInstall(){
showAccounts 17 showAccounts 17
} }
# 最后一次支持XTLS的v2ray-core
xtlsV2rayCoreInstall(){
v2rayCoreVersion=v4.32.1
customInstallType=
totalProgress=17
mkdirTools 1
installTools 2
# 申请tls
initTLSNginxConfig 3
installTLS 4
handleNginx stop
initNginxConfig 5
randomPathFunction 6
# 安装V2Ray
installV2Ray 7
installV2RayService 8
installTrojanGo 9
installTrojanService 10
customCDNIP 11
initV2RayConfig all 12
initTrojanGoConfig 13
installCronTLS 14
nginxBlog 15
handleV2Ray stop
sleep 2
handleV2Ray start
handleNginx start
handleTrojanGo stop
sleep 1
handleTrojanGo start
# 生成账号
checkGFWStatue 16
showAccounts 17
}
# xray-core 安装 # xray-core 安装
xrayCoreInstall(){ xrayCoreInstall(){
customInstallType= customInstallType=
@ -2822,17 +2851,16 @@ selectCoreInstall(){
exit 0 exit 0
;; ;;
2) 2)
v2rayCoreInstall v2rayCoreVersion=
;; ;;
3) 3)
xtlsV2rayCoreInstall v2rayCoreVersion=v4.32.1
;; ;;
*) *)
echoContent red ' ---> 选择错误,重新选择' echoContent red ' ---> 选择错误,重新选择'
selectCoreInstall selectCoreInstall
;; ;;
esac esac
} }
# 杀死sleep # 杀死sleep
# killSleep(){ # killSleep(){