From 8b4bea45dbb481e49df6783896640619d524477d Mon Sep 17 00:00:00 2001 From: mack-a <57424792+mack-a@users.noreply.github.com> Date: Tue, 13 Oct 2020 17:14:06 +0800 Subject: [PATCH 1/4] =?UTF-8?q?feat(=E8=84=9A=E6=9C=AC):=20update?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- install.sh | 424 +++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 376 insertions(+), 48 deletions(-) diff --git a/install.sh b/install.sh index 55bae61..a13681e 100644 --- a/install.sh +++ b/install.sh @@ -15,6 +15,7 @@ uuidws= uuidtcp= uuidVlessWS= uuidtcpdirect= +customInstallType= trap 'onCtrlC' INT function onCtrlC () { @@ -57,7 +58,7 @@ echoContent(){ mkdirTools(){ echoContent skyBlue "\n进度 $1/${totalProgress} : 创建文件夹" mkdir -p /etc/v2ray-agent/tls - mkdir -p /etc/v2ray-agent/v2ray + mkdir -p /etc/v2ray-agent/v2ray/conf mkdir -p /etc/v2ray-agent/trojan mkdir -p /etc/systemd/system/ } @@ -783,48 +784,13 @@ checkGFWStatue(){ # 验证整个服务是否可用 # progressTools "yellow" "验证服务是否可用--->" echoContent skyBlue "\n进度 $1/${totalProgress} : 验证服务是否可用" - if [[ "${globalType}" = "wss" ]] + if [[ "${globalType}" = "vlesstcpws" ]] then - - sleep 3 - if [[ ! -z `curl -s -L https://${domain}/${customPath}|grep -v grep|grep "Bad Request"` ]] + if [[ ! -z `ps -ef|grep -v grep|grep v2ray` ]] then - echoContent green " ---> 服务可用" + echoContent green " ---> 服务启动成功" else - echoContent red " ---> 服务不可用" - progressTools "red" " 1.请检查Cloudflare->域名->SSL/TLS->Overview->Your SSL/TLS encryption mode is 是否是Full--->" - progressTools "red" " 2.请执行[ps -ef|grep v2ray]查看结果是否有如下信息,如果存在则执行脚本选择[4查看账号]即可--->" - progressTools "red" " /etc/v2ray-agent/trojan/trojan-go -config /etc/v2ray-agent/trojan/config.json" - progressTools "red" " /etc/v2ray-agent/v2ray/v2ray -config /etc/v2ray-agent/v2ray/config.json" - progressTools "red" " 3.如以上都无法解决,请联系开发者[https://t.me/mack_a]" - - progressTools "red" " 错误日志:`curl -s -L https://${domain}/${customPath}`" - exit 0 - fi - elif [[ "${globalType}" = "tcp" ]] - then - echo '' > /etc/v2ray-agent/v2ray/v2ray_access.log - curl --connect-time 3 --max-time 1 --url https://${domain} > /dev/null 2>&1 - sleep 0.1 - if [[ ! -z `cat /etc/v2ray-agent/v2ray/v2ray_access.log|grep -v grep|grep "Not Found"` ]] - then - echoContent green " ---> 服务可用" - else - progressTools "red" " 服务不可用" - progressTools "red" " 1.请检查云朵是否关闭" - progressTools "red" " 2.请手动尝试使用账号并观察日志,日志路径[/etc/v2ray-agent/v2ray/v2ray_access.log]" - exit 0 - fi - elif [[ "${globalType}" = "vlesstcpws" ]] - then - echoContent green " ---> 等待三秒" - sleep 3 - if [[ ! -z `curl -s -L https://${domain}/${customPath}|grep -v grep|grep "Bad Request"` ]] - then - echoContent green " ---> 服务可用" - else - progressTools "red" " 服务不可用,请检查Cloudflare->域名->SSL/TLS->Overview->Your SSL/TLS encryption mode is 是否是Full--->" - progressTools "red" " 错误日志:`curl -s -L https://${domain}/${customPath}`" + progressTools "red" " ---> 服务不可用,请检查终端是否有日志打印" exit 0 fi fi @@ -836,7 +802,11 @@ installV2RayService(){ then rm -rf /etc/systemd/system/v2ray.service touch /etc/systemd/system/v2ray.service - + execStart='/etc/v2ray-agent/v2ray/v2ray -config /etc/v2ray-agent/v2ray/config.json' + if [[ ! -z ${customInstallType} ]] + then + execStart='/etc/v2ray-agent/v2ray/v2ray -confdir /etc/v2ray-agent/v2ray/conf' + fi cat << EOF > /etc/systemd/system/v2ray.service [Unit] Description=V2Ray - A unified platform for anti-censorship @@ -849,7 +819,7 @@ installV2RayService(){ User=root CapabilityBoundingSet=CAP_NET_BIND_SERVICE CAP_NET_RAW NoNewPrivileges=yes - ExecStart=/etc/v2ray-agent/v2ray/v2ray -config /etc/v2ray-agent/v2ray/config.json + ExecStart=${execStart} Restart=on-failure RestartPreventExitStatus=23 @@ -993,7 +963,8 @@ initV2RayConfig(){ uuidtcpdirect=`/etc/v2ray-agent/v2ray/v2ctl uuid` echoContent skyBlue "\n进度 $2/${totalProgress} : 初始化V2Ray配置" - + rm -rf /etc/v2ray-agent/v2ray/conf/* + rm -rf /etc/v2ray-agent/v2ray/config.json if [[ "$1" = "vlesstcpws" ]] then cat << EOF > /etc/v2ray-agent/v2ray/config.json @@ -1154,6 +1125,209 @@ initV2RayConfig(){ ] } } +EOF + elif [[ "$1" = "custom" ]] + then + # log + cat << EOF > /etc/v2ray-agent/v2ray/conf/log.json +{ + "log": { + "access": "/etc/v2ray-agent/v2ray/v2ray_access.log", + "error": "/etc/v2ray-agent/v2ray/v2ray_error.log", + "loglevel": "debug" + } +} +EOF + # outbounds + cat << EOF > /etc/v2ray-agent/v2ray/conf/outbounds.json +{ + "outbounds": [ + { + "protocol": "freedom", + "settings": { + "domainStrategy": "UseIP" + } + } + ] +} +EOF + # dns + cat << EOF > /etc/v2ray-agent/v2ray/conf/dns.json +{ + "dns": { + "servers": [ + "74.82.42.42", + "8.8.8.8", + "8.8.4.4", + "1.1.1.1", + "localhost" + ] + } +} +EOF + # VLESS_TCP_TLS/XTLS + # 没有path则回落到此端口 + local fallbacksList='{"dest":31296,"xver":0}' + + if [[ ! -z `echo ${customInstallType}|grep 4` ]] + then + fallbacksList='{"dest":80,"xver":0}' + fi + + # {"dest":31296,"xver":0},{"path":"/${customPath}","dest":31299,"xver":1},{"path":"/${customPath}tcp","dest":31298,"xver":1},{"path":"/${customPath}ws","dest":31297,"xver":1} + + # VLESS_WS_TLS + if [[ ! -z `echo ${customInstallType}|grep 1` ]] + then + fallbacksList=${fallbacksList}',{"path":"/${customPath}ws","dest":31297,"xver":1}' + cat << EOF > /etc/v2ray-agent/v2ray/conf/VLESS_WS_inbounds.json +{ +"inbounds":[ + { + "port": 31297, + "listen": "127.0.0.1", + "protocol": "vless", + "settings": { + "clients": [ + { + "id": "${uuidVlessWS}", + "level": 0, + "email": "${domain}_vless_ws" + } + ], + "decryption": "none" + }, + "streamSettings": { + "network": "ws", + "security": "none", + "wsSettings": { + "acceptProxyProtocol": true, + "path": "/${customPath}ws" + } + } + } + ] +} +EOF + fi +# VMess_TCP + if [[ ! -z `echo ${customInstallType}|grep 2` ]] + then + fallbacksList=${fallbacksList}',{"path":"/${customPath}tcp","dest":31298,"xver":1}' + cat << EOF > /etc/v2ray-agent/v2ray/conf/VMess_TCP_inbounds.json +{ +"inbounds":[ + { + "port": 31298, + "listen": "127.0.0.1", + "protocol": "vmess", + "settings": { + "clients": [ + { + "id": "${uuidVmessTcp}", + "level": 0, + "alterId": 1, + "email": "${domain}_vmess_tcp" + } + ] + }, + "streamSettings": { + "network": "tcp", + "security": "none", + "tcpSettings": { + "acceptProxyProtocol": true, + "header": { + "type": "http", + "request": { + "path": [ + "/${customPath}tcp" + ] + } + } + } + } + } +] +} +EOF + # VMess_WS + if [[ ! -z `echo ${customInstallType}|grep 3` ]] + then + fallbacksList=${fallbacksList}',{"path":"/${customPath}","dest":31299,"xver":1}' + cat << EOF > /etc/v2ray-agent/v2ray/conf/VMess_WS_inbounds.json +{ +"inbounds":[ +{ + "port": 31299, + "protocol": "vmess", + "settings": { + "clients": [ + { + "id": "${uuidws}", + "alterId": 1, + "add": "${add}", + "level": 0, + "email": "${domain}_vmess_ws" + } + ] + }, + "streamSettings": { + "network": "ws", + "security": "none", + "wsSettings": { + "acceptProxyProtocol": true, + "path": "/${customPath}" + } + } + } +] +} +EOF + fi + + fi + cat << EOF > /etc/v2ray-agent/v2ray/conf/VLESS_TCP_inbounds.json +{ + "inbounds":[ + { + "port": 443, + "protocol": "vless", + "settings": { + "clients": [ + { + "id": "${uuidtcp}", + "flow":"xtls-rprx-origin", + "email": "${domain}_VLESS_XTLS/TLS-origin_TCP" + }, + { + "id": "${uuidtcpdirect}", + "flow":"xtls-rprx-direct", + "email": "${domain}_VLESS_XTLS/TLS-direct_TCP" + } + ], + "decryption": "none", + "fallbacks": [ + ${fallbacksList} + ] + }, + "streamSettings": { + "network": "tcp", + "security": "xtls", + "xtlsSettings": { + "alpn": [ + "http/1.1" + ], + "certificates": [ + { + "certificateFile": "/etc/v2ray-agent/tls/${domain}.crt", + "keyFile": "/etc/v2ray-agent/tls/${domain}.key" + } + ] + } + } + } + ] +} EOF fi } @@ -1374,7 +1548,7 @@ showAccounts(){ showStatus= local host= echoContent skyBlue "\n进度 $1/${totalProgress} : 账号" - if [[ -d "/etc/v2ray-agent/" ]] && [[ -d "/etc/v2ray-agent/v2ray/" ]] && [[ -f "/etc/v2ray-agent/v2ray/config.json" ]] + if [[ -d "/etc/v2ray-agent/" ]] && [[ -d "/etc/v2ray-agent/v2ray/" ]] && [[ -f "/etc/v2ray-agent/v2ray/config.json" ]] && [[ -z "${customInstallType}" ]] then showStatus=true # VLESS tcp @@ -1414,7 +1588,6 @@ showAccounts(){ echoContent skyBlue "\n============================ VLESS TCP TLS/XTLS-direct ===========================" defaultBase64Code vlesstcp ${tcpDirectEmail} "${tcpIDirect}" "${host}" ${add} - echoContent skyBlue "\n================================ VLESS WS TLS CDN ================================" defaultBase64Code vlessws ${vlessWSEmail} "${vlessWSID}" "${host}" "${vlessWSPath}" ${wsAdd} @@ -1423,7 +1596,65 @@ showAccounts(){ echoContent skyBlue "\n================================= VMess TCP TLS =================================" defaultBase64Code vmesstcp ${vmessTCPEmail} "${vmessTCPID}" "${host}" "${vmessTCPath}" "${host}" + + elif [[ -d "/etc/v2ray-agent/" ]] && [[ -d "/etc/v2ray-agent/v2ray/" ]] && [[ -d "/etc/v2ray-agent/v2ray/conf" ]] && [[ ! -z "${customInstallType}" ]] + then + showStatus=true + + # VLESS tcp + local tcp=`cat /etc/v2ray-agent/v2ray/conf/VLESS_TCP_inbounds.json|jq .inbounds[0]` + local tcpID=`echo ${tcp}|jq .settings.clients[0].id` + local tcpEmail="`echo ${tcp}|jq .settings.clients[0].email|awk -F '["]' '{print $2}'`" + + # XTLS Direct + local tcpIDirect=`echo ${tcp}|jq .settings.clients[1].id` + 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}'` + echoContent skyBlue "\n============================ VLESS TCP TLS/XTLS-origin ===========================" + defaultBase64Code vlesstcp ${tcpEmail} "${tcpID}" "${host}" ${add} + + echoContent skyBlue "\n============================ VLESS TCP TLS/XTLS-direct ===========================" + defaultBase64Code vlesstcp ${tcpDirectEmail} "${tcpIDirect}" "${host}" ${add} + + if [[ ! -z "${customInstallType}" ]] + then + if [[ ! -z `echo ${customInstallType}|grep 1` ]] + then + # VLESS ws + local vlessWS=`cat /etc/v2ray-agent/v2ray/conf/VLESS_WS_inbounds.json|jq .inbounds[0]` + local vlessWSID=`echo ${vlessWS}|jq .settings.clients[0].id` + local vlessWSAdd=`echo ${vlessWS}|jq .settings.clients[0].add|awk -F '["]' '{print $2}'` + local vlessWSEmail="`echo ${vlessWS}|jq .settings.clients[0].email|awk -F '["]' '{print $2}'`" + local vlessWSPath=`echo ${vlessWS}|jq .streamSettings.wsSettings.path` + + echoContent skyBlue "\n================================ VLESS WS TLS CDN ================================" + defaultBase64Code vlessws ${vlessWSEmail} "${vlessWSID}" "${host}" "${vlessWSPath}" ${wsAdd} + fi + if [[ ! -z `echo ${customInstallType}|grep 2` ]] + then + local ws=`cat /etc/v2ray-agent/v2ray/conf/VMess_TCP_inbounds.json|jq .inbounds[0]` + local wsID=`echo ${ws}|jq .settings.clients[0].id` + local wsAdd=`echo ${ws}|jq .settings.clients[0].add|awk -F '["]' '{print $2}'` + local wsEmail="`echo ${ws}|jq .settings.clients[0].email|awk -F '["]' '{print $2}'`" + local wsPath=`echo ${ws}|jq .streamSettings.wsSettings.path` + + echoContent skyBlue "\n================================= VMess TCP TLS =================================" + defaultBase64Code vmesstcp ${vmessTCPEmail} "${vmessTCPID}" "${host}" "${vmessTCPath}" "${host}" + fi + if [[ ! -z `echo ${customInstallType}|grep 3` ]] + then + local vmessTCP=`cat /etc/v2ray-agent/v2ray/conf/VMess_WS_inbounds.json|jq .inbounds[0]` + local vmessTCPID=`echo ${vmessTCP}|jq .settings.clients[0].id` + local vmessTCPAdd=`echo ${vmessTCP}|jq .settings.clients[0].add|awk -F '["]' '{print $2}'` + local vmessTCPEmail="`echo ${vmessTCP}|jq .settings.clients[0].email|awk -F '["]' '{print $2}'`" + local vmessTCPath=`echo ${vmessTCP}|jq .streamSettings.tcpSettings.header.request.path[0]` + + echoContent skyBlue "\n================================ VMess WS TLS CDN ================================" + defaultBase64Code vmessws ${wsEmail} "${wsID}" "${host}" "${wsPath}" ${wsAdd} + fi + fi fi + if [[ -d "/etc/v2ray-agent/" ]] && [[ -d "/etc/v2ray-agent/trojan/" ]] && [[ -f "/etc/v2ray-agent/trojan/config.json" ]] then showStatus=true @@ -1640,6 +1871,96 @@ resetUUID(){ showAccounts 1 fi } +# 个性化安装 +customInstall(){ + echoContent skyBlue "\n========================个性化安装============================" + echoContent yellow "VLESS前置,默认安装0,如果只需要安装0,则只选择0即可" + echoContent yellow "0.VLESS+TLS/XTLS+TCP" + echoContent yellow "1.VLESS+TLS+WS[CDN]" + echoContent yellow "2.VMess+TLS+TCP" + echoContent yellow "3.VMess+TLS+WS[CDN]" + echoContent yellow "4.Trojan、Trojan+WS[CDN]" + read -p "请选择[多选],[例如:123]:" customInstallType + echoContent skyBlue "--------------------------------------------------------------" + if [[ -z ${customInstallType} ]] + then + echoContent red " ---> 不可为空" + customInstall + exit 0; + fi + if [[ "${customInstallType}" =~ ^[0-4]+$ ]] + then + totalProgress=17 + globalType=vlesstcpws + mkdirTools 1 + installTools 2 + # 申请tls + initTLSNginxConfig 3 + installTLS 4 + handleNginx stop + initNginxConfig vlesstcpws 5 + # 随机path + if [[ ! -z `echo ${customInstallType}|grep 1` ]] || [[ ! -z `echo ${customInstallType}|grep 3` ]] || [[ ! -z `echo ${customInstallType}|grep 4` ]] + then + randomPathFunction 6 + customCDNIP 7 + fi + nginxBlog 8 + handleNginx start + + # 安装V2Ray + installV2Ray 9 + installV2RayService 10 + initV2RayConfig custom 11 + if [[ ! -z `echo ${customInstallType}|grep 4` ]] + then + installTrojanGo 12 + installTrojanService 13 + initTrojanGoConfig 14 + handleTrojanGo stop + handleTrojanGo start + else + # 这里需要删除trojan的服务 + handleTrojanGo stop + rm -rf /etc/v2ray-agent/trojan/* + rm -rf /etc/systemd/system/trojan-go.service + fi + installCronTLS 15 + handleV2Ray stop + handleV2Ray start + # 生成账号 + checkGFWStatue 16 + showAccounts 17 + else + echoContent red " ---> 输入不合法" + fi +} +# 初始化个性化安装类型 +initCustomInstallType(){ + customInstallType= + customInstallType= + if [[ -d "/etc/v2ray-agent/" ]] && [[ -d "/etc/v2ray-agent/v2ray/" ]] && [[ -d "/etc/v2ray-agent/v2ray/conf" ]] + then + while read row + do + echo row:${row} + if [[ ! -z `echo ${row}|grep VLESS_WS_inbounds` ]] + then + customInstallType=${customInstallType}'1' + fi + if [[ ! -z `echo ${row}|grep VMess_TCP_inbounds` ]] + then + customInstallType=${customInstallType}'2' + fi + if [[ ! -z `echo ${row}|grep VMess_WS_inbounds` ]] + then + customInstallType=${customInstallType}'3' + fi + done < <(echo `ls /etc/v2ray-agent/v2ray/conf|grep -v grep|grep inbounds.json|awk -F "[.]" '{print $1}'`) + + echo done:${customInstallType} + fi +} # 主菜单 menu(){ cd @@ -1650,7 +1971,7 @@ menu(){ echoContent green "描述:七合一共存脚本" echoContent red "==============================================================" echoContent yellow "1.安装" - echoContent yellow "2.任意组合安装[todo]" + echoContent yellow "2.任意组合安装" echoContent skyBlue "-------------------------工具管理-----------------------------" echoContent yellow "3.查看账号" echoContent yellow "4.自动排错" @@ -1667,10 +1988,14 @@ menu(){ echoContent yellow "13.卸载脚本" echoContent red "==============================================================" automaticUpgrade + initCustomInstallType read -p "请选择:" selectInstallType case ${selectInstallType} in 1) - installV2RayVLESSTCPWSTLS + defaultInstall + ;; + 2) + customInstall ;; 3) showAccounts 1 @@ -1780,7 +2105,9 @@ checkLog(){ sleep 2 menu } -installV2RayVLESSTCPWSTLS(){ +# 默认安装 +defaultInstall(){ + customInstallType= totalProgress=17 globalType=vlesstcpws mkdirTools 1 @@ -1852,3 +2179,4 @@ checkSystem(){ checkSystem menu + From 99d978ffd1354520f50e44027e10e1b89f355541 Mon Sep 17 00:00:00 2001 From: mack-a <57424792+mack-a@users.noreply.github.com> Date: Tue, 13 Oct 2020 17:43:42 +0800 Subject: [PATCH 2/4] =?UTF-8?q?feat(=E8=84=9A=E6=9C=AC):=20=E5=85=BC?= =?UTF-8?q?=E5=AE=B9=E5=AE=8C=E5=85=A8=E5=AE=89=E8=A3=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- install.sh | 64 +++++----- shell/find_best_cdn_ip.sh | 241 ++++++++++++-------------------------- 2 files changed, 115 insertions(+), 190 deletions(-) diff --git a/install.sh b/install.sh index a13681e..032cfba 100644 --- a/install.sh +++ b/install.sh @@ -982,6 +982,7 @@ initV2RayConfig(){ "clients": [ { "id": "${uuidtcp}", + "add": "${add}", "flow":"xtls-rprx-origin", "email": "${domain}_VLESS_XTLS/TLS-origin_TCP" }, @@ -1038,7 +1039,6 @@ initV2RayConfig(){ { "id": "${uuidws}", "alterId": 1, - "add": "${add}", "level": 0, "email": "${domain}_vmess_ws" } @@ -1286,6 +1286,7 @@ EOF fi fi + # VLESS_TCP cat << EOF > /etc/v2ray-agent/v2ray/conf/VLESS_TCP_inbounds.json { "inbounds":[ @@ -1296,6 +1297,7 @@ EOF "clients": [ { "id": "${uuidtcp}", + "add": "${add}", "flow":"xtls-rprx-origin", "email": "${domain}_VLESS_XTLS/TLS-origin_TCP" }, @@ -1555,7 +1557,7 @@ showAccounts(){ local tcp=`cat /etc/v2ray-agent/v2ray/config.json|jq .inbounds[0]` local tcpID=`echo ${tcp}|jq .settings.clients[0].id` local tcpEmail="`echo ${tcp}|jq .settings.clients[0].email|awk -F '["]' '{print $2}'`" - + local CDNADD=`echo ${tcp}|jq .settings.clients[0].add|awk -F '["]' '{print $2}'` # XTLS Direct local tcpIDirect=`echo ${tcp}|jq .settings.clients[1].id` local tcpDirectEmail="`echo ${tcp}|jq .settings.clients[1].email|awk -F '["]' '{print $2}'`" @@ -1564,21 +1566,18 @@ showAccounts(){ # VLESS ws local vlessWS=`cat /etc/v2ray-agent/v2ray/config.json|jq .inbounds[3]` local vlessWSID=`echo ${vlessWS}|jq .settings.clients[0].id` - local vlessWSAdd=`echo ${vlessWS}|jq .settings.clients[0].add|awk -F '["]' '{print $2}'` local vlessWSEmail="`echo ${vlessWS}|jq .settings.clients[0].email|awk -F '["]' '{print $2}'`" local vlessWSPath=`echo ${vlessWS}|jq .streamSettings.wsSettings.path` # Vmess ws local ws=`cat /etc/v2ray-agent/v2ray/config.json|jq .inbounds[1]` local wsID=`echo ${ws}|jq .settings.clients[0].id` - local wsAdd=`echo ${ws}|jq .settings.clients[0].add|awk -F '["]' '{print $2}'` local wsEmail="`echo ${ws}|jq .settings.clients[0].email|awk -F '["]' '{print $2}'`" local wsPath=`echo ${ws}|jq .streamSettings.wsSettings.path` # Vmess tcp local vmessTCP=`cat /etc/v2ray-agent/v2ray/config.json|jq .inbounds[2]` local vmessTCPID=`echo ${vmessTCP}|jq .settings.clients[0].id` - local vmessTCPAdd=`echo ${vmessTCP}|jq .settings.clients[0].add|awk -F '["]' '{print $2}'` local vmessTCPEmail="`echo ${vmessTCP}|jq .settings.clients[0].email|awk -F '["]' '{print $2}'`" local vmessTCPath=`echo ${vmessTCP}|jq .streamSettings.tcpSettings.header.request.path[0]` @@ -1589,10 +1588,10 @@ showAccounts(){ echoContent skyBlue "\n============================ VLESS TCP TLS/XTLS-direct ===========================" defaultBase64Code vlesstcp ${tcpDirectEmail} "${tcpIDirect}" "${host}" ${add} echoContent skyBlue "\n================================ VLESS WS TLS CDN ================================" - defaultBase64Code vlessws ${vlessWSEmail} "${vlessWSID}" "${host}" "${vlessWSPath}" ${wsAdd} + defaultBase64Code vlessws ${vlessWSEmail} "${vlessWSID}" "${host}" "${vlessWSPath}" ${CDNADD} echoContent skyBlue "\n================================ VMess WS TLS CDN ================================" - defaultBase64Code vmessws ${wsEmail} "${wsID}" "${host}" "${wsPath}" ${wsAdd} + defaultBase64Code vmessws ${wsEmail} "${wsID}" "${host}" "${wsPath}" ${CDNADD} echoContent skyBlue "\n================================= VMess TCP TLS =================================" defaultBase64Code vmesstcp ${vmessTCPEmail} "${vmessTCPID}" "${host}" "${vmessTCPath}" "${host}" @@ -1606,6 +1605,7 @@ showAccounts(){ local tcpID=`echo ${tcp}|jq .settings.clients[0].id` local tcpEmail="`echo ${tcp}|jq .settings.clients[0].email|awk -F '["]' '{print $2}'`" + local CDNADD=`echo ${tcp}|jq .settings.clients[0].add|awk -F '["]' '{print $2}'` # XTLS Direct local tcpIDirect=`echo ${tcp}|jq .settings.clients[1].id` local tcpDirectEmail="`echo ${tcp}|jq .settings.clients[1].email|awk -F '["]' '{print $2}'`" @@ -1623,34 +1623,34 @@ showAccounts(){ # VLESS ws local vlessWS=`cat /etc/v2ray-agent/v2ray/conf/VLESS_WS_inbounds.json|jq .inbounds[0]` local vlessWSID=`echo ${vlessWS}|jq .settings.clients[0].id` - local vlessWSAdd=`echo ${vlessWS}|jq .settings.clients[0].add|awk -F '["]' '{print $2}'` + local vlessWSAdd=`echo ${tcp}|jq .settings.clients[0].add|awk -F '["]' '{print $2}'` local vlessWSEmail="`echo ${vlessWS}|jq .settings.clients[0].email|awk -F '["]' '{print $2}'`" local vlessWSPath=`echo ${vlessWS}|jq .streamSettings.wsSettings.path` echoContent skyBlue "\n================================ VLESS WS TLS CDN ================================" - defaultBase64Code vlessws ${vlessWSEmail} "${vlessWSID}" "${host}" "${vlessWSPath}" ${wsAdd} + defaultBase64Code vlessws ${vlessWSEmail} "${vlessWSID}" "${host}" "${vlessWSPath}" ${CDNADD} fi if [[ ! -z `echo ${customInstallType}|grep 2` ]] then - local ws=`cat /etc/v2ray-agent/v2ray/conf/VMess_TCP_inbounds.json|jq .inbounds[0]` - local wsID=`echo ${ws}|jq .settings.clients[0].id` - local wsAdd=`echo ${ws}|jq .settings.clients[0].add|awk -F '["]' '{print $2}'` - local wsEmail="`echo ${ws}|jq .settings.clients[0].email|awk -F '["]' '{print $2}'`" - local wsPath=`echo ${ws}|jq .streamSettings.wsSettings.path` + + local vmessTCP=`cat /etc/v2ray-agent/v2ray/conf/VMess_TCP_inbounds.json|jq .inbounds[0]` + local vmessTCPID=`echo ${vmessTCP}|jq .settings.clients[0].id` + local vmessTCPEmail="`echo ${vmessTCP}|jq .settings.clients[0].email|awk -F '["]' '{print $2}'`" + local vmessTCPath=`echo ${vmessTCP}|jq .streamSettings.tcpSettings.header.request.path[0]` echoContent skyBlue "\n================================= VMess TCP TLS =================================" defaultBase64Code vmesstcp ${vmessTCPEmail} "${vmessTCPID}" "${host}" "${vmessTCPath}" "${host}" fi if [[ ! -z `echo ${customInstallType}|grep 3` ]] then - local vmessTCP=`cat /etc/v2ray-agent/v2ray/conf/VMess_WS_inbounds.json|jq .inbounds[0]` - local vmessTCPID=`echo ${vmessTCP}|jq .settings.clients[0].id` - local vmessTCPAdd=`echo ${vmessTCP}|jq .settings.clients[0].add|awk -F '["]' '{print $2}'` - local vmessTCPEmail="`echo ${vmessTCP}|jq .settings.clients[0].email|awk -F '["]' '{print $2}'`" - local vmessTCPath=`echo ${vmessTCP}|jq .streamSettings.tcpSettings.header.request.path[0]` + + local ws=`cat /etc/v2ray-agent/v2ray/conf/VMess_WS_inbounds.json|jq .inbounds[1]` + local wsID=`echo ${ws}|jq .settings.clients[0].id` + local wsEmail="`echo ${ws}|jq .settings.clients[0].email|awk -F '["]' '{print $2}'`" + local wsPath=`echo ${ws}|jq .streamSettings.wsSettings.path` echoContent skyBlue "\n================================ VMess WS TLS CDN ================================" - defaultBase64Code vmessws ${wsEmail} "${wsID}" "${host}" "${wsPath}" ${wsAdd} + defaultBase64Code vmessws ${wsEmail} "${wsID}" "${host}" "${wsPath}" ${CDNADD} fi fi fi @@ -1754,9 +1754,20 @@ checkFail(){ # 修改V2Ray CDN节点 updateV2RayCDN(){ echoContent skyBlue "\n进度 $1/${totalProgress} : 修改CDN节点" - if [[ -d "/etc/v2ray-agent" ]] && [[ -d "/etc/v2ray-agent/v2ray" ]] && [[ -f "/etc/v2ray-agent/v2ray/config.json" ]] + if [[ -d "/etc/v2ray-agent" ]] && [[ -d "/etc/v2ray-agent/v2ray" ]] then - local add=`cat /etc/v2ray-agent/v2ray/config.json|grep -v grep|grep add` + local configPath= + if [[ -f "/etc/v2ray-agent/v2ray/config.json" ]] + then + configPath="/etc/v2ray-agent/v2ray/config.json" + elif [[ -d "/etc/v2ray-agent/v2ray/conf" ]] && [[ -f "/etc/v2ray-agent/v2ray/conf/VLESS_TCP_inbounds.json" ]] + then + configPath="/etc/v2ray-agent/v2ray/conf/VLESS_TCP_inbounds.json" + else + echoContent red " ---> 未安装" + exit 0; + fi + local add=`cat ${configPath}|grep -v grep|grep add` if [[ ! -z ${add} ]] then echoContent red "==============================================================" @@ -1786,10 +1797,10 @@ updateV2RayCDN(){ add=`echo ${add}|awk -F '["]' '{print $4}'` if [[ ! -z ${add} ]] then - sed -i "s/${add}/${setDomain}/g" `grep "${add}" -rl /etc/v2ray-agent/v2ray/config.json` + sed -i "s/${add}/${setDomain}/g" `grep "${add}" -rl ${configPath}` fi - # sed -i "s/domain08.qiu4.ml1/domain08.qiu4.ml/g" `grep "domain08.qiu4.ml1" -rl /etc/v2ray-agent/v2ray/config.json` - if [[ `cat /etc/v2ray-agent/v2ray/config.json|grep -v grep|grep add|awk -F '["]' '{print $4}'` = ${setDomain} ]] + # sed -i "s/domain08.qiu4.ml1/domain08.qiu4.ml/g" `grep "domain08.qiu4.ml1" -rl ${configPath}` + if [[ `cat ${configPath}|grep -v grep|grep add|awk -F '["]' '{print $4}'` = ${setDomain} ]] then echoContent green " ---> V2Ray CDN修改成功" handleV2Ray stop @@ -2178,5 +2189,4 @@ checkSystem(){ } checkSystem -menu - +menu \ No newline at end of file diff --git a/shell/find_best_cdn_ip.sh b/shell/find_best_cdn_ip.sh index e6bbfff..0b62244 100755 --- a/shell/find_best_cdn_ip.sh +++ b/shell/find_best_cdn_ip.sh @@ -1,167 +1,82 @@ -#!/usr/bin/env bash -num=5 -ip=() -timeout=1000 -echoType='echo -e' -trap 'onCtrlC' INT -function onCtrlC () { - statisticalContent - exit; -} -# 计算 -statisticalContent(){ - if [[ ! -z `ls /tmp|grep -v grep|grep ping.log` ]] +echoContent skyBlue "\n进度 $1/${totalProgress} : 修改CDN节点" + if [[ -d "/etc/v2ray-agent" ]] && [[ -d "/etc/v2ray-agent/v2ray" ]] then - echoContent red "=============================================" - echoContent yellow '计算中--->' - # 排序计算 - echoContent red "排序规则:丢包率>波动>平均延迟,只展示最优的三十条" - echoContent red "依次展示为:[ ip 丢包率 最小延迟 平均延迟 最大延迟 波动 ]" - cat /tmp/ping.log|sort -t ' ' -k 2n -k 6n -k 4n|head -30 - echoContent red "=============================================" - fi + local configPath= + if [[ -f "/etc/v2ray-agent/v2ray/config.json" ]] + then + configPath="${configPath}" + elif [[ -d "/etc/v2ray-agent/v2ray/conf" ]] && [[ -f "/etc/v2ray-agent/v2ray/conf/VLESS_TCP_inbounds.json" ]] + then + configPath="/etc/v2ray-agent/v2ray/conf/VLESS_TCP_inbounds.json" + else + echoContent red " ---> 未安装" + exit 0; + fi + local add=`cat ${configPath}|grep -v grep|grep add` + if [[ ! -z ${add} ]] + then + echoContent red "==============================================================" + echoContent yellow "1.CNAME www.digitalocean.com" + echoContent yellow "2.CNAME amp.cloudflare.com" + echoContent yellow "3.CNAME domain08.qiu4.ml" + echoContent yellow "4.手动输入" + echoContent red "==============================================================" + read -p "请选择:" selectCDNType + case ${selectCDNType} in + 1) + setDomain="www.digitalocean.com" + ;; + 2) + setDomain="amp.cloudflare.com" + ;; + 3) + setDomain="domain08.qiu4.ml" + ;; + 4) + read -p "请输入想要自定义CDN IP或者域名:" setDomain + ;; + esac + if [[ ! -z ${setDomain} ]] + then + # v2ray + add=`echo ${add}|awk -F '["]' '{print $4}'` + if [[ ! -z ${add} ]] + then + sed -i "s/${add}/${setDomain}/g" `grep "${add}" -rl ${configPath}` + fi + # sed -i "s/domain08.qiu4.ml1/domain08.qiu4.ml/g" `grep "domain08.qiu4.ml1" -rl ${configPath}` + if [[ `cat ${configPath}|grep -v grep|grep add|awk -F '["]' '{print $4}'` = ${setDomain} ]] + then + echoContent green " ---> V2Ray CDN修改成功" + handleV2Ray stop + handleV2Ray start + else + echoContent red " ---> 修改V2Ray CDN失败" + fi -} -# echo工具类 -echoContent(){ - case $1 in - # 红色 - "red") - ${echoType} "\033[31m$2 \033[0m" - ;; - # 天蓝色 - "skyBlue") - ${echoType} "\033[36m$2 \033[0m" - ;; - # 绿色 - "green") - ${echoType} "\033[32m$2 \033[0m" - ;; - # 白色 - "white") - ${echoType} "\033[37m$2 \033[0m" - ;; - "magenta") - ${echoType} "\033[31m$2 \033[0m" - ;; - "skyBlue") - ${echoType} "\033[36m$2 \033[0m" - ;; - # 黄色 - "yellow") - ${echoType} "\033[33m$2 \033[0m" - ;; - esac -} -# 测试 -pingTool(){ - echo ''>/tmp/ping.log - echoContent red "=============================================" - echoContent green "默认测试为五次,超时为1000ms" - echoContent red "=============================================" - read -p "请输入单个ip测试次数【默认为5次】:" testNum - if [[ "$testNum" =~ ^[0-9]+$ ]] - then - num=${testNum} + # trojan + if [[ -d "/etc/v2ray-agent/trojan" ]] && [[ -f "/etc/v2ray-agent/trojan/config.json" ]] + then + add=`cat /etc/v2ray-agent/trojan/config.json|jq .websocket.add|awk -F '["]' '{print $2}'` + if [[ ! -z ${add} ]] + then + sed -i "s/${add}/${setDomain}/g" `grep "${add}" -rl /etc/v2ray-agent/trojan/config.json` + fi + fi + + if [[ `cat /etc/v2ray-agent/trojan/config.json|jq .websocket.add|awk -F '["]' '{print $2}'` = ${setDomain} ]] + then + echoContent green "\n ---> Trojan CDN修改成功" + handleTrojanGo stop + handleTrojanGo start + else + echoContent red " ---> 修改Trojan CDN失败" + fi + fi + else + echoContent red " ---> 未安装可用类型" + fi else - echoContent red '使用默认' + echoContent red " ---> 未安装" fi - echoContent yellow "一共${#ip[*]}个IP,每个ip测试${num}次,大约耗时`expr ${#ip[*]} \* ${num} / 60`分钟" - echoContent yellow "可以中途Ctrl+c,这样只会计算、统计已经记录下来的" - for ((i=0;i<${#ip[*]};i++)) - do - if [[ -z ${ip[$i]} ]] - then - continue; - fi - pingResult=`ping -c ${num} -W ${timeout} ${ip[$i]}` - packetLoss=`echo ${pingResult}|awk -F "[%]" '{print $1}'|awk -F "[p][a][c][k][e][t][s][ ][r][e][c][e][i][v][e][d][,][ ]" '{print $2}'` - roundTrip=`echo ${pingResult}|awk -F "[r][o][u][n][d][-][t][r][i][p]" '{print $2}'|awk '{print $3}'|awk -F "[/]" '{print $1"."$2"."$3"."$4}'|awk -F "[/]" '{print $1$2$3$4}'|awk -F "[.]" '{print $1" "$3" "$5" "$7}'` - if [[ "${release}" = "ubuntu" ]] || [[ "${release}" = "debian" ]] || [[ "${release}" = "centos" ]] - then - packetLoss=`echo ${pingResult}|awk -F "[%]" '{print $1}'|awk -F "[r][e][c][e][i][v][e][d][,][ ]" '{print $2}'` - roundTrip=`echo ${pingResult}|awk -F "[r][t][t]" '{print $2}'|awk '{print $3}'|awk -F "[/]" '{print $1"."$2"."$3"."$4}'|awk -F "[/]" '{print $1$2$3$4}'|awk -F "[.]" '{print $1" "$3" "$5" "$7}'` - fi - - ## |awk -F "[/]" '{print $1$2$3}'|awk -F "[.]" '{print $1" "$3" "$5" "$7}' - if [[ -z ${roundTrip} ]] - then - roundTrip="无" - fi - echo "ip:${ip[$i]},丢包率:${packetLoss}%,最小/平均/最大/波动:${roundTrip}" - echo "${ip[$i]} ${packetLoss} ${roundTrip}" >> /tmp/ping.log - done - statisticalContent -} -# 查找国家和地区 -findCountry(){ - if [[ -z `ls /tmp|grep -v grep|grep ips` ]] - then - echoContent red "缺少ip库,请联系作者。" - exit 0; - fi - echoContent red "=============================================" - cat /tmp/ips|awk -F "[|]" '{print $1}'|awk -F "[-]" '{print $3}'|uniq|awk '{print NR":"$0}' - echoContent red "=============================================" - read -p "输入上述数字:" selectType - if [[ -z `cat /tmp/ips|awk -F "[|]" '{print $1}'|awk -F "[-]" '{print $3}'|uniq|awk '{print NR":"$0}'|grep -v grep|grep ${selectType}` ]] - then - echoContent red '输入有误,请重新输入' - findCountry - fi - findIPList ${selectType} -} -# 查找ip -findIPList(){ - country=`cat /tmp/ips|awk -F "[|]" '{print $1}'|awk -F "[-]" '{print $3}'|uniq|awk '{print NR":"$0}'|grep -v grep|grep ${selectType}|sort -t ':' -k 1n|head -1|awk -F "[:]" '{print $2}'` - # cat /tmp/ips|awk -F "[|]" '{print $1}'|awk -F "[-]" '{print $3}'|uniq|awk '{print NR":"$0}'|grep -v grep|grep 1|sort -t ':' -k 1n|head -1|awk -F "[:]" '{print $2}' - echoContent red "=============================================" - cat /tmp/ips|grep -v grep|grep ${country}|awk -F "[|]" '{print $1}'|awk -F "[-]" '{print $1"-"$2}'|awk '{print "["NR"]"":"$0}' - read -p "请输入上述数字进行测试相应的ip段:" selectType - if [[ -z ${selectType} ]] - then - echoContent red '输入有误请重新输入!' - findIPList $1 - fi - echo ${country} - # cat /tmp/ips|grep -v grep|grep 中国移动|awk -F "[|]" '{print NR"-"$2}'|grep 174-|head -1 |awk -F "[|]" '{print $2}' - eval $(cat /tmp/ips|grep -v grep|grep ${country}|awk -F "[|]" '{print NR"-"$2}'|grep ${selectType}-|head -1|awk -F "[-]" '{print $2}'|awk '{split($0,serverNameList," ");for(i in serverNameList) print "ip["i"]="serverNameList[i]}') - pingTool -} -# 检查系统 -checkSystem(){ - if [[ "`uname`" = "Darwin" ]] - then - release="Darwin" - elif [[ ! -z `find /etc -name "redhat-release"` ]] || [[ ! -z `cat /proc/version | grep -i "centos" | grep -v grep ` ]] || [[ ! -z `cat /proc/version | grep -i "red hat" | grep -v grep ` ]] || [[ ! -z `cat /proc/version | grep -i "redhat" | grep -v grep ` ]] - then - release="centos" - elif [[ ! -z `cat /etc/issue | grep -i "ubuntu" | grep -v grep` ]] || [[ ! -z `cat /proc/version | grep -i "ubuntu" | grep -v grep` ]] - then - release="ubuntu" - elif [[ ! -z `cat /etc/issue | grep -i "debian" | grep -v grep` ]] || [[ ! -z `cat /proc/version | grep -i "debian" | grep -v grep` ]] - then - release="debian" - fi - if [[ -z ${release} ]] - then - echoContent red "本脚本不支持此系统,请将下方日志反馈给开发者" - cat /etc/issue - cat /proc/version - killSleep > /dev/null 2>&1 - exit 0; - fi -} -# 下载ip库 -downloadIPs(){ - if [[ -z `ls /tmp|grep -v grep|grep ips` ]] - then - echoContent yellow '开始下载ip库' - wget -q -P /tmp/ https://raw.githubusercontent.com/mack-a/v2ray-agent/dev/fodder/ips/ips - echoContent yellow '下载结束' - fi -} -downloadIPs -checkSystem -findCountry - + menu \ No newline at end of file From 899ea2231f0c00a6719aed6b142e8117a2f75356 Mon Sep 17 00:00:00 2001 From: mack-a <57424792+mack-a@users.noreply.github.com> Date: Tue, 13 Oct 2020 17:48:44 +0800 Subject: [PATCH 3/4] =?UTF-8?q?feat(=E8=84=9A=E6=9C=AC):=20=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E6=9B=B4=E6=8D=A2CDN=E8=8A=82=E7=82=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- install.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/install.sh b/install.sh index 032cfba..f82dcc2 100644 --- a/install.sh +++ b/install.sh @@ -1819,12 +1819,13 @@ updateV2RayCDN(){ fi fi - if [[ `cat /etc/v2ray-agent/trojan/config.json|jq .websocket.add|awk -F '["]' '{print $2}'` = ${setDomain} ]] + if [[ -d "/etc/v2ray-agent/trojan" ]] && [[ -f "/etc/v2ray-agent/trojan/config.json" ]] && [[ `cat /etc/v2ray-agent/trojan/config.json|jq .websocket.add|awk -F '["]' '{print $2}'` = ${setDomain} ]] then echoContent green "\n ---> Trojan CDN修改成功" handleTrojanGo stop handleTrojanGo start - else + elif [[ -d "/etc/v2ray-agent/trojan" ]] && [[ -f "/etc/v2ray-agent/trojan/config.json" ]] + then echoContent red " ---> 修改Trojan CDN失败" fi fi From ed7c545424c0fe7732a61711929aea036e5a407d Mon Sep 17 00:00:00 2001 From: mack-a <57424792+mack-a@users.noreply.github.com> Date: Tue, 13 Oct 2020 17:50:20 +0800 Subject: [PATCH 4/4] feat(version): upgrade --- install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install.sh b/install.sh index f82dcc2..bd8040d 100644 --- a/install.sh +++ b/install.sh @@ -1978,7 +1978,7 @@ menu(){ cd echoContent red "\n==============================================================" echoContent green "作者:mack-a" - echoContent green "当前版本:v2.0.15" + echoContent green "当前版本:v2.0.16" echoContent green "Github:https://github.com/mack-a/v2ray-agent" echoContent green "描述:七合一共存脚本" echoContent red "=============================================================="