2019-11-06 10:58:06 +08:00
#!/usr/bin/env bash
2020-11-26 10:27:06 +08:00
# 检测区
# -------------------------------------------------------------
2020-11-25 11:30:54 +08:00
# 检查系统
2021-05-27 14:22:54 +08:00
export LANG = en_US.UTF-8
2021-07-19 16:19:08 +08:00
2021-05-31 15:11:14 +08:00
echoContent( ) {
case $1 in
# 红色
"red" )
# shellcheck disable=SC2154
${ echoType } " \033[31m ${ printN } $2 \033[0m "
; ;
# 天蓝色
"skyBlue" )
${ echoType } " \033[1;36m ${ printN } $2 \033[0m "
; ;
# 绿色
"green" )
${ echoType } " \033[32m ${ printN } $2 \033[0m "
; ;
# 白色
"white" )
${ echoType } " \033[37m ${ printN } $2 \033[0m "
; ;
"magenta" )
${ echoType } " \033[31m ${ printN } $2 \033[0m "
; ;
# 黄色
"yellow" )
${ echoType } " \033[33m ${ printN } $2 \033[0m "
; ;
esac
}
2021-01-14 17:28:13 +08:00
checkSystem( ) {
2021-01-15 15:46:40 +08:00
if [ [ -n $( find /etc -name "redhat-release" ) ] ] || grep </proc/version -q -i "centos" ; then
2021-05-07 15:43:41 +08:00
mkdir -p /etc/yum.repos.d
2021-09-03 15:19:21 +08:00
if [ [ -f "/etc/centos-release" ] ] ; then
2021-05-31 15:11:14 +08:00
centosVersion = $( rpm -q centos-release | awk -F "[-]" '{print $3}' | awk -F "[.]" '{print $1}' )
2021-01-14 17:28:13 +08:00
2021-08-11 17:09:26 +08:00
if [ [ -z " ${ centosVersion } " ] ] && grep </etc/centos-release -q -i "release 8" ; then
2021-05-31 15:11:14 +08:00
centosVersion = 8
fi
2021-01-14 17:28:13 +08:00
fi
2021-05-31 15:11:14 +08:00
2020-11-25 11:30:54 +08:00
release = "centos"
installType = 'yum -y install'
2021-05-17 16:01:56 +08:00
removeType = 'yum -y remove'
2020-11-25 11:30:54 +08:00
upgrade = "yum update -y --skip-broken"
2021-01-15 15:24:08 +08:00
2021-01-15 15:46:40 +08:00
elif grep </etc/issue -q -i "debian" && [ [ -f "/etc/issue" ] ] || grep </etc/issue -q -i "debian" && [ [ -f "/proc/version" ] ] ; then
2020-11-25 11:30:54 +08:00
release = "debian"
installType = 'apt -y install'
2021-06-21 22:29:24 +08:00
upgrade = "apt update"
2021-09-09 10:48:28 +08:00
updateReleaseInfoChange = 'apt-get --allow-releaseinfo-change update'
2021-05-17 16:01:56 +08:00
removeType = 'apt -y autoremove'
2021-01-15 15:24:08 +08:00
2021-01-15 15:46:40 +08:00
elif grep </etc/issue -q -i "ubuntu" && [ [ -f "/etc/issue" ] ] || grep </etc/issue -q -i "ubuntu" && [ [ -f "/proc/version" ] ] ; then
2020-11-25 11:30:54 +08:00
release = "ubuntu"
2021-05-17 16:01:56 +08:00
installType = 'apt -y install'
2021-06-21 22:29:24 +08:00
upgrade = "apt update"
2021-09-09 10:48:28 +08:00
updateReleaseInfoChange = 'apt-get --allow-releaseinfo-change update'
2021-05-17 16:01:56 +08:00
removeType = 'apt -y autoremove'
2021-09-03 15:19:21 +08:00
if grep </etc/issue -q -i "16." ; then
2021-07-19 16:13:10 +08:00
release =
fi
2021-01-14 17:28:13 +08:00
fi
2021-01-15 15:24:08 +08:00
2021-01-14 17:28:13 +08:00
if [ [ -z ${ release } ] ] ; then
2021-07-19 16:13:10 +08:00
echoContent red "\n本脚本不支持此系统, 请将下方日志反馈给开发者\n"
echoContent yellow " $( cat /etc/issue) "
echoContent yellow " $( cat /proc/version) "
2021-01-14 17:28:13 +08:00
exit 0
fi
2020-11-25 11:30:54 +08:00
}
2021-05-26 17:27:52 +08:00
# 检查CPU提供商
checkCPUVendor( ) {
2021-05-31 15:11:14 +08:00
if [ [ -n $( which uname) ] ] ; then
2021-09-03 15:19:21 +08:00
if [ [ " $( uname) " = = "Linux" ] ] ; then
2021-05-31 15:11:14 +08:00
case " $( uname -m) " in
'amd64' | 'x86_64' )
xrayCoreCPUVendor = "Xray-linux-64"
v2rayCoreCPUVendor = "v2ray-linux-64"
2022-11-08 15:04:46 +08:00
hysteriaCoreCPUVendor = "hysteria-linux-amd64"
2021-09-03 15:19:21 +08:00
; ;
2021-05-31 15:11:14 +08:00
'armv8' | 'aarch64' )
2021-09-03 15:19:21 +08:00
xrayCoreCPUVendor = "Xray-linux-arm64-v8a"
2021-05-31 15:11:14 +08:00
v2rayCoreCPUVendor = "v2ray-linux-arm64-v8a"
2022-11-08 15:04:46 +08:00
hysteriaCoreCPUVendor = "hysteria-linux-arm64"
2021-09-03 15:19:21 +08:00
; ;
2021-05-31 15:11:14 +08:00
*)
2021-09-03 15:19:21 +08:00
echo " 不支持此CPU架构--->"
exit 1
; ;
esac
2021-05-26 17:27:52 +08:00
fi
2021-05-31 15:11:14 +08:00
else
echoContent red " 无法识别此CPU架构, 默认amd64、x86_64--->"
xrayCoreCPUVendor = "Xray-linux-64"
v2rayCoreCPUVendor = "v2ray-linux-64"
2021-05-26 17:27:52 +08:00
fi
}
2020-11-25 11:30:54 +08:00
# 初始化全局变量
2021-01-14 17:28:13 +08:00
initVar( ) {
installType = 'yum -y install'
removeType = 'yum -y remove'
upgrade = "yum -y update"
echoType = 'echo -e'
2020-11-26 10:27:06 +08:00
2021-05-26 17:27:52 +08:00
# 核心支持的cpu版本
2021-05-31 15:11:14 +08:00
xrayCoreCPUVendor = ""
v2rayCoreCPUVendor = ""
2022-11-08 15:04:46 +08:00
hysteriaCoreCPUVendor = ""
2022-04-24 16:36:27 +08:00
2021-01-14 17:28:13 +08:00
# 域名
domain =
2020-11-26 10:27:06 +08:00
2021-01-14 17:28:13 +08:00
# CDN节点的address
add =
2020-11-26 10:27:06 +08:00
2021-01-14 17:28:13 +08:00
# 安装总进度
totalProgress = 1
2020-11-25 17:06:40 +08:00
2021-01-14 17:28:13 +08:00
# 1.xray-core安装
# 2.v2ray-core 安装
# 3.v2ray-core[xtls] 安装
coreInstallType =
2020-11-25 11:30:54 +08:00
2021-01-14 17:28:13 +08:00
# 核心安装path
# coreInstallPath=
2020-12-21 17:30:21 +08:00
2021-01-14 17:28:13 +08:00
# v2ctl Path
ctlPath =
# 1.全部安装
# 2.个性化安装
# v2rayAgentInstallType=
2020-11-25 11:30:54 +08:00
2021-01-14 17:28:13 +08:00
# 当前的个性化安装方式 01234
currentInstallProtocolType =
2020-11-25 17:06:40 +08:00
2021-09-17 17:46:07 +08:00
# 当前alpn的顺序
currentAlpn =
2021-07-02 11:29:43 +08:00
# 前置类型
frontingType =
2021-01-14 17:28:13 +08:00
# 选择的个性化安装方式
selectCustomInstallType =
2020-11-25 17:06:40 +08:00
2021-04-08 17:53:19 +08:00
# v2ray-core、xray-core配置文件的路径
2021-01-14 17:28:13 +08:00
configPath =
2020-11-25 17:06:40 +08:00
2022-11-08 15:04:46 +08:00
# hysteria 配置文件的路径
hysteriaConfigPath =
2021-01-14 17:28:13 +08:00
# 配置文件的path
currentPath =
2020-11-25 17:06:40 +08:00
2021-01-14 17:28:13 +08:00
# 配置文件的host
currentHost =
2020-11-25 17:06:40 +08:00
2021-01-14 17:28:13 +08:00
# 安装时选择的core类型
selectCoreType =
2020-11-25 17:06:40 +08:00
2021-01-14 17:28:13 +08:00
# 默认core版本
v2rayCoreVersion =
2020-11-26 10:27:06 +08:00
2021-01-14 17:28:13 +08:00
# 随机路径
customPath =
2020-11-26 10:27:06 +08:00
2021-01-14 17:28:13 +08:00
# centos version
centosVersion =
2020-11-26 16:43:05 +08:00
2021-01-14 17:28:13 +08:00
# UUID
currentUUID =
2020-12-18 17:40:05 +08:00
2022-03-16 17:47:52 +08:00
# previousClients
previousClients =
2021-08-12 18:18:36 +08:00
localIP =
2021-01-12 14:58:45 +08:00
2021-01-14 17:28:13 +08:00
# 集成更新证书逻辑不再使用单独的脚本--RenewTLS
renewTLS = $1
2021-08-12 15:33:32 +08:00
# tls安装失败后尝试的次数
installTLSCount =
2021-11-10 14:21:05 +08:00
# BTPanel状态
BTPanelStatus =
# nginx配置文件路径
2021-11-10 15:42:31 +08:00
nginxConfigPath = /etc/nginx/conf.d/
2022-09-06 17:20:52 +08:00
# 是否为预览版
prereleaseStatus = false
2022-09-20 18:05:40 +08:00
# ssl类型
sslType =
# ssl邮箱
sslEmail =
2022-09-21 17:52:28 +08:00
# 检查天数
sslRenewalDays = 90
2022-09-23 17:53:15 +08:00
# dns ssl状态
dnsSSLStatus =
2022-09-26 17:50:55 +08:00
# dns tls domain
dnsTLSDomain =
2022-10-02 20:50:46 +08:00
2022-10-09 17:27:01 +08:00
# 该域名是否通过dns安装通配符证书
installDNSACMEStatus =
2022-10-11 16:02:05 +08:00
# 自定义端口
customPort =
2022-11-08 15:04:46 +08:00
# hysteria端口
hysteriaPort =
# hysteria协议
hysteriaProtocol =
# hysteria延迟
hysteriaLag =
# hysteria下行速度
hysteriaClientDownloadSpeed =
# hysteria上行速度
hysteriaClientUploadSpeed =
2020-11-25 11:30:54 +08:00
}
2022-09-26 17:50:55 +08:00
# 读取tls证书详情
readAcmeTLS( ) {
2022-10-27 17:48:12 +08:00
if [ [ -n " ${ currentHost } " ] ] ; then
dnsTLSDomain = $( echo " ${ currentHost } " | awk -F "[.]" '{print $(NF-1)"."$NF}' )
fi
2022-09-26 17:50:55 +08:00
if [ [ -d " $HOME /.acme.sh/*. ${ dnsTLSDomain } _ecc " && -f " $HOME /.acme.sh/*. ${ dnsTLSDomain } _ecc/*. ${ dnsTLSDomain } .key " && -f " $HOME /.acme.sh/*. ${ dnsTLSDomain } _ecc/*. ${ dnsTLSDomain } .cer " ] ] ; then
2022-10-09 17:27:01 +08:00
installDNSACMEStatus = true
2022-09-26 17:50:55 +08:00
fi
}
2022-10-11 16:02:05 +08:00
# 读取默认自定义端口
readCustomPort( ) {
if [ [ -n " ${ configPath } " ] ] ; then
local port =
port = $( jq -r .inbounds[ 0] .port " ${ configPath } 02_VLESS_TCP_inbounds.json " )
if [ [ " ${ port } " != "443" ] ] ; then
customPort = ${ port }
fi
fi
}
2020-11-25 11:30:54 +08:00
# 检测安装方式
2021-01-14 17:28:13 +08:00
readInstallType( ) {
coreInstallType =
configPath =
2022-11-08 15:04:46 +08:00
hysteriaConfigPath =
2021-01-14 17:28:13 +08:00
# 1.检测安装目录
if [ [ -d "/etc/v2ray-agent" ] ] ; then
# 检测安装方式 v2ray-core
if [ [ -d "/etc/v2ray-agent/v2ray" && -f "/etc/v2ray-agent/v2ray/v2ray" && -f "/etc/v2ray-agent/v2ray/v2ctl" ] ] ; then
if [ [ -d "/etc/v2ray-agent/v2ray/conf" && -f "/etc/v2ray-agent/v2ray/conf/02_VLESS_TCP_inbounds.json" ] ] ; then
configPath = /etc/v2ray-agent/v2ray/conf/
2022-03-16 17:47:52 +08:00
if grep </etc/v2ray-agent/v2ray/conf/02_VLESS_TCP_inbounds.json -q '"security": "tls"' ; then
2021-01-14 17:28:13 +08:00
# 不带XTLS的v2ray-core
coreInstallType = 2
ctlPath = /etc/v2ray-agent/v2ray/v2ctl
2022-03-16 17:47:52 +08:00
elif grep </etc/v2ray-agent/v2ray/conf/02_VLESS_TCP_inbounds.json -q '"security": "xtls"' ; then
2021-01-14 17:28:13 +08:00
# 带XTLS的v2ray-core
ctlPath = /etc/v2ray-agent/v2ray/v2ctl
coreInstallType = 3
fi
fi
fi
if [ [ -d "/etc/v2ray-agent/xray" && -f "/etc/v2ray-agent/xray/xray" ] ] ; then
# 这里检测xray-core
2021-07-01 22:48:51 +08:00
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" ] ] ; then
2021-01-14 17:28:13 +08:00
# xray-core
configPath = /etc/v2ray-agent/xray/conf/
ctlPath = /etc/v2ray-agent/xray/xray
coreInstallType = 1
fi
fi
2022-11-08 15:04:46 +08:00
if [ [ -d "/etc/v2ray-agent/hysteria" && -f "/etc/v2ray-agent/hysteria/hysteria" ] ] ; then
# 这里检测 hysteria
if [ [ -d "/etc/v2ray-agent/hysteria/conf" ] ] && [ [ -f "/etc/v2ray-agent/hysteria/conf/config.json" ] ] && [ [ -f "/etc/v2ray-agent/hysteria/conf/client_network.json" ] ] ; then
hysteriaConfigPath = /etc/v2ray-agent/hysteria/conf/
fi
fi
2021-01-14 17:28:13 +08:00
fi
2020-11-25 11:30:54 +08:00
}
2020-12-17 18:02:09 +08:00
# 读取协议类型
2021-01-14 17:28:13 +08:00
readInstallProtocolType( ) {
currentInstallProtocolType =
while read -r row; do
2021-09-03 15:19:21 +08:00
if echo " ${ row } " | grep -q 02_trojan_TCP_inbounds; then
2021-07-01 22:48:51 +08:00
currentInstallProtocolType = ${ currentInstallProtocolType } 'trojan'
2021-07-02 11:29:43 +08:00
frontingType = 02_trojan_TCP_inbounds
2021-07-01 22:48:51 +08:00
fi
2021-09-03 15:19:21 +08:00
if echo " ${ row } " | grep -q VLESS_TCP_inbounds; then
2021-01-14 17:28:13 +08:00
currentInstallProtocolType = ${ currentInstallProtocolType } '0'
2021-07-02 11:29:43 +08:00
frontingType = 02_VLESS_TCP_inbounds
2021-01-14 17:28:13 +08:00
fi
2021-09-03 15:19:21 +08:00
if echo " ${ row } " | grep -q VLESS_WS_inbounds; then
2021-01-14 17:28:13 +08:00
currentInstallProtocolType = ${ currentInstallProtocolType } '1'
fi
2021-09-03 15:19:21 +08:00
if echo " ${ row } " | grep -q trojan_gRPC_inbounds; then
2021-01-14 17:28:13 +08:00
currentInstallProtocolType = ${ currentInstallProtocolType } '2'
fi
2021-09-03 15:19:21 +08:00
if echo " ${ row } " | grep -q VMess_WS_inbounds; then
2021-01-14 17:28:13 +08:00
currentInstallProtocolType = ${ currentInstallProtocolType } '3'
fi
2021-09-03 15:19:21 +08:00
if echo " ${ row } " | grep -q 04_trojan_TCP_inbounds; then
2021-06-25 16:42:42 +08:00
currentInstallProtocolType = ${ currentInstallProtocolType } '4'
fi
2021-09-03 15:19:21 +08:00
if echo " ${ row } " | grep -q VLESS_gRPC_inbounds; then
2021-04-28 16:26:40 +08:00
currentInstallProtocolType = ${ currentInstallProtocolType } '5'
fi
2021-09-03 15:19:21 +08:00
done < <( find ${ configPath } -name "*inbounds.json" | awk -F "[.]" '{print $1}' )
2022-11-08 15:04:46 +08:00
if [ [ -n " ${ hysteriaConfigPath } " ] ] ; then
currentInstallProtocolType = ${ currentInstallProtocolType } '6'
fi
2020-11-25 11:30:54 +08:00
}
2020-05-23 23:21:43 +08:00
2021-11-10 14:21:05 +08:00
# 检查是否安装宝塔
checkBTPanel( ) {
if pgrep -f "BT-Panel" ; then
nginxConfigPath = /www/server/panel/vhost/nginx/
BTPanelStatus = true
fi
}
2021-09-17 17:46:07 +08:00
# 读取当前alpn的顺序
readInstallAlpn( ) {
if [ [ -n ${ currentInstallProtocolType } ] ] ; then
2021-09-20 01:51:28 +08:00
local alpn
alpn = $( jq -r .inbounds[ 0] .streamSettings.xtlsSettings.alpn[ 0] ${ configPath } ${ frontingType } .json)
2021-09-17 17:46:07 +08:00
if [ [ -n ${ alpn } ] ] ; then
currentAlpn = ${ alpn }
fi
fi
}
2021-09-20 01:51:28 +08:00
# 检查防火墙
allowPort( ) {
# 如果防火墙启动状态则添加相应的开放端口
if systemctl status netfilter-persistent 2>/dev/null | grep -q "active (exited)" ; then
local updateFirewalldStatus =
2022-04-21 17:07:44 +08:00
if ! iptables -L | grep -q " $1 (mack-a) " ; then
2021-09-20 01:51:28 +08:00
updateFirewalldStatus = true
2022-04-21 17:07:44 +08:00
iptables -I INPUT -p tcp --dport " $1 " -m comment --comment " allow $1 (mack-a) " -j ACCEPT
2021-09-20 01:51:28 +08:00
fi
if echo " ${ updateFirewalldStatus } " | grep -q "true" ; then
netfilter-persistent save
fi
elif systemctl status ufw 2>/dev/null | grep -q "active (exited)" ; then
2022-04-29 15:31:43 +08:00
if ufw status | grep -q "Status: active" ; then
if ! ufw status | grep -q " $1 " ; then
sudo ufw allow " $1 "
checkUFWAllowPort " $1 "
fi
fi
elif
systemctl status firewalld 2>/dev/null | grep -q "active (running)"
then
2021-09-20 01:51:28 +08:00
local updateFirewalldStatus =
2022-04-21 17:07:44 +08:00
if ! firewall-cmd --list-ports --permanent | grep -qw " $1 /tcp " ; then
2021-09-20 01:51:28 +08:00
updateFirewalldStatus = true
2022-04-21 17:07:44 +08:00
firewall-cmd --zone= public --add-port= " $1 /tcp " --permanent
checkFirewalldAllowPort " $1 "
2021-09-20 01:51:28 +08:00
fi
if echo " ${ updateFirewalldStatus } " | grep -q "true" ; then
firewall-cmd --reload
fi
fi
}
# 检查80、443端口占用情况
checkPortUsedStatus( ) {
if lsof -i tcp:80 | grep -q LISTEN; then
echoContent red "\n ---> 80端口被占用, 请手动关闭后安装\n"
lsof -i tcp:80 | grep LISTEN
exit 0
fi
if lsof -i tcp:443 | grep -q LISTEN; then
echoContent red "\n ---> 443端口被占用, 请手动关闭后安装\n"
lsof -i tcp:80 | grep LISTEN
exit 0
fi
}
# 输出ufw端口开放状态
checkUFWAllowPort( ) {
if ufw status | grep -q " $1 " ; then
echoContent green " ---> $1 端口开放成功 "
else
echoContent red " ---> $1 端口开放失败 "
exit 0
fi
}
2022-03-24 17:23:03 +08:00
# 输出firewall-cmd端口开放状态
2021-09-20 01:51:28 +08:00
checkFirewalldAllowPort( ) {
if firewall-cmd --list-ports --permanent | grep -q " $1 " ; then
echoContent green " ---> $1 端口开放成功 "
else
echoContent red " ---> $1 端口开放失败 "
exit 0
fi
}
2022-11-08 15:04:46 +08:00
# 读取hysteria网络环境
readHysteriaConfig( ) {
if [ [ -n " ${ hysteriaConfigPath } " ] ] ; then
hysteriaLag = $( jq -r .hysteriaLag <" ${ hysteriaConfigPath } client_network.json " )
hysteriaClientDownloadSpeed = $( jq -r .hysteriaClientDownloadSpeed <" ${ hysteriaConfigPath } client_network.json " )
hysteriaClientUploadSpeed = $( jq -r .hysteriaClientUploadSpeed <" ${ hysteriaConfigPath } client_network.json " )
hysteriaPort = $( jq -r .listen <" ${ hysteriaConfigPath } config.json " | awk -F "[:]" '{print $2}' )
hysteriaProtocol = $( jq -r .protocol <" ${ hysteriaConfigPath } config.json " )
fi
}
2020-11-25 17:06:40 +08:00
# 检查文件目录以及path路径
2021-01-14 17:28:13 +08:00
readConfigHostPathUUID( ) {
currentPath =
2022-04-15 16:35:41 +08:00
currentDefaultPort =
2021-01-14 17:28:13 +08:00
currentUUID =
currentHost =
2022-04-24 11:09:27 +08:00
# currentPort=
2021-01-14 17:28:13 +08:00
currentAdd =
# 读取path
if [ [ -n " ${ configPath } " ] ] ; then
2021-09-03 15:19:21 +08:00
local fallback
fallback = $( jq -r -c '.inbounds[0].settings.fallbacks[]|select(.path)' ${ configPath } ${ frontingType } .json | head -1)
2021-06-03 17:00:59 +08:00
2021-09-03 15:19:21 +08:00
local path
path = $( echo " ${ fallback } " | jq -r .path | awk -F "[/]" '{print $2}' )
2021-06-03 17:00:59 +08:00
2021-09-03 15:19:21 +08:00
if [ [ $( echo " ${ fallback } " | jq -r .dest) = = 31297 ] ] ; then
2021-06-03 17:00:59 +08:00
currentPath = $( echo " ${ path } " | awk -F "[w][s]" '{print $1}' )
2021-09-03 15:19:21 +08:00
elif [ [ $( echo " ${ fallback } " | jq -r .dest) = = 31298 ] ] ; then
2021-06-03 17:00:59 +08:00
currentPath = $( echo " ${ path } " | awk -F "[t][c][p]" '{print $1}' )
2021-09-03 15:19:21 +08:00
elif [ [ $( echo " ${ fallback } " | jq -r .dest) = = 31299 ] ] ; then
2021-06-03 17:00:59 +08:00
currentPath = $( echo " ${ path } " | awk -F "[v][w][s]" '{print $1}' )
2021-01-14 17:28:13 +08:00
fi
2022-05-03 22:58:37 +08:00
# 尝试读取alpn h2 Path
2022-05-05 17:29:37 +08:00
2022-05-03 22:58:37 +08:00
if [ [ -z " ${ currentPath } " ] ] ; then
dest = $( jq -r -c '.inbounds[0].settings.fallbacks[]|select(.alpn)|.dest' ${ configPath } ${ frontingType } .json | head -1)
2022-05-05 17:29:37 +08:00
if [ [ " ${ dest } " = = "31302" || " ${ dest } " = = "31304" ] ] ; then
2022-05-03 22:58:37 +08:00
if grep -q "trojangrpc {" <${ nginxConfigPath } alone.conf; then
currentPath = $( grep "trojangrpc {" <${ nginxConfigPath } alone.conf | awk -F "[/]" '{print $2}' | awk -F "[t][r][o][j][a][n]" '{print $1}' )
elif grep -q "grpc {" <${ nginxConfigPath } alone.conf; then
currentPath = $( grep "grpc {" <${ nginxConfigPath } alone.conf | head -1 | awk -F "[/]" '{print $2}' | awk -F "[g][r][p][c]" '{print $1}' )
fi
fi
fi
2022-04-15 16:35:41 +08:00
local defaultPortFile =
defaultPortFile = $( find ${ configPath } * | grep "default" )
if [ [ -n " ${ defaultPortFile } " ] ] ; then
currentDefaultPort = $( echo " ${ defaultPortFile } " | awk -F [ _] '{print $4}' )
else
2022-10-25 13:57:16 +08:00
currentDefaultPort = $( jq -r .inbounds[ 0] .port ${ configPath } 02_VLESS_TCP_inbounds.json)
2022-04-15 16:35:41 +08:00
fi
2021-01-14 17:28:13 +08:00
fi
if [ [ " ${ coreInstallType } " = = "1" ] ] ; then
2021-07-02 11:29:43 +08:00
currentHost = $( jq -r .inbounds[ 0] .streamSettings.xtlsSettings.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)
2021-09-03 15:19:21 +08:00
if [ [ " ${ currentAdd } " = = "null" ] ] ; then
2021-06-04 17:28:57 +08:00
currentAdd = ${ currentHost }
fi
2022-04-24 11:09:27 +08:00
# currentPort=$(jq .inbounds[0].port ${configPath}${frontingType}.json)
2021-01-14 17:28:13 +08:00
elif [ [ " ${ coreInstallType } " = = "2" || " ${ coreInstallType } " = = "3" ] ] ; then
if [ [ " ${ coreInstallType } " = = "3" ] ] ; then
2022-03-16 17:47:52 +08:00
2021-07-02 11:29:43 +08:00
currentHost = $( jq -r .inbounds[ 0] .streamSettings.xtlsSettings.certificates[ 0] .certificateFile ${ configPath } ${ frontingType } .json | awk -F '[t][l][s][/]' '{print $2}' | awk -F '[.][c][r][t]' '{print $1}' )
2021-01-14 17:28:13 +08:00
else
2021-07-02 11:29:43 +08:00
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}' )
2021-01-14 17:28:13 +08:00
fi
2021-07-02 11:29:43 +08:00
currentAdd = $( jq -r .inbounds[ 0] .settings.clients[ 0] .add ${ configPath } ${ frontingType } .json)
2021-06-04 17:28:57 +08:00
2021-09-03 15:19:21 +08:00
if [ [ " ${ currentAdd } " = = "null" ] ] ; then
2021-06-04 17:28:57 +08:00
currentAdd = ${ currentHost }
fi
2021-07-02 11:29:43 +08:00
currentUUID = $( jq -r .inbounds[ 0] .settings.clients[ 0] .id ${ configPath } ${ frontingType } .json)
2022-04-24 11:09:27 +08:00
# currentPort=$(jq .inbounds[0].port ${configPath}${frontingType}.json)
2021-01-14 17:28:13 +08:00
fi
2020-11-25 17:06:40 +08:00
}
2021-03-23 15:06:17 +08:00
# 状态展示
showInstallStatus( ) {
if [ [ -n " ${ coreInstallType } " ] ] ; then
if [ [ " ${ coreInstallType } " = = 1 ] ] ; then
if [ [ -n $( pgrep -f xray/xray) ] ] ; then
2022-03-24 17:23:03 +08:00
echoContent yellow "\n核心: Xray-core[运行中]"
2021-03-23 15:06:17 +08:00
else
2022-03-24 17:23:03 +08:00
echoContent yellow "\n核心: Xray-core[未运行]"
2021-03-23 15:06:17 +08:00
fi
elif [ [ " ${ coreInstallType } " = = 2 || " ${ coreInstallType } " = = 3 ] ] ; then
if [ [ -n $( pgrep -f v2ray/v2ray) ] ] ; then
2022-03-24 17:23:03 +08:00
echoContent yellow "\n核心: v2ray-core[运行中]"
2021-03-23 15:06:17 +08:00
else
2022-03-24 17:23:03 +08:00
echoContent yellow "\n核心: v2ray-core[未运行]"
2021-03-23 15:06:17 +08:00
fi
fi
# 读取协议类型
readInstallProtocolType
if [ [ -n ${ currentInstallProtocolType } ] ] ; then
2022-03-24 17:23:03 +08:00
echoContent yellow "已安装协议: \c"
2021-03-23 15:06:17 +08:00
fi
if echo ${ currentInstallProtocolType } | grep -q 0; then
if [ [ " ${ coreInstallType } " = = 2 ] ] ; then
echoContent yellow "VLESS+TCP[TLS] \c"
else
echoContent yellow "VLESS+TCP[TLS/XTLS] \c"
fi
fi
2021-07-01 22:48:51 +08:00
if echo ${ currentInstallProtocolType } | grep -q trojan; then
if [ [ " ${ coreInstallType } " = = 1 ] ] ; then
echoContent yellow "Trojan+TCP[TLS/XTLS] \c"
fi
fi
2021-03-23 15:06:17 +08:00
if echo ${ currentInstallProtocolType } | grep -q 1; then
echoContent yellow "VLESS+WS[TLS] \c"
fi
if echo ${ currentInstallProtocolType } | grep -q 2; then
2021-07-01 22:48:51 +08:00
echoContent yellow "Trojan+gRPC[TLS] \c"
2021-03-23 15:06:17 +08:00
fi
if echo ${ currentInstallProtocolType } | grep -q 3; then
echoContent yellow "VMess+WS[TLS] \c"
fi
if echo ${ currentInstallProtocolType } | grep -q 4; then
2021-06-25 15:57:37 +08:00
echoContent yellow "Trojan+TCP[TLS] \c"
2021-03-23 15:06:17 +08:00
fi
2021-04-28 16:26:40 +08:00
if echo ${ currentInstallProtocolType } | grep -q 5; then
echoContent yellow "VLESS+gRPC[TLS] \c"
fi
2021-03-23 15:06:17 +08:00
fi
}
2020-11-26 16:43:05 +08:00
# 清理旧残留
2021-01-14 17:28:13 +08:00
cleanUp( ) {
if [ [ " $1 " = = "v2rayClean" ] ] ; then
rm -rf " $( find /etc/v2ray-agent/v2ray/* | grep -E '(config_full.json|conf)' ) "
2021-05-26 17:27:52 +08:00
handleV2Ray stop >/dev/null
2021-01-14 17:28:13 +08:00
rm -f /etc/systemd/system/v2ray.service
elif [ [ " $1 " = = "xrayClean" ] ] ; then
rm -rf " $( find /etc/v2ray-agent/xray/* | grep -E '(config_full.json|conf)' ) "
2021-05-26 17:27:52 +08:00
handleXray stop >/dev/null
2021-01-14 17:28:13 +08:00
rm -f /etc/systemd/system/xray.service
elif [ [ " $1 " = = "v2rayDel" ] ] ; then
rm -rf /etc/v2ray-agent/v2ray/*
elif [ [ " $1 " = = "xrayDel" ] ] ; then
rm -rf /etc/v2ray-agent/xray/*
fi
2020-11-25 17:06:40 +08:00
}
2020-11-26 11:51:50 +08:00
2021-09-03 15:19:21 +08:00
initVar " $1 "
2020-11-26 10:27:06 +08:00
checkSystem
2021-05-26 17:27:52 +08:00
checkCPUVendor
2020-11-26 16:43:05 +08:00
readInstallType
2022-10-11 16:02:05 +08:00
readCustomPort
2020-12-17 18:02:09 +08:00
readInstallProtocolType
2020-11-26 16:43:05 +08:00
readConfigHostPathUUID
2021-09-17 17:46:07 +08:00
readInstallAlpn
2021-11-10 14:21:05 +08:00
checkBTPanel
2020-11-26 10:27:06 +08:00
# -------------------------------------------------------------
2020-11-25 17:06:40 +08:00
# 初始化安装目录
2021-01-14 17:28:13 +08:00
mkdirTools( ) {
mkdir -p /etc/v2ray-agent/tls
2021-01-18 17:00:50 +08:00
mkdir -p /etc/v2ray-agent/subscribe
2021-01-25 15:32:32 +08:00
mkdir -p /etc/v2ray-agent/subscribe_tmp
2021-01-14 17:28:13 +08:00
mkdir -p /etc/v2ray-agent/v2ray/conf
2022-03-16 17:47:52 +08:00
mkdir -p /etc/v2ray-agent/v2ray/tmp
2021-01-14 17:28:13 +08:00
mkdir -p /etc/v2ray-agent/xray/conf
2022-03-16 17:47:52 +08:00
mkdir -p /etc/v2ray-agent/xray/tmp
2021-01-14 17:28:13 +08:00
mkdir -p /etc/v2ray-agent/trojan
2022-11-08 15:04:46 +08:00
mkdir -p /etc/v2ray-agent/hysteria/conf
2021-01-14 17:28:13 +08:00
mkdir -p /etc/systemd/system/
mkdir -p /tmp/v2ray-agent-tls/
2020-10-15 16:06:53 +08:00
}
2020-11-25 11:30:54 +08:00
2020-05-23 23:21:43 +08:00
# 安装工具包
2021-01-14 17:28:13 +08:00
installTools( ) {
echoContent skyBlue " \n进度 $1 / ${ totalProgress } : 安装工具 "
# 修复ubuntu个别系统问题
if [ [ " ${ release } " = = "ubuntu" ] ] ; then
dpkg --configure -a
fi
2021-01-15 11:00:49 +08:00
if [ [ -n $( pgrep -f "apt" ) ] ] ; then
2021-01-14 17:43:24 +08:00
pgrep -f apt | xargs kill -9
2021-01-14 17:28:13 +08:00
fi
2021-05-07 15:43:41 +08:00
echoContent green " ---> 检查、安装更新【新机器会很慢,如长时间无反应,请手动停止后重新执行】"
2021-01-14 17:28:13 +08:00
2021-09-09 10:48:28 +08:00
${ upgrade } >/etc/v2ray-agent/install.log 2>& 1
if grep <"/etc/v2ray-agent/install.log" -q "changed" ; then
${ updateReleaseInfoChange } >/dev/null 2>& 1
fi
2021-01-14 17:28:13 +08:00
if [ [ " ${ release } " = = "centos" ] ] ; then
rm -rf /var/run/yum.pid
2021-05-19 16:10:23 +08:00
${ installType } epel-release >/dev/null 2>& 1
2021-01-14 17:28:13 +08:00
fi
2021-05-07 15:43:41 +08:00
2021-01-18 11:00:50 +08:00
# [[ -z `find /usr/bin /usr/sbin |grep -v grep|grep -w curl` ]]
2021-01-14 17:28:13 +08:00
2021-01-18 11:00:50 +08:00
if ! find /usr/bin /usr/sbin | grep -q -w wget; then
2021-01-14 17:28:13 +08:00
echoContent green " ---> 安装wget"
${ installType } wget >/dev/null 2>& 1
fi
2021-01-18 11:00:50 +08:00
if ! find /usr/bin /usr/sbin | grep -q -w curl; then
2021-01-14 17:28:13 +08:00
echoContent green " ---> 安装curl"
${ installType } curl >/dev/null 2>& 1
fi
2021-01-18 11:00:50 +08:00
if ! find /usr/bin /usr/sbin | grep -q -w unzip; then
2021-01-14 17:28:13 +08:00
echoContent green " ---> 安装unzip"
${ installType } unzip >/dev/null 2>& 1
fi
2021-01-18 11:00:50 +08:00
if ! find /usr/bin /usr/sbin | grep -q -w socat; then
2021-01-14 17:28:13 +08:00
echoContent green " ---> 安装socat"
${ installType } socat >/dev/null 2>& 1
fi
2021-01-18 11:00:50 +08:00
if ! find /usr/bin /usr/sbin | grep -q -w tar; then
2021-01-14 17:28:13 +08:00
echoContent green " ---> 安装tar"
${ installType } tar >/dev/null 2>& 1
fi
2021-01-18 11:00:50 +08:00
if ! find /usr/bin /usr/sbin | grep -q -w cron; then
2021-01-14 17:28:13 +08:00
echoContent green " ---> 安装crontabs"
if [ [ " ${ release } " = = "ubuntu" ] ] || [ [ " ${ release } " = = "debian" ] ] ; then
${ installType } cron >/dev/null 2>& 1
else
${ installType } crontabs >/dev/null 2>& 1
fi
fi
2021-01-18 11:00:50 +08:00
if ! find /usr/bin /usr/sbin | grep -q -w jq; then
2021-01-14 17:28:13 +08:00
echoContent green " ---> 安装jq"
${ installType } jq >/dev/null 2>& 1
fi
2021-01-18 11:00:50 +08:00
if ! find /usr/bin /usr/sbin | grep -q -w binutils; then
2021-01-14 17:28:13 +08:00
echoContent green " ---> 安装binutils"
${ installType } binutils >/dev/null 2>& 1
fi
2021-01-18 11:00:50 +08:00
if ! find /usr/bin /usr/sbin | grep -q -w ping6; then
2021-01-14 17:28:13 +08:00
echoContent green " ---> 安装ping6"
${ installType } inetutils-ping >/dev/null 2>& 1
fi
2021-01-19 14:54:59 +08:00
if ! find /usr/bin /usr/sbin | grep -q -w qrencode; then
echoContent green " ---> 安装qrencode"
${ installType } qrencode >/dev/null 2>& 1
fi
2021-09-03 15:19:21 +08:00
if ! find /usr/bin /usr/sbin | grep -q -w sudo; then
2021-06-21 22:29:24 +08:00
echoContent green " ---> 安装sudo"
${ installType } sudo >/dev/null 2>& 1
fi
if ! find /usr/bin /usr/sbin | grep -q -w lsb-release; then
echoContent green " ---> 安装lsb-release"
${ installType } lsb-release >/dev/null 2>& 1
fi
2021-09-20 01:51:28 +08:00
if ! find /usr/bin /usr/sbin | grep -q -w lsof; then
echoContent green " ---> 安装lsof"
${ installType } lsof >/dev/null 2>& 1
fi
2022-09-26 17:50:55 +08:00
if ! find /usr/bin /usr/sbin | grep -q -w dig; then
echoContent green " ---> 安装dig"
2022-10-25 11:30:52 +08:00
if echo " ${ installType } " | grep -q -w "apt" ; then
2022-09-26 17:50:55 +08:00
${ installType } dnsutils >/dev/null 2>& 1
2022-10-25 11:30:52 +08:00
elif echo " ${ installType } " | grep -q -w "yum" ; then
2022-09-26 17:50:55 +08:00
${ installType } bind-utils >/dev/null 2>& 1
fi
fi
2022-09-23 17:53:15 +08:00
2021-05-17 16:01:56 +08:00
# 检测nginx版本, 并提供是否卸载的选项
2021-01-18 11:00:50 +08:00
if ! find /usr/bin /usr/sbin | grep -q -w nginx; then
2021-01-14 17:28:13 +08:00
echoContent green " ---> 安装nginx"
2021-05-07 15:43:41 +08:00
installNginxTools
2021-05-17 16:01:56 +08:00
else
nginxVersion = $( nginx -v 2>& 1)
nginxVersion = $( echo " ${ nginxVersion } " | awk -F "[n][g][i][n][x][/]" '{print $2}' | awk -F "[.]" '{print $2}' )
if [ [ ${ nginxVersion } -lt 14 ] ] ; then
read -r -p "读取到当前的Nginx版本不支持gRPC, 会导致安装失败, 是否卸载Nginx后重新安装 ? [y/n]:" unInstallNginxStatus
if [ [ " ${ unInstallNginxStatus } " = = "y" ] ] ; then
2021-05-19 16:10:23 +08:00
${ removeType } nginx >/dev/null 2>& 1
2021-05-17 16:01:56 +08:00
echoContent yellow " ---> nginx卸载完成"
echoContent green " ---> 安装nginx"
installNginxTools >/dev/null 2>& 1
else
exit 0
fi
fi
2021-05-07 15:43:41 +08:00
fi
2021-01-18 11:00:50 +08:00
if ! find /usr/bin /usr/sbin | grep -q -w semanage; then
2021-01-14 17:28:13 +08:00
echoContent green " ---> 安装semanage"
${ installType } bash-completion >/dev/null 2>& 1
2021-05-17 16:01:56 +08:00
if [ [ " ${ centosVersion } " = = "7" ] ] ; then
policyCoreUtils = "policycoreutils-python.x86_64"
elif [ [ " ${ centosVersion } " = = "8" ] ] ; then
policyCoreUtils = "policycoreutils-python-utils-2.9-9.el8.noarch"
fi
2021-01-14 17:28:13 +08:00
if [ [ -n " ${ policyCoreUtils } " ] ] ; then
${ installType } ${ policyCoreUtils } >/dev/null 2>& 1
fi
if [ [ -n $( which semanage) ] ] ; then
semanage port -a -t http_port_t -p tcp 31300
fi
fi
2021-01-18 11:00:50 +08:00
if [ [ ! -d " $HOME /.acme.sh " ] ] || [ [ -d " $HOME /.acme.sh " && -z $( find " $HOME /.acme.sh/acme.sh " ) ] ] ; then
2021-01-14 17:28:13 +08:00
echoContent green " ---> 安装acme.sh"
2022-09-20 18:05:40 +08:00
curl -s https://get.acme.sh | sh >/etc/v2ray-agent/tls/acme.log 2>& 1
2021-01-19 11:53:38 +08:00
if [ [ ! -d " $HOME /.acme.sh " ] ] || [ [ -z $( find " $HOME /.acme.sh/acme.sh " ) ] ] ; then
2021-01-14 17:28:13 +08:00
echoContent red " acme安装失败--->"
2021-06-22 11:58:56 +08:00
tail -n 100 /etc/v2ray-agent/tls/acme.log
2022-03-24 17:23:03 +08:00
echoContent yellow "错误排查:"
2022-02-03 21:45:03 +08:00
echoContent red " 1.获取Github文件失败, 请等待Github恢复后尝试, 恢复进度可查看 [https://www.githubstatus.com/]"
2021-01-14 17:28:13 +08:00
echoContent red " 2.acme.sh脚本出现bug, 可查看[https://github.com/acmesh-official/acme.sh] issues"
2022-08-11 23:33:52 +08:00
echoContent red " 3.如纯IPv6机器, 请设置NAT64,可执行下方命令"
echoContent skyBlue " echo -e \"nameserver 2001:67c:2b0::4\\\nnameserver 2001:67c:2b0::6\" >> /etc/resolv.conf"
2021-01-14 17:28:13 +08:00
exit 0
fi
fi
2020-05-23 23:21:43 +08:00
}
2020-11-25 17:06:40 +08:00
2021-05-07 15:43:41 +08:00
# 安装Nginx
installNginxTools( ) {
if [ [ " ${ release } " = = "debian" ] ] ; then
sudo apt install gnupg2 ca-certificates lsb-release -y >/dev/null 2>& 1
echo " deb http://nginx.org/packages/mainline/debian $( lsb_release -cs) nginx " | sudo tee /etc/apt/sources.list.d/nginx.list >/dev/null 2>& 1
echo -e "Package: *\nPin: origin nginx.org\nPin: release o=nginx\nPin-Priority: 900\n" | sudo tee /etc/apt/preferences.d/99nginx >/dev/null 2>& 1
curl -o /tmp/nginx_signing.key https://nginx.org/keys/nginx_signing.key >/dev/null 2>& 1
# gpg --dry-run --quiet --import --import-options import-show /tmp/nginx_signing.key
sudo mv /tmp/nginx_signing.key /etc/apt/trusted.gpg.d/nginx_signing.asc
sudo apt update >/dev/null 2>& 1
elif [ [ " ${ release } " = = "ubuntu" ] ] ; then
sudo apt install gnupg2 ca-certificates lsb-release -y >/dev/null 2>& 1
echo " deb http://nginx.org/packages/mainline/ubuntu $( lsb_release -cs) nginx " | sudo tee /etc/apt/sources.list.d/nginx.list >/dev/null 2>& 1
echo -e "Package: *\nPin: origin nginx.org\nPin: release o=nginx\nPin-Priority: 900\n" | sudo tee /etc/apt/preferences.d/99nginx >/dev/null 2>& 1
curl -o /tmp/nginx_signing.key https://nginx.org/keys/nginx_signing.key >/dev/null 2>& 1
# gpg --dry-run --quiet --import --import-options import-show /tmp/nginx_signing.key
sudo mv /tmp/nginx_signing.key /etc/apt/trusted.gpg.d/nginx_signing.asc
sudo apt update >/dev/null 2>& 1
elif [ [ " ${ release } " = = "centos" ] ] ; then
${ installType } yum-utils >/dev/null 2>& 1
cat <<EOF >/etc/yum.repos.d/nginx.repo
[ nginx-stable]
name = nginx stable repo
baseurl = http://nginx.org/packages/centos/\$ releasever/\$ basearch/
gpgcheck = 1
enabled = 1
gpgkey = https://nginx.org/keys/nginx_signing.key
module_hotfixes = true
[ nginx-mainline]
name = nginx mainline repo
baseurl = http://nginx.org/packages/mainline/centos/\$ releasever/\$ basearch/
gpgcheck = 1
enabled = 0
gpgkey = https://nginx.org/keys/nginx_signing.key
module_hotfixes = true
EOF
2021-05-17 16:01:56 +08:00
sudo yum-config-manager --enable nginx-mainline >/dev/null 2>& 1
2021-05-07 15:43:41 +08:00
fi
${ installType } nginx >/dev/null 2>& 1
2021-05-07 17:27:06 +08:00
systemctl daemon-reload
systemctl enable nginx
2021-05-07 15:43:41 +08:00
}
2021-06-21 17:36:04 +08:00
# 安装warp
2021-09-03 15:19:21 +08:00
installWarp( ) {
${ installType } gnupg2 -y >/dev/null 2>& 1
2021-06-21 17:36:04 +08:00
if [ [ " ${ release } " = = "debian" ] ] ; then
2021-06-22 11:58:56 +08:00
curl -s https://pkg.cloudflareclient.com/pubkey.gpg | sudo apt-key add - >/dev/null 2>& 1
2021-06-21 17:36:04 +08:00
echo " deb http://pkg.cloudflareclient.com/ $( lsb_release -cs) main " | sudo tee /etc/apt/sources.list.d/cloudflare-client.list >/dev/null 2>& 1
sudo apt update >/dev/null 2>& 1
elif [ [ " ${ release } " = = "ubuntu" ] ] ; then
2021-06-22 11:58:56 +08:00
curl -s https://pkg.cloudflareclient.com/pubkey.gpg | sudo apt-key add - >/dev/null 2>& 1
2021-06-21 23:37:09 +08:00
echo "deb http://pkg.cloudflareclient.com/ focal main" | sudo tee /etc/apt/sources.list.d/cloudflare-client.list >/dev/null 2>& 1
2021-06-21 17:36:04 +08:00
sudo apt update >/dev/null 2>& 1
elif [ [ " ${ release } " = = "centos" ] ] ; then
${ installType } yum-utils >/dev/null 2>& 1
2021-09-03 15:19:21 +08:00
sudo rpm -ivh " http://pkg.cloudflareclient.com/cloudflare-release-el ${ centosVersion } .rpm " >/dev/null 2>& 1
2021-06-21 17:36:04 +08:00
fi
2021-06-21 22:29:24 +08:00
2021-06-22 11:58:56 +08:00
echoContent green " ---> 安装WARP"
2021-06-21 17:36:04 +08:00
${ installType } cloudflare-warp >/dev/null 2>& 1
2021-09-03 15:19:21 +08:00
if [ [ -z $( which warp-cli) ] ] ; then
echoContent red " ---> 安装WARP失败"
exit 0
2021-06-21 22:29:24 +08:00
fi
2021-06-29 09:59:01 +08:00
systemctl enable warp-svc
2021-06-21 23:37:09 +08:00
warp-cli --accept-tos register
warp-cli --accept-tos set-mode proxy
warp-cli --accept-tos set-proxy-port 31303
warp-cli --accept-tos connect
2022-01-14 11:50:10 +08:00
warp-cli --accept-tos enable-always-on
2021-09-03 15:19:21 +08:00
# if [[]];then
# fi
# todo curl --socks5 127.0.0.1:31303 https://www.cloudflare.com/cdn-cgi/trace
2021-06-21 17:36:04 +08:00
# systemctl daemon-reload
# systemctl enable cloudflare-warp
}
2020-08-18 15:45:55 +08:00
# 初始化Nginx申请证书配置
2021-01-14 17:28:13 +08:00
initTLSNginxConfig( ) {
handleNginx stop
echoContent skyBlue " \n进度 $1 / ${ totalProgress } : 初始化Nginx申请证书配置 "
if [ [ -n " ${ currentHost } " ] ] ; then
echo
read -r -p "读取到上次安装记录,是否使用上次安装时的域名 ? [y/n]:" historyDomainStatus
if [ [ " ${ historyDomainStatus } " = = "y" ] ] ; then
domain = ${ currentHost }
2022-03-24 17:23:03 +08:00
echoContent yellow " \n ---> 域名: ${ domain } "
2021-01-14 17:28:13 +08:00
else
echo
2022-03-24 17:23:03 +08:00
echoContent yellow "请输入要配置的域名 例: www.v2ray-agent.com --->"
2021-01-14 17:28:13 +08:00
read -r -p "域名:" domain
fi
else
echo
2022-03-24 17:23:03 +08:00
echoContent yellow "请输入要配置的域名 例: www.v2ray-agent.com --->"
2021-01-14 17:28:13 +08:00
read -r -p "域名:" domain
fi
if [ [ -z ${ domain } ] ] ; then
echoContent red " 域名不可为空--->"
2022-01-14 11:50:10 +08:00
initTLSNginxConfig 3
2021-01-14 17:28:13 +08:00
else
2022-09-26 17:50:55 +08:00
dnsTLSDomain = $( echo " ${ domain } " | awk -F "[.]" '{print $(NF-1)"."$NF}' )
2022-10-11 16:02:05 +08:00
customPortFunction
local port = 80
if [ [ -n " ${ customPort } " ] ] ; then
port = ${ customPort }
fi
2021-01-14 17:28:13 +08:00
# 修改配置
2021-11-10 14:21:05 +08:00
touch ${ nginxConfigPath } alone.conf
cat <<EOF >${ nginxConfigPath } alone.conf
2021-08-12 18:18:36 +08:00
server {
2022-10-11 16:02:05 +08:00
listen ${ port } ;
listen [ ::] :${ port } ;
2021-08-12 18:18:36 +08:00
server_name ${ domain } ;
root /usr/share/nginx/html;
location ~ /.well-known {
allow all;
}
location /test {
return 200 'fjkvymb6len' ;
}
location /ip {
proxy_set_header Host \$ host;
proxy_set_header X-Real-IP \$ remote_addr;
proxy_set_header REMOTE-HOST \$ remote_addr;
proxy_set_header X-Forwarded-For \$ proxy_add_x_forwarded_for;
default_type text/plain;
return 200 \$ proxy_add_x_forwarded_for;
}
}
EOF
2021-01-14 17:28:13 +08:00
fi
2022-10-02 20:50:46 +08:00
readAcmeTLS
2020-10-19 16:41:44 +08:00
}
2020-11-25 17:06:40 +08:00
2020-12-03 16:46:11 +08:00
# 修改nginx重定向配置
2021-01-14 17:28:13 +08:00
updateRedirectNginxConf( ) {
2020-12-28 13:54:38 +08:00
2021-12-26 16:36:27 +08:00
if [ [ ${ BTPanelStatus } = = "true" ] ] ; then
2021-11-10 14:21:05 +08:00
2021-12-16 16:55:28 +08:00
cat <<EOF >${ nginxConfigPath } alone.conf
2021-11-10 14:21:05 +08:00
server {
listen 127.0.0.1:31300;
server_name _;
return 403;
}
EOF
2022-10-11 16:02:05 +08:00
elif [ [ -n " ${ customPort } " ] ] ; then
2021-12-16 16:55:28 +08:00
cat <<EOF >${ nginxConfigPath } alone.conf
2022-10-11 16:02:05 +08:00
server {
listen 127.0.0.1:31300;
server_name _;
return 403;
}
2020-12-28 13:54:38 +08:00
EOF
2021-11-10 14:21:05 +08:00
fi
2021-09-03 15:19:21 +08:00
if echo " ${ selectCustomInstallType } " | grep -q 2 && echo " ${ selectCustomInstallType } " | grep -q 5 || [ [ -z " ${ selectCustomInstallType } " ] ] ; then
2021-07-01 00:04:12 +08:00
2021-11-10 14:21:05 +08:00
cat <<EOF >>${ nginxConfigPath } alone.conf
2021-05-07 17:27:06 +08:00
server {
2022-02-09 16:56:15 +08:00
listen 127.0.0.1:31302 http2 so_keepalive = on;
2021-05-07 17:27:06 +08:00
server_name ${ domain } ;
root /usr/share/nginx/html;
2022-02-09 16:56:15 +08:00
client_header_timeout 1071906480m;
keepalive_timeout 1071906480m;
2021-06-21 14:10:21 +08:00
location /s/ {
2022-02-09 16:56:15 +08:00
add_header Content-Type text/plain;
alias /etc/v2ray-agent/subscribe/;
2021-06-21 14:10:21 +08:00
}
2021-07-01 00:04:12 +08:00
location /${ currentPath } grpc {
2022-02-09 16:56:15 +08:00
if ( \$ content_type !~ "application/grpc" ) {
return 404;
}
client_max_body_size 0;
grpc_set_header X-Real-IP \$ proxy_add_x_forwarded_for;
2021-06-29 09:59:01 +08:00
client_body_timeout 1071906480m;
2022-02-09 16:56:15 +08:00
grpc_read_timeout 1071906480m;
2021-05-07 17:27:06 +08:00
grpc_pass grpc://127.0.0.1:31301;
}
2021-07-01 00:04:12 +08:00
location /${ currentPath } trojangrpc {
2022-02-09 16:56:15 +08:00
if ( \$ content_type !~ "application/grpc" ) {
return 404;
}
client_max_body_size 0;
grpc_set_header X-Real-IP \$ proxy_add_x_forwarded_for;
2021-07-01 00:04:12 +08:00
client_body_timeout 1071906480m;
2022-02-09 16:56:15 +08:00
grpc_read_timeout 1071906480m;
2021-07-01 00:04:12 +08:00
grpc_pass grpc://127.0.0.1:31304;
}
2022-04-24 11:09:27 +08:00
location / {
add_header Strict-Transport-Security "max-age=15552000; preload" always;
}
2021-07-01 00:04:12 +08:00
}
EOF
2021-09-03 15:19:21 +08:00
elif echo " ${ selectCustomInstallType } " | grep -q 5 || [ [ -z " ${ selectCustomInstallType } " ] ] ; then
2021-11-10 14:21:05 +08:00
cat <<EOF >>${ nginxConfigPath } alone.conf
2021-07-01 00:04:12 +08:00
server {
listen 127.0.0.1:31302 http2;
server_name ${ domain } ;
root /usr/share/nginx/html;
location /s/ {
add_header Content-Type text/plain;
alias /etc/v2ray-agent/subscribe/;
}
location /${ currentPath } grpc {
client_max_body_size 0;
# keepalive_time 1071906480m;
keepalive_requests 4294967296;
client_body_timeout 1071906480m;
send_timeout 1071906480m;
lingering_close always;
grpc_read_timeout 1071906480m;
grpc_send_timeout 1071906480m;
2021-08-13 22:33:06 +08:00
grpc_pass grpc://127.0.0.1:31301;
2021-07-01 00:04:12 +08:00
}
2021-05-07 17:27:06 +08:00
}
2021-06-17 15:23:34 +08:00
EOF
2021-09-03 15:19:21 +08:00
elif echo " ${ selectCustomInstallType } " | grep -q 2 || [ [ -z " ${ selectCustomInstallType } " ] ] ; then
2021-07-01 00:04:12 +08:00
2021-11-10 14:21:05 +08:00
cat <<EOF >>${ nginxConfigPath } alone.conf
2021-07-01 00:04:12 +08:00
server {
listen 127.0.0.1:31302 http2;
server_name ${ domain } ;
root /usr/share/nginx/html;
location /s/ {
add_header Content-Type text/plain;
alias /etc/v2ray-agent/subscribe/;
}
location /${ currentPath } trojangrpc {
client_max_body_size 0;
# keepalive_time 1071906480m;
keepalive_requests 4294967296;
client_body_timeout 1071906480m;
send_timeout 1071906480m;
lingering_close always;
grpc_read_timeout 1071906480m;
grpc_send_timeout 1071906480m;
grpc_pass grpc://127.0.0.1:31301;
}
}
EOF
2021-06-24 10:14:42 +08:00
else
2021-07-01 00:04:12 +08:00
2021-11-10 14:21:05 +08:00
cat <<EOF >>${ nginxConfigPath } alone.conf
2021-06-17 15:23:34 +08:00
server {
listen 127.0.0.1:31302 http2;
server_name ${ domain } ;
root /usr/share/nginx/html;
2021-06-21 14:10:21 +08:00
location /s/ {
add_header Content-Type text/plain;
alias /etc/v2ray-agent/subscribe/;
}
2021-06-17 15:23:34 +08:00
location / {
}
}
2021-05-06 23:49:53 +08:00
EOF
fi
2020-12-28 13:54:38 +08:00
2021-11-10 14:21:05 +08:00
cat <<EOF >>${ nginxConfigPath } alone.conf
2021-05-07 17:27:06 +08:00
server {
2021-05-27 17:59:23 +08:00
listen 127.0.0.1:31300;
2021-05-07 17:27:06 +08:00
server_name ${ domain } ;
root /usr/share/nginx/html;
location /s/ {
add_header Content-Type text/plain;
alias /etc/v2ray-agent/subscribe/;
}
location / {
2021-06-22 11:58:56 +08:00
add_header Strict-Transport-Security "max-age=15552000; preload" always;
2021-05-07 17:27:06 +08:00
}
}
2020-12-28 13:54:38 +08:00
EOF
2020-12-03 16:46:11 +08:00
}
2020-12-17 18:02:09 +08:00
2020-10-19 16:41:44 +08:00
# 检查ip
2021-01-14 17:28:13 +08:00
checkIP( ) {
2021-08-13 15:16:06 +08:00
echoContent skyBlue "\n ---> 检查域名ip中"
2022-10-11 16:02:05 +08:00
local checkDomain = ${ domain }
if [ [ -n " ${ customPort } " ] ] ; then
checkDomain = " http:// ${ domain } : ${ customPort } "
fi
localIP = $( curl -s -m 2 " ${ checkDomain } /ip " )
2021-08-12 18:18:36 +08:00
handleNginx stop
2021-09-03 15:19:21 +08:00
if [ [ -z ${ localIP } ] ] || ! echo " ${ localIP } " | sed '1{s/[^(]*(//;s/).*//;q}' | grep -q '\.' && ! echo " ${ localIP } " | sed '1{s/[^(]*(//;s/).*//;q}' | grep -q ':' ; then
2021-08-12 18:18:36 +08:00
echoContent red "\n ---> 未检测到当前域名的ip"
2022-07-04 15:47:57 +08:00
echoContent skyBlue " ---> 请依次进行下列检查"
echoContent yellow " ---> 1.检查域名是否书写正确"
echoContent yellow " ---> 2.检查域名dns解析是否正确"
echoContent yellow " ---> 3.如解析正确, 请等待dns生效, 预计三分钟内生效"
echoContent yellow " ---> 4.如报Nginx启动问题, 请手动启动nginx查看错误, 如自己无法处理请提issues"
2022-11-08 15:04:46 +08:00
echoContent yellow " ---> 5.错误日志: ${ localIP } "
2022-10-11 16:02:05 +08:00
echo
2022-07-04 15:47:57 +08:00
echoContent skyBlue " ---> 如以上设置都正确,请重新安装纯净系统后再次尝试"
2022-11-08 15:04:46 +08:00
2021-09-03 15:19:21 +08:00
if [ [ -n ${ localIP } ] ] ; then
2021-09-20 01:51:28 +08:00
echoContent yellow " ---> 检测返回值异常, 建议手动卸载nginx后重新执行脚本"
fi
2022-10-11 16:02:05 +08:00
local portFirewallPortStatus = "443、80"
if [ [ -n " ${ customPort } " ] ] ; then
portFirewallPortStatus = " ${ customPort } "
fi
echoContent red " ---> 请检查防火墙规则是否开放 ${ portFirewallPortStatus } \n "
read -r -p " 是否通过脚本修改防火墙规则开放 ${ portFirewallPortStatus } 端口?[y/n]: " allPortFirewallStatus
2021-09-20 01:51:28 +08:00
if [ [ ${ allPortFirewallStatus } = = "y" ] ] ; then
2022-10-11 16:02:05 +08:00
if [ [ -n " ${ customPort } " ] ] ; then
allowPort " ${ customPort } "
else
allowPort 80
allowPort 443
fi
2021-09-20 01:51:28 +08:00
handleNginx start
checkIP
else
exit 0
2021-08-12 18:18:36 +08:00
fi
2021-09-20 01:51:28 +08:00
else
if echo " ${ localIP } " | awk -F "[,]" '{print $2}' | grep -q "." || echo " ${ localIP } " | awk -F "[,]" '{print $2}' | grep -q ":" ; then
echoContent red "\n ---> 检测到多个ip, 请确认是否关闭cloudflare的云朵"
echoContent yellow " ---> 关闭云朵后等待三分钟后重试"
2022-03-24 17:23:03 +08:00
echoContent yellow " ---> 检测到的ip如下:[ ${ localIP } ] "
2021-09-20 01:51:28 +08:00
exit 0
2021-08-04 17:11:14 +08:00
fi
2022-03-24 17:23:03 +08:00
echoContent green " ---> 当前域名ip为:[ ${ localIP } ] "
2021-01-14 17:28:13 +08:00
fi
2019-11-06 10:58:06 +08:00
}
2022-09-20 18:05:40 +08:00
# 自定义email
customSSLEmail( ) {
2022-09-21 17:52:28 +08:00
if echo " $1 " | grep -q "validate email" ; then
read -r -p "是否重新输入邮箱地址[y/n]:" sslEmailStatus
if [ [ " ${ sslEmailStatus } " = = "y" ] ] ; then
sed '/ACCOUNT_EMAIL/d' /root/.acme.sh/account.conf >/root/.acme.sh/account.conf_tmp && mv /root/.acme.sh/account.conf_tmp /root/.acme.sh/account.conf
else
exit 0
fi
fi
2022-09-20 18:05:40 +08:00
if [ [ -d "/root/.acme.sh" && -f "/root/.acme.sh/account.conf" ] ] ; then
2022-09-21 15:59:33 +08:00
if ! grep -q "ACCOUNT_EMAIL" <"/root/.acme.sh/account.conf" && ! echo " ${ sslType } " | grep -q "letsencrypt" ; then
2022-09-20 18:05:40 +08:00
read -r -p "请输入邮箱地址:" sslEmail
if echo " ${ sslEmail } " | grep -q "@" ; then
echo " ACCOUNT_EMAIL=' ${ sslEmail } ' " >>/root/.acme.sh/account.conf
echoContent green " ---> 添加成功"
else
echoContent yellow "请重新输入正确的邮箱格式[例: username@example.com]"
customSSLEmail
fi
fi
fi
}
# 选择ssl安装类型
switchSSLType( ) {
if [ [ -z " ${ sslType } " ] ] ; then
echoContent red "\n=============================================================="
2022-09-21 15:59:33 +08:00
echoContent yellow "1.letsencrypt[默认]"
2022-09-20 18:05:40 +08:00
echoContent yellow "2.zerossl"
2022-10-12 17:36:05 +08:00
echoContent yellow "3.buypass[不支持DNS申请]"
2022-09-20 18:05:40 +08:00
echoContent red "=============================================================="
2022-09-21 15:59:33 +08:00
read -r -p "请选择[回车]使用默认:" selectSSLType
case ${ selectSSLType } in
1)
sslType = "letsencrypt"
; ;
2)
sslType = "zerossl"
; ;
3)
sslType = "buypass"
; ;
*)
sslType = "letsencrypt"
; ;
esac
2022-09-21 17:52:28 +08:00
touch /etc/v2ray-agent/tls
echo " ${ sslType } " >/etc/v2ray-agent/tls/ssl_type
2022-09-23 17:53:15 +08:00
fi
}
2022-11-08 15:04:46 +08:00
# 选择acme安装证书方式
selectAcmeInstallSSL( ) {
2022-09-23 17:53:15 +08:00
local installSSLIPv6 =
if echo " ${ localIP } " | grep -q ":" ; then
installSSLIPv6 = "--listen-v6"
fi
2022-09-26 17:50:55 +08:00
echo
2022-10-11 16:02:05 +08:00
if [ [ -n " ${ customPort } " ] ] ; then
2022-10-12 17:36:05 +08:00
if [ [ " ${ selectSSLType } " = = "3" ] ] ; then
echoContent red " ---> buypass不支持免费通配符证书"
echo
exit
fi
2022-09-23 17:53:15 +08:00
dnsSSLStatus = true
2022-10-11 16:02:05 +08:00
else
read -r -p "是否使用DNS申请证书[y/n]:" installSSLDNStatus
if [ [ ${ installSSLDNStatus } = = 'y' ] ] ; then
dnsSSLStatus = true
fi
2022-09-23 17:53:15 +08:00
fi
2022-11-08 15:04:46 +08:00
acmeInstallSSL
readAcmeTLS
}
2022-09-23 17:53:15 +08:00
2022-11-08 15:04:46 +08:00
# 安装SSL证书
acmeInstallSSL( ) {
2022-09-23 17:53:15 +08:00
if [ [ " ${ dnsSSLStatus } " = = "true" ] ] ; then
2022-09-26 17:50:55 +08:00
sudo " $HOME /.acme.sh/acme.sh " --issue -d " *. ${ dnsTLSDomain } " --dns --yes-I-know-dns-manual-mode-enough-go-ahead-please --standalone -k ec-256 --server " ${ sslType } " ${ installSSLIPv6 } 2>& 1 | tee -a /etc/v2ray-agent/tls/acme.log >/dev/null
local txtValue =
txtValue = $( tail -n 10 /etc/v2ray-agent/tls/acme.log | grep "TXT value" | awk -F "'" '{print $2}' )
2022-09-23 17:53:15 +08:00
if [ [ -n " ${ txtValue } " ] ] ; then
echoContent green " ---> 请手动添加DNS TXT记录"
2022-11-08 15:04:46 +08:00
echoContent yellow " ---> 添加方法请参考此教程, https://github.com/mack-a/v2ray-agent/blob/master/documents/dns_txt.md"
2022-09-23 17:53:15 +08:00
echoContent green " ---> name: _acme-challenge"
echoContent green " ---> value: ${ txtValue } "
echoContent yellow " ---> 添加完成后等请等待1-2分钟"
2022-10-09 17:27:01 +08:00
echo
2022-09-23 17:53:15 +08:00
read -r -p "是否添加完成[y/n]:" addDNSTXTRecordStatus
if [ [ " ${ addDNSTXTRecordStatus } " = = "y" ] ] ; then
2022-09-26 17:50:55 +08:00
local txtAnswer =
txtAnswer = $( dig +nocmd " _acme-challenge. ${ dnsTLSDomain } " txt +noall +answer | awk -F "[\"]" '{print $2}' )
if [ [ " ${ txtAnswer } " = = " ${ txtValue } " ] ] ; then
echoContent green " ---> TXT记录验证通过"
echoContent green " ---> 生成证书中"
sudo " $HOME /.acme.sh/acme.sh " --renew -d " *. ${ dnsTLSDomain } " --yes-I-know-dns-manual-mode-enough-go-ahead-please --ecc --server " ${ sslType } " ${ installSSLIPv6 } 2>& 1 | tee -a /etc/v2ray-agent/tls/acme.log >/dev/null
else
echoContent red " ---> 验证失败, 请等待1-2分钟后重新尝试"
2022-11-08 15:04:46 +08:00
acmeInstallSSL
2022-09-26 17:50:55 +08:00
fi
2022-09-23 17:53:15 +08:00
else
echoContent red " ---> 放弃"
exit 0
fi
fi
2022-09-26 17:50:55 +08:00
else
2022-10-19 17:43:06 +08:00
echoContent green " ---> 生成证书中"
2022-10-25 11:30:52 +08:00
sudo " $HOME /.acme.sh/acme.sh " --issue -d " ${ tlsDomain } " --standalone -k ec-256 --server " ${ sslType } " ${ installSSLIPv6 } 2>& 1 | tee -a /etc/v2ray-agent/tls/acme.log >/dev/null
2022-09-20 18:05:40 +08:00
fi
}
2022-10-11 16:02:05 +08:00
# 自定义端口
customPortFunction( ) {
local historyCustomPortStatus =
if [ [ -n " ${ customPort } " ] ] ; then
echo
read -r -p "读取到上次安装时的端口,是否使用上次安装时的端口 ? [y/n]:" historyCustomPortStatus
if [ [ " ${ historyCustomPortStatus } " = = "y" ] ] ; then
echoContent yellow " \n ---> 端口: ${ customPort } "
fi
fi
if [ [ " ${ historyCustomPortStatus } " = = "n" || -z " ${ customPort } " ] ] ; then
echo
2022-11-08 15:04:46 +08:00
echoContent yellow "请输入端口[默认: 443], 如自定义端口, 只允许使用DNS申请证书[回车使用默认]"
2022-10-11 16:02:05 +08:00
read -r -p "端口:" customPort
2022-10-19 17:43:06 +08:00
if [ [ -n " ${ customPort } " ] ] ; then
if ( ( customPort >= 1 && customPort <= 65535) ) ; then
checkCustomPort
else
2022-10-25 13:57:16 +08:00
echoContent red " ---> 端口输入错误"
2022-10-19 17:43:06 +08:00
exit
fi
2022-10-11 16:02:05 +08:00
else
2022-10-19 17:43:06 +08:00
echoContent yellow "\n ---> 端口: 443"
2022-10-11 16:02:05 +08:00
fi
fi
}
# 检测端口是否占用
checkCustomPort( ) {
if lsof -i " tcp: ${ customPort } " | grep -q LISTEN; then
echoContent red " \n ---> ${ customPort } 端口被占用,请手动关闭后安装\n "
lsof -i tcp:80 | grep LISTEN
exit 0
fi
}
2022-09-23 17:53:15 +08:00
2020-05-23 23:21:43 +08:00
# 安装TLS
2021-01-14 17:28:13 +08:00
installTLS( ) {
echoContent skyBlue " \n进度 $1 / ${ totalProgress } : 申请TLS证书\n "
local tlsDomain = ${ domain }
2022-09-26 17:50:55 +08:00
2021-01-14 17:28:13 +08:00
# 安装tls
2021-06-17 15:23:34 +08:00
if [ [ -f " /etc/v2ray-agent/tls/ ${ tlsDomain } .crt " && -f " /etc/v2ray-agent/tls/ ${ tlsDomain } .key " && -n $( cat " /etc/v2ray-agent/tls/ ${ tlsDomain } .crt " ) ] ] || [ [ -d " $HOME /.acme.sh/ ${ tlsDomain } _ecc " && -f " $HOME /.acme.sh/ ${ tlsDomain } _ecc/ ${ tlsDomain } .key " && -f " $HOME /.acme.sh/ ${ tlsDomain } _ecc/ ${ tlsDomain } .cer " ] ] ; then
2021-01-14 17:28:13 +08:00
echoContent green " ---> 检测到证书"
2021-12-26 16:36:27 +08:00
# checkTLStatus
2021-09-22 11:43:55 +08:00
renewalTLS
if [ [ -z $( find /etc/v2ray-agent/tls/ -name " ${ tlsDomain } .crt " ) ] ] || [ [ -z $( find /etc/v2ray-agent/tls/ -name " ${ tlsDomain } .key " ) ] ] || [ [ -z $( cat " /etc/v2ray-agent/tls/ ${ tlsDomain } .crt " ) ] ] ; then
2021-11-08 11:14:27 +08:00
sudo " $HOME /.acme.sh/acme.sh " --installcert -d " ${ tlsDomain } " --fullchainpath " /etc/v2ray-agent/tls/ ${ tlsDomain } .crt " --keypath " /etc/v2ray-agent/tls/ ${ tlsDomain } .key " --ecc >/dev/null
else
2021-12-26 16:36:27 +08:00
echoContent yellow " ---> 如未过期或者自定义证书请选择[n]\n"
2021-11-08 11:14:27 +08:00
read -r -p "是否重新安装?[y/n]:" reInstallStatus
if [ [ " ${ reInstallStatus } " = = "y" ] ] ; then
rm -rf /etc/v2ray-agent/tls/*
installTLS " $1 "
fi
2021-01-14 17:28:13 +08:00
fi
2021-09-22 11:43:55 +08:00
2021-01-25 11:57:29 +08:00
elif [ [ -d " $HOME /.acme.sh " ] ] && [ [ ! -f " $HOME /.acme.sh/ ${ tlsDomain } _ecc/ ${ tlsDomain } .cer " || ! -f " $HOME /.acme.sh/ ${ tlsDomain } _ecc/ ${ tlsDomain } .key " ] ] ; then
2021-01-14 17:28:13 +08:00
echoContent green " ---> 安装TLS证书"
2022-09-20 18:05:40 +08:00
2022-10-09 17:27:01 +08:00
if [ [ " ${ installDNSACMEStatus } " != "true" ] ] ; then
switchSSLType
customSSLEmail
2022-11-08 15:04:46 +08:00
selectAcmeInstallSSL
2022-10-09 17:27:01 +08:00
else
echoContent green " ---> 检测到已安装通配符证书,自动生成中"
fi
2022-09-20 18:05:40 +08:00
2022-10-09 17:27:01 +08:00
if [ [ " ${ installDNSACMEStatus } " = = "true" ] ] ; then
2022-09-26 17:50:55 +08:00
echo
if [ [ -d " $HOME /.acme.sh/*. ${ dnsTLSDomain } _ecc " && -f " $HOME /.acme.sh/*. ${ dnsTLSDomain } _ecc/*. ${ dnsTLSDomain } .key " && -f " $HOME /.acme.sh/*. ${ dnsTLSDomain } _ecc/*. ${ dnsTLSDomain } .cer " ] ] ; then
sudo " $HOME /.acme.sh/acme.sh " --installcert -d " *. ${ dnsTLSDomain } " --fullchainpath " /etc/v2ray-agent/tls/ ${ tlsDomain } .crt " --keypath " /etc/v2ray-agent/tls/ ${ tlsDomain } .key " --ecc >/dev/null
fi
2021-01-14 17:28:13 +08:00
2022-09-26 17:50:55 +08:00
elif [ [ -d " $HOME /.acme.sh/ ${ tlsDomain } _ecc " && -f " $HOME /.acme.sh/ ${ tlsDomain } _ecc/ ${ tlsDomain } .key " && -f " $HOME /.acme.sh/ ${ tlsDomain } _ecc/ ${ tlsDomain } .cer " ] ] ; then
2021-06-17 15:23:34 +08:00
sudo " $HOME /.acme.sh/acme.sh " --installcert -d " ${ tlsDomain } " --fullchainpath " /etc/v2ray-agent/tls/ ${ tlsDomain } .crt " --keypath " /etc/v2ray-agent/tls/ ${ tlsDomain } .key " --ecc >/dev/null
fi
2022-09-26 17:50:55 +08:00
2021-09-03 15:19:21 +08:00
if [ [ ! -f " /etc/v2ray-agent/tls/ ${ tlsDomain } .crt " || ! -f " /etc/v2ray-agent/tls/ ${ tlsDomain } .key " ] ] || [ [ -z $( cat " /etc/v2ray-agent/tls/ ${ tlsDomain } .key " ) || -z $( cat " /etc/v2ray-agent/tls/ ${ tlsDomain } .crt " ) ] ] ; then
2021-06-17 15:23:34 +08:00
tail -n 10 /etc/v2ray-agent/tls/acme.log
2021-09-03 15:19:21 +08:00
if [ [ ${ installTLSCount } = = "1" ] ] ; then
2021-08-12 15:33:32 +08:00
echoContent red " ---> TLS安装失败, 请检查acme日志"
exit 0
fi
2022-09-21 17:52:28 +08:00
installTLSCount = 1
echo
2021-09-20 01:51:28 +08:00
echoContent red " ---> TLS安装失败, 正在检查80、443端口是否开放"
2022-04-21 17:07:44 +08:00
allowPort 80
allowPort 443
2021-08-12 15:33:32 +08:00
echoContent yellow " ---> 重新尝试安装TLS证书"
2022-09-21 17:52:28 +08:00
if tail -n 10 /etc/v2ray-agent/tls/acme.log | grep -q "Could not validate email address as valid" ; then
echoContent red " ---> 邮箱无法通过SSL厂商验证, 请重新输入"
echo
customSSLEmail "validate email"
installTLS " $1 "
2022-09-26 17:50:55 +08:00
else
installTLS " $1 "
2022-09-21 17:52:28 +08:00
fi
2021-01-14 17:28:13 +08:00
fi
2022-09-26 17:50:55 +08:00
2021-01-14 17:28:13 +08:00
echoContent green " ---> TLS生成成功"
else
echoContent yellow " ---> 未安装acme.sh"
exit 0
fi
2020-08-10 17:17:14 +08:00
}
2020-09-25 16:08:25 +08:00
# 配置伪装博客
2021-01-14 17:28:13 +08:00
initNginxConfig( ) {
echoContent skyBlue " \n进度 $1 / ${ totalProgress } : 配置Nginx "
2020-08-18 16:22:06 +08:00
2021-11-10 14:21:05 +08:00
cat <<EOF >${ nginxConfigPath } alone.conf
2020-08-29 23:12:20 +08:00
server {
listen 80;
2020-12-25 10:05:26 +08:00
listen [ ::] :80;
2020-08-29 23:12:20 +08:00
server_name ${ domain } ;
root /usr/share/nginx/html;
location ~ /.well-known { allow all; }
location /test { return 200 'fjkvymb6len' ; }
}
EOF
2020-08-18 13:44:19 +08:00
}
2020-11-25 17:06:40 +08:00
2020-08-18 13:44:19 +08:00
# 自定义/随机路径
2021-01-14 17:28:13 +08:00
randomPathFunction( ) {
echoContent skyBlue " \n进度 $1 / ${ totalProgress } : 生成随机路径 "
if [ [ -n " ${ currentPath } " ] ] ; then
echo
read -r -p "读取到上次安装记录, 是否使用上次安装时的path路径 ? [y/n]:" historyPathStatus
echo
fi
if [ [ " ${ historyPathStatus } " = = "y" ] ] ; then
customPath = ${ currentPath }
echoContent green " ---> 使用成功\n"
else
echoContent yellow "请输入自定义路径[例: alone],不需要斜杠,[回车]随机路径"
read -r -p '路径:' customPath
if [ [ -z " ${ customPath } " ] ] ; then
2021-09-03 15:19:21 +08:00
customPath = $( head -n 50 /dev/urandom | sed 's/[^a-z]//g' | strings -n 4 | tr '[:upper:]' '[:lower:]' | head -1)
2021-01-14 17:28:13 +08:00
currentPath = ${ customPath : 0 : 4 }
2021-06-22 14:34:35 +08:00
customPath = ${ currentPath }
2021-06-04 18:01:24 +08:00
else
currentPath = ${ customPath }
2021-01-14 17:28:13 +08:00
fi
2021-06-04 18:01:24 +08:00
2021-01-14 17:28:13 +08:00
fi
2022-03-24 17:23:03 +08:00
echoContent yellow " \n path: ${ currentPath } "
2021-01-14 17:28:13 +08:00
echoContent skyBlue "\n----------------------------"
2020-08-18 13:44:19 +08:00
}
2020-08-18 15:45:55 +08:00
# Nginx伪装博客
2021-01-14 17:28:13 +08:00
nginxBlog( ) {
echoContent skyBlue " \n进度 $1 / ${ totalProgress } : 添加伪装站点 "
if [ [ -d "/usr/share/nginx/html" && -f "/usr/share/nginx/html/check" ] ] ; then
echo
2022-03-24 17:23:03 +08:00
read -r -p "检测到安装伪装站点,是否需要重新安装[y/n]:" nginxBlogInstallStatus
2021-01-14 17:28:13 +08:00
if [ [ " ${ nginxBlogInstallStatus } " = = "y" ] ] ; then
rm -rf /usr/share/nginx/html
2021-09-03 15:19:21 +08:00
randomNum = $(( RANDOM % 6 + 1 ))
2021-07-04 01:08:14 +08:00
wget -q -P /usr/share/nginx https://raw.githubusercontent.com/mack-a/v2ray-agent/master/fodder/blog/unable/html${ randomNum } .zip >/dev/null
2021-06-23 16:46:42 +08:00
unzip -o /usr/share/nginx/html${ randomNum } .zip -d /usr/share/nginx/html >/dev/null
rm -f /usr/share/nginx/html${ randomNum } .zip*
2021-01-14 17:28:13 +08:00
echoContent green " ---> 添加伪装站点成功"
fi
else
2021-09-03 15:19:21 +08:00
randomNum = $(( RANDOM % 6 + 1 ))
2021-01-14 17:28:13 +08:00
rm -rf /usr/share/nginx/html
2021-07-04 01:08:14 +08:00
wget -q -P /usr/share/nginx https://raw.githubusercontent.com/mack-a/v2ray-agent/master/fodder/blog/unable/html${ randomNum } .zip >/dev/null
2021-06-23 16:46:42 +08:00
unzip -o /usr/share/nginx/html${ randomNum } .zip -d /usr/share/nginx/html >/dev/null
rm -f /usr/share/nginx/html${ randomNum } .zip*
2021-01-14 17:28:13 +08:00
echoContent green " ---> 添加伪装站点成功"
fi
2020-12-01 10:02:44 +08:00
2020-08-18 13:44:19 +08:00
}
2022-05-02 22:08:21 +08:00
# 修改http_port_t端口
updateSELinuxHTTPPortT( ) {
$( find /usr/bin /usr/sbin | grep -w journalctl) -xe >/etc/v2ray-agent/nginx_error.log 2>& 1
if find /usr/bin /usr/sbin | grep -q -w semanage && find /usr/bin /usr/sbin | grep -q -w getenforce && grep -E "31300|31302" </etc/v2ray-agent/nginx_error.log | grep -q "Permission denied" ; then
echoContent red " ---> 检查SELinux端口是否开放"
if ! $( find /usr/bin /usr/sbin | grep -w semanage) port -l | grep http_port | grep -q 31300; then
$( find /usr/bin /usr/sbin | grep -w semanage) port -a -t http_port_t -p tcp 31300
echoContent green " ---> http_port_t 31300 端口开放成功"
fi
if ! $( find /usr/bin /usr/sbin | grep -w semanage) port -l | grep http_port | grep -q 31302; then
$( find /usr/bin /usr/sbin | grep -w semanage) port -a -t http_port_t -p tcp 31302
echoContent green " ---> http_port_t 31302 端口开放成功"
fi
handleNginx start
else
exit 0
fi
}
2020-08-18 13:44:19 +08:00
# 操作Nginx
2021-01-14 17:28:13 +08:00
handleNginx( ) {
2021-01-15 11:53:32 +08:00
if [ [ -z $( pgrep -f "nginx" ) ] ] && [ [ " $1 " = = "start" ] ] ; then
2022-05-02 22:08:21 +08:00
systemctl start nginx 2>/etc/v2ray-agent/nginx_error.log
2021-01-14 17:28:13 +08:00
sleep 0.5
2021-09-03 15:19:21 +08:00
if [ [ -z $( pgrep -f nginx) ] ] ; then
2021-04-09 17:12:16 +08:00
echoContent red " ---> Nginx启动失败"
echoContent red " ---> 请手动尝试安装nginx后, 再次执行脚本"
2022-05-02 22:08:21 +08:00
if grep -q "journalctl -xe" </etc/v2ray-agent/nginx_error.log; then
updateSELinuxHTTPPortT
fi
# exit 0
else
echoContent green " ---> Nginx启动成功"
2021-01-14 17:28:13 +08:00
fi
2022-05-02 22:08:21 +08:00
2021-09-03 15:19:21 +08:00
elif [ [ -n $( pgrep -f "nginx" ) ] ] && [ [ " $1 " = = "stop" ] ] ; then
2021-12-16 16:55:28 +08:00
systemctl stop nginx
2021-01-14 17:28:13 +08:00
sleep 0.5
2021-01-15 11:53:32 +08:00
if [ [ -n $( pgrep -f "nginx" ) ] ] ; then
pgrep -f "nginx" | xargs kill -9
2021-01-14 17:28:13 +08:00
fi
2022-04-18 16:33:15 +08:00
echoContent green " ---> Nginx关闭成功"
2021-01-14 17:28:13 +08:00
fi
2019-11-06 10:58:06 +08:00
}
2020-11-25 17:06:40 +08:00
2020-08-18 13:44:19 +08:00
# 定时任务更新tls证书
2021-01-14 17:28:13 +08:00
installCronTLS( ) {
2021-04-27 16:45:03 +08:00
echoContent skyBlue " \n进度 $1 / ${ totalProgress } : 添加定时维护证书 "
2021-03-19 23:21:59 +08:00
crontab -l >/etc/v2ray-agent/backup_crontab.cron
2021-09-03 15:19:21 +08:00
local historyCrontab
historyCrontab = $( sed '/v2ray-agent/d;/acme.sh/d' /etc/v2ray-agent/backup_crontab.cron)
2021-06-10 10:44:48 +08:00
echo " ${ historyCrontab } " >/etc/v2ray-agent/backup_crontab.cron
2021-05-26 15:01:47 +08:00
echo "30 1 * * * /bin/bash /etc/v2ray-agent/install.sh RenewTLS >> /etc/v2ray-agent/crontab_tls.log 2>&1" >>/etc/v2ray-agent/backup_crontab.cron
2021-03-23 15:06:17 +08:00
crontab /etc/v2ray-agent/backup_crontab.cron
2021-04-20 16:23:02 +08:00
echoContent green "\n ---> 添加定时维护证书成功"
2020-07-03 18:01:32 +08:00
}
2020-11-25 17:06:40 +08:00
2020-09-11 16:36:29 +08:00
# 更新证书
2021-01-14 17:28:13 +08:00
renewalTLS( ) {
2022-10-27 17:48:12 +08:00
2021-09-22 11:43:55 +08:00
if [ [ -n $1 ] ] ; then
echoContent skyBlue " \n进度 $1 /1 : 更新证书 "
fi
2022-10-27 17:48:12 +08:00
readAcmeTLS
2021-11-24 13:51:04 +08:00
local domain = ${ currentHost }
2021-12-16 16:55:28 +08:00
if [ [ -z " ${ currentHost } " && -n " ${ tlsDomain } " ] ] ; then
2021-11-24 13:51:04 +08:00
domain = ${ tlsDomain }
fi
2021-01-14 17:28:13 +08:00
2022-09-21 17:52:28 +08:00
if [ [ -f "/etc/v2ray-agent/tls/ssl_type" ] ] ; then
if grep -q "buypass" <"/etc/v2ray-agent/tls/ssl_type" ; then
sslRenewalDays = 180
fi
fi
2022-10-11 16:02:05 +08:00
if [ [ -d " $HOME /.acme.sh/ ${ domain } _ecc " && -f " $HOME /.acme.sh/ ${ domain } _ecc/ ${ domain } .key " && -f " $HOME /.acme.sh/ ${ domain } _ecc/ ${ domain } .cer " ] ] || [ [ " ${ installDNSACMEStatus } " = = "true" ] ] ; then
2022-10-02 20:50:46 +08:00
modifyTime =
2022-10-11 16:02:05 +08:00
if [ [ " ${ installDNSACMEStatus } " = = "true" ] ] ; then
2022-10-02 20:50:46 +08:00
modifyTime = $( stat " $HOME /.acme.sh/*. ${ dnsTLSDomain } _ecc/*. ${ dnsTLSDomain } .cer " | sed -n '7,6p' | awk '{print $2" "$3" "$4" "$5}' )
else
modifyTime = $( stat " $HOME /.acme.sh/ ${ domain } _ecc/ ${ domain } .cer " | sed -n '7,6p' | awk '{print $2" "$3" "$4" "$5}' )
fi
2021-01-14 17:28:13 +08:00
modifyTime = $( date +%s -d " ${ modifyTime } " )
currentTime = $( date +%s)
2021-09-06 15:07:12 +08:00
( ( stampDiff = currentTime - modifyTime) )
( ( days = stampDiff / 86400) )
2022-09-21 17:52:28 +08:00
( ( remainingDays = sslRenewalDays - days) )
2021-09-06 11:53:02 +08:00
2021-01-14 17:28:13 +08:00
tlsStatus = ${ remainingDays }
if [ [ ${ remainingDays } -le 0 ] ] ; then
tlsStatus = "已过期"
fi
2021-05-26 15:01:47 +08:00
echoContent skyBlue " ---> 证书检查日期: $( date "+%F %H:%M:%S" ) "
2021-01-14 17:28:13 +08:00
echoContent skyBlue " ---> 证书生成日期: $( date -d @" ${ modifyTime } " +"%F %H:%M:%S" ) "
echoContent skyBlue " ---> 证书生成天数: ${ days } "
echoContent skyBlue " ---> 证书剩余天数:" ${ tlsStatus }
2021-05-26 15:01:47 +08:00
echoContent skyBlue " ---> 证书过期前最后一天自动更新,如更新失败请手动更新"
2021-01-14 17:28:13 +08:00
if [ [ ${ remainingDays } -le 1 ] ] ; then
echoContent yellow " ---> 重新生成证书"
handleNginx stop
sudo " $HOME /.acme.sh/acme.sh " --cron --home " $HOME /.acme.sh "
2021-11-24 13:51:04 +08:00
sudo " $HOME /.acme.sh/acme.sh " --installcert -d " ${ domain } " --fullchainpath /etc/v2ray-agent/tls/" ${ domain } .crt " --keypath /etc/v2ray-agent/tls/" ${ domain } .key " --ecc
2021-03-04 16:15:53 +08:00
reloadCore
2021-12-08 15:25:25 +08:00
handleNginx start
2021-01-14 17:28:13 +08:00
else
echoContent green " ---> 证书有效"
fi
else
echoContent red " ---> 未安装"
fi
2020-09-11 16:36:29 +08:00
}
2020-11-24 15:39:47 +08:00
# 查看TLS证书的状态
2021-01-14 17:28:13 +08:00
checkTLStatus( ) {
2021-09-22 11:43:55 +08:00
if [ [ -d " $HOME /.acme.sh/ ${ currentHost } _ecc " ] ] && [ [ -f " $HOME /.acme.sh/ ${ currentHost } _ecc/ ${ currentHost } .key " ] ] && [ [ -f " $HOME /.acme.sh/ ${ currentHost } _ecc/ ${ currentHost } .cer " ] ] ; then
modifyTime = $( stat " $HOME /.acme.sh/ ${ currentHost } _ecc/ ${ currentHost } .cer " | sed -n '7,6p' | awk '{print $2" "$3" "$4" "$5}' )
2021-01-14 17:28:13 +08:00
2021-09-22 11:43:55 +08:00
modifyTime = $( date +%s -d " ${ modifyTime } " )
currentTime = $( date +%s)
( ( stampDiff = currentTime - modifyTime) )
( ( days = stampDiff / 86400) )
2022-09-21 17:52:28 +08:00
( ( remainingDays = sslRenewalDays - days) )
2021-09-06 11:53:02 +08:00
2021-09-22 11:43:55 +08:00
tlsStatus = ${ remainingDays }
if [ [ ${ remainingDays } -le 0 ] ] ; then
tlsStatus = "已过期"
2021-01-14 17:28:13 +08:00
fi
2021-09-22 11:43:55 +08:00
echoContent skyBlue " ---> 证书生成日期: $( date -d " @ ${ modifyTime } " +"%F %H:%M:%S" ) "
echoContent skyBlue " ---> 证书生成天数: ${ days } "
echoContent skyBlue " ---> 证书剩余天数: ${ tlsStatus } "
2021-01-14 17:28:13 +08:00
fi
2020-11-24 15:39:47 +08:00
}
2020-11-20 17:57:50 +08:00
# 安装V2Ray、指定版本
2021-01-14 17:28:13 +08:00
installV2Ray( ) {
readInstallType
echoContent skyBlue " \n进度 $1 / ${ totalProgress } : 安装V2Ray "
if [ [ " ${ coreInstallType } " != "2" && " ${ coreInstallType } " != "3" ] ] ; then
if [ [ " ${ selectCoreType } " = = "2" ] ] ; then
2021-06-03 11:54:30 +08:00
2022-09-20 18:05:40 +08:00
version = $( curl -s https://api.github.com/repos/v2fly/v2ray-core/releases | jq -r '.[]|select (.prerelease==false)|.tag_name' | grep -v 'v5' | head -1)
2021-01-14 17:28:13 +08:00
else
version = ${ v2rayCoreVersion }
fi
echoContent green " ---> v2ray-core版本: ${ version } "
if wget --help | grep -q show-progress; then
2021-05-26 17:27:52 +08:00
wget -c -q --show-progress -P /etc/v2ray-agent/v2ray/ " https://github.com/v2fly/v2ray-core/releases/download/ ${ version } / ${ v2rayCoreCPUVendor } .zip "
2021-01-14 17:28:13 +08:00
else
2021-05-26 17:27:52 +08:00
wget -c -P /etc/v2ray-agent/v2ray/ " https://github.com/v2fly/v2ray-core/releases/download/ ${ version } / ${ v2rayCoreCPUVendor } .zip " >/dev/null 2>& 1
2021-01-14 17:28:13 +08:00
fi
2021-09-03 15:19:21 +08:00
unzip -o " /etc/v2ray-agent/v2ray/ ${ v2rayCoreCPUVendor } .zip " -d /etc/v2ray-agent/v2ray >/dev/null
rm -rf " /etc/v2ray-agent/v2ray/ ${ v2rayCoreCPUVendor } .zip "
2021-01-14 17:28:13 +08:00
else
if [ [ " ${ selectCoreType } " = = "3" ] ] ; then
echoContent green " ---> 锁定v2ray-core版本为v4.32.1"
rm -f /etc/v2ray-agent/v2ray/v2ray
rm -f /etc/v2ray-agent/v2ray/v2ctl
installV2Ray " $1 "
else
echoContent green " ---> v2ray-core版本: $( /etc/v2ray-agent/v2ray/v2ray --version | awk '{print $2}' | head -1) "
read -r -p "是否更新、升级?[y/n]:" reInstallV2RayStatus
if [ [ " ${ reInstallV2RayStatus } " = = "y" ] ] ; then
rm -f /etc/v2ray-agent/v2ray/v2ray
rm -f /etc/v2ray-agent/v2ray/v2ctl
installV2Ray " $1 "
fi
fi
fi
2020-08-18 13:44:19 +08:00
}
2020-11-25 17:06:40 +08:00
2022-11-08 15:04:46 +08:00
# 安装 hysteria
installHysteria( ) {
readInstallType
echoContent skyBlue " \n进度 $1 / ${ totalProgress } : 安装Hysteria "
if [ [ -z " ${ hysteriaConfigPath } " ] ] ; then
version = $( curl -s https://api.github.com/repos/HyNetwork/hysteria/releases | jq -r '.[]|select (.prerelease==false)|.tag_name' | head -1)
echoContent green " ---> Hysteria版本: ${ version } "
if wget --help | grep -q show-progress; then
wget -c -q --show-progress -P /etc/v2ray-agent/hysteria/ " https://github.com/HyNetwork/hysteria/releases/download/ ${ version } / ${ hysteriaCoreCPUVendor } "
else
wget -c -P /etc/v2ray-agent/hysteria/ " https://github.com/HyNetwork/hysteria/releases/download/ ${ version } / ${ hysteriaCoreCPUVendor } " >/dev/null 2>& 1
fi
mv " /etc/v2ray-agent/hysteria/ ${ hysteriaCoreCPUVendor } " /etc/v2ray-agent/hysteria/hysteria
chmod 655 /etc/v2ray-agent/hysteria/hysteria
else
echoContent green " ---> Hysteria版本: $( /etc/v2ray-agent/hysteria/hysteria --version | awk '{print $3}' ) "
read -r -p "是否更新、升级?[y/n]:" reInstallHysteriaStatus
if [ [ " ${ reInstallHysteriaStatus } " = = "y" ] ] ; then
rm -f /etc/v2ray-agent/hysteria/hysteria
installHysteria " $1 "
fi
fi
}
2020-11-26 11:51:50 +08:00
# 安装xray
2021-01-14 17:28:13 +08:00
installXray( ) {
readInstallType
echoContent skyBlue " \n进度 $1 / ${ totalProgress } : 安装Xray "
if [ [ " ${ coreInstallType } " != "1" ] ] ; then
2021-06-03 11:54:30 +08:00
2022-02-09 16:56:15 +08:00
version = $( curl -s https://api.github.com/repos/XTLS/Xray-core/releases | jq -r '.[]|select (.prerelease==false)|.tag_name' | head -1)
2021-01-14 17:28:13 +08:00
echoContent green " ---> Xray-core版本: ${ version } "
if wget --help | grep -q show-progress; then
2021-05-26 17:27:52 +08:00
wget -c -q --show-progress -P /etc/v2ray-agent/xray/ " https://github.com/XTLS/Xray-core/releases/download/ ${ version } / ${ xrayCoreCPUVendor } .zip "
2021-01-14 17:28:13 +08:00
else
2021-05-26 17:27:52 +08:00
wget -c -P /etc/v2ray-agent/xray/ " https://github.com/XTLS/Xray-core/releases/download/ ${ version } / ${ xrayCoreCPUVendor } .zip " >/dev/null 2>& 1
2021-01-14 17:28:13 +08:00
fi
2021-09-03 15:19:21 +08:00
unzip -o " /etc/v2ray-agent/xray/ ${ xrayCoreCPUVendor } .zip " -d /etc/v2ray-agent/xray >/dev/null
rm -rf " /etc/v2ray-agent/xray/ ${ xrayCoreCPUVendor } .zip "
2021-01-14 17:28:13 +08:00
chmod 655 /etc/v2ray-agent/xray/xray
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 "
fi
fi
2020-11-26 11:51:50 +08:00
}
2020-11-30 16:34:43 +08:00
# v2ray版本管理
2021-01-14 17:28:13 +08:00
v2rayVersionManageMenu( ) {
echoContent skyBlue " \n进度 $1 / ${ totalProgress } : V2Ray版本管理 "
if [ [ ! -d "/etc/v2ray-agent/v2ray/" ] ] ; then
echoContent red " ---> 没有检测到安装目录,请执行脚本安装内容"
menu
exit 0
fi
echoContent red "\n=============================================================="
2022-02-08 14:43:37 +08:00
echoContent yellow "1.升级v2ray-core"
echoContent yellow "2.回退v2ray-core"
2021-04-19 15:26:18 +08:00
echoContent yellow "3.关闭v2ray-core"
echoContent yellow "4.打开v2ray-core"
echoContent yellow "5.重启v2ray-core"
2021-01-14 17:28:13 +08:00
echoContent red "=============================================================="
2021-09-20 01:51:28 +08:00
read -r -p "请选择:" selectV2RayType
2021-01-14 17:28:13 +08:00
if [ [ " ${ selectV2RayType } " = = "1" ] ] ; then
updateV2Ray
elif [ [ " ${ selectV2RayType } " = = "2" ] ] ; then
2021-02-02 14:19:29 +08:00
echoContent yellow "\n1.只可以回退最近的五个版本"
2021-01-14 17:28:13 +08:00
echoContent yellow "2.不保证回退后一定可以正常使用"
echoContent yellow "3.如果回退的版本不支持当前的config, 则会无法连接, 谨慎操作"
echoContent skyBlue "------------------------Version-------------------------------"
2022-09-20 18:05:40 +08:00
curl -s https://api.github.com/repos/v2fly/v2ray-core/releases | jq -r '.[]|select (.prerelease==false)|.tag_name' | grep -v 'v5' | head -5 | awk '{print ""NR""":"$0}'
2021-06-03 15:29:32 +08:00
2021-01-14 17:28:13 +08:00
echoContent skyBlue "--------------------------------------------------------------"
2022-03-24 17:23:03 +08:00
read -r -p "请输入要回退的版本:" selectV2rayVersionType
2022-09-20 18:05:40 +08:00
version = $( curl -s https://api.github.com/repos/v2fly/v2ray-core/releases | jq -r '.[]|select (.prerelease==false)|.tag_name' | grep -v 'v5' | head -5 | awk '{print ""NR""":"$0}' | grep " ${ selectV2rayVersionType } : " | awk -F "[:]" '{print $2}' )
2021-01-14 17:28:13 +08:00
if [ [ -n " ${ version } " ] ] ; then
2021-09-03 15:19:21 +08:00
updateV2Ray " ${ version } "
2021-01-14 17:28:13 +08:00
else
echoContent red "\n ---> 输入有误,请重新输入"
v2rayVersionManageMenu 1
fi
2022-08-11 23:33:52 +08:00
elif [ [ " ${ selectV2RayType } " = = "3" ] ] ; then
2021-04-19 15:26:18 +08:00
handleV2Ray stop
2022-08-11 23:33:52 +08:00
elif [ [ " ${ selectV2RayType } " = = "4" ] ] ; then
2021-04-19 15:26:18 +08:00
handleV2Ray start
2022-08-11 23:33:52 +08:00
elif [ [ " ${ selectV2RayType } " = = "5" ] ] ; then
2021-04-19 15:26:18 +08:00
reloadCore
2021-01-14 17:28:13 +08:00
fi
2020-10-10 15:58:57 +08:00
}
2020-11-25 17:06:40 +08:00
2020-11-30 16:34:43 +08:00
# xray版本管理
2021-01-14 17:28:13 +08:00
xrayVersionManageMenu( ) {
echoContent skyBlue " \n进度 $1 / ${ totalProgress } : Xray版本管理 "
if [ [ ! -d "/etc/v2ray-agent/xray/" ] ] ; then
echoContent red " ---> 没有检测到安装目录,请执行脚本安装内容"
menu
exit 0
fi
echoContent red "\n=============================================================="
2022-02-08 14:43:37 +08:00
echoContent yellow "1.升级Xray-core"
2022-09-06 17:20:52 +08:00
echoContent yellow "2.升级Xray-core 预览版"
echoContent yellow "3.回退Xray-core"
echoContent yellow "4.关闭Xray-core"
echoContent yellow "5.打开Xray-core"
echoContent yellow "6.重启Xray-core"
2021-01-14 17:28:13 +08:00
echoContent red "=============================================================="
2021-09-20 01:51:28 +08:00
read -r -p "请选择:" selectXrayType
2021-01-14 17:28:13 +08:00
if [ [ " ${ selectXrayType } " = = "1" ] ] ; then
updateXray
elif [ [ " ${ selectXrayType } " = = "2" ] ] ; then
2022-09-06 17:20:52 +08:00
prereleaseStatus = true
updateXray
elif [ [ " ${ selectXrayType } " = = "3" ] ] ; then
2022-02-09 16:56:15 +08:00
echoContent yellow "\n1.只可以回退最近的五个版本"
2021-01-14 17:28:13 +08:00
echoContent yellow "2.不保证回退后一定可以正常使用"
echoContent yellow "3.如果回退的版本不支持当前的config, 则会无法连接, 谨慎操作"
echoContent skyBlue "------------------------Version-------------------------------"
2022-02-09 16:56:15 +08:00
curl -s https://api.github.com/repos/XTLS/Xray-core/releases | jq -r '.[]|select (.prerelease==false)|.tag_name' | head -5 | awk '{print ""NR""":"$0}'
2021-01-14 17:28:13 +08:00
echoContent skyBlue "--------------------------------------------------------------"
2022-03-24 17:23:03 +08:00
read -r -p "请输入要回退的版本:" selectXrayVersionType
2022-02-09 16:56:15 +08:00
version = $( curl -s https://api.github.com/repos/XTLS/Xray-core/releases | jq -r '.[]|select (.prerelease==false)|.tag_name' | head -5 | awk '{print ""NR""":"$0}' | grep " ${ selectXrayVersionType } : " | awk -F "[:]" '{print $2}' )
2021-01-14 17:28:13 +08:00
if [ [ -n " ${ version } " ] ] ; then
updateXray " ${ version } "
else
echoContent red "\n ---> 输入有误,请重新输入"
xrayVersionManageMenu 1
fi
2021-04-19 15:26:18 +08:00
elif [ [ " ${ selectXrayType } " = = "4" ] ] ; then
2022-09-06 17:20:52 +08:00
handleXray stop
2021-04-19 15:26:18 +08:00
elif [ [ " ${ selectXrayType } " = = "5" ] ] ; then
2022-09-06 17:20:52 +08:00
handleXray start
elif [ [ " ${ selectXrayType } " = = "6" ] ] ; then
2021-04-19 15:26:18 +08:00
reloadCore
2021-01-14 17:28:13 +08:00
fi
2020-11-30 16:34:43 +08:00
}
2020-10-10 15:58:57 +08:00
# 更新V2Ray
2021-01-14 17:28:13 +08:00
updateV2Ray( ) {
readInstallType
if [ [ -z " ${ coreInstallType } " ] ] ; then
if [ [ -n " $1 " ] ] ; then
version = $1
else
2022-09-20 18:05:40 +08:00
version = $( curl -s https://api.github.com/repos/v2fly/v2ray-core/releases | jq -r '.[]|select (.prerelease==false)|.tag_name' | grep -v 'v5' | head -1)
2021-01-14 17:28:13 +08:00
fi
# 使用锁定的版本
if [ [ -n " ${ v2rayCoreVersion } " ] ] ; then
version = ${ v2rayCoreVersion }
fi
echoContent green " ---> v2ray-core版本: ${ version } "
if wget --help | grep -q show-progress; then
2021-05-26 17:27:52 +08:00
wget -c -q --show-progress -P /etc/v2ray-agent/v2ray/ " https://github.com/v2fly/v2ray-core/releases/download/ ${ version } / ${ v2rayCoreCPUVendor } .zip "
2021-01-14 17:28:13 +08:00
else
2021-05-26 17:27:52 +08:00
wget -c -P " /etc/v2ray-agent/v2ray/ https://github.com/v2fly/v2ray-core/releases/download/ ${ version } / ${ v2rayCoreCPUVendor } .zip " >/dev/null 2>& 1
2021-01-14 17:28:13 +08:00
fi
2021-09-03 15:19:21 +08:00
unzip -o " /etc/v2ray-agent/v2ray/ ${ v2rayCoreCPUVendor } .zip " -d /etc/v2ray-agent/v2ray >/dev/null
rm -rf " /etc/v2ray-agent/v2ray/ ${ v2rayCoreCPUVendor } .zip "
2021-01-14 17:28:13 +08:00
handleV2Ray stop
handleV2Ray start
else
echoContent green " ---> 当前v2ray-core版本: $( /etc/v2ray-agent/v2ray/v2ray --version | awk '{print $2}' | head -1) "
if [ [ -n " $1 " ] ] ; then
version = $1
else
2022-09-20 18:05:40 +08:00
version = $( curl -s https://api.github.com/repos/v2fly/v2ray-core/releases | jq -r '.[]|select (.prerelease==false)|.tag_name' | grep -v 'v5' | head -1)
2021-01-14 17:28:13 +08:00
fi
if [ [ -n " ${ v2rayCoreVersion } " ] ] ; then
version = ${ v2rayCoreVersion }
fi
if [ [ -n " $1 " ] ] ; then
read -r -p " 回退版本为 ${ version } ,是否继续?[y/n]: " rollbackV2RayStatus
if [ [ " ${ rollbackV2RayStatus } " = = "y" ] ] ; then
if [ [ " ${ coreInstallType } " = = "2" || " ${ coreInstallType } " = = "3" ] ] ; then
echoContent green " ---> 当前v2ray-core版本: $( /etc/v2ray-agent/v2ray/v2ray --version | awk '{print $2}' | head -1) "
elif [ [ " ${ coreInstallType } " = = "1" ] ] ; then
echoContent green " ---> 当前Xray-core版本: $( /etc/v2ray-agent/xray/xray --version | awk '{print $2}' | head -1) "
fi
handleV2Ray stop
rm -f /etc/v2ray-agent/v2ray/v2ray
rm -f /etc/v2ray-agent/v2ray/v2ctl
updateV2Ray " ${ version } "
else
echoContent green " ---> 放弃回退版本"
fi
elif [ [ " ${ version } " = = " v $( /etc/v2ray-agent/v2ray/v2ray --version | awk '{print $2}' | head -1) " ] ] ; then
read -r -p "当前版本与最新版相同,是否重新安装?[y/n]:" reInstallV2RayStatus
if [ [ " ${ reInstallV2RayStatus } " = = "y" ] ] ; then
handleV2Ray stop
rm -f /etc/v2ray-agent/v2ray/v2ray
rm -f /etc/v2ray-agent/v2ray/v2ctl
updateV2Ray
else
echoContent green " ---> 放弃重新安装"
fi
else
2022-03-24 17:23:03 +08:00
read -r -p " 最新版本为: ${ version } ,是否更新?[y/n]: " installV2RayStatus
2021-01-14 17:28:13 +08:00
if [ [ " ${ installV2RayStatus } " = = "y" ] ] ; then
rm -f /etc/v2ray-agent/v2ray/v2ray
rm -f /etc/v2ray-agent/v2ray/v2ctl
updateV2Ray
else
echoContent green " ---> 放弃更新"
fi
fi
fi
2020-09-03 15:32:27 +08:00
}
2020-10-10 15:58:57 +08:00
2020-11-30 16:34:43 +08:00
# 更新Xray
2021-01-14 17:28:13 +08:00
updateXray( ) {
readInstallType
if [ [ -z " ${ coreInstallType } " ] ] ; then
if [ [ -n " $1 " ] ] ; then
version = $1
else
2022-09-06 17:20:52 +08:00
version = $( curl -s https://api.github.com/repos/XTLS/Xray-core/releases | jq -r " .[]|select (.prerelease== ${ prereleaseStatus } )|.tag_name " | head -1)
2021-01-14 17:28:13 +08:00
fi
echoContent green " ---> Xray-core版本: ${ version } "
2021-01-15 11:53:32 +08:00
if wget --help | grep -q show-progress; then
2021-05-26 17:27:52 +08:00
wget -c -q --show-progress -P /etc/v2ray-agent/xray/ " https://github.com/XTLS/Xray-core/releases/download/ ${ version } / ${ xrayCoreCPUVendor } .zip "
2021-01-14 17:28:13 +08:00
else
2021-05-26 17:27:52 +08:00
wget -c -P /etc/v2ray-agent/xray/ " https://github.com/XTLS/Xray-core/releases/download/ ${ version } / ${ xrayCoreCPUVendor } .zip " >/dev/null 2>& 1
2021-01-14 17:28:13 +08:00
fi
2021-09-03 15:19:21 +08:00
unzip -o " /etc/v2ray-agent/xray/ ${ xrayCoreCPUVendor } .zip " -d /etc/v2ray-agent/xray >/dev/null
rm -rf " /etc/v2ray-agent/xray/ ${ xrayCoreCPUVendor } .zip "
2021-01-14 17:28:13 +08:00
chmod 655 /etc/v2ray-agent/xray/xray
handleXray stop
handleXray start
else
echoContent green " ---> 当前Xray-core版本: $( /etc/v2ray-agent/xray/xray --version | awk '{print $2}' | head -1) "
if [ [ -n " $1 " ] ] ; then
version = $1
else
2022-09-06 17:20:52 +08:00
version = $( curl -s https://api.github.com/repos/XTLS/Xray-core/releases | jq -r " .[]|select (.prerelease== ${ prereleaseStatus } )|.tag_name " | head -1)
2021-01-14 17:28:13 +08:00
fi
if [ [ -n " $1 " ] ] ; then
read -r -p " 回退版本为 ${ version } ,是否继续?[y/n]: " rollbackXrayStatus
if [ [ " ${ rollbackXrayStatus } " = = "y" ] ] ; then
echoContent green " ---> 当前Xray-core版本: $( /etc/v2ray-agent/xray/xray --version | awk '{print $2}' | head -1) "
handleXray stop
rm -f /etc/v2ray-agent/xray/xray
updateXray " ${ version } "
else
echoContent green " ---> 放弃回退版本"
fi
elif [ [ " ${ version } " = = " v $( /etc/v2ray-agent/xray/xray --version | awk '{print $2}' | head -1) " ] ] ; then
read -r -p "当前版本与最新版相同,是否重新安装?[y/n]:" reInstallXrayStatus
if [ [ " ${ reInstallXrayStatus } " = = "y" ] ] ; then
handleXray stop
rm -f /etc/v2ray-agent/xray/xray
rm -f /etc/v2ray-agent/xray/xray
updateXray
else
echoContent green " ---> 放弃重新安装"
fi
else
2022-03-24 17:23:03 +08:00
read -r -p " 最新版本为: ${ version } ,是否更新?[y/n]: " installXrayStatus
2021-01-14 17:28:13 +08:00
if [ [ " ${ installXrayStatus } " = = "y" ] ] ; then
rm -f /etc/v2ray-agent/xray/xray
updateXray
else
echoContent green " ---> 放弃更新"
fi
fi
fi
2020-11-30 16:34:43 +08:00
}
2020-10-15 15:09:20 +08:00
2020-08-18 13:44:19 +08:00
# 验证整个服务是否可用
2021-01-14 17:28:13 +08:00
checkGFWStatue( ) {
2021-01-15 16:43:39 +08:00
readInstallType
2021-01-14 17:28:13 +08:00
echoContent skyBlue " \n进度 $1 / ${ totalProgress } : 验证服务启动状态 "
2021-01-15 16:43:39 +08:00
if [ [ " ${ coreInstallType } " = = "1" ] ] && [ [ -n $( pgrep -f xray/xray) ] ] ; then
echoContent green " ---> 服务启动成功"
elif [ [ " ${ coreInstallType } " = = "2" || " ${ coreInstallType } " = = "3" ] ] && [ [ -n $( pgrep -f v2ray/v2ray) ] ] ; then
2021-01-14 17:28:13 +08:00
echoContent green " ---> 服务启动成功"
else
echoContent red " ---> 服务启动失败,请检查终端是否有日志打印"
exit 0
fi
2021-01-15 16:43:39 +08:00
2020-05-23 23:21:43 +08:00
}
2020-11-25 17:06:40 +08:00
2020-09-21 15:21:16 +08:00
# V2Ray开机自启
2021-01-14 17:28:13 +08:00
installV2RayService( ) {
echoContent skyBlue " \n进度 $1 / ${ totalProgress } : 配置V2Ray开机自启 "
if [ [ -n $( find /bin /usr/bin -name "systemctl" ) ] ] ; then
rm -rf /etc/systemd/system/v2ray.service
touch /etc/systemd/system/v2ray.service
execStart = '/etc/v2ray-agent/v2ray/v2ray -confdir /etc/v2ray-agent/v2ray/conf'
cat <<EOF >/etc/systemd/system/v2ray.service
2020-10-17 14:41:02 +08:00
[ Unit]
Description = V2Ray - A unified platform for anti-censorship
Documentation = https://v2ray.com https://guide.v2fly.org
After = network.target nss-lookup.target
Wants = network-online.target
[ Service]
Type = simple
User = root
CapabilityBoundingSet = CAP_NET_BIND_SERVICE CAP_NET_RAW
NoNewPrivileges = yes
ExecStart = ${ execStart }
Restart = on-failure
RestartPreventExitStatus = 23
2022-06-20 17:22:45 +08:00
LimitNPROC = 10000
LimitNOFILE = 1000000
2020-10-17 14:41:02 +08:00
[ Install]
WantedBy = multi-user.target
2020-08-04 16:56:55 +08:00
EOF
2021-01-14 17:28:13 +08:00
systemctl daemon-reload
systemctl enable v2ray.service
echoContent green " ---> 配置V2Ray开机自启成功"
fi
2020-08-18 13:44:19 +08:00
}
2020-11-26 11:51:50 +08:00
2022-11-08 15:04:46 +08:00
# 安装hysteria开机自启
installHysteriaService( ) {
echoContent skyBlue " \n进度 $1 / ${ totalProgress } : 配置Hysteria开机自启 "
if [ [ -n $( find /bin /usr/bin -name "systemctl" ) ] ] ; then
rm -rf /etc/systemd/system/hysteria.service
touch /etc/systemd/system/hysteria.service
execStart = '/etc/v2ray-agent/hysteria/hysteria --log-level info -c /etc/v2ray-agent/hysteria/conf/config.json server'
cat <<EOF >/etc/systemd/system/hysteria.service
[ Unit]
Description = Hysteria Service
Documentation = https://github.com/HyNetwork/hysteria/wiki
After = network.target nss-lookup.target
Wants = network-online.target
[ Service]
Type = simple
User = root
CapabilityBoundingSet = CAP_NET_BIND_SERVICE CAP_NET_RAW
NoNewPrivileges = yes
ExecStart = ${ execStart }
Restart = on-failure
RestartPreventExitStatus = 23
LimitNPROC = 10000
LimitNOFILE = 1000000
[ Install]
WantedBy = multi-user.target
EOF
systemctl daemon-reload
systemctl enable hysteria.service
echoContent green " ---> 配置Hysteria开机自启成功"
fi
}
2020-11-26 11:51:50 +08:00
# Xray开机自启
2021-01-14 17:28:13 +08:00
installXrayService( ) {
echoContent skyBlue " \n进度 $1 / ${ totalProgress } : 配置Xray开机自启 "
if [ [ -n $( find /bin /usr/bin -name "systemctl" ) ] ] ; then
rm -rf /etc/systemd/system/xray.service
touch /etc/systemd/system/xray.service
execStart = '/etc/v2ray-agent/xray/xray run -confdir /etc/v2ray-agent/xray/conf'
cat <<EOF >/etc/systemd/system/xray.service
2020-11-26 11:51:50 +08:00
[ Unit]
2022-06-20 17:22:45 +08:00
Description = Xray Service
Documentation = https://github.com/XTLS/Xray-core
2020-11-26 11:51:50 +08:00
After = network.target nss-lookup.target
Wants = network-online.target
[ Service]
Type = simple
User = root
CapabilityBoundingSet = CAP_NET_BIND_SERVICE CAP_NET_RAW
NoNewPrivileges = yes
ExecStart = ${ execStart }
Restart = on-failure
RestartPreventExitStatus = 23
2022-06-20 17:22:45 +08:00
LimitNPROC = 10000
LimitNOFILE = 1000000
2020-11-26 11:51:50 +08:00
[ Install]
WantedBy = multi-user.target
EOF
2021-01-14 17:28:13 +08:00
systemctl daemon-reload
systemctl enable xray.service
echoContent green " ---> 配置Xray开机自启成功"
fi
2020-11-26 11:51:50 +08:00
}
2020-09-25 18:01:23 +08:00
2020-08-18 13:44:19 +08:00
# 操作V2Ray
2021-01-14 17:28:13 +08:00
handleV2Ray( ) {
# shellcheck disable=SC2010
2021-01-14 17:43:24 +08:00
if find /bin /usr/bin | grep -q systemctl && ls /etc/systemd/system/ | grep -q v2ray.service; then
2021-01-15 11:00:49 +08:00
if [ [ -z $( pgrep -f "v2ray/v2ray" ) ] ] && [ [ " $1 " = = "start" ] ] ; then
2021-01-14 17:28:13 +08:00
systemctl start v2ray.service
2021-01-15 11:00:49 +08:00
elif [ [ -n $( pgrep -f "v2ray/v2ray" ) ] ] && [ [ " $1 " = = "stop" ] ] ; then
2021-01-14 17:28:13 +08:00
systemctl stop v2ray.service
fi
fi
2021-03-23 11:45:05 +08:00
sleep 0.8
2021-01-14 17:28:13 +08:00
if [ [ " $1 " = = "start" ] ] ; then
2021-01-15 11:00:49 +08:00
if [ [ -n $( pgrep -f "v2ray/v2ray" ) ] ] ; then
2021-01-14 17:28:13 +08:00
echoContent green " ---> V2Ray启动成功"
else
echoContent red "V2Ray启动失败"
2021-06-22 20:46:59 +08:00
echoContent red "请手动执行【/etc/v2ray-agent/v2ray/v2ray -confdir /etc/v2ray-agent/v2ray/conf】, 查看错误日志"
2021-01-14 17:28:13 +08:00
exit 0
fi
elif [ [ " $1 " = = "stop" ] ] ; then
2021-01-15 11:00:49 +08:00
if [ [ -z $( pgrep -f "v2ray/v2ray" ) ] ] ; then
2021-01-14 17:28:13 +08:00
echoContent green " ---> V2Ray关闭成功"
else
echoContent red "V2Ray关闭失败"
echoContent red "请手动执行【ps -ef|grep -v grep|grep v2ray|awk '{print \$2}'|xargs kill -9】"
exit 0
fi
fi
2020-05-23 23:21:43 +08:00
}
2022-11-08 15:04:46 +08:00
# 操作Hysteria
handleHysteria( ) {
# shellcheck disable=SC2010
if find /bin /usr/bin | grep -q systemctl && ls /etc/systemd/system/ | grep -q hysteria.service; then
if [ [ -z $( pgrep -f "hysteria/hysteria" ) ] ] && [ [ " $1 " = = "start" ] ] ; then
systemctl start hysteria.service
elif [ [ -n $( pgrep -f "hysteria/hysteria" ) ] ] && [ [ " $1 " = = "stop" ] ] ; then
systemctl stop hysteria.service
fi
fi
sleep 0.8
if [ [ " $1 " = = "start" ] ] ; then
if [ [ -n $( pgrep -f "hysteria/hysteria" ) ] ] ; then
echoContent green " ---> Hysteria启动成功"
else
echoContent red "Hysteria启动失败"
echoContent red "请手动执行【/etc/v2ray-agent/hysteria/hysteria --log-level debug -c /etc/v2ray-agent/hysteria/conf/config.json server】, 查看错误日志"
exit 0
fi
elif [ [ " $1 " = = "stop" ] ] ; then
if [ [ -z $( pgrep -f "hysteria/hysteria" ) ] ] ; then
echoContent green " ---> Hysteria关闭成功"
else
echoContent red "Hysteria关闭失败"
echoContent red "请手动执行【ps -ef|grep -v grep|grep hysteria|awk '{print \$2}'|xargs kill -9】"
exit 0
fi
fi
}
2020-11-26 11:51:50 +08:00
# 操作xray
2021-01-14 17:28:13 +08:00
handleXray( ) {
2021-09-03 15:19:21 +08:00
if [ [ -n $( find /bin /usr/bin -name "systemctl" ) ] ] && [ [ -n $( find /etc/systemd/system/ -name "xray.service" ) ] ] ; then
2021-01-15 11:00:49 +08:00
if [ [ -z $( pgrep -f "xray/xray" ) ] ] && [ [ " $1 " = = "start" ] ] ; then
2021-01-14 17:28:13 +08:00
systemctl start xray.service
2021-01-15 11:00:49 +08:00
elif [ [ -n $( pgrep -f "xray/xray" ) ] ] && [ [ " $1 " = = "stop" ] ] ; then
2021-01-14 17:28:13 +08:00
systemctl stop xray.service
fi
fi
2021-03-23 11:45:05 +08:00
sleep 0.8
2021-01-14 17:28:13 +08:00
if [ [ " $1 " = = "start" ] ] ; then
2021-01-15 11:00:49 +08:00
if [ [ -n $( pgrep -f "xray/xray" ) ] ] ; then
2021-01-14 17:28:13 +08:00
echoContent green " ---> Xray启动成功"
else
2022-03-30 15:53:39 +08:00
echoContent red "Xray启动失败"
2021-06-22 20:46:59 +08:00
echoContent red "请手动执行【/etc/v2ray-agent/xray/xray -confdir /etc/v2ray-agent/xray/conf】, 查看错误日志"
2021-01-14 17:28:13 +08:00
exit 0
fi
elif [ [ " $1 " = = "stop" ] ] ; then
2021-01-15 11:00:49 +08:00
if [ [ -z $( pgrep -f "xray/xray" ) ] ] ; then
2021-01-14 17:28:13 +08:00
echoContent green " ---> Xray关闭成功"
else
echoContent red "xray关闭失败"
echoContent red "请手动执行【ps -ef|grep -v grep|grep xray|awk '{print \$2}'|xargs kill -9】"
exit 0
fi
fi
2020-11-26 11:51:50 +08:00
}
2022-03-16 17:47:52 +08:00
# 获取clients配置
getClients( ) {
local path = $1
2022-03-18 11:51:00 +08:00
2022-03-16 17:47:52 +08:00
local addClientsStatus = $2
previousClients =
if [ [ ${ addClientsStatus } = = "true" ] ] ; then
if [ [ ! -f " ${ path } " ] ] ; then
echo
2022-03-28 16:55:06 +08:00
local protocol
protocol = $( echo " ${ path } " | awk -F "[_]" '{print $2 $3}' )
2022-03-18 11:51:00 +08:00
echoContent yellow " 没有读取到此协议[ ${ protocol } ]上一次安装的配置文件, 采用配置文件的第一个uuid "
2022-03-16 17:47:52 +08:00
else
previousClients = $( jq -r ".inbounds[0].settings.clients" " ${ path } " )
fi
fi
}
# 添加client配置
addClients( ) {
local path = $1
local addClientsStatus = $2
if [ [ ${ addClientsStatus } = = "true" && -n " ${ previousClients } " ] ] ; then
config = $( jq -r " .inbounds[0].settings.clients = ${ previousClients } " " ${ path } " )
echo " ${ config } " | jq . >" ${ path } "
fi
}
2022-11-08 15:04:46 +08:00
# 添加hysteria配置
addClientsHysteria( ) {
local path = $1
local addClientsStatus = $2
if [ [ ${ addClientsStatus } = = "true" && -n " ${ previousClients } " ] ] ; then
local uuids =
uuids = $( echo " ${ previousClients } " | jq -r [ .[ ] .id] )
config = $( jq -r " .auth.config = ${ uuids } " " ${ path } " )
echo " ${ config } " | jq . >" ${ path } "
fi
}
# 初始化hysteria端口
initHysteriaPort( ) {
2022-11-08 17:49:30 +08:00
readHysteriaConfig
if [ [ -n " ${ hysteriaPort } " ] ] ; then
read -r -p "读取到上次安装时的端口,是否使用上次安装时的端口 ? [y/n]:" historyHysteriaPortStatus
if [ [ " ${ historyHysteriaPortStatus } " = = "y" ] ] ; then
echoContent yellow " \n ---> 端口: ${ hysteriaPort } "
else
hysteriaPort =
fi
fi
if [ [ -z " ${ hysteriaPort } " ] ] ; then
echoContent yellow "请输入Hysteria端口[例: 10000],不可与其他服务重复"
read -r -p "端口:" hysteriaPort
fi
2022-11-08 15:04:46 +08:00
if [ [ -z ${ hysteriaPort } ] ] ; then
2022-11-09 14:10:28 +08:00
echoContent red " ---> 端口不可为空"
2022-11-08 15:04:46 +08:00
initHysteriaPort " $2 "
2022-11-09 14:10:28 +08:00
elif ( ( hysteriaPort < 1 || hysteriaPort > 65535) ) ; then
echoContent red " ---> 端口不合法"
2022-11-08 15:04:46 +08:00
initHysteriaPort " $2 "
fi
allowPort " ${ hysteriaPort } "
}
# 初始化hysteria的协议
initHysteriaProtocol( ) {
echoContent skyBlue "\n请选择协议类型"
echoContent red "=============================================================="
echoContent yellow "1.udp(QUIC)(默认)"
echoContent yellow "2.faketcp"
echoContent yellow "3.wechat-video"
echoContent red "=============================================================="
read -r -p "请选择:" selectHysteriaProtocol
case ${ selectHysteriaProtocol } in
1)
hysteriaProtocol = "udp"
; ;
2)
hysteriaProtocol = "faketcp"
; ;
3)
hysteriaProtocol = "wechat-video"
; ;
*)
hysteriaProtocol = "udp"
; ;
esac
2022-11-08 17:49:30 +08:00
echoContent yellow " \n ---> 协议: ${ hysteriaProtocol } \n "
2022-11-08 15:04:46 +08:00
}
# 初始化hysteria网络信息
initHysteriaNetwork( ) {
echoContent yellow "请输入本地到服务器的平均延迟, 请按照真实情况填写( 默认: 180, 单位: ms) "
read -r -p "延迟:" hysteriaLag
if [ [ -z " ${ hysteriaLag } " ] ] ; then
hysteriaLag = 180
2022-11-08 17:49:30 +08:00
echoContent yellow " \n ---> 延迟: ${ hysteriaLag } \n "
2022-11-08 15:04:46 +08:00
fi
echoContent yellow "请输入本地带宽峰值的下行速度( 默认: 100, 单位: Mbps) "
2022-11-08 17:49:30 +08:00
read -r -p "下行速度:" hysteriaClientDownloadSpeed
2022-11-08 15:04:46 +08:00
if [ [ -z " ${ hysteriaClientDownloadSpeed } " ] ] ; then
hysteriaClientDownloadSpeed = 100
2022-11-08 17:49:30 +08:00
echoContent yellow " \n ---> 下行速度: ${ hysteriaClientDownloadSpeed } \n "
2022-11-08 15:04:46 +08:00
fi
2021-01-14 17:28:13 +08:00
2022-11-08 15:04:46 +08:00
echoContent yellow "请输入本地带宽峰值的上行速度( 默认: 50, 单位: Mbps) "
2022-11-08 17:49:30 +08:00
read -r -p "上行速度:" hysteriaClientUploadSpeed
2022-11-08 15:04:46 +08:00
if [ [ -z " ${ hysteriaClientUploadSpeed } " ] ] ; then
hysteriaClientUploadSpeed = 50
2022-11-08 17:49:30 +08:00
echoContent yellow " \n ---> 上行速度: ${ hysteriaClientUploadSpeed } \n "
2022-11-08 15:04:46 +08:00
fi
cat <<EOF >/etc/v2ray-agent/hysteria/conf/client_network.json
{
"hysteriaLag" :" ${ hysteriaLag } " ,
"hysteriaClientUploadSpeed" :" ${ hysteriaClientUploadSpeed } " ,
"hysteriaClientDownloadSpeed" :" ${ hysteriaClientDownloadSpeed } "
}
EOF
}
2022-04-24 16:36:27 +08:00
# 初始化Hysteria配置
initHysteriaConfig( ) {
2022-11-08 15:04:46 +08:00
echoContent skyBlue " \n进度 $1 / ${ totalProgress } : 初始化Hysteria配置 "
initHysteriaPort
initHysteriaProtocol
initHysteriaNetwork
getClients " ${ configPath } /02_VLESS_TCP_inbounds.json " true
cat <<EOF >/etc/v2ray-agent/hysteria/conf/config.json
{
"listen" : " : ${ hysteriaPort } " ,
2022-11-08 17:49:30 +08:00
"protocol" : " ${ hysteriaProtocol } " ,
2022-11-08 15:04:46 +08:00
"disable_udp" : false,
"cert" : " /etc/v2ray-agent/tls/ ${ currentHost } .crt " ,
"key" : " /etc/v2ray-agent/tls/ ${ currentHost } .key " ,
"auth" : {
"mode" : "passwords" ,
"config" : [ ]
} ,
"up_mbps" :${ hysteriaClientUploadSpeed } ,
"down_mbps" :${ hysteriaClientDownloadSpeed } ,
"alpn" : "h3" ,
"recv_window_conn" : 15728640,
"recv_window_client" : 67108864,
"max_conn_client" : 4096,
"disable_mtu_discovery" : true,
"resolve_preference" : "46" ,
"resolver" : "https://8.8.8.8:443/dns-query"
}
EOF
addClientsHysteria "/etc/v2ray-agent/hysteria/conf/config.json" true
2022-04-24 16:36:27 +08:00
}
2020-05-23 23:21:43 +08:00
# 初始化V2Ray 配置文件
2021-01-14 17:28:13 +08:00
initV2RayConfig( ) {
echoContent skyBlue " \n进度 $2 / ${ totalProgress } : 初始化V2Ray配置 "
2021-03-23 11:45:05 +08:00
echo
2021-07-03 16:40:14 +08:00
2021-03-23 11:45:05 +08:00
read -r -p "是否自定义UUID ? [y/n]:" customUUIDStatus
echo
if [ [ " ${ customUUIDStatus } " = = "y" ] ] ; then
read -r -p "请输入合法的UUID:" currentCustomUUID
if [ [ -n " ${ currentCustomUUID } " ] ] ; then
uuid = ${ currentCustomUUID }
fi
fi
2022-03-16 17:47:52 +08:00
local addClientsStatus =
2021-03-23 11:45:05 +08:00
if [ [ -n " ${ currentUUID } " && -z " ${ uuid } " ] ] ; then
2021-01-14 17:28:13 +08:00
read -r -p "读取到上次安装记录, 是否使用上次安装时的UUID ? [y/n]:" historyUUIDStatus
if [ [ " ${ historyUUIDStatus } " = = "y" ] ] ; then
uuid = ${ currentUUID }
2022-03-16 17:47:52 +08:00
addClientsStatus = true
2021-01-19 11:47:16 +08:00
else
uuid = $( /etc/v2ray-agent/v2ray/v2ctl uuid)
2021-01-14 17:28:13 +08:00
fi
2021-03-23 11:45:05 +08:00
elif [ [ -z " ${ uuid } " ] ] ; then
2021-01-14 17:28:13 +08:00
uuid = $( /etc/v2ray-agent/v2ray/v2ctl uuid)
fi
2021-01-19 11:47:16 +08:00
2021-01-14 17:28:13 +08:00
if [ [ -z " ${ uuid } " ] ] ; then
2022-03-16 17:47:52 +08:00
addClientsStatus =
2021-01-14 17:28:13 +08:00
echoContent red "\n ---> uuid读取错误, 重新生成"
uuid = $( /etc/v2ray-agent/v2ray/v2ctl uuid)
fi
2022-03-16 17:47:52 +08:00
movePreviousConfig
2021-12-24 16:29:54 +08:00
# log
2021-01-14 17:28:13 +08:00
cat <<EOF >/etc/v2ray-agent/v2ray/conf/00_log.json
2020-11-20 17:57:50 +08:00
{
"log" : {
2021-04-08 17:53:19 +08:00
"error" : "/etc/v2ray-agent/v2ray/error.log" ,
2020-12-07 10:01:04 +08:00
"loglevel" : "warning"
2020-11-20 17:57:50 +08:00
}
}
2020-10-13 17:14:06 +08:00
EOF
2021-01-14 17:28:13 +08:00
# outbounds
if [ [ -n " ${ pingIPv6 } " ] ] ; then
cat <<EOF >/etc/v2ray-agent/v2ray/conf/10_ipv6_outbounds.json
2020-12-31 12:21:46 +08:00
{
"outbounds" : [
{
"protocol" : "freedom" ,
"settings" : { } ,
"tag" : "direct"
}
]
}
EOF
2021-12-24 16:29:54 +08:00
else
2021-01-14 17:28:13 +08:00
cat <<EOF >/etc/v2ray-agent/v2ray/conf/10_ipv4_outbounds.json
2020-10-13 17:14:06 +08:00
{
2021-06-15 16:27:56 +08:00
"outbounds" :[
2020-10-13 17:14:06 +08:00
{
2021-06-15 16:27:56 +08:00
"protocol" :"freedom" ,
"settings" :{
"domainStrategy" :"UseIPv4"
} ,
"tag" :"IPv4-out"
} ,
{
"protocol" :"freedom" ,
"settings" :{
"domainStrategy" :"UseIPv6"
} ,
"tag" :"IPv6-out"
} ,
{
"protocol" :"blackhole" ,
"tag" :"blackhole-out"
2020-12-18 17:40:05 +08:00
}
]
}
EOF
2021-01-14 17:28:13 +08:00
fi
2021-07-16 17:09:55 +08:00
2021-01-14 17:28:13 +08:00
# dns
cat <<EOF >/etc/v2ray-agent/v2ray/conf/11_dns.json
2020-10-13 17:14:06 +08:00
{
"dns" : {
"servers" : [
"localhost"
]
}
}
EOF
2021-12-24 16:29:54 +08:00
# VLESS_TCP_TLS
2021-01-14 17:28:13 +08:00
# 回落nginx
2021-06-17 15:23:34 +08:00
local fallbacksList = '{"dest":31300,"xver":0},{"alpn":"h2","dest":31302,"xver":0}'
2021-01-14 17:28:13 +08:00
2021-12-24 16:29:54 +08:00
# trojan
2021-09-03 15:19:21 +08:00
if echo " ${ selectCustomInstallType } " | grep -q 4 || [ [ " $1 " = = "all" ] ] ; then
2022-03-16 17:47:52 +08:00
2021-06-25 15:57:37 +08:00
fallbacksList = '{"dest":31296,"xver":1},{"alpn":"h2","dest":31302,"xver":0}'
2022-03-16 17:47:52 +08:00
getClients " ${ configPath } ../tmp/04_trojan_TCP_inbounds.json " " ${ addClientsStatus } "
2021-09-03 15:19:21 +08:00
cat <<EOF >/etc/v2ray-agent/v2ray/conf/04_trojan_TCP_inbounds.json
2021-06-25 15:57:37 +08:00
{
"inbounds" :[
{
"port" : 31296,
"listen" : "127.0.0.1" ,
"protocol" : "trojan" ,
"tag" :"trojanTCP" ,
"settings" : {
"clients" : [
{
"password" : " ${ uuid } " ,
2022-11-08 15:04:46 +08:00
"email" : " ${ domain } _ ${ uuid } "
2021-06-25 15:57:37 +08:00
}
] ,
"fallbacks" :[
{ "dest" :"31300" }
]
} ,
"streamSettings" : {
"network" : "tcp" ,
"security" : "none" ,
"tcpSettings" : {
"acceptProxyProtocol" : true
}
}
}
]
}
EOF
2022-03-16 17:47:52 +08:00
addClients "/etc/v2ray-agent/v2ray/conf/04_trojan_TCP_inbounds.json" " ${ addClientsStatus } "
2021-01-14 17:28:13 +08:00
fi
# VLESS_WS_TLS
if echo " ${ selectCustomInstallType } " | grep -q 1 || [ [ " $1 " = = "all" ] ] ; then
fallbacksList = ${ fallbacksList } ',{"path":"/' ${ customPath } 'ws","dest":31297,"xver":1}'
2022-03-16 17:47:52 +08:00
getClients " ${ configPath } ../tmp/03_VLESS_WS_inbounds.json " " ${ addClientsStatus } "
2021-01-14 17:28:13 +08:00
cat <<EOF >/etc/v2ray-agent/v2ray/conf/03_VLE SS_WS_inbounds.json
2020-10-13 17:14:06 +08:00
{
"inbounds" :[
2020-12-18 10:52:52 +08:00
{
2022-03-30 15:53:39 +08:00
"port" : 31297,
"listen" : "127.0.0.1" ,
"protocol" : "vless" ,
"tag" :"VLESSWS" ,
"settings" : {
"clients" : [
{
"id" : " ${ uuid } " ,
2022-11-08 15:04:46 +08:00
"email" : " ${ domain } _ ${ uuid } "
2022-03-30 15:53:39 +08:00
}
] ,
"decryption" : "none"
} ,
"streamSettings" : {
"network" : "ws" ,
"security" : "none" ,
"wsSettings" : {
"acceptProxyProtocol" : true,
"path" : " / ${ customPath } ws "
}
}
}
2020-12-18 10:52:52 +08:00
]
2020-10-13 17:14:06 +08:00
}
EOF
2022-03-16 17:47:52 +08:00
addClients "/etc/v2ray-agent/v2ray/conf/03_VLESS_WS_inbounds.json" " ${ addClientsStatus } "
2021-01-14 17:28:13 +08:00
fi
2020-12-18 10:52:52 +08:00
2021-12-24 16:29:54 +08:00
# trojan_grpc
if echo " ${ selectCustomInstallType } " | grep -q 2 || [ [ " $1 " = = "all" ] ] ; then
if ! echo " ${ selectCustomInstallType } " | grep -q 5 && [ [ -n ${ selectCustomInstallType } ] ] ; then
fallbacksList = ${ fallbacksList //31302/31304 }
fi
2022-03-16 17:47:52 +08:00
getClients " ${ configPath } ../tmp/04_trojan_gRPC_inbounds.json " " ${ addClientsStatus } "
2021-12-24 16:29:54 +08:00
cat <<EOF >/etc/v2ray-agent/v2ray/conf/04_trojan_gRPC_inbounds.json
{
"inbounds" : [
{
"port" : 31304,
"listen" : "127.0.0.1" ,
"protocol" : "trojan" ,
"tag" : "trojangRPCTCP" ,
"settings" : {
"clients" : [
{
"password" : " ${ uuid } " ,
2022-11-08 15:04:46 +08:00
"email" : " ${ domain } _ ${ uuid } "
2021-12-24 16:29:54 +08:00
}
] ,
"fallbacks" : [
{
"dest" : "31300"
}
]
} ,
"streamSettings" : {
"network" : "grpc" ,
"grpcSettings" : {
"serviceName" : " ${ customPath } trojangrpc "
}
}
}
]
}
EOF
2022-03-16 17:47:52 +08:00
addClients "/etc/v2ray-agent/v2ray/conf/04_trojan_gRPC_inbounds.json" " ${ addClientsStatus } "
2021-12-24 16:29:54 +08:00
fi
2021-01-14 17:28:13 +08:00
# VMess_WS
if echo " ${ selectCustomInstallType } " | grep -q 3 || [ [ " $1 " = = "all" ] ] ; then
fallbacksList = ${ fallbacksList } ',{"path":"/' ${ customPath } 'vws","dest":31299,"xver":1}'
2022-03-16 17:47:52 +08:00
getClients " ${ configPath } ../tmp/05_VMess_WS_inbounds.json " " ${ addClientsStatus } "
2021-01-14 17:28:13 +08:00
cat <<EOF >/etc/v2ray-agent/v2ray/conf/05_VMess_WS_inbounds.json
2020-10-13 17:14:06 +08:00
{
"inbounds" :[
{
2021-08-13 15:41:07 +08:00
"listen" : "127.0.0.1" ,
2020-12-18 10:52:52 +08:00
"port" : 31299,
"protocol" : "vmess" ,
"tag" :"VMessWS" ,
"settings" : {
"clients" : [
{
"id" : " ${ uuid } " ,
2021-06-24 15:51:42 +08:00
"alterId" : 0,
2020-12-18 10:52:52 +08:00
"add" : " ${ add } " ,
2022-11-08 15:04:46 +08:00
"email" : " ${ domain } _ ${ uuid } "
2020-10-13 17:14:06 +08:00
}
2020-12-18 10:52:52 +08:00
]
} ,
"streamSettings" : {
"network" : "ws" ,
"security" : "none" ,
"wsSettings" : {
"acceptProxyProtocol" : true,
2021-01-02 13:51:53 +08:00
"path" : " / ${ customPath } vws "
2020-10-13 17:14:06 +08:00
}
2020-12-18 10:52:52 +08:00
}
}
2020-10-13 17:14:06 +08:00
]
}
2021-04-28 16:26:40 +08:00
EOF
2022-03-16 17:47:52 +08:00
addClients "/etc/v2ray-agent/v2ray/conf/05_VMess_WS_inbounds.json" " ${ addClientsStatus } "
2021-04-28 16:26:40 +08:00
fi
2021-12-24 16:29:54 +08:00
2021-04-28 16:26:40 +08:00
if echo " ${ selectCustomInstallType } " | grep -q 5 || [ [ " $1 " = = "all" ] ] ; then
2022-03-16 17:47:52 +08:00
getClients " ${ configPath } ../tmp/06_VLESS_gRPC_inbounds.json " " ${ addClientsStatus } "
2021-06-10 14:24:36 +08:00
cat <<EOF >/etc/v2ray-agent/v2ray/conf/06_VLE SS_gRPC_inbounds.json
2021-04-28 16:26:40 +08:00
{
"inbounds" :[
{
"port" : 31301,
"listen" : "127.0.0.1" ,
"protocol" : "vless" ,
"tag" :"VLESSGRPC" ,
"settings" : {
"clients" : [
{
"id" : " ${ uuid } " ,
"add" : " ${ add } " ,
2022-11-08 15:04:46 +08:00
"email" : " ${ domain } _ ${ uuid } "
2021-04-28 16:26:40 +08:00
}
] ,
"decryption" : "none"
} ,
"streamSettings" : {
"network" : "grpc" ,
"grpcSettings" : {
"serviceName" : " ${ customPath } grpc "
}
}
}
]
}
2020-10-13 17:14:06 +08:00
EOF
2022-03-16 17:47:52 +08:00
addClients "/etc/v2ray-agent/v2ray/conf/06_VLESS_gRPC_inbounds.json" " ${ addClientsStatus } "
2021-01-14 17:28:13 +08:00
fi
2020-12-18 10:52:52 +08:00
2021-01-14 17:28:13 +08:00
# VLESS_TCP
2022-03-16 17:47:52 +08:00
getClients " ${ configPath } ../tmp/02_VLESS_TCP_inbounds.json " " ${ addClientsStatus } "
2022-10-11 16:02:05 +08:00
local defaultPort = 443
if [ [ -n " ${ customPort } " ] ] ; then
defaultPort = ${ customPort }
fi
2021-12-24 16:29:54 +08:00
cat <<EOF >/etc/v2ray-agent/v2ray/conf/02_VLE SS_TCP_inbounds.json
2020-10-13 17:14:06 +08:00
{
2020-12-18 10:52:52 +08:00
"inbounds" :[
{
2022-10-11 16:02:05 +08:00
"port" : ${ defaultPort } ,
2020-12-18 10:52:52 +08:00
"protocol" : "vless" ,
"tag" :"VLESSTCP" ,
"settings" : {
"clients" : [
{
"id" : " ${ uuid } " ,
"add" :" ${ add } " ,
2021-12-24 16:29:54 +08:00
"email" : " ${ domain } _VLESS_TLS-direct_TCP "
2020-10-13 17:14:06 +08:00
}
2020-12-18 10:52:52 +08:00
] ,
"decryption" : "none" ,
"fallbacks" : [
${ fallbacksList }
]
} ,
"streamSettings" : {
"network" : "tcp" ,
2021-12-24 16:29:54 +08:00
"security" : "tls" ,
"tlsSettings" : {
2022-04-21 11:54:49 +08:00
"minVersion" : "1.2" ,
2020-12-18 10:52:52 +08:00
"alpn" : [
2021-12-24 16:29:54 +08:00
"http/1.1" ,
"h2"
2020-12-18 10:52:52 +08:00
] ,
"certificates" : [
{
"certificateFile" : " /etc/v2ray-agent/tls/ ${ domain } .crt " ,
2021-12-24 16:29:54 +08:00
"keyFile" : " /etc/v2ray-agent/tls/ ${ domain } .key " ,
"ocspStapling" : 3600,
"usage" :"encipherment"
2020-12-18 10:52:52 +08:00
}
]
2020-10-13 17:14:06 +08:00
}
2020-12-18 10:52:52 +08:00
}
}
]
2020-10-13 17:14:06 +08:00
}
2020-08-04 17:27:37 +08:00
EOF
2022-03-16 17:47:52 +08:00
addClients "/etc/v2ray-agent/v2ray/conf/02_VLESS_TCP_inbounds.json" " ${ addClientsStatus } "
2021-12-24 16:29:54 +08:00
2019-11-06 10:58:06 +08:00
}
2020-11-25 17:06:40 +08:00
2021-07-01 22:48:51 +08:00
# 初始化Xray Trojan XTLS 配置文件
2021-09-03 15:19:21 +08:00
initXrayFrontingConfig( ) {
2021-07-01 22:48:51 +08:00
if [ [ -z " ${ configPath } " ] ] ; then
echoContent red " ---> 未安装,请使用脚本安装"
menu
exit 0
fi
2021-09-03 15:19:21 +08:00
if [ [ " ${ coreInstallType } " != "1" ] ] ; then
2021-07-01 22:48:51 +08:00
echoContent red " ---> 未安装可用类型"
fi
local xtlsType =
if echo ${ currentInstallProtocolType } | grep -q trojan; then
xtlsType = VLESS
else
xtlsType = Trojan
fi
echoContent skyBlue " \n功能 1/ ${ totalProgress } : 前置切换为 ${ xtlsType } "
echoContent red "\n=============================================================="
echoContent yellow "# 注意事项\n"
echoContent yellow " 会将前置替换为 ${ xtlsType } "
2022-10-13 17:36:38 +08:00
echoContent yellow "如果前置是Trojan, 查看账号时则会出现两个Trojan协议的节点, 有一个不可用xtls"
2021-07-01 22:48:51 +08:00
echoContent yellow "再次执行可切换至上一次的前置\n"
echoContent yellow " 1.切换至 ${ xtlsType } "
echoContent red "=============================================================="
2021-09-20 01:51:28 +08:00
read -r -p "请选择:" selectType
2021-07-01 22:48:51 +08:00
if [ [ " ${ selectType } " = = "1" ] ] ; then
2021-09-03 15:19:21 +08:00
if [ [ " ${ xtlsType } " = = "Trojan" ] ] ; then
2021-07-01 22:48:51 +08:00
2021-09-03 15:19:21 +08:00
local VLESSConfig
VLESSConfig = $( cat ${ configPath } ${ frontingType } .json)
2021-07-01 22:48:51 +08:00
VLESSConfig = ${ VLESSConfig // "id" / "password" }
VLESSConfig = ${ VLESSConfig //VLESSTCP/TrojanTCPXTLS }
VLESSConfig = ${ VLESSConfig //VLESS/Trojan }
VLESSConfig = ${ VLESSConfig // "vless" / "trojan" }
VLESSConfig = ${ VLESSConfig // "id" / "password" }
echo " ${ VLESSConfig } " | jq . >${ configPath } 02_trojan_TCP_inbounds.json
2021-09-03 15:19:21 +08:00
rm ${ configPath } ${ frontingType } .json
2021-07-01 22:48:51 +08:00
elif [ [ " ${ xtlsType } " = = "VLESS" ] ] ; then
2021-09-03 15:19:21 +08:00
local VLESSConfig
VLESSConfig = $( cat ${ configPath } 02_trojan_TCP_inbounds.json)
2021-07-01 22:48:51 +08:00
VLESSConfig = ${ VLESSConfig // "password" / "id" }
VLESSConfig = ${ VLESSConfig //TrojanTCPXTLS/VLESSTCP }
VLESSConfig = ${ VLESSConfig //Trojan/VLESS }
VLESSConfig = ${ VLESSConfig // "trojan" / "vless" }
VLESSConfig = ${ VLESSConfig // "password" / "id" }
echo " ${ VLESSConfig } " | jq . >${ configPath } 02_VLESS_TCP_inbounds.json
rm ${ configPath } 02_trojan_TCP_inbounds.json
fi
reloadCore
fi
2021-09-03 15:19:21 +08:00
exit 0
2021-07-01 22:48:51 +08:00
}
2022-03-16 17:47:52 +08:00
# 移动上次配置文件至临时文件
movePreviousConfig( ) {
if [ [ -n " ${ configPath } " ] ] && [ [ -f " ${ configPath } 02_VLESS_TCP_inbounds.json " ] ] ; then
rm -rf ${ configPath } ../tmp/*
mv ${ configPath } * ${ configPath } ../tmp/
fi
}
2020-11-26 11:51:50 +08:00
# 初始化Xray 配置文件
2021-01-14 17:28:13 +08:00
initXrayConfig( ) {
echoContent skyBlue " \n进度 $2 / ${ totalProgress } : 初始化Xray配置 "
2021-03-23 11:45:05 +08:00
echo
2021-07-03 16:40:14 +08:00
local uuid =
2022-03-16 17:47:52 +08:00
local addClientsStatus =
2021-07-03 16:40:14 +08:00
if [ [ -n " ${ currentUUID } " ] ] ; then
2021-01-14 17:28:13 +08:00
read -r -p "读取到上次安装记录, 是否使用上次安装时的UUID ? [y/n]:" historyUUIDStatus
if [ [ " ${ historyUUIDStatus } " = = "y" ] ] ; then
2022-03-16 17:47:52 +08:00
addClientsStatus = true
2021-01-14 17:28:13 +08:00
uuid = ${ currentUUID }
2021-07-03 16:40:14 +08:00
echoContent green "\n ---> 使用成功"
2021-01-14 17:28:13 +08:00
fi
2021-07-03 16:40:14 +08:00
fi
2021-09-03 15:19:21 +08:00
if [ [ -z " ${ uuid } " ] ] ; then
2021-07-03 16:40:14 +08:00
echoContent yellow "请输入自定义UUID[需合法], [回车]随机UUID"
read -r -p 'UUID:' customUUID
2021-09-03 15:19:21 +08:00
if [ [ -n ${ customUUID } ] ] ; then
2021-07-03 16:40:14 +08:00
uuid = ${ customUUID }
else
uuid = $( /etc/v2ray-agent/xray/xray uuid)
fi
2021-01-14 17:28:13 +08:00
fi
2021-03-23 11:45:05 +08:00
2021-01-14 17:28:13 +08:00
if [ [ -z " ${ uuid } " ] ] ; then
2022-03-16 17:47:52 +08:00
addClientsStatus =
2021-01-14 17:28:13 +08:00
echoContent red "\n ---> uuid读取错误, 重新生成"
uuid = $( /etc/v2ray-agent/xray/xray uuid)
fi
2021-07-03 16:40:14 +08:00
echoContent yellow " \n ${ uuid } "
2021-01-14 17:28:13 +08:00
2022-03-16 17:47:52 +08:00
movePreviousConfig
2021-01-14 17:28:13 +08:00
# log
cat <<EOF >/etc/v2ray-agent/xray/conf/00_log.json
2020-11-26 11:51:50 +08:00
{
"log" : {
2021-04-08 17:53:19 +08:00
"error" : "/etc/v2ray-agent/xray/error.log" ,
2020-12-07 10:01:04 +08:00
"loglevel" : "warning"
2020-11-26 11:51:50 +08:00
}
}
2020-12-01 17:05:48 +08:00
EOF
2021-01-14 17:28:13 +08:00
# outbounds
if [ [ -n " ${ pingIPv6 } " ] ] ; then
cat <<EOF >/etc/v2ray-agent/xray/conf/10_ipv6_outbounds.json
2020-12-31 12:21:46 +08:00
{
"outbounds" : [
{
"protocol" : "freedom" ,
"settings" : { } ,
"tag" : "direct"
}
]
}
EOF
2021-01-14 17:28:13 +08:00
else
cat <<EOF >/etc/v2ray-agent/xray/conf/10_ipv4_outbounds.json
2020-11-26 11:51:50 +08:00
{
2021-06-15 16:27:56 +08:00
"outbounds" :[
2020-11-26 11:51:50 +08:00
{
2021-06-15 16:27:56 +08:00
"protocol" :"freedom" ,
"settings" :{
"domainStrategy" :"UseIPv4"
} ,
"tag" :"IPv4-out"
} ,
{
"protocol" :"freedom" ,
"settings" :{
"domainStrategy" :"UseIPv6"
} ,
"tag" :"IPv6-out"
} ,
{
"protocol" :"blackhole" ,
"tag" :"blackhole-out"
2020-12-18 17:40:05 +08:00
}
]
}
EOF
2021-01-14 17:28:13 +08:00
fi
2020-12-18 17:40:05 +08:00
2021-01-14 17:28:13 +08:00
# dns
cat <<EOF >/etc/v2ray-agent/xray/conf/11_dns.json
2020-11-26 11:51:50 +08:00
{
"dns" : {
"servers" : [
"localhost"
]
}
}
EOF
2021-06-25 14:36:57 +08:00
2021-01-14 17:28:13 +08:00
# VLESS_TCP_TLS/XTLS
# 回落nginx
2021-06-17 15:23:34 +08:00
local fallbacksList = '{"dest":31300,"xver":0},{"alpn":"h2","dest":31302,"xver":0}'
2021-01-14 17:28:13 +08:00
2021-06-25 14:36:57 +08:00
# trojan
2021-09-03 15:19:21 +08:00
if echo " ${ selectCustomInstallType } " | grep -q 4 || [ [ " $1 " = = "all" ] ] ; then
2021-06-28 14:55:43 +08:00
fallbacksList = '{"dest":31296,"xver":1},{"alpn":"h2","dest":31302,"xver":0}'
2022-03-16 17:47:52 +08:00
getClients " ${ configPath } ../tmp/04_trojan_TCP_inbounds.json " " ${ addClientsStatus } "
2021-06-25 14:36:57 +08:00
cat <<EOF >/etc/v2ray-agent/xray/conf/04_trojan_TCP_inbounds.json
{
"inbounds" :[
{
"port" : 31296,
"listen" : "127.0.0.1" ,
"protocol" : "trojan" ,
"tag" :"trojanTCP" ,
"settings" : {
"clients" : [
{
"password" : " ${ uuid } " ,
2022-11-08 15:04:46 +08:00
"email" : " ${ domain } _ ${ uuid } "
2021-06-25 14:36:57 +08:00
}
] ,
"fallbacks" :[
{ "dest" :"31300" }
]
} ,
"streamSettings" : {
"network" : "tcp" ,
"security" : "none" ,
"tcpSettings" : {
"acceptProxyProtocol" : true
}
}
}
]
}
EOF
2022-03-16 17:47:52 +08:00
addClients "/etc/v2ray-agent/xray/conf/04_trojan_TCP_inbounds.json" " ${ addClientsStatus } "
2021-01-14 17:28:13 +08:00
fi
# VLESS_WS_TLS
if echo " ${ selectCustomInstallType } " | grep -q 1 || [ [ " $1 " = = "all" ] ] ; then
fallbacksList = ${ fallbacksList } ',{"path":"/' ${ customPath } 'ws","dest":31297,"xver":1}'
2022-03-16 17:47:52 +08:00
getClients " ${ configPath } ../tmp/03_VLESS_WS_inbounds.json " " ${ addClientsStatus } "
2021-01-14 17:28:13 +08:00
cat <<EOF >/etc/v2ray-agent/xray/conf/03_VLE SS_WS_inbounds.json
2020-11-26 11:51:50 +08:00
{
"inbounds" :[
2020-12-17 18:02:09 +08:00
{
2022-03-30 15:53:39 +08:00
"port" : 31297,
"listen" : "127.0.0.1" ,
"protocol" : "vless" ,
"tag" :"VLESSWS" ,
"settings" : {
"clients" : [
{
"id" : " ${ uuid } " ,
2022-11-08 15:04:46 +08:00
"email" : " ${ domain } _ ${ uuid } "
2022-03-30 15:53:39 +08:00
}
] ,
"decryption" : "none"
} ,
"streamSettings" : {
"network" : "ws" ,
"security" : "none" ,
"wsSettings" : {
"acceptProxyProtocol" : true,
"path" : " / ${ customPath } ws "
}
}
}
2020-12-17 18:02:09 +08:00
]
2020-11-26 11:51:50 +08:00
}
EOF
2022-03-16 17:47:52 +08:00
addClients "/etc/v2ray-agent/xray/conf/03_VLESS_WS_inbounds.json" " ${ addClientsStatus } "
2021-01-14 17:28:13 +08:00
fi
2020-12-17 18:02:09 +08:00
2021-07-01 00:04:12 +08:00
# trojan_grpc
2021-09-03 15:19:21 +08:00
if echo " ${ selectCustomInstallType } " | grep -q 2 || [ [ " $1 " = = "all" ] ] ; then
if ! echo " ${ selectCustomInstallType } " | grep -q 5 && [ [ -n ${ selectCustomInstallType } ] ] ; then
2021-07-01 21:09:17 +08:00
fallbacksList = ${ fallbacksList //31302/31304 }
fi
2022-03-16 17:47:52 +08:00
getClients " ${ configPath } ../tmp/04_trojan_gRPC_inbounds.json " " ${ addClientsStatus } "
2021-07-01 00:04:12 +08:00
cat <<EOF >/etc/v2ray-agent/xray/conf/04_trojan_gRPC_inbounds.json
{
"inbounds" : [
{
"port" : 31304,
"listen" : "127.0.0.1" ,
"protocol" : "trojan" ,
"tag" : "trojangRPCTCP" ,
"settings" : {
"clients" : [
{
"password" : " ${ uuid } " ,
2022-11-08 15:04:46 +08:00
"email" : " ${ domain } _ ${ uuid } "
2021-07-01 00:04:12 +08:00
}
] ,
"fallbacks" : [
{
"dest" : "31300"
}
]
} ,
"streamSettings" : {
"network" : "grpc" ,
"grpcSettings" : {
"serviceName" : " ${ customPath } trojangrpc "
}
}
}
]
}
EOF
2022-03-16 17:47:52 +08:00
addClients "/etc/v2ray-agent/xray/conf/04_trojan_gRPC_inbounds.json" " ${ addClientsStatus } "
2021-07-01 00:04:12 +08:00
fi
2021-01-14 17:28:13 +08:00
# VMess_WS
2021-01-15 16:43:39 +08:00
if echo " ${ selectCustomInstallType } " | grep -q 3 || [ [ " $1 " = = "all" ] ] ; then
2021-01-14 17:28:13 +08:00
fallbacksList = ${ fallbacksList } ',{"path":"/' ${ customPath } 'vws","dest":31299,"xver":1}'
2022-03-16 17:47:52 +08:00
getClients " ${ configPath } ../tmp/05_VMess_WS_inbounds.json " " ${ addClientsStatus } "
2021-01-14 17:28:13 +08:00
cat <<EOF >/etc/v2ray-agent/xray/conf/05_VMess_WS_inbounds.json
2020-11-26 11:51:50 +08:00
{
"inbounds" :[
{
2021-08-13 15:41:07 +08:00
"listen" : "127.0.0.1" ,
2020-12-17 18:02:09 +08:00
"port" : 31299,
"protocol" : "vmess" ,
"tag" :"VMessWS" ,
"settings" : {
"clients" : [
{
"id" : " ${ uuid } " ,
2021-06-24 15:51:42 +08:00
"alterId" : 0,
2020-12-17 18:02:09 +08:00
"add" : " ${ add } " ,
2022-11-08 15:04:46 +08:00
"email" : " ${ domain } _ ${ uuid } "
2020-11-26 11:51:50 +08:00
}
2020-12-17 18:02:09 +08:00
]
} ,
"streamSettings" : {
"network" : "ws" ,
"security" : "none" ,
"wsSettings" : {
"acceptProxyProtocol" : true,
2021-01-02 13:51:53 +08:00
"path" : " / ${ customPath } vws "
2020-11-26 11:51:50 +08:00
}
2020-12-17 18:02:09 +08:00
}
}
2020-11-26 11:51:50 +08:00
]
}
EOF
2022-03-16 17:47:52 +08:00
addClients "/etc/v2ray-agent/xray/conf/05_VMess_WS_inbounds.json" " ${ addClientsStatus } "
2021-01-14 17:28:13 +08:00
fi
2020-11-26 11:51:50 +08:00
2021-04-28 16:26:40 +08:00
if echo " ${ selectCustomInstallType } " | grep -q 5 || [ [ " $1 " = = "all" ] ] ; then
2022-03-16 17:47:52 +08:00
getClients " ${ configPath } ../tmp/06_VLESS_gRPC_inbounds.json " " ${ addClientsStatus } "
2021-04-28 16:26:40 +08:00
cat <<EOF >/etc/v2ray-agent/xray/conf/06_VLE SS_gRPC_inbounds.json
{
"inbounds" :[
{
"port" : 31301,
"listen" : "127.0.0.1" ,
"protocol" : "vless" ,
"tag" :"VLESSGRPC" ,
"settings" : {
"clients" : [
{
"id" : " ${ uuid } " ,
"add" : " ${ add } " ,
2022-11-08 15:04:46 +08:00
"email" : " ${ domain } _ ${ uuid } "
2021-04-28 16:26:40 +08:00
}
] ,
"decryption" : "none"
} ,
"streamSettings" : {
"network" : "grpc" ,
"grpcSettings" : {
"serviceName" : " ${ customPath } grpc "
}
}
}
]
}
EOF
2022-03-16 17:47:52 +08:00
addClients "/etc/v2ray-agent/xray/conf/06_VLESS_gRPC_inbounds.json" " ${ addClientsStatus } "
2021-04-28 16:26:40 +08:00
fi
2021-01-14 17:28:13 +08:00
# VLESS_TCP
2022-03-16 17:47:52 +08:00
getClients " ${ configPath } ../tmp/02_VLESS_TCP_inbounds.json " " ${ addClientsStatus } "
2022-10-11 16:02:05 +08:00
local defaultPort = 443
if [ [ -n " ${ customPort } " ] ] ; then
defaultPort = ${ customPort }
fi
2021-01-14 17:28:13 +08:00
cat <<EOF >/etc/v2ray-agent/xray/conf/02_VLE SS_TCP_inbounds.json
2020-11-26 11:51:50 +08:00
{
2020-12-17 18:02:09 +08:00
"inbounds" :[
{
2022-10-11 16:02:05 +08:00
"port" : ${ defaultPort } ,
2020-12-17 18:02:09 +08:00
"protocol" : "vless" ,
"tag" :"VLESSTCP" ,
"settings" : {
"clients" : [
{
"id" : " ${ uuid } " ,
"add" :" ${ add } " ,
"flow" :"xtls-rprx-direct" ,
2022-11-08 15:04:46 +08:00
"email" : " ${ domain } _ ${ uuid } "
2020-11-26 11:51:50 +08:00
}
2020-12-17 18:02:09 +08:00
] ,
"decryption" : "none" ,
"fallbacks" : [
${ fallbacksList }
]
} ,
"streamSettings" : {
"network" : "tcp" ,
"security" : "xtls" ,
"xtlsSettings" : {
2022-04-21 11:54:49 +08:00
"minVersion" : "1.2" ,
2020-12-17 18:02:09 +08:00
"alpn" : [
2021-08-16 16:57:50 +08:00
"http/1.1" ,
"h2"
2020-12-17 18:02:09 +08:00
] ,
"certificates" : [
{
"certificateFile" : " /etc/v2ray-agent/tls/ ${ domain } .crt " ,
2021-01-02 13:51:53 +08:00
"keyFile" : " /etc/v2ray-agent/tls/ ${ domain } .key " ,
"ocspStapling" : 3600,
"usage" :"encipherment"
2020-12-17 18:02:09 +08:00
}
]
2020-11-26 11:51:50 +08:00
}
2020-12-17 18:02:09 +08:00
}
}
]
2020-11-26 11:51:50 +08:00
}
EOF
2022-03-16 17:47:52 +08:00
addClients "/etc/v2ray-agent/xray/conf/02_VLESS_TCP_inbounds.json" " ${ addClientsStatus } "
2020-11-26 11:51:50 +08:00
}
2020-12-17 18:02:09 +08:00
2020-11-26 11:51:50 +08:00
# 初始化Trojan-Go配置
2021-01-14 17:28:13 +08:00
initTrojanGoConfig( ) {
2020-11-26 11:51:50 +08:00
2021-01-14 17:28:13 +08:00
echoContent skyBlue " \n进度 $1 / ${ totalProgress } : 初始化Trojan配置 "
cat <<EOF >/etc/v2ray-agent/trojan/config_full.json
2020-11-26 11:51:50 +08:00
{
"run_type" : "server" ,
"local_addr" : "127.0.0.1" ,
"local_port" : 31296,
"remote_addr" : "127.0.0.1" ,
2021-06-22 17:42:23 +08:00
"remote_port" : 31300,
2020-12-09 17:10:55 +08:00
"disable_http_check" :true,
2020-12-07 10:01:04 +08:00
"log_level" :3,
2020-11-26 11:51:50 +08:00
"log_file" :"/etc/v2ray-agent/trojan/trojan.log" ,
"password" : [
" ${ uuid } "
] ,
"dns" :[
"localhost"
] ,
"transport_plugin" :{
"enabled" :true,
"type" :"plaintext"
} ,
"websocket" : {
"enabled" : true,
"path" : " / ${ customPath } tws " ,
"host" : " ${ domain } " ,
"add" :" ${ add } "
} ,
"router" : {
"enabled" : false
}
}
EOF
}
# 自定义CDN IP
2021-01-14 17:28:13 +08:00
customCDNIP( ) {
2021-08-13 15:16:06 +08:00
echoContent skyBlue " \n进度 $1 / ${ totalProgress } : 添加cloudflare自选CNAME "
echoContent red "\n=============================================================="
echoContent yellow "# 注意事项"
echoContent yellow "\n教程地址:"
echoContent skyBlue "https://github.com/mack-a/v2ray-agent/blob/master/documents/optimize_V2Ray.md"
echoContent red "\n如对Cloudflare优化不了解, 请不要使用"
echoContent yellow "\n 1.移动:104.16.123.96"
echoContent yellow " 2.联通:www.cloudflare.com"
echoContent yellow " 3.电信:www.digitalocean.com"
2021-01-14 17:28:13 +08:00
echoContent skyBlue "----------------------------"
2021-08-13 15:16:06 +08:00
read -r -p "请选择[回车不使用]:" selectCloudflareType
2021-09-03 15:19:21 +08:00
case ${ selectCloudflareType } in
1)
add = "104.16.123.96"
; ;
2)
add = "www.cloudflare.com"
; ;
3)
add = "www.digitalocean.com"
; ;
*)
2021-01-14 17:28:13 +08:00
add = " ${ domain } "
2021-08-13 15:16:06 +08:00
echoContent yellow "\n ---> 不使用"
; ;
2021-09-03 15:19:21 +08:00
esac
2020-11-26 11:51:50 +08:00
}
# 通用
2021-01-14 17:28:13 +08:00
defaultBase64Code( ) {
local type = $1
2021-07-02 11:29:43 +08:00
local email = $2
2021-01-14 17:28:13 +08:00
local id = $3
2022-04-15 16:35:41 +08:00
port = ${ currentDefaultPort }
2021-09-03 15:19:21 +08:00
local subAccount
2022-04-22 16:37:14 +08:00
subAccount = $( echo " ${ email } " | awk -F "[_]" '{print $1}' ) _$( echo " ${ id } _currentHost " | md5sum | awk '{print $1}' )
2021-01-14 17:28:13 +08:00
if [ [ " ${ type } " = = "vlesstcp" ] ] ; then
2021-09-03 15:19:21 +08:00
if [ [ " ${ coreInstallType } " = = "1" ] ] && echo " ${ currentInstallProtocolType } " | grep -q 0; then
2021-01-14 17:28:13 +08:00
echoContent yellow " ---> 通用格式(VLESS+TCP+TLS/xtls-rprx-direct)"
2022-04-22 16:37:14 +08:00
echoContent green " vless:// ${ id } @ ${ currentHost } : ${ currentDefaultPort } ?encryption=none&security=xtls&type=tcp&host= ${ currentHost } &headerType=none&sni= ${ currentHost } &flow=xtls-rprx-direct# ${ email } \n "
2021-01-18 17:59:35 +08:00
2021-01-19 15:14:53 +08:00
echoContent yellow " ---> 格式化明文(VLESS+TCP+TLS/xtls-rprx-direct)"
2022-04-22 16:37:14 +08:00
echoContent green " 协议类型:VLESS, 地址: ${ currentHost } ,端口: ${ currentDefaultPort } , 用户ID:${ id } ,安全:xtls, 传输方式:tcp, flow:xtls-rprx-direct, 账户名: ${ email } \n "
2021-01-25 15:32:32 +08:00
cat <<EOF >>" /etc/v2ray-agent/subscribe_tmp/ ${ subAccount } "
2022-04-22 16:37:14 +08:00
vless://${ id } @${ currentHost } :${ currentDefaultPort } ?encryption= none& security = xtls& type = tcp& host = ${ currentHost } & headerType = none& sni = ${ currentHost } & flow = xtls-rprx-direct#${ email }
2021-01-19 11:47:16 +08:00
EOF
2021-01-14 17:28:13 +08:00
echoContent yellow " ---> 二维码 VLESS(VLESS+TCP+TLS/xtls-rprx-direct)"
2022-04-22 16:37:14 +08:00
echoContent green " https://api.qrserver.com/v1/create-qr-code/?size=400x400&data=vless%3A%2F%2F ${ id } %40 ${ currentHost } %3A ${ currentDefaultPort } %3Fencryption%3Dnone%26security%3Dxtls%26type%3Dtcp%26 ${ currentHost } %3D ${ currentHost } %26headerType%3Dnone%26sni%3D ${ currentHost } %26flow%3Dxtls-rprx-direct%23 ${ email } \n "
2021-01-14 17:28:13 +08:00
2021-01-20 16:56:20 +08:00
echoContent skyBlue "----------------------------------------------------------------------------------"
2021-01-14 17:28:13 +08:00
echoContent yellow " ---> 通用格式(VLESS+TCP+TLS/xtls-rprx-splice)"
2022-04-22 16:37:14 +08:00
echoContent green " vless:// ${ id } @ ${ currentHost } : ${ currentDefaultPort } ?encryption=none&security=xtls&type=tcp&host= ${ currentHost } &headerType=none&sni= ${ currentHost } &flow=xtls-rprx-splice# ${ email /direct/splice } \n "
2021-01-18 17:59:35 +08:00
2021-01-19 15:14:53 +08:00
echoContent yellow " ---> 格式化明文(VLESS+TCP+TLS/xtls-rprx-splice)"
2022-04-22 16:37:14 +08:00
echoContent green " 协议类型:VLESS, 地址: ${ currentHost } ,端口: ${ currentDefaultPort } , 用户ID:${ id } ,安全:xtls, 传输方式:tcp, flow:xtls-rprx-splice, 账户名: ${ email /direct/splice } \n "
2021-01-25 15:32:32 +08:00
cat <<EOF >>" /etc/v2ray-agent/subscribe_tmp/ ${ subAccount } "
2022-04-22 16:37:14 +08:00
vless://${ id } @${ currentHost } :${ currentDefaultPort } ?encryption= none& security = xtls& type = tcp& host = ${ currentHost } & headerType = none& sni = ${ currentHost } & flow = xtls-rprx-splice#${ email /direct/splice }
2021-01-19 11:47:16 +08:00
EOF
2021-01-14 17:28:13 +08:00
echoContent yellow " ---> 二维码 VLESS(VLESS+TCP+TLS/xtls-rprx-splice)"
2022-04-22 16:37:14 +08:00
echoContent green " https://api.qrserver.com/v1/create-qr-code/?size=400x400&data=vless%3A%2F%2F ${ id } %40 ${ currentHost } %3A ${ currentDefaultPort } %3Fencryption%3Dnone%26security%3Dxtls%26type%3Dtcp%26 ${ currentHost } %3D ${ currentHost } %26headerType%3Dnone%26sni%3D ${ currentHost } %26flow%3Dxtls-rprx-splice%23 ${ email /direct/splice } \n "
2021-01-14 17:28:13 +08:00
2021-09-03 15:19:21 +08:00
elif [ [ " ${ coreInstallType } " = = 2 || " ${ coreInstallType } " = = "3" ] ] ; then
2021-01-14 17:28:13 +08:00
echoContent yellow " ---> 通用格式(VLESS+TCP+TLS)"
2022-04-22 16:37:14 +08:00
echoContent green " vless:// ${ id } @ ${ currentHost } : ${ currentDefaultPort } ?security=tls&encryption=none&host= ${ currentHost } &headerType=none&type=tcp# ${ email } \n "
2021-01-18 17:59:35 +08:00
2021-01-19 15:14:53 +08:00
echoContent yellow " ---> 格式化明文(VLESS+TCP+TLS/xtls-rprx-splice)"
2022-04-22 16:37:14 +08:00
echoContent green " 协议类型:VLESS, 地址: ${ currentHost } ,端口: ${ currentDefaultPort } , 用户ID:${ id } ,安全:tls, 传输方式:tcp, 账户名: ${ email /direct/splice } \n "
2021-01-19 15:14:53 +08:00
2021-01-25 15:32:32 +08:00
cat <<EOF >>" /etc/v2ray-agent/subscribe_tmp/ ${ subAccount } "
2022-04-22 16:37:14 +08:00
vless://${ id } @${ currentHost } :${ currentDefaultPort } ?security= tls& encryption = none& host = ${ currentHost } & headerType = none& type = tcp#${ email }
2021-01-19 11:47:16 +08:00
EOF
2021-01-14 17:28:13 +08:00
echoContent yellow " ---> 二维码 VLESS(VLESS+TCP+TLS)"
2022-04-22 16:37:14 +08:00
echoContent green " https://api.qrserver.com/v1/create-qr-code/?size=400x400&data=vless%3a%2f%2f ${ id } %40 ${ currentHost } %3a ${ currentDefaultPort } %3fsecurity%3dtls%26encryption%3dnone%26host%3d ${ currentHost } %26headerType%3dnone%26type%3dtcp%23 ${ email } \n "
2021-01-14 17:28:13 +08:00
fi
2021-07-02 11:29:43 +08:00
elif [ [ " ${ type } " = = "trojanTCPXTLS" ] ] ; then
2021-09-03 15:19:21 +08:00
echoContent yellow " ---> 通用格式(Trojan+TCP+TLS/xtls-rprx-direct)"
2022-04-22 16:37:14 +08:00
echoContent green " trojan:// ${ id } @ ${ currentHost } : ${ currentDefaultPort } ?encryption=none&security=xtls&type=tcp&host= ${ currentHost } &headerType=none&sni= ${ currentHost } &flow=xtls-rprx-direct# ${ email } \n "
2021-07-01 22:48:51 +08:00
2021-09-03 15:19:21 +08:00
echoContent yellow " ---> 格式化明文(Trojan+TCP+TLS/xtls-rprx-direct)"
2022-04-22 16:37:14 +08:00
echoContent green " 协议类型:Trojan, 地址: ${ currentHost } ,端口: ${ currentDefaultPort } , 用户ID:${ id } ,安全:xtls, 传输方式:tcp, flow:xtls-rprx-direct, 账户名: ${ email } \n "
2021-09-03 15:19:21 +08:00
cat <<EOF >>" /etc/v2ray-agent/subscribe_tmp/ ${ subAccount } "
2022-04-22 16:37:14 +08:00
trojan://${ id } @${ currentHost } :${ currentDefaultPort } ?encryption= none& security = xtls& type = tcp& host = ${ currentHost } & headerType = none& sni = ${ currentHost } & flow = xtls-rprx-direct#${ email }
2021-07-01 22:48:51 +08:00
EOF
2021-09-03 15:19:21 +08:00
echoContent yellow " ---> 二维码 Trojan(Trojan+TCP+TLS/xtls-rprx-direct)"
2022-04-22 16:37:14 +08:00
echoContent green " https://api.qrserver.com/v1/create-qr-code/?size=400x400&data=trojan%3A%2F%2F ${ id } %40 ${ currentHost } %3A ${ currentDefaultPort } %3Fencryption%3Dnone%26security%3Dxtls%26type%3Dtcp%26 ${ currentHost } %3D ${ currentHost } %26headerType%3Dnone%26sni%3D ${ currentHost } %26flow%3Dxtls-rprx-direct%23 ${ email } \n "
2021-07-01 22:48:51 +08:00
2021-09-03 15:19:21 +08:00
echoContent skyBlue "----------------------------------------------------------------------------------"
2021-07-01 22:48:51 +08:00
2021-09-03 15:19:21 +08:00
echoContent yellow " ---> 通用格式(Trojan+TCP+TLS/xtls-rprx-splice)"
2022-04-22 16:37:14 +08:00
echoContent green " trojan:// ${ id } @ ${ currentHost } : ${ currentDefaultPort } ?encryption=none&security=xtls&type=tcp&host= ${ currentHost } &headerType=none&sni= ${ currentHost } &flow=xtls-rprx-splice# ${ email /direct/splice } \n "
2021-07-01 22:48:51 +08:00
2021-09-03 15:19:21 +08:00
echoContent yellow " ---> 格式化明文(Trojan+TCP+TLS/xtls-rprx-splice)"
2022-04-22 16:37:14 +08:00
echoContent green " 协议类型:VLESS, 地址: ${ currentHost } ,端口: ${ currentDefaultPort } , 用户ID:${ id } ,安全:xtls, 传输方式:tcp, flow:xtls-rprx-splice, 账户名: ${ email /direct/splice } \n "
2021-09-03 15:19:21 +08:00
cat <<EOF >>" /etc/v2ray-agent/subscribe_tmp/ ${ subAccount } "
2022-04-22 16:37:14 +08:00
trojan://${ id } @${ currentHost } :${ currentDefaultPort } ?encryption= none& security = xtls& type = tcp& host = ${ currentHost } & headerType = none& sni = ${ currentHost } & flow = xtls-rprx-splice#${ email /direct/splice }
2021-07-01 22:48:51 +08:00
EOF
2021-09-03 15:19:21 +08:00
echoContent yellow " ---> 二维码 Trojan(Trojan+TCP+TLS/xtls-rprx-splice)"
2022-04-22 16:37:14 +08:00
echoContent green " https://api.qrserver.com/v1/create-qr-code/?size=400x400&data=trojan%3A%2F%2F ${ id } %40 ${ currentHost } %3A ${ currentDefaultPort } %3Fencryption%3Dnone%26security%3Dxtls%26type%3Dtcp%26 ${ currentHost } %3D ${ currentHost } %26headerType%3Dnone%26sni%3D ${ currentHost } %26flow%3Dxtls-rprx-splice%23 ${ email /direct/splice } \n "
2021-07-01 22:48:51 +08:00
2021-09-06 15:07:12 +08:00
elif [ [ " ${ type } " = = "vmessws" ] ] ; then
2022-04-22 16:37:14 +08:00
qrCodeBase64Default = $( echo -n " {\"port\": ${ currentDefaultPort } ,\"ps\":\" ${ email } \",\"tls\":\"tls\",\"id\":\" ${ id } \",\"aid\":0,\"v\":2,\"host\":\" ${ currentHost } \",\"type\":\"none\",\"path\":\"/ ${ currentPath } vws\",\"net\":\"ws\",\"add\":\" ${ currentAdd } \",\"allowInsecure\":0,\"method\":\"none\",\"peer\":\" ${ currentHost } \",\"sni\":\" ${ currentHost } \"} " | base64 -w 0)
2021-09-03 15:19:21 +08:00
qrCodeBase64Default = " ${ qrCodeBase64Default // / } "
2021-01-15 11:00:49 +08:00
2021-01-14 17:28:13 +08:00
echoContent yellow " ---> 通用json(VMess+WS+TLS)"
2022-05-05 17:29:37 +08:00
echoContent green " {\"port\": ${ currentDefaultPort } ,\"ps\":\" ${ email } \",\"tls\":\"tls\",\"id\":\" ${ id } \",\"aid\":0,\"v\":2,\"host\":\" ${ currentHost } \",\"type\":\"none\",\"path\":\"/ ${ currentPath } vws\",\"net\":\"ws\",\"add\":\" ${ currentAdd } \",\"allowInsecure\":0,\"method\":\"none\",\"peer\":\" ${ currentHost } \",\"sni\":\" ${ currentHost } \"}\n "
2021-01-14 17:28:13 +08:00
echoContent yellow " ---> 通用vmess(VMess+WS+TLS)链接"
echoContent green " vmess:// ${ qrCodeBase64Default } \n "
echoContent yellow " ---> 二维码 vmess(VMess+WS+TLS)"
2021-01-19 11:47:16 +08:00
2021-01-25 15:32:32 +08:00
cat <<EOF >>" /etc/v2ray-agent/subscribe_tmp/ ${ subAccount } "
2021-01-19 11:47:16 +08:00
vmess://${ qrCodeBase64Default }
EOF
2021-04-28 16:26:40 +08:00
echoContent green " https://api.qrserver.com/v1/create-qr-code/?size=400x400&data=vmess:// ${ qrCodeBase64Default } \n "
2021-01-14 17:28:13 +08:00
2022-04-22 16:37:14 +08:00
# elif [[ "${type}" == "vmesstcp" ]]; then
#
# echoContent red "path:${path}"
# qrCodeBase64Default=$(echo -n "{\"add\":\"${add}\",\"aid\":0,\"host\":\"${host}\",\"id\":\"${id}\",\"net\":\"tcp\",\"path\":\"${path}\",\"port\":${port},\"ps\":\"${email}\",\"scy\":\"none\",\"sni\":\"${host}\",\"tls\":\"tls\",\"v\":2,\"type\":\"http\",\"allowInsecure\":0,\"peer\":\"${host}\",\"obfs\":\"http\",\"obfsParam\":\"${host}\"}" | base64)
# qrCodeBase64Default="${qrCodeBase64Default// /}"
#
# echoContent yellow " ---> 通用json(VMess+TCP+TLS)"
# echoContent green " {\"port\":'${port}',\"ps\":\"${email}\",\"tls\":\"tls\",\"id\":\"${id}\",\"aid\":0,\"v\":2,\"host\":\"${host}\",\"type\":\"http\",\"path\":\"${path}\",\"net\":\"http\",\"add\":\"${add}\",\"allowInsecure\":0,\"method\":\"post\",\"peer\":\"${host}\",\"obfs\":\"http\",\"obfsParam\":\"${host}\"}\n"
# echoContent yellow " ---> 通用vmess(VMess+TCP+TLS)链接"
# echoContent green " vmess://${qrCodeBase64Default}\n"
#
# cat <<EOF >>"/etc/v2ray-agent/subscribe_tmp/${subAccount}"
#vmess://${qrCodeBase64Default}
#EOF
# echoContent yellow " ---> 二维码 vmess(VMess+TCP+TLS)"
# echoContent green " https://api.qrserver.com/v1/create-qr-code/?size=400x400&data=vmess://${qrCodeBase64Default}\n"
2021-01-14 17:28:13 +08:00
elif [ [ " ${ type } " = = "vlessws" ] ] ; then
echoContent yellow " ---> 通用格式(VLESS+WS+TLS)"
2022-05-05 17:29:37 +08:00
echoContent green " vless:// ${ id } @ ${ currentAdd } : ${ currentDefaultPort } ?encryption=none&security=tls&type=ws&host= ${ currentHost } &sni= ${ currentHost } &path=/ ${ currentPath } ws# ${ email } \n "
2021-01-14 17:28:13 +08:00
2021-01-19 15:14:53 +08:00
echoContent yellow " ---> 格式化明文(VLESS+WS+TLS)"
2022-04-22 16:37:14 +08:00
echoContent green " 协议类型:VLESS, 地址: ${ currentAdd } ,伪装域名/SNI: ${ currentHost } ,端口: ${ currentDefaultPort } , 用户ID:${ id } ,安全:tls, 传输方式:ws, 路径:/ ${ currentPath } ws, 账户名: ${ email } \n "
2021-01-19 15:14:53 +08:00
2021-01-25 15:32:32 +08:00
cat <<EOF >>" /etc/v2ray-agent/subscribe_tmp/ ${ subAccount } "
2022-05-05 17:29:37 +08:00
vless://${ id } @${ currentAdd } :${ currentDefaultPort } ?encryption= none& security = tls& type = ws& host = ${ currentHost } & sni = ${ currentHost } & path = /${ currentPath } ws#${ email }
2021-01-19 11:47:16 +08:00
EOF
2021-01-18 17:59:35 +08:00
2021-12-24 14:44:32 +08:00
echoContent yellow " ---> 二维码 VLESS(VLESS+WS+TLS)"
2022-04-22 16:37:14 +08:00
echoContent green " https://api.qrserver.com/v1/create-qr-code/?size=400x400&data=vless%3A%2F%2F ${ id } %40 ${ currentAdd } %3A ${ currentDefaultPort } %3Fencryption%3Dnone%26security%3Dtls%26type%3Dws%26host%3D ${ currentHost } %26sni%3D ${ currentHost } %26path%3D%252f ${ currentPath } ws%23 ${ email } "
2021-04-28 16:26:40 +08:00
elif [ [ " ${ type } " = = "vlessgrpc" ] ] ; then
2021-06-03 17:00:59 +08:00
echoContent yellow " ---> 通用格式(VLESS+gRPC+TLS)"
2022-05-06 16:41:50 +08:00
echoContent green " vless:// ${ id } @ ${ currentAdd } : ${ currentDefaultPort } ?encryption=none&security=tls&type=grpc&host= ${ currentHost } &path= ${ currentPath } grpc&serviceName= ${ currentPath } grpc&alpn=h2&sni= ${ currentHost } # ${ email } \n "
2021-06-03 17:00:59 +08:00
2021-04-28 16:26:40 +08:00
echoContent yellow " ---> 格式化明文(VLESS+gRPC+TLS)"
2022-05-06 16:41:50 +08:00
echoContent green " 协议类型:VLESS, 地址: ${ currentAdd } ,伪装域名/SNI: ${ currentHost } ,端口: ${ currentDefaultPort } , 用户ID:${ id } ,安全:tls, 传输方式:gRPC, alpn:h2, serviceName: ${ currentPath } grpc, 账户名: ${ email } \n "
2021-01-14 17:28:13 +08:00
2021-06-02 11:30:08 +08:00
cat <<EOF >>" /etc/v2ray-agent/subscribe_tmp/ ${ subAccount } "
2022-05-06 16:41:50 +08:00
vless://${ id } @${ currentAdd } :${ currentDefaultPort } ?encryption= none& security = tls& type = grpc& host = ${ currentHost } & path = ${ currentPath } grpc& serviceName = ${ currentPath } grpc& alpn = h2& sni = ${ currentHost } #${email}
2021-06-02 11:30:08 +08:00
EOF
2021-05-01 16:46:36 +08:00
echoContent yellow " ---> 二维码 VLESS(VLESS+gRPC+TLS)"
2022-05-06 16:41:50 +08:00
echoContent green " https://api.qrserver.com/v1/create-qr-code/?size=400x400&data=vless%3A%2F%2F ${ id } %40 ${ currentAdd } %3A ${ currentDefaultPort } %3Fencryption%3Dnone%26security%3Dtls%26type%3Dgrpc%26host%3D ${ currentHost } %26serviceName%3D ${ currentPath } grpc%26path%3D ${ currentPath } grpc%26sni%3D ${ currentHost } %26alpn%3Dh2%23 ${ email } "
2021-05-01 16:46:36 +08:00
2021-05-07 16:16:32 +08:00
elif [ [ " ${ type } " = = "trojan" ] ] ; then
2021-01-14 17:28:13 +08:00
# URLEncode
echoContent yellow " ---> Trojan(TLS)"
2022-04-22 16:37:14 +08:00
echoContent green " trojan:// ${ id } @ ${ currentHost } : ${ currentDefaultPort } ?peer= ${ currentHost } &sni= ${ currentHost } &alpn=http/1.1# ${ currentHost } _Trojan\n "
2021-01-18 17:59:35 +08:00
2021-01-25 15:32:32 +08:00
cat <<EOF >>" /etc/v2ray-agent/subscribe_tmp/ ${ subAccount } "
2022-04-22 16:37:14 +08:00
trojan://${ id } @${ currentHost } :${ currentDefaultPort } ?peer= ${ currentHost } & sni = ${ currentHost } & alpn = http/1.1#${ email } _Trojan
2021-01-19 11:47:16 +08:00
EOF
2021-01-14 17:28:13 +08:00
echoContent yellow " ---> 二维码 Trojan(TLS)"
2022-04-22 16:37:14 +08:00
echoContent green " https://api.qrserver.com/v1/create-qr-code/?size=400x400&data=trojan%3a%2f%2f ${ id } %40 ${ currentHost } %3a ${ port } %3fpeer%3d ${ currentHost } %26sni%3d ${ currentHost } %26alpn%3Dhttp/1.1%23 ${ email } \n "
2021-01-14 17:28:13 +08:00
2021-07-01 00:04:12 +08:00
elif [ [ " ${ type } " = = "trojangrpc" ] ] ; then
# URLEncode
echoContent yellow " ---> Trojan gRPC(TLS)"
2022-05-06 16:41:50 +08:00
echoContent green " trojan:// ${ id } @ ${ currentAdd } : ${ currentDefaultPort } ?encryption=none&peer= ${ currentHost } &security=tls&type=grpc&sni= ${ currentHost } &alpn=h2&path= ${ currentPath } trojangrpc&serviceName= ${ currentPath } trojangrpc# ${ email } \n "
2021-07-01 00:04:12 +08:00
cat <<EOF >>" /etc/v2ray-agent/subscribe_tmp/ ${ subAccount } "
2022-05-06 16:41:50 +08:00
trojan://${ id } @${ currentAdd } :${ currentDefaultPort } ?encryption= none& peer = ${ currentHost } & security = tls& type = grpc& sni = ${ currentHost } & alpn = h2& path = ${ currentPath } trojangrpc& serviceName = ${ currentPath } trojangrpc#${ email }
2021-07-01 00:04:12 +08:00
EOF
echoContent yellow " ---> 二维码 Trojan gRPC(TLS)"
2022-05-06 16:41:50 +08:00
echoContent green " https://api.qrserver.com/v1/create-qr-code/?size=400x400&data=trojan%3a%2f%2f ${ id } %40 ${ currentAdd } %3a ${ currentDefaultPort } %3Fencryption%3Dnone%26security%3Dtls%26peer%3d ${ currentHost } %26type%3Dgrpc%26sni%3d ${ currentHost } %26path%3D ${ currentPath } trojangrpc%26alpn%3Dh2%26serviceName%3D ${ currentPath } trojangrpc%23 ${ email } \n "
2022-11-08 15:04:46 +08:00
elif [ [ " ${ type } " = = "hysteria" ] ] ; then
echoContent yellow " ---> Hysteria(TLS)"
echoContent green " hysteria:// ${ currentHost } : ${ hysteriaPort } ?protocol= ${ hysteriaProtocol } &auth= ${ id } &peer= ${ currentHost } &insecure=0&alpn=h3&upmbps= ${ hysteriaClientUploadSpeed } &downmbps= ${ hysteriaClientDownloadSpeed } # ${ email } \n "
cat <<EOF >>" /etc/v2ray-agent/subscribe_tmp/ ${ subAccount } "
hysteria://${ currentHost } :${ hysteriaPort } ?protocol= ${ hysteriaProtocol } & auth = ${ id } & peer = ${ currentHost } & insecure = 0& alpn = h3& upmbps = ${ hysteriaClientUploadSpeed } & downmbps = ${ hysteriaClientDownloadSpeed } #${email}
EOF
echoContent yellow " ---> 二维码 Hysteria(TLS)"
echoContent green " https://api.qrserver.com/v1/create-qr-code/?size=400x400&data=hysteria%3A%2F%2F ${ currentHost } %3A ${ hysteriaPort } %3Fprotocol%3D ${ hysteriaProtocol } %26auth%3D ${ id } %26peer%3D ${ currentHost } %26insecure%3D0%26alpn%3Dh3%26upmbps%3D ${ hysteriaClientUploadSpeed } %26downmbps%3D ${ hysteriaClientDownloadSpeed } %23 ${ email } \n "
2021-01-14 17:28:13 +08:00
fi
2021-09-03 15:19:21 +08:00
2020-08-18 15:45:55 +08:00
}
2021-09-03 15:19:21 +08:00
2020-09-04 15:25:07 +08:00
# 账号
2021-01-14 17:28:13 +08:00
showAccounts( ) {
readInstallType
readInstallProtocolType
2021-07-02 11:29:43 +08:00
readConfigHostPathUUID
2022-11-08 15:04:46 +08:00
readHysteriaConfig
2021-01-14 17:28:13 +08:00
echoContent skyBlue " \n进度 $1 / ${ totalProgress } : 账号 "
2021-01-15 11:53:32 +08:00
local show
2021-01-14 17:28:13 +08:00
# VLESS TCP
2021-01-15 11:53:32 +08:00
if [ [ -n " ${ configPath } " ] ] ; then
show = 1
2021-09-03 15:19:21 +08:00
if echo " ${ currentInstallProtocolType } " | grep -q trojan; then
2021-07-01 22:48:51 +08:00
echoContent skyBlue "===================== Trojan TCP TLS/XTLS-direct/XTLS-splice ======================\n"
jq .inbounds[ 0] .settings.clients ${ configPath } 02_trojan_TCP_inbounds.json | jq -c '.[]' | while read -r user; do
2022-11-08 15:04:46 +08:00
local email =
email = $( echo " ${ user } " | jq -r .email)
echoContent skyBlue " \n ---> 账号: ${ email } "
defaultBase64Code trojanTCPXTLS " ${ email } " " $( echo " ${ user } " | jq -r .password) "
2021-07-01 22:48:51 +08:00
done
else
2021-01-20 16:56:20 +08:00
echoContent skyBlue "===================== VLESS TCP TLS/XTLS-direct/XTLS-splice ======================\n"
2021-01-15 11:53:32 +08:00
jq .inbounds[ 0] .settings.clients ${ configPath } 02_VLESS_TCP_inbounds.json | jq -c '.[]' | while read -r user; do
2022-11-08 15:04:46 +08:00
local email =
email = $( echo " ${ user } " | jq -r .email)
echoContent skyBlue " \n ---> 账号: ${ email } "
2021-06-02 11:30:08 +08:00
echo
2022-11-08 15:04:46 +08:00
defaultBase64Code vlesstcp " ${ email } " " $( echo " ${ user } " | jq -r .id) "
2021-01-15 11:53:32 +08:00
done
fi
2021-01-14 17:28:13 +08:00
2021-01-15 11:53:32 +08:00
# VLESS WS
2021-07-01 22:48:51 +08:00
if echo ${ currentInstallProtocolType } | grep -q 1; then
2021-01-15 11:53:32 +08:00
echoContent skyBlue "\n================================ VLESS WS TLS CDN ================================\n"
2021-01-14 17:28:13 +08:00
2021-01-15 11:53:32 +08:00
jq .inbounds[ 0] .settings.clients ${ configPath } 03_VLESS_WS_inbounds.json | jq -c '.[]' | while read -r user; do
2022-11-08 15:04:46 +08:00
local email =
email = $( echo " ${ user } " | jq -r .email)
echoContent skyBlue " \n ---> 账号: ${ email } "
2021-06-02 11:30:08 +08:00
echo
2021-04-28 16:26:40 +08:00
local path = " ${ currentPath } ws "
2022-04-22 16:37:14 +08:00
# if [[ ${coreInstallType} == "1" ]]; then
# echoContent yellow "Xray的0-RTT path后面会有, 不兼容以v2ray为核心的客户端, 请手动删除后使用\n"
# path="${currentPath}ws"
# fi
2022-11-08 15:04:46 +08:00
defaultBase64Code vlessws " ${ email } " " $( echo " ${ user } " | jq -r .id) "
2021-01-15 11:53:32 +08:00
done
fi
2021-01-14 17:28:13 +08:00
2021-01-15 11:53:32 +08:00
# VMess WS
2021-07-01 22:48:51 +08:00
if echo ${ currentInstallProtocolType } | grep -q 3; then
2021-01-15 11:53:32 +08:00
echoContent skyBlue "\n================================ VMess WS TLS CDN ================================\n"
2021-04-28 16:26:40 +08:00
local path = " ${ currentPath } vws "
if [ [ ${ coreInstallType } = = "1" ] ] ; then
2021-12-24 14:44:32 +08:00
path = " ${ currentPath } vws "
2021-04-28 16:26:40 +08:00
fi
2021-01-15 11:53:32 +08:00
jq .inbounds[ 0] .settings.clients ${ configPath } 05_VMess_WS_inbounds.json | jq -c '.[]' | while read -r user; do
2022-11-08 15:04:46 +08:00
local email =
email = $( echo " ${ user } " | jq -r .email)
echoContent skyBlue " \n ---> 账号: ${ email } "
2021-06-02 11:30:08 +08:00
echo
2022-11-08 15:04:46 +08:00
defaultBase64Code vmessws " ${ email } " " $( echo " ${ user } " | jq -r .id) "
2021-04-28 16:26:40 +08:00
done
fi
2021-06-13 21:47:43 +08:00
2021-04-28 16:26:40 +08:00
# VLESS grpc
2021-07-01 22:48:51 +08:00
if echo ${ currentInstallProtocolType } | grep -q 5; then
2021-05-02 14:44:27 +08:00
echoContent skyBlue "\n=============================== VLESS gRPC TLS CDN ===============================\n"
2021-12-24 14:44:32 +08:00
echoContent red "\n --->gRPC处于测试阶段, 可能对你使用的客户端不兼容, 如不能使用请忽略"
2022-04-24 11:09:27 +08:00
# local serviceName
# serviceName=$(jq -r .inbounds[0].streamSettings.grpcSettings.serviceName ${configPath}06_VLESS_gRPC_inbounds.json)
2021-04-28 16:26:40 +08:00
jq .inbounds[ 0] .settings.clients ${ configPath } 06_VLESS_gRPC_inbounds.json | jq -c '.[]' | while read -r user; do
2022-11-08 15:04:46 +08:00
local email =
email = $( echo " ${ user } " | jq -r .email)
echoContent skyBlue " \n ---> 账号: ${ email } "
2021-06-02 11:30:08 +08:00
echo
2022-11-08 15:04:46 +08:00
defaultBase64Code vlessgrpc " ${ email } " " $( echo " ${ user } " | jq -r .id) "
2021-01-15 11:53:32 +08:00
done
fi
2021-01-14 17:28:13 +08:00
fi
2021-06-25 15:57:37 +08:00
# trojan tcp
2021-07-01 22:48:51 +08:00
if echo ${ currentInstallProtocolType } | grep -q 4; then
2021-01-14 17:28:13 +08:00
echoContent skyBlue "\n================================== Trojan TLS ==================================\n"
2021-06-25 15:57:37 +08:00
jq .inbounds[ 0] .settings.clients ${ configPath } 04_trojan_TCP_inbounds.json | jq -c '.[]' | while read -r user; do
2022-11-08 15:04:46 +08:00
local email =
email = $( echo " ${ user } " | jq -r .email)
echoContent skyBlue " \n ---> 账号: ${ email } "
2022-04-22 16:37:14 +08:00
2022-11-08 15:04:46 +08:00
defaultBase64Code trojan " ${ email } " " $( echo " ${ user } " | jq -r .password) "
2021-01-14 17:28:13 +08:00
done
2021-06-25 15:57:37 +08:00
fi
2021-01-14 17:28:13 +08:00
2021-07-01 22:48:51 +08:00
if echo ${ currentInstallProtocolType } | grep -q 2; then
2021-07-01 00:04:12 +08:00
echoContent skyBlue "\n================================ Trojan gRPC TLS ================================\n"
2021-12-24 14:44:32 +08:00
echoContent red "\n --->gRPC处于测试阶段, 可能对你使用的客户端不兼容, 如不能使用请忽略"
2021-07-01 00:04:12 +08:00
jq .inbounds[ 0] .settings.clients ${ configPath } 04_trojan_gRPC_inbounds.json | jq -c '.[]' | while read -r user; do
2022-11-08 15:04:46 +08:00
local email =
email = $( echo " ${ user } " | jq -r .email)
echoContent skyBlue " \n ---> 账号: ${ email } "
2021-07-01 00:04:12 +08:00
echo
2022-11-08 15:04:46 +08:00
defaultBase64Code trojangrpc " ${ email } " " $( echo " ${ user } " | jq -r .password) "
2021-07-01 00:04:12 +08:00
done
fi
2022-11-08 15:04:46 +08:00
if echo ${ currentInstallProtocolType } | grep -q 6; then
echoContent skyBlue "\n================================ Hysteria TLS ================================\n"
echoContent red "\n --->Hysteria速度依赖与本地的网络环境, 如果被QoS使用体验会非常差。IDC也有可能认为是攻击, 请谨慎使用"
jq .auth.config ${ hysteriaConfigPath } config.json | jq -r '.[]' | while read -r user; do
local vlessUser =
vlessUser = $( jq '.inbounds[0].settings.clients[]|select(.id=="' " ${ user } " '")' ${ configPath } 02_VLESS_TCP_inbounds.json)
local email =
email = $( echo " ${ vlessUser } " | jq -r .email)
if [ [ -n ${ vlessUser } ] ] ; then
echoContent skyBlue " \n ---> 账号: ${ email } "
echo
defaultBase64Code hysteria " ${ email } " " ${ user } "
fi
done
fi
2021-07-01 00:04:12 +08:00
2021-01-15 11:53:32 +08:00
if [ [ -z ${ show } ] ] ; then
echoContent red " ---> 未安装"
fi
2020-09-04 11:55:08 +08:00
}
2022-04-15 16:35:41 +08:00
# 移除nginx302配置
removeNginx302( ) {
2022-04-24 11:09:27 +08:00
local count = 0
grep -n "return 302" <"/etc/nginx/conf.d/alone.conf" | while read -r line; do
if ! echo " ${ line } " | grep -q "request_uri" ; then
local removeIndex =
removeIndex = $( echo " ${ line } " | awk -F "[:]" '{print $1}' )
removeIndex = $(( removeIndex + count))
sed -i " ${ removeIndex } d " /etc/nginx/conf.d/alone.conf
count = $(( count - 1 ))
fi
done
2022-04-18 16:33:15 +08:00
}
# 检查302是否成功
checkNginx302( ) {
local domain302Status =
domain302Status = $( curl -s " https:// ${ currentHost } " )
if echo " ${ domain302Status } " | grep -q "302" ; then
local domain302Result =
domain302Result = $( curl -L -s " https:// ${ currentHost } " )
if [ [ -n " ${ domain302Result } " ] ] ; then
echoContent green " ---> 302重定向设置成功"
exit 0
fi
fi
echoContent red " ---> 302重定向设置失败, 请仔细检查是否和示例相同"
backupNginxConfig restoreBackup
}
# 备份恢复nginx文件
backupNginxConfig( ) {
if [ [ " $1 " = = "backup" ] ] ; then
cp /etc/nginx/conf.d/alone.conf /etc/v2ray-agent/alone_backup.conf
echoContent green " ---> nginx配置文件备份成功"
fi
if [ [ " $1 " = = "restoreBackup" ] ] && [ [ -f "/etc/v2ray-agent/alone_backup.conf" ] ] ; then
cp /etc/v2ray-agent/alone_backup.conf /etc/nginx/conf.d/alone.conf
echoContent green " ---> nginx配置文件恢复备份成功"
rm /etc/v2ray-agent/alone_backup.conf
fi
}
# 添加302配置
addNginx302( ) {
2022-04-24 11:09:27 +08:00
# local line302Result=
# line302Result=$(| tail -n 1)
local count = 1
grep -n "Strict-Transport-Security" <"/etc/nginx/conf.d/alone.conf" | while read -r line; do
if [ [ -n " ${ line } " ] ] ; then
local insertIndex =
insertIndex = " $( echo " ${ line } " | awk -F "[:]" '{print $1}' ) "
insertIndex = $(( insertIndex + count))
sed " ${ insertIndex } i return 302 ' $1 '; " /etc/nginx/conf.d/alone.conf >/etc/nginx/conf.d/tmpfile && mv /etc/nginx/conf.d/tmpfile /etc/nginx/conf.d/alone.conf
count = $(( count + 1 ))
else
echoContent red " ---> 302添加失败"
backupNginxConfig restoreBackup
fi
2022-04-18 16:33:15 +08:00
2022-04-24 11:09:27 +08:00
done
2022-04-15 16:35:41 +08:00
}
2022-04-24 11:09:27 +08:00
2020-12-09 16:53:00 +08:00
# 更新伪装站
2021-01-14 17:28:13 +08:00
updateNginxBlog( ) {
echoContent skyBlue " \n进度 $1 / ${ totalProgress } : 更换伪装站点 "
echoContent red "=============================================================="
echoContent yellow "# 如需自定义,请手动复制模版文件到 /usr/share/nginx/html \n"
2021-07-04 01:01:49 +08:00
echoContent yellow "1.新手引导"
echoContent yellow "2.游戏网站"
echoContent yellow "3.个人博客01"
echoContent yellow "4.企业站"
2021-01-27 16:24:23 +08:00
echoContent yellow "5.解锁加密的音乐文件模版[https://github.com/ix64/unlock-music]"
echoContent yellow "6.mikutap[https://github.com/HFIProgramming/mikutap]"
2021-07-04 01:01:49 +08:00
echoContent yellow "7.企业站02"
echoContent yellow "8.个人博客02"
echoContent yellow "9.404自动跳转baidu"
2022-04-15 16:35:41 +08:00
echoContent yellow "10.302重定向网站"
2021-01-14 17:28:13 +08:00
echoContent red "=============================================================="
2021-09-20 01:51:28 +08:00
read -r -p "请选择:" selectInstallNginxBlogType
2021-01-14 17:28:13 +08:00
2022-04-15 16:35:41 +08:00
if [ [ " ${ selectInstallNginxBlogType } " = = "10" ] ] ; then
echoContent red "\n=============================================================="
echoContent yellow "重定向的优先级更高, 配置302之后如果更改伪装站点, 根路由下伪装站点将不起作用"
echoContent yellow "如想要伪装站点实现作用需删除302重定向配置\n"
echoContent yellow "1.添加"
echoContent yellow "2.删除"
echoContent red "=============================================================="
read -r -p "请选择:" redirectStatus
if [ [ " ${ redirectStatus } " = = "1" ] ] ; then
2022-04-18 16:33:15 +08:00
backupNginxConfig backup
read -r -p "请输入要重定向的域名,例如 https://www.baidu.com:" redirectDomain
2022-04-15 16:35:41 +08:00
removeNginx302
2022-04-18 16:33:15 +08:00
addNginx302 " ${ redirectDomain } "
handleNginx stop
handleNginx start
if [ [ -z $( pgrep -f nginx) ] ] ; then
backupNginxConfig restoreBackup
handleNginx start
exit 0
fi
checkNginx302
exit 0
2022-04-15 16:35:41 +08:00
fi
if [ [ " ${ redirectStatus } " = = "2" ] ] ; then
removeNginx302
2022-04-18 16:33:15 +08:00
echoContent green " ---> 移除302重定向成功"
exit 0
2022-04-15 16:35:41 +08:00
fi
fi
2021-07-04 01:01:49 +08:00
if [ [ " ${ selectInstallNginxBlogType } " = ~ ^[ 1-9] $ ] ] ; then
2021-07-04 01:08:14 +08:00
rm -rf /usr/share/nginx/*
2021-01-14 17:28:13 +08:00
if wget --help | grep -q show-progress; then
2021-07-04 01:08:14 +08:00
wget -c -q --show-progress -P /usr/share/nginx " https://raw.githubusercontent.com/mack-a/v2ray-agent/master/fodder/blog/unable/html ${ selectInstallNginxBlogType } .zip " >/dev/null
2021-01-14 17:28:13 +08:00
else
2021-07-04 01:08:14 +08:00
wget -c -P /usr/share/nginx " https://raw.githubusercontent.com/mack-a/v2ray-agent/master/fodder/blog/unable/html ${ selectInstallNginxBlogType } .zip " >/dev/null
2021-01-14 17:28:13 +08:00
fi
unzip -o " /usr/share/nginx/html ${ selectInstallNginxBlogType } .zip " -d /usr/share/nginx/html >/dev/null
rm -f " /usr/share/nginx/html ${ selectInstallNginxBlogType } .zip* "
2021-01-15 11:53:32 +08:00
echoContent green " ---> 更换伪站成功"
2021-01-14 17:28:13 +08:00
else
echoContent red " ---> 选择错误,请重新选择"
updateNginxBlog
fi
2020-12-09 16:53:00 +08:00
}
2021-04-14 16:00:26 +08:00
# 添加新端口
addCorePort( ) {
echoContent skyBlue " \n功能 1/ ${ totalProgress } : 添加新端口 "
echoContent red "\n=============================================================="
echoContent yellow "# 注意事项\n"
2021-05-02 14:44:27 +08:00
echoContent yellow "支持批量添加"
2022-11-08 15:04:46 +08:00
echoContent yellow "不影响默认端口的使用"
echoContent yellow "查看账号时,只会展示默认端口的账号"
2021-05-02 14:44:27 +08:00
echoContent yellow "不允许有特殊字符,注意逗号的格式"
echoContent yellow "录入示例:2053,2083,2087\n"
2021-04-19 15:26:18 +08:00
2021-04-15 09:34:18 +08:00
echoContent yellow "1.添加端口"
2021-04-19 15:26:18 +08:00
echoContent yellow "2.删除端口"
2021-04-15 09:34:18 +08:00
echoContent red "=============================================================="
2021-09-20 01:51:28 +08:00
read -r -p "请选择:" selectNewPortType
2021-04-15 09:34:18 +08:00
if [ [ " ${ selectNewPortType } " = = "1" ] ] ; then
2022-03-24 17:23:03 +08:00
read -r -p "请输入端口号:" newPort
2022-04-15 16:35:41 +08:00
read -r -p "请输入默认的端口号,同时会更改订阅端口以及节点端口,[回车]默认443:" defaultPort
if [ [ -n " ${ defaultPort } " ] ] ; then
rm -rf " $( find ${ configPath } * | grep "default" ) "
fi
2021-04-15 09:34:18 +08:00
if [ [ -n " ${ newPort } " ] ] ; then
2021-05-02 14:44:27 +08:00
while read -r port; do
2022-04-15 16:35:41 +08:00
rm -rf " $( find ${ configPath } * | grep " ${ port } " ) "
local fileName =
if [ [ -n " ${ defaultPort } " && " ${ port } " = = " ${ defaultPort } " ] ] ; then
fileName = " ${ configPath } 02_dokodemodoor_inbounds_ ${ port } _default.json "
else
fileName = " ${ configPath } 02_dokodemodoor_inbounds_ ${ port } .json "
fi
2022-04-21 17:07:44 +08:00
# 开放端口
allowPort " ${ port } "
2022-10-11 16:02:05 +08:00
local settingsPort = 443
if [ [ -n " ${ customPort } " ] ] ; then
settingsPort = ${ customPort }
fi
2022-04-15 16:35:41 +08:00
cat <<EOF >" ${ fileName } "
2021-04-14 16:00:26 +08:00
{
"inbounds" : [
2022-04-15 16:35:41 +08:00
{
"listen" : "0.0.0.0" ,
"port" : ${ port } ,
"protocol" : "dokodemo-door" ,
"settings" : {
"address" : "127.0.0.1" ,
2022-10-11 16:02:05 +08:00
"port" : ${ settingsPort } ,
2022-04-15 16:35:41 +08:00
"network" : "tcp" ,
"followRedirect" : false
} ,
"tag" : " dokodemo-door-newPort- ${ port } "
}
2021-04-14 16:00:26 +08:00
]
}
EOF
2021-05-02 14:44:27 +08:00
done < <( echo " ${ newPort } " | tr ',' '\n' )
2021-04-15 09:34:18 +08:00
echoContent green " ---> 添加成功"
reloadCore
fi
elif [ [ " ${ selectNewPortType } " = = "2" ] ] ; then
2021-04-19 15:29:13 +08:00
2021-09-03 15:19:21 +08:00
find ${ configPath } -name "*dokodemodoor*" | awk -F "[c][o][n][f][/]" '{print ""NR""":"$2}'
2022-03-24 17:23:03 +08:00
read -r -p "请输入要删除的端口编号:" portIndex
2021-09-03 15:19:21 +08:00
local dokoConfig
dokoConfig = $( find ${ configPath } -name "*dokodemodoor*" | awk -F "[c][o][n][f][/]" '{print ""NR""":"$2}' | grep " ${ portIndex } : " )
2021-04-19 15:26:18 +08:00
if [ [ -n " ${ dokoConfig } " ] ] ; then
2021-09-03 15:19:21 +08:00
rm " ${ configPath } / $( echo " ${ dokoConfig } " | awk -F "[:]" '{print $2}' ) "
2021-04-19 15:26:18 +08:00
reloadCore
else
echoContent yellow "\n ---> 编号输入错误,请重新选择"
addCorePort
fi
fi
2021-04-03 18:46:11 +08:00
}
2021-04-19 15:26:18 +08:00
2020-09-02 16:48:05 +08:00
# 卸载脚本
2021-01-14 17:28:13 +08:00
unInstall( ) {
read -r -p "是否确认卸载安装内容?[y/n]:" unInstallStatus
if [ [ " ${ unInstallStatus } " != "y" ] ] ; then
echoContent green " ---> 放弃卸载"
menu
2021-03-12 15:38:33 +08:00
exit 0
2021-01-14 17:28:13 +08:00
fi
handleNginx stop
2021-01-15 11:00:49 +08:00
if [ [ -z $( pgrep -f "nginx" ) ] ] ; then
2021-01-14 17:28:13 +08:00
echoContent green " ---> 停止Nginx成功"
fi
2022-03-30 15:53:39 +08:00
if [ [ " ${ coreInstallType } " = = "1" ] ] ; then
handleXray stop
rm -rf /etc/systemd/system/xray.service
echoContent green " ---> 删除Xray开机自启完成"
elif [ [ " ${ coreInstallType } " = = "2" ] ] ; then
handleV2Ray stop
rm -rf /etc/systemd/system/v2ray.service
echoContent green " ---> 删除V2Ray开机自启完成"
fi
2021-11-05 14:36:46 +08:00
2022-11-08 15:04:46 +08:00
if [ [ -z " ${ hysteriaConfigPath } " ] ] ; then
handleHysteria stop
rm -rf /etc/systemd/system/hysteria.service
echoContent green " ---> 删除Hysteria开机自启完成"
fi
2021-11-08 11:14:27 +08:00
if [ [ -f "/root/.acme.sh/acme.sh.env" ] ] && grep -q 'acme.sh.env' </root/.bashrc; then
2021-11-05 14:36:46 +08:00
sed -i 's/. "\/root\/.acme.sh\/acme.sh.env"//g' " $( grep '. "/root/.acme.sh/acme.sh.env"' -rl /root/.bashrc) "
fi
2021-06-16 15:17:26 +08:00
rm -rf /root/.acme.sh
echoContent green " ---> 删除acme.sh完成"
2021-03-12 16:06:46 +08:00
2021-01-14 17:28:13 +08:00
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
mv /etc/v2ray-agent/tls /tmp/v2ray-agent-tls
if [ [ -n $( find /tmp/v2ray-agent-tls -name '*.key' ) ] ] ; then
echoContent yellow " ---> 备份证书成功,请注意留存。[/tmp/v2ray-agent-tls]"
fi
fi
rm -rf /etc/v2ray-agent
2021-11-10 14:21:05 +08:00
rm -rf ${ nginxConfigPath } alone.conf
2022-03-28 16:55:06 +08:00
if [ [ -d "/usr/share/nginx/html" && -f "/usr/share/nginx/html/check" ] ] ; then
rm -rf /usr/share/nginx/html
echoContent green " ---> 删除伪装网站完成"
fi
2021-01-14 17:28:13 +08:00
rm -rf /usr/bin/vasma
rm -rf /usr/sbin/vasma
echoContent green " ---> 卸载快捷方式完成"
2021-04-20 16:23:02 +08:00
echoContent green " ---> 卸载v2ray-agent脚本完成"
2020-07-21 14:03:18 +08:00
}
2020-10-22 17:23:50 +08:00
2022-11-08 15:04:46 +08:00
#updateGeoSite
2020-10-05 11:16:39 +08:00
# 修改V2Ray CDN节点
2021-01-14 17:28:13 +08:00
updateV2RayCDN( ) {
# todo 重构此方法
echoContent skyBlue " \n进度 $1 / ${ totalProgress } : 修改CDN节点 "
2021-09-03 15:19:21 +08:00
if [ [ -n " ${ currentAdd } " ] ] ; then
2021-01-14 17:28:13 +08:00
echoContent red "=============================================================="
echoContent yellow "1.CNAME www.digitalocean.com"
2021-03-05 10:29:03 +08:00
echoContent yellow "2.CNAME www.cloudflare.com"
2021-03-09 17:18:51 +08:00
echoContent yellow "3.CNAME hostmonit.com"
2021-01-14 17:28:13 +08:00
echoContent yellow "4.手动输入"
echoContent red "=============================================================="
read -r -p "请选择:" selectCDNType
case ${ selectCDNType } in
1)
setDomain = "www.digitalocean.com"
; ;
2)
2021-03-05 10:29:03 +08:00
setDomain = "www.cloudflare.com"
2021-01-14 17:28:13 +08:00
; ;
3)
2021-03-09 17:18:51 +08:00
setDomain = "hostmonit.com"
2021-01-14 17:28:13 +08:00
; ;
4)
read -r -p "请输入想要自定义CDN IP或者域名:" setDomain
; ;
esac
if [ [ -n ${ setDomain } ] ] ; then
2021-09-03 15:19:21 +08:00
if [ [ -n " ${ currentAdd } " ] ] ; then
sed -i " s/\" ${ currentAdd } \"/\" ${ setDomain } \"/g " " $( grep " ${ currentAdd } " -rl ${ configPath } ${ frontingType } .json) "
2021-01-14 17:28:13 +08:00
fi
2021-09-03 15:19:21 +08:00
if [ [ $( jq -r .inbounds[ 0] .settings.clients[ 0] .add ${ configPath } ${ frontingType } .json) = = " ${ setDomain } " ] ] ; then
2021-01-14 17:28:13 +08:00
echoContent green " ---> CDN修改成功"
2021-03-04 16:15:53 +08:00
reloadCore
2021-01-14 17:28:13 +08:00
else
echoContent red " ---> 修改CDN失败"
fi
fi
else
echoContent red " ---> 未安装可用类型"
fi
2020-10-05 11:16:39 +08:00
}
2020-10-27 16:43:03 +08:00
2020-12-21 17:30:21 +08:00
# manageUser 用户管理
2021-01-14 17:28:13 +08:00
manageUser( ) {
echoContent skyBlue " \n进度 $1 / ${ totalProgress } : 多用户管理 "
echoContent skyBlue "-----------------------------------------------------"
echoContent yellow "1.添加用户"
echoContent yellow "2.删除用户"
echoContent skyBlue "-----------------------------------------------------"
2021-09-20 01:51:28 +08:00
read -r -p "请选择:" manageUserType
2021-01-14 17:28:13 +08:00
if [ [ " ${ manageUserType } " = = "1" ] ] ; then
addUser
elif [ [ " ${ manageUserType } " = = "2" ] ] ; then
removeUser
else
echoContent red " ---> 选择错误"
fi
2020-12-21 17:30:21 +08:00
}
2020-11-30 14:54:10 +08:00
2020-12-29 11:15:54 +08:00
# 自定义uuid
2021-01-14 17:28:13 +08:00
customUUID( ) {
2022-03-24 17:23:03 +08:00
# read -r -p "是否自定义UUID ? [y/n]:" customUUIDStatus
# echo
# if [[ "${customUUIDStatus}" == "y" ]]; then
read -r -p "请输入合法的UUID, [回车]随机UUID:" currentCustomUUID
2021-01-14 17:28:13 +08:00
echo
2022-03-24 17:23:03 +08:00
if [ [ -z " ${ currentCustomUUID } " ] ] ; then
# echoContent red " ---> UUID不可为空"
currentCustomUUID = $( ${ ctlPath } uuid)
echoContent yellow " uuid: ${ currentCustomUUID } \n "
else
jq -r -c '.inbounds[0].settings.clients[].id' ${ configPath } ${ frontingType } .json | while read -r line; do
if [ [ " ${ line } " = = " ${ currentCustomUUID } " ] ] ; then
echo >/tmp/v2ray-agent
2021-01-14 17:28:13 +08:00
fi
2022-03-24 17:23:03 +08:00
done
if [ [ -f "/tmp/v2ray-agent" && -n $( cat /tmp/v2ray-agent) ] ] ; then
echoContent red " ---> UUID不可重复"
rm /tmp/v2ray-agent
exit 0
2021-01-14 17:28:13 +08:00
fi
fi
2022-03-24 17:23:03 +08:00
# fi
2020-12-29 11:15:54 +08:00
}
2020-12-30 15:46:33 +08:00
# 自定义email
2021-01-14 17:28:13 +08:00
customUserEmail( ) {
2022-03-24 17:23:03 +08:00
# read -r -p "是否自定义email ? [y/n]:" customEmailStatus
# echo
# if [[ "${customEmailStatus}" == "y" ]]; then
read -r -p "请输入合法的email, [回车]随机email:" currentCustomEmail
2021-01-14 17:28:13 +08:00
echo
2022-03-24 17:23:03 +08:00
if [ [ -z " ${ currentCustomEmail } " ] ] ; then
currentCustomEmail = " ${ currentHost } _ ${ currentCustomUUID } "
echoContent yellow " email: ${ currentCustomEmail } \n "
2022-03-28 16:55:06 +08:00
# echoContent red " ---> email不可为空"
2022-03-24 17:23:03 +08:00
else
jq -r -c '.inbounds[0].settings.clients[].email' ${ configPath } ${ frontingType } .json | while read -r line; do
if [ [ " ${ line } " = = " ${ currentCustomEmail } " ] ] ; then
echo >/tmp/v2ray-agent
2021-01-14 17:28:13 +08:00
fi
2022-03-24 17:23:03 +08:00
done
if [ [ -f "/tmp/v2ray-agent" && -n $( cat /tmp/v2ray-agent) ] ] ; then
echoContent red " ---> email不可重复"
rm /tmp/v2ray-agent
exit 0
2021-01-14 17:28:13 +08:00
fi
fi
2022-03-24 17:23:03 +08:00
# fi
2020-12-30 15:46:33 +08:00
}
2020-12-21 17:30:21 +08:00
# 添加用户
2021-01-14 17:28:13 +08:00
addUser( ) {
2021-02-24 15:57:51 +08:00
2021-01-19 11:47:16 +08:00
echoContent yellow "添加新用户后,需要重新查看订阅"
2022-03-24 17:23:03 +08:00
read -r -p "请输入要添加的用户数量:" userNum
2021-01-14 17:28:13 +08:00
echo
if [ [ -z ${ userNum } || ${ userNum } -le 0 ] ] ; then
echoContent red " ---> 输入有误,请重新输入"
2021-03-12 15:38:33 +08:00
exit 0
2021-01-14 17:28:13 +08:00
fi
# 生成用户
if [ [ " ${ userNum } " = = "1" ] ] ; then
customUUID
customUserEmail
fi
while [ [ ${ userNum } -gt 0 ] ] ; do
2021-09-03 15:19:21 +08:00
local users =
2021-01-14 17:28:13 +08:00
( ( userNum--) ) || true
if [ [ -n " ${ currentCustomUUID } " ] ] ; then
uuid = ${ currentCustomUUID }
else
uuid = $( ${ ctlPath } uuid)
fi
2021-09-03 15:19:21 +08:00
2021-01-14 17:28:13 +08:00
if [ [ -n " ${ currentCustomEmail } " ] ] ; then
email = ${ currentCustomEmail }
else
email = ${ currentHost } _${ uuid }
fi
2021-09-03 15:19:21 +08:00
# 兼容v2ray-core
users = " {\"id\":\" ${ uuid } \",\"flow\":\"xtls-rprx-direct\",\"email\":\" ${ email } \",\"alterId\":0} "
2021-02-24 15:57:51 +08:00
2021-09-03 15:19:21 +08:00
if [ [ " ${ coreInstallType } " = = "2" ] ] ; then
users = " {\"id\":\" ${ uuid } \",\"email\":\" ${ email } \",\"alterId\":0} "
2021-01-14 17:28:13 +08:00
fi
2021-07-02 11:29:43 +08:00
2021-09-03 15:19:21 +08:00
if echo ${ currentInstallProtocolType } | grep -q 0; then
local vlessUsers = " ${ users // \, \" alterId \" : 0 / } "
2021-01-14 17:28:13 +08:00
2021-09-03 15:19:21 +08:00
local vlessTcpResult
vlessTcpResult = $( jq -r " .inbounds[0].settings.clients += [ ${ vlessUsers } ] " ${ configPath } ${ frontingType } .json)
echo " ${ vlessTcpResult } " | jq . >${ configPath } ${ frontingType } .json
fi
2021-01-14 17:28:13 +08:00
2021-09-03 15:19:21 +08:00
if echo ${ currentInstallProtocolType } | grep -q trojan; then
local trojanXTLSUsers = " ${ users // \, \" alterId \" : 0 / } "
trojanXTLSUsers = ${ trojanXTLSUsers // "id" / "password" }
2021-01-14 17:28:13 +08:00
2021-09-03 15:19:21 +08:00
local trojanXTLSResult
trojanXTLSResult = $( jq -r " .inbounds[0].settings.clients += [ ${ trojanXTLSUsers } ] " ${ configPath } ${ frontingType } .json)
echo " ${ trojanXTLSResult } " | jq . >${ configPath } ${ frontingType } .json
fi
2021-07-03 00:36:52 +08:00
2021-09-03 15:19:21 +08:00
if echo ${ currentInstallProtocolType } | grep -q 1; then
local vlessUsers = " ${ users // \, \" alterId \" : 0 / } "
vlessUsers = " ${ vlessUsers // \" flow \" : \" xtls -rprx-direct \" \, / } "
local vlessWsResult
vlessWsResult = $( jq -r " .inbounds[0].settings.clients += [ ${ vlessUsers } ] " ${ configPath } 03_VLESS_WS_inbounds.json)
echo " ${ vlessWsResult } " | jq . >${ configPath } 03_VLESS_WS_inbounds.json
fi
2021-01-14 17:28:13 +08:00
2021-09-03 15:19:21 +08:00
if echo ${ currentInstallProtocolType } | grep -q 2; then
local trojangRPCUsers = " ${ users // \" flow \" : \" xtls -rprx-direct \" \, / } "
trojangRPCUsers = " ${ trojangRPCUsers // \, \" alterId \" : 0 / } "
trojangRPCUsers = ${ trojangRPCUsers // "id" / "password" }
2021-02-26 14:34:12 +08:00
2021-09-03 15:19:21 +08:00
local trojangRPCResult
trojangRPCResult = $( jq -r " .inbounds[0].settings.clients += [ ${ trojangRPCUsers } ] " ${ configPath } 04_trojan_gRPC_inbounds.json)
echo " ${ trojangRPCResult } " | jq . >${ configPath } 04_trojan_gRPC_inbounds.json
fi
2021-01-14 17:28:13 +08:00
2021-09-03 15:19:21 +08:00
if echo ${ currentInstallProtocolType } | grep -q 3; then
local vmessUsers = " ${ users // \" flow \" : \" xtls -rprx-direct \" \, / } "
2021-06-06 11:09:03 +08:00
2021-09-03 15:19:21 +08:00
local vmessWsResult
vmessWsResult = $( jq -r " .inbounds[0].settings.clients += [ ${ vmessUsers } ] " ${ configPath } 05_VMess_WS_inbounds.json)
echo " ${ vmessWsResult } " | jq . >${ configPath } 05_VMess_WS_inbounds.json
fi
2021-06-06 11:09:03 +08:00
2021-09-03 15:19:21 +08:00
if echo ${ currentInstallProtocolType } | grep -q 5; then
local vlessGRPCUsers = " ${ users // \" flow \" : \" xtls -rprx-direct \" \, / } "
vlessGRPCUsers = " ${ vlessGRPCUsers // \, \" alterId \" : 0 / } "
2021-06-25 15:57:37 +08:00
2021-09-03 15:19:21 +08:00
local vlessGRPCResult
vlessGRPCResult = $( jq -r " .inbounds[0].settings.clients += [ ${ vlessGRPCUsers } ] " ${ configPath } 06_VLESS_gRPC_inbounds.json)
echo " ${ vlessGRPCResult } " | jq . >${ configPath } 06_VLESS_gRPC_inbounds.json
fi
2021-06-25 15:57:37 +08:00
2021-09-03 15:19:21 +08:00
if echo ${ currentInstallProtocolType } | grep -q 4; then
local trojanUsers = " ${ users // \" flow \" : \" xtls -rprx-direct \" \, / } "
trojanUsers = " ${ trojanUsers //id/password } "
trojanUsers = " ${ trojanUsers // \, \" alterId \" : 0 / } "
2021-01-14 17:28:13 +08:00
2021-09-03 15:19:21 +08:00
local trojanTCPResult
trojanTCPResult = $( jq -r " .inbounds[0].settings.clients += [ ${ trojanUsers } ] " ${ configPath } 04_trojan_TCP_inbounds.json)
echo " ${ trojanTCPResult } " | jq . >${ configPath } 04_trojan_TCP_inbounds.json
fi
2022-11-08 15:04:46 +08:00
if echo ${ currentInstallProtocolType } | grep -q 6; then
local hysteriaResult
hysteriaResult = $( jq -r " .auth.config += [\" ${ uuid } \"] " ${ hysteriaConfigPath } config.json)
echo " ${ hysteriaResult } " | jq . >${ hysteriaConfigPath } config.json
fi
2021-09-03 15:19:21 +08:00
done
2021-06-25 15:57:37 +08:00
2021-03-04 16:15:53 +08:00
reloadCore
2021-01-14 17:28:13 +08:00
echoContent green " ---> 添加完成"
2021-11-24 13:51:04 +08:00
manageAccount 1
2020-10-12 15:53:48 +08:00
}
2020-10-13 17:14:06 +08:00
2020-12-29 11:15:54 +08:00
# 移除用户
2021-01-14 17:28:13 +08:00
removeUser( ) {
2021-09-03 15:19:21 +08:00
if echo ${ currentInstallProtocolType } | grep -q 0 || echo ${ currentInstallProtocolType } | grep -q trojan; then
2021-07-02 11:29:43 +08:00
jq -r -c .inbounds[ 0] .settings.clients[ ] .email ${ configPath } ${ frontingType } .json | awk '{print NR""":"$0}'
2021-01-14 17:28:13 +08:00
read -r -p "请选择要删除的用户编号[仅支持单个删除]:" delUserIndex
2021-07-02 11:29:43 +08:00
if [ [ $( jq -r '.inbounds[0].settings.clients|length' ${ configPath } ${ frontingType } .json) -lt ${ delUserIndex } ] ] ; then
2021-01-14 17:28:13 +08:00
echoContent red " ---> 选择错误"
else
2021-09-03 15:19:21 +08:00
delUserIndex = $(( delUserIndex - 1 ))
2021-01-14 17:28:13 +08:00
local vlessTcpResult
2021-07-02 11:29:43 +08:00
vlessTcpResult = $( jq -r 'del(.inbounds[0].settings.clients[' ${ delUserIndex } '])' ${ configPath } ${ frontingType } .json)
echo " ${ vlessTcpResult } " | jq . >${ configPath } ${ frontingType } .json
2021-01-14 17:28:13 +08:00
fi
fi
if [ [ -n " ${ delUserIndex } " ] ] ; then
if echo ${ currentInstallProtocolType } | grep -q 1; then
local vlessWSResult
vlessWSResult = $( jq -r 'del(.inbounds[0].settings.clients[' ${ delUserIndex } '])' ${ configPath } 03_VLESS_WS_inbounds.json)
echo " ${ vlessWSResult } " | jq . >${ configPath } 03_VLESS_WS_inbounds.json
fi
if echo ${ currentInstallProtocolType } | grep -q 2; then
2021-07-02 11:29:43 +08:00
local trojangRPCUsers
trojangRPCUsers = $( jq -r 'del(.inbounds[0].settings.clients[' ${ delUserIndex } '])' ${ configPath } 04_trojan_gRPC_inbounds.json)
echo " ${ trojangRPCUsers } " | jq . >${ configPath } 04_trojan_gRPC_inbounds.json
2021-01-14 17:28:13 +08:00
fi
if echo ${ currentInstallProtocolType } | grep -q 3; then
local vmessWSResult
vmessWSResult = $( jq -r 'del(.inbounds[0].settings.clients[' ${ delUserIndex } '])' ${ configPath } 05_VMess_WS_inbounds.json)
echo " ${ vmessWSResult } " | jq . >${ configPath } 05_VMess_WS_inbounds.json
fi
2021-06-06 11:09:03 +08:00
if echo ${ currentInstallProtocolType } | grep -q 5; then
local vlessGRPCResult
vlessGRPCResult = $( jq -r 'del(.inbounds[0].settings.clients[' ${ delUserIndex } '])' ${ configPath } 06_VLESS_gRPC_inbounds.json)
echo " ${ vlessGRPCResult } " | jq . >${ configPath } 06_VLESS_gRPC_inbounds.json
fi
2021-01-14 17:28:13 +08:00
if echo ${ currentInstallProtocolType } | grep -q 4; then
2021-06-25 15:57:37 +08:00
local trojanTCPResult
trojanTCPResult = $( jq -r 'del(.inbounds[0].settings.clients[' ${ delUserIndex } '])' ${ configPath } 04_trojan_TCP_inbounds.json)
echo " ${ trojanTCPResult } " | jq . >${ configPath } 04_trojan_TCP_inbounds.json
2021-01-14 17:28:13 +08:00
fi
2021-07-02 11:29:43 +08:00
2022-11-08 15:04:46 +08:00
if echo ${ currentInstallProtocolType } | grep -q 6; then
local hysteriaResult
hysteriaResult = $( jq -r 'del(.auth.config[' ${ delUserIndex } '])' ${ hysteriaConfigPath } config.json)
echo " ${ hysteriaResult } " | jq . >${ hysteriaConfigPath } config.json
fi
2021-03-04 16:15:53 +08:00
reloadCore
2021-01-14 17:28:13 +08:00
fi
2021-09-03 15:19:21 +08:00
manageAccount 1
2020-12-29 11:15:54 +08:00
}
2020-11-25 17:06:40 +08:00
# 更新脚本
2021-01-14 17:28:13 +08:00
updateV2RayAgent( ) {
echoContent skyBlue " \n进度 $1 / ${ totalProgress } : 更新v2ray-agent脚本 "
2021-03-01 14:52:58 +08:00
rm -rf /etc/v2ray-agent/install.sh
2021-02-03 11:43:48 +08:00
if wget --help | grep -q show-progress; then
wget -c -q --show-progress -P /etc/v2ray-agent/ -N --no-check-certificate "https://raw.githubusercontent.com/mack-a/v2ray-agent/master/install.sh"
else
wget -c -q -P /etc/v2ray-agent/ -N --no-check-certificate "https://raw.githubusercontent.com/mack-a/v2ray-agent/master/install.sh"
fi
sudo chmod 700 /etc/v2ray-agent/install.sh
2021-09-03 15:19:21 +08:00
local version
2022-03-24 17:23:03 +08:00
version = $( grep '当前版本:v' "/etc/v2ray-agent/install.sh" | awk -F "[v]" '{print $2}' | tail -n +2 | head -n 1 | awk -F "[\"]" '{print $1}' )
2021-02-03 11:43:48 +08:00
echoContent green "\n ---> 更新完毕"
echoContent yellow " ---> 请手动执行[vasma]打开脚本"
echoContent green " ---> 当前版本: ${ version } \n "
2021-03-01 14:52:58 +08:00
echoContent yellow "如更新不成功,请手动执行下面命令\n"
2021-09-03 15:19:21 +08:00
echoContent skyBlue "wget -P /root -N --no-check-certificate https://raw.githubusercontent.com/mack-a/v2ray-agent/master/install.sh && chmod 700 /root/install.sh && /root/install.sh"
2021-03-01 14:52:58 +08:00
echo
2021-02-03 11:43:48 +08:00
exit 0
2020-08-18 13:44:19 +08:00
}
2020-11-25 17:06:40 +08:00
2021-08-12 15:33:32 +08:00
# 防火墙
2021-09-03 15:19:21 +08:00
handleFirewall( ) {
if systemctl status ufw 2>/dev/null | grep -q "active (exited)" && [ [ " $1 " = = "stop" ] ] ; then
2021-08-12 15:33:32 +08:00
systemctl stop ufw >/dev/null 2>& 1
systemctl disable ufw >/dev/null 2>& 1
echoContent green " ---> ufw关闭成功"
fi
2021-09-03 15:19:21 +08:00
if systemctl status firewalld 2>/dev/null | grep -q "active (running)" && [ [ " $1 " = = "stop" ] ] ; then
2021-08-12 15:33:32 +08:00
systemctl stop firewalld >/dev/null 2>& 1
systemctl disable firewalld >/dev/null 2>& 1
echoContent green " ---> firewalld关闭成功"
fi
}
2020-09-02 16:48:05 +08:00
# 安装BBR
2021-01-14 17:28:13 +08:00
bbrInstall( ) {
echoContent red "\n=============================================================="
2021-03-12 15:38:33 +08:00
echoContent green "BBR、DD脚本用的[ylx2016]的成熟作品,地址[https://github.com/ylx2016/Linux-NetSpeed],请熟知"
echoContent yellow "1.安装脚本【推荐原版BBR+FQ】"
2021-02-03 11:48:03 +08:00
echoContent yellow "2.回退主目录"
2021-01-14 17:28:13 +08:00
echoContent red "=============================================================="
2021-09-20 01:51:28 +08:00
read -r -p "请选择:" installBBRStatus
2021-01-14 17:28:13 +08:00
if [ [ " ${ installBBRStatus } " = = "1" ] ] ; then
wget -N --no-check-certificate "https://raw.githubusercontent.com/ylx2016/Linux-NetSpeed/master/tcp.sh" && chmod +x tcp.sh && ./tcp.sh
else
menu
fi
2020-09-02 16:48:05 +08:00
}
2020-11-25 17:06:40 +08:00
2020-10-04 13:33:07 +08:00
# 查看、检查日志
2021-01-14 17:28:13 +08:00
checkLog( ) {
2021-04-08 17:53:19 +08:00
if [ [ -z ${ configPath } ] ] ; then
2021-01-14 17:28:13 +08:00
echoContent red " ---> 没有检测到安装目录,请执行脚本安装内容"
fi
2021-04-18 14:37:04 +08:00
local logStatus = false
2021-09-03 15:19:21 +08:00
if grep -q "access" ${ configPath } 00_log.json; then
2021-04-18 14:37:04 +08:00
logStatus = true
fi
2021-04-08 17:53:19 +08:00
echoContent skyBlue " \n功能 $1 / ${ totalProgress } : 查看日志 "
echoContent red "\n=============================================================="
2021-04-20 16:23:02 +08:00
echoContent yellow "# 建议仅调试时打开access日志\n"
2021-04-18 14:37:04 +08:00
2021-04-20 16:23:02 +08:00
if [ [ " ${ logStatus } " = = "false" ] ] ; then
2021-04-18 14:37:04 +08:00
echoContent yellow "1.打开access日志"
else
echoContent yellow "1.关闭access日志"
fi
echoContent yellow "2.监听access日志"
echoContent yellow "3.监听error日志"
2021-06-15 11:37:32 +08:00
echoContent yellow "4.查看证书定时任务日志"
echoContent yellow "5.查看证书安装日志"
echoContent yellow "6.清空日志"
2021-01-14 17:28:13 +08:00
echoContent red "=============================================================="
2021-09-20 01:51:28 +08:00
read -r -p "请选择:" selectAccessLogType
2021-04-08 17:53:19 +08:00
local configPathLog = ${ configPath //conf \/ / }
case ${ selectAccessLogType } in
2021-01-14 17:28:13 +08:00
1)
2021-04-20 16:23:02 +08:00
if [ [ " ${ logStatus } " = = "false" ] ] ; then
2021-04-18 14:37:04 +08:00
cat <<EOF >${ configPath } 00_log.json
2021-04-08 17:53:19 +08:00
{
"log" : {
"access" :" ${ configPathLog } access.log " ,
"error" : " ${ configPathLog } error.log " ,
2021-05-28 16:01:49 +08:00
"loglevel" : "debug"
2021-04-08 17:53:19 +08:00
}
}
EOF
2021-04-20 16:23:02 +08:00
elif [ [ " ${ logStatus } " = = "true" ] ] ; then
2021-04-18 14:37:04 +08:00
cat <<EOF >${ configPath } 00_log.json
2021-04-08 17:53:19 +08:00
{
"log" : {
"error" : " ${ configPathLog } error.log " ,
"loglevel" : "warning"
}
}
EOF
2021-04-18 14:37:04 +08:00
fi
2021-04-08 17:53:19 +08:00
reloadCore
2021-04-18 14:37:04 +08:00
checkLog 1
2021-01-14 17:28:13 +08:00
; ;
2021-04-18 14:37:04 +08:00
2)
2021-04-08 17:53:19 +08:00
tail -f ${ configPathLog } access.log
2021-01-14 17:28:13 +08:00
; ;
2021-04-18 14:37:04 +08:00
3)
2021-04-08 17:53:19 +08:00
tail -f ${ configPathLog } error.log
2021-01-14 17:28:13 +08:00
; ;
2021-04-18 14:37:04 +08:00
4)
2021-05-26 15:01:47 +08:00
tail -n 100 /etc/v2ray-agent/crontab_tls.log
; ;
5)
2021-06-15 11:37:32 +08:00
tail -n 100 /etc/v2ray-agent/tls/acme.log
; ;
6)
2021-04-08 17:53:19 +08:00
echo >${ configPathLog } access.log
echo >${ configPathLog } error.log
2021-01-14 17:28:13 +08:00
; ;
esac
2020-10-04 13:33:07 +08:00
}
2020-12-17 18:02:09 +08:00
2020-10-15 14:19:02 +08:00
# 脚本快捷方式
2021-01-14 17:28:13 +08:00
aliasInstall( ) {
2022-03-24 17:23:03 +08:00
if [ [ -f " $HOME /install.sh " ] ] && [ [ -d "/etc/v2ray-agent" ] ] && grep <" $HOME /install.sh " -q "作者:mack-a" ; then
2021-01-14 17:28:13 +08:00
mv " $HOME /install.sh " /etc/v2ray-agent/install.sh
2021-07-02 21:57:39 +08:00
local vasmaType =
2021-09-03 15:19:21 +08:00
if [ [ -d "/usr/bin/" ] ] ; then
if [ [ ! -f "/usr/bin/vasma" ] ] ; then
2021-07-02 21:57:39 +08:00
ln -s /etc/v2ray-agent/install.sh /usr/bin/vasma
chmod 700 /usr/bin/vasma
vasmaType = true
fi
2021-01-14 17:28:13 +08:00
rm -rf " $HOME /install.sh "
2021-09-03 15:19:21 +08:00
elif [ [ -d "/usr/sbin" ] ] ; then
if [ [ ! -f "/usr/sbin/vasma" ] ] ; then
2021-07-02 21:57:39 +08:00
ln -s /etc/v2ray-agent/install.sh /usr/sbin/vasma
chmod 700 /usr/sbin/vasma
vasmaType = true
fi
2021-01-14 17:28:13 +08:00
rm -rf " $HOME /install.sh "
fi
2021-09-03 15:19:21 +08:00
if [ [ " ${ vasmaType } " = = "true" ] ] ; then
2021-07-02 21:57:39 +08:00
echoContent green "快捷方式创建成功,可执行[vasma]重新打开脚本"
fi
2021-01-14 17:28:13 +08:00
fi
2020-10-15 14:19:02 +08:00
}
2020-11-25 17:06:40 +08:00
2020-12-18 17:40:05 +08:00
# 检查ipv6、ipv4
2021-01-14 17:28:13 +08:00
checkIPv6( ) {
2021-11-08 11:14:27 +08:00
# pingIPv6=$(ping6 -c 1 www.google.com | sed '2{s/[^(]*(//;s/).*//;q;}' | tail -n +2)
pingIPv6 = $( ping6 -c 1 www.google.com | sed -n '1p' | sed 's/.*(//g;s/).*//g' )
2021-01-14 17:28:13 +08:00
if [ [ -z " ${ pingIPv6 } " ] ] ; then
echoContent red " ---> 不支持ipv6"
2021-03-12 15:38:33 +08:00
exit 0
2021-01-14 17:28:13 +08:00
fi
2020-12-18 17:40:05 +08:00
}
2021-06-15 16:27:56 +08:00
# ipv6 分流
2021-04-12 17:11:52 +08:00
ipv6Routing( ) {
2021-01-14 17:28:13 +08:00
if [ [ -z " ${ configPath } " ] ] ; then
echoContent red " ---> 未安装,请使用脚本安装"
menu
2021-03-12 15:38:33 +08:00
exit 0
2021-01-14 17:28:13 +08:00
fi
checkIPv6
2021-04-12 17:11:52 +08:00
echoContent skyBlue " \n功能 1/ ${ totalProgress } : IPv6分流 "
2021-01-14 17:28:13 +08:00
echoContent red "\n=============================================================="
2021-04-12 17:11:52 +08:00
echoContent yellow "1.添加域名"
echoContent yellow "2.卸载IPv6分流"
echoContent red "=============================================================="
2021-01-14 17:28:13 +08:00
read -r -p "请选择:" ipv6Status
if [ [ " ${ ipv6Status } " = = "1" ] ] ; then
2021-04-12 17:11:52 +08:00
echoContent red "=============================================================="
echoContent yellow "# 注意事项\n"
echoContent yellow "1.规则仅支持预定义域名列表[https://github.com/v2fly/domain-list-community]"
echoContent yellow "2.详细文档[https://www.v2fly.org/config/routing.html]"
echoContent yellow "3.如内核启动失败请检查域名后重新添加域名"
echoContent yellow "4.不允许有特殊字符,注意逗号的格式"
echoContent yellow "5.每次添加都是重新添加,不会保留上次域名"
2022-10-27 23:45:06 +08:00
echoContent yellow "6.强烈建议屏蔽国内的网站, 下方输入【cn】即可屏蔽"
echoContent yellow "7.录入示例:google,youtube,facebook,cn\n"
2021-09-03 15:19:21 +08:00
read -r -p "请按照上面示例录入域名:" domainList
2021-04-12 17:11:52 +08:00
2021-09-03 15:19:21 +08:00
if [ [ -f " ${ configPath } 09_routing.json " ] ] ; then
2021-06-21 17:36:04 +08:00
2022-02-03 21:45:03 +08:00
unInstallRouting IPv6-out outboundTag
2021-06-15 16:27:56 +08:00
2021-09-03 15:19:21 +08:00
routing = $( jq -r " .routing.rules += [{\"type\":\"field\",\"domain\":[\"geosite: ${ domainList //,/ \" , \" geosite : } \"],\"outboundTag\":\"IPv6-out\"}] " ${ configPath } 09_routing.json)
2021-06-15 16:27:56 +08:00
2021-09-03 15:19:21 +08:00
echo " ${ routing } " | jq . >${ configPath } 09_routing.json
2021-06-21 17:36:04 +08:00
2021-06-15 16:27:56 +08:00
else
2021-09-03 15:19:21 +08:00
cat <<EOF >" ${ configPath } 09_routing.json "
2020-12-18 17:40:05 +08:00
{
"routing" :{
2020-12-23 10:37:32 +08:00
"domainStrategy" : "IPOnDemand" ,
2020-12-18 17:40:05 +08:00
"rules" : [
{
"type" : "field" ,
"domain" : [
2021-04-12 17:11:52 +08:00
" geosite: ${ domainList //,/ \" , \" geosite : } "
2020-12-18 17:40:05 +08:00
] ,
2021-04-12 17:11:52 +08:00
"outboundTag" : "IPv6-out"
2020-12-18 17:40:05 +08:00
}
]
}
}
EOF
2021-09-03 15:19:21 +08:00
fi
2020-12-18 17:40:05 +08:00
2021-06-21 17:36:04 +08:00
unInstallOutbounds IPv6-out
outbounds = $( jq -r '.outbounds += [{"protocol":"freedom","settings":{"domainStrategy":"UseIPv6"},"tag":"IPv6-out"}]' ${ configPath } 10_ipv4_outbounds.json)
2021-09-03 15:19:21 +08:00
echo " ${ outbounds } " | jq . >${ configPath } 10_ipv4_outbounds.json
2021-06-21 17:36:04 +08:00
2021-04-12 17:11:52 +08:00
echoContent green " ---> 添加成功"
2020-12-28 15:12:53 +08:00
2021-01-14 17:28:13 +08:00
elif [ [ " ${ ipv6Status } " = = "2" ] ] ; then
2020-12-28 15:12:53 +08:00
2022-02-03 21:45:03 +08:00
unInstallRouting IPv6-out outboundTag
2021-06-21 17:36:04 +08:00
unInstallOutbounds IPv6-out
2021-06-15 16:27:56 +08:00
echoContent green " ---> IPv6分流卸载成功"
2021-01-14 17:28:13 +08:00
else
echoContent red " ---> 选择错误"
2021-03-12 15:38:33 +08:00
exit 0
2021-01-14 17:28:13 +08:00
fi
2020-12-28 15:12:53 +08:00
2021-03-04 16:15:53 +08:00
reloadCore
2020-12-18 17:40:05 +08:00
}
2021-07-16 17:09:55 +08:00
# bt下载管理
btTools( ) {
if [ [ -z " ${ configPath } " ] ] ; then
echoContent red " ---> 未安装,请使用脚本安装"
menu
exit 0
fi
echoContent skyBlue " \n功能 1/ ${ totalProgress } : bt下载管理 "
echoContent red "\n=============================================================="
2021-09-03 15:19:21 +08:00
if [ [ -f ${ configPath } 09_routing.json ] ] && grep -q bittorrent <${ configPath } 09_routing.json; then
2022-03-24 17:23:03 +08:00
echoContent yellow "当前状态:已禁用"
2021-07-16 17:09:55 +08:00
else
2022-03-24 17:23:03 +08:00
echoContent yellow "当前状态:未禁用"
2021-07-16 17:09:55 +08:00
fi
echoContent yellow "1.禁用"
echoContent yellow "2.打开"
echoContent red "=============================================================="
read -r -p "请选择:" btStatus
if [ [ " ${ btStatus } " = = "1" ] ] ; then
2021-09-03 15:19:21 +08:00
if [ [ -f " ${ configPath } 09_routing.json " ] ] ; then
2021-07-16 17:09:55 +08:00
2022-02-03 21:45:03 +08:00
unInstallRouting blackhole-out outboundTag
2021-07-16 17:09:55 +08:00
routing = $( jq -r '.routing.rules += [{"type":"field","outboundTag":"blackhole-out","protocol":["bittorrent"]}]' ${ configPath } 09_routing.json)
2021-09-03 15:19:21 +08:00
echo " ${ routing } " | jq . >${ configPath } 09_routing.json
2021-07-16 17:09:55 +08:00
else
cat <<EOF >${ configPath } 09_routing.json
{
"routing" :{
"domainStrategy" : "IPOnDemand" ,
"rules" : [
{
"type" : "field" ,
"outboundTag" : "blackhole-out" ,
"protocol" : [ "bittorrent" ]
}
]
}
}
EOF
2021-09-03 15:19:21 +08:00
fi
2021-07-16 17:09:55 +08:00
installSniffing
unInstallOutbounds blackhole-out
outbounds = $( jq -r '.outbounds += [{"protocol":"blackhole","tag":"blackhole-out"}]' ${ configPath } 10_ipv4_outbounds.json)
2021-09-03 15:19:21 +08:00
echo " ${ outbounds } " | jq . >${ configPath } 10_ipv4_outbounds.json
2021-07-16 17:09:55 +08:00
echoContent green " ---> BT下载禁用成功"
elif [ [ " ${ btStatus } " = = "2" ] ] ; then
unInstallSniffing
2022-01-29 18:06:56 +08:00
unInstallRouting blackhole-out outboundTag bittorrent
2021-07-16 17:09:55 +08:00
2022-01-29 18:06:56 +08:00
# unInstallOutbounds blackhole-out
2021-07-16 17:09:55 +08:00
echoContent green " ---> BT下载打开成功"
else
echoContent red " ---> 选择错误"
exit 0
fi
reloadCore
}
2022-01-29 18:06:56 +08:00
# 域名黑名单
blacklist( ) {
if [ [ -z " ${ configPath } " ] ] ; then
echoContent red " ---> 未安装,请使用脚本安装"
menu
exit 0
fi
echoContent skyBlue " \n进度 $1 / ${ totalProgress } : 域名黑名单 "
echoContent red "\n=============================================================="
echoContent yellow "1.添加域名"
echoContent yellow "2.删除黑名单"
echoContent red "=============================================================="
read -r -p "请选择:" blacklistStatus
if [ [ " ${ blacklistStatus } " = = "1" ] ] ; then
echoContent red "=============================================================="
echoContent yellow "# 注意事项\n"
echoContent yellow "1.规则仅支持预定义域名列表[https://github.com/v2fly/domain-list-community]"
echoContent yellow "2.详细文档[https://www.v2fly.org/config/routing.html]"
echoContent yellow "3.如内核启动失败请检查域名后重新添加域名"
echoContent yellow "4.不允许有特殊字符,注意逗号的格式"
echoContent yellow "5.每次添加都是重新添加,不会保留上次域名"
echoContent yellow "6.录入示例:speedtest,facebook\n"
read -r -p "请按照上面示例录入域名:" domainList
if [ [ -f " ${ configPath } 09_routing.json " ] ] ; then
unInstallRouting blackhole-out outboundTag
routing = $( jq -r " .routing.rules += [{\"type\":\"field\",\"domain\":[\"geosite: ${ domainList //,/ \" , \" geosite : } \"],\"outboundTag\":\"blackhole-out\"}] " ${ configPath } 09_routing.json)
echo " ${ routing } " | jq . >${ configPath } 09_routing.json
else
cat <<EOF >${ configPath } 09_routing.json
{
"routing" :{
"domainStrategy" : "IPOnDemand" ,
"rules" : [
{
"type" : "field" ,
"domain" : [
" geosite: ${ domainList //,/ \" , \" geosite : } "
] ,
"outboundTag" : "blackhole-out"
}
]
}
}
EOF
fi
echoContent green " ---> 添加成功"
elif [ [ " ${ blacklistStatus } " = = "2" ] ] ; then
unInstallRouting blackhole-out outboundTag
echoContent green " ---> 域名黑名单删除成功"
else
echoContent red " ---> 选择错误"
exit 0
fi
reloadCore
}
2021-06-21 17:36:04 +08:00
# 根据tag卸载Routing
2021-09-03 15:19:21 +08:00
unInstallRouting( ) {
2021-06-21 17:36:04 +08:00
local tag = $1
2021-12-16 16:55:28 +08:00
local type = $2
2022-01-29 18:06:56 +08:00
local protocol = $3
2021-06-21 17:36:04 +08:00
2021-09-03 15:19:21 +08:00
if [ [ -f " ${ configPath } 09_routing.json " ] ] ; then
local routing
2021-12-16 16:55:28 +08:00
if grep -q " ${ tag } " ${ configPath } 09_routing.json && grep -q " ${ type } " ${ configPath } 09_routing.json; then
jq -c .routing.rules[ ] ${ configPath } 09_routing.json | while read -r line; do
local index = $(( index + 1 ))
local delStatus = 0
if [ [ " ${ type } " = = "outboundTag" ] ] && echo " ${ line } " | jq .outboundTag | grep -q " ${ tag } " ; then
delStatus = 1
elif [ [ " ${ type } " = = "inboundTag" ] ] && echo " ${ line } " | jq .inboundTag | grep -q " ${ tag } " ; then
delStatus = 1
fi
2022-01-29 18:06:56 +08:00
if [ [ -n ${ protocol } ] ] && echo " ${ line } " | jq .protocol | grep -q " ${ protocol } " ; then
delStatus = 1
elif [ [ -z ${ protocol } ] ] && [ [ $( echo " ${ line } " | jq .protocol) != "null" ] ] ; then
delStatus = 0
fi
2021-12-16 16:55:28 +08:00
if [ [ ${ delStatus } = = 1 ] ] ; then
routing = $( jq -r 'del(.routing.rules[' " $(( " ${ index } " - 1 )) " '])' ${ configPath } 09_routing.json)
echo " ${ routing } " | jq . >${ configPath } 09_routing.json
fi
done
2021-06-21 17:36:04 +08:00
fi
fi
}
# 根据tag卸载出站
2021-09-03 15:19:21 +08:00
unInstallOutbounds( ) {
2021-06-21 17:36:04 +08:00
local tag = $1
2021-09-03 15:19:21 +08:00
if grep -q " ${ tag } " ${ configPath } 10_ipv4_outbounds.json; then
local ipv6OutIndex
ipv6OutIndex = $( jq .outbounds[ ] .tag ${ configPath } 10_ipv4_outbounds.json | awk '{print ""NR""":"$0}' | grep " ${ tag } " | awk -F "[:]" '{print $1}' | head -1)
if [ [ ${ ipv6OutIndex } -gt 0 ] ] ; then
routing = $( jq -r 'del(.outbounds[' $(( " ${ ipv6OutIndex } " - 1 )) '])' ${ configPath } 10_ipv4_outbounds.json)
echo " ${ routing } " | jq . >${ configPath } 10_ipv4_outbounds.json
2021-06-21 17:36:04 +08:00
fi
fi
}
2021-07-16 17:09:55 +08:00
# 卸载嗅探
2021-09-03 15:19:21 +08:00
unInstallSniffing( ) {
find ${ configPath } -name "*inbounds.json*" | awk -F "[c][o][n][f][/]" '{print $2}' | while read -r inbound; do
sniffing = $( jq -r 'del(.inbounds[0].sniffing)' " ${ configPath } ${ inbound } " )
echo " ${ sniffing } " | jq . >" ${ configPath } ${ inbound } "
2021-07-16 17:09:55 +08:00
done
}
# 安装嗅探
2021-09-03 15:19:21 +08:00
installSniffing( ) {
find ${ configPath } -name "*inbounds.json*" | awk -F "[c][o][n][f][/]" '{print $2}' | while read -r inbound; do
sniffing = $( jq -r '.inbounds[0].sniffing = {"enabled":true,"destOverride":["http","tls"]}' " ${ configPath } ${ inbound } " )
echo " ${ sniffing } " | jq . >" ${ configPath } ${ inbound } "
2021-07-16 17:09:55 +08:00
done
}
2021-06-21 17:36:04 +08:00
# warp分流
2021-09-03 15:19:21 +08:00
warpRouting( ) {
2021-06-21 17:36:04 +08:00
echoContent skyBlue " \n进度 $1 / ${ totalProgress } : WARP分流 "
2021-08-11 17:09:26 +08:00
echoContent red "=============================================================="
2022-01-29 18:06:56 +08:00
# echoContent yellow "# 注意事项\n"
# echoContent yellow "1.官方warp经过几轮测试有bug, 重启会导致warp失效, 并且无法启动, 也有可能CPU使用率暴涨"
# echoContent yellow "2.不重启机器可正常使用, 如果非要使用官方warp, 建议不重启机器"
# echoContent yellow "3.有的机器重启后仍正常使用"
# echoContent yellow "4.重启后无法使用,也可卸载重新安装"
2021-06-21 17:36:04 +08:00
# 安装warp
2021-09-03 15:19:21 +08:00
if [ [ -z $( which warp-cli) ] ] ; then
2021-06-21 17:36:04 +08:00
echo
2021-06-22 11:58:56 +08:00
read -r -p "WARP未安装, 是否安装 ? [y/n]:" installCloudflareWarpStatus
2021-09-03 15:19:21 +08:00
if [ [ " ${ installCloudflareWarpStatus } " = = "y" ] ] ; then
2021-06-21 17:36:04 +08:00
installWarp
else
echoContent yellow " ---> 放弃安装"
exit 0
fi
fi
echoContent red "\n=============================================================="
echoContent yellow "1.添加域名"
echoContent yellow "2.卸载WARP分流"
echoContent red "=============================================================="
read -r -p "请选择:" warpStatus
if [ [ " ${ warpStatus } " = = "1" ] ] ; then
echoContent red "=============================================================="
echoContent yellow "# 注意事项\n"
echoContent yellow "1.规则仅支持预定义域名列表[https://github.com/v2fly/domain-list-community]"
echoContent yellow "2.详细文档[https://www.v2fly.org/config/routing.html]"
echoContent yellow "3.只可以把流量分流给warp, 不可指定是ipv4或者ipv6"
echoContent yellow "4.如内核启动失败请检查域名后重新添加域名"
echoContent yellow "5.不允许有特殊字符,注意逗号的格式"
echoContent yellow "6.每次添加都是重新添加,不会保留上次域名"
echoContent yellow "7.录入示例:google,youtube,facebook\n"
2021-09-03 15:19:21 +08:00
read -r -p "请按照上面示例录入域名:" domainList
2021-06-21 17:36:04 +08:00
2021-09-03 15:19:21 +08:00
if [ [ -f " ${ configPath } 09_routing.json " ] ] ; then
2021-12-16 16:55:28 +08:00
unInstallRouting warp-socks-out outboundTag
2021-06-21 17:36:04 +08:00
2021-09-03 15:19:21 +08:00
routing = $( jq -r " .routing.rules += [{\"type\":\"field\",\"domain\":[\"geosite: ${ domainList //,/ \" , \" geosite : } \"],\"outboundTag\":\"warp-socks-out\"}] " ${ configPath } 09_routing.json)
2021-06-21 17:36:04 +08:00
2021-09-03 15:19:21 +08:00
echo " ${ routing } " | jq . >${ configPath } 09_routing.json
2021-06-21 17:36:04 +08:00
else
cat <<EOF >${ configPath } 09_routing.json
{
"routing" :{
"domainStrategy" : "IPOnDemand" ,
"rules" : [
{
"type" : "field" ,
"domain" : [
" geosite: ${ domainList //,/ \" , \" geosite : } "
] ,
"outboundTag" : "warp-socks-out"
}
]
}
}
EOF
fi
unInstallOutbounds warp-socks-out
2021-09-03 15:19:21 +08:00
local outbounds
outbounds = $( jq -r '.outbounds += [{"protocol":"socks","settings":{"servers":[{"address":"127.0.0.1","port":31303}]},"tag":"warp-socks-out"}]' ${ configPath } 10_ipv4_outbounds.json)
2021-06-21 17:36:04 +08:00
2021-09-03 15:19:21 +08:00
echo " ${ outbounds } " | jq . >${ configPath } 10_ipv4_outbounds.json
2021-06-21 17:36:04 +08:00
echoContent green " ---> 添加成功"
elif [ [ " ${ warpStatus } " = = "2" ] ] ; then
2021-08-11 17:09:26 +08:00
${ removeType } cloudflare-warp >/dev/null 2>& 1
2021-12-16 16:55:28 +08:00
unInstallRouting warp-socks-out outboundTag
2021-06-21 17:36:04 +08:00
unInstallOutbounds warp-socks-out
echoContent green " ---> WARP分流卸载成功"
else
echoContent red " ---> 选择错误"
exit 0
fi
reloadCore
}
2021-02-24 15:57:51 +08:00
# 流媒体工具箱
streamingToolbox( ) {
echoContent skyBlue " \n功能 1/ ${ totalProgress } : 流媒体工具箱 "
echoContent red "\n=============================================================="
2021-09-03 15:19:21 +08:00
# echoContent yellow "1.Netflix检测"
2021-12-16 16:55:28 +08:00
echoContent yellow "1.任意门落地机解锁流媒体"
2021-08-16 17:19:32 +08:00
echoContent yellow "2.DNS解锁流媒体"
2022-05-02 01:03:05 +08:00
echoContent yellow "3.VMess+WS+TLS解锁流媒体"
2021-02-24 15:57:51 +08:00
read -r -p "请选择:" selectType
case ${ selectType } in
1)
2021-12-16 16:55:28 +08:00
dokodemoDoorUnblockStreamingMedia
2021-02-24 15:57:51 +08:00
; ;
2021-08-16 17:19:32 +08:00
2)
2021-03-04 17:35:55 +08:00
dnsUnlockNetflix
; ;
2022-05-02 01:03:05 +08:00
3)
unblockVMessWSTLSStreamingMedia
; ;
2021-02-24 15:57:51 +08:00
esac
2021-02-24 16:28:27 +08:00
2021-02-24 15:57:51 +08:00
}
2021-12-16 16:55:28 +08:00
# 任意门解锁流媒体
dokodemoDoorUnblockStreamingMedia( ) {
echoContent skyBlue " \n功能 1/ ${ totalProgress } : 任意门落地机解锁流媒体 "
2021-02-24 15:57:51 +08:00
echoContent red "\n=============================================================="
2021-03-04 16:15:53 +08:00
echoContent yellow "# 注意事项"
echoContent yellow "任意门解锁详解,请查看此文章[https://github.com/mack-a/v2ray-agent/blob/master/documents/netflix/dokodemo-unblock_netflix.md]\n"
echoContent yellow "1.添加出站"
echoContent yellow "2.添加入站"
echoContent yellow "3.卸载"
2021-02-24 15:57:51 +08:00
read -r -p "请选择:" selectType
case ${ selectType } in
1)
2021-12-16 16:55:28 +08:00
setDokodemoDoorUnblockStreamingMediaOutbounds
2021-02-24 15:57:51 +08:00
; ;
2)
2021-12-16 16:55:28 +08:00
setDokodemoDoorUnblockStreamingMediaInbounds
2021-03-04 16:15:53 +08:00
; ;
3)
2021-12-16 16:55:28 +08:00
removeDokodemoDoorUnblockStreamingMedia
2021-02-24 15:57:51 +08:00
; ;
esac
}
2022-05-02 01:03:05 +08:00
# VMess+WS+TLS 出战解锁流媒体【仅出站】
unblockVMessWSTLSStreamingMedia( ) {
echoContent skyBlue " \n功能 1/ ${ totalProgress } : VMess+WS+TLS 出站解锁流媒体 "
echoContent red "\n=============================================================="
echoContent yellow "# 注意事项"
echoContent yellow "适合通过其他服务商提供的VMess解锁服务\n"
echoContent yellow "1.添加出站"
echoContent yellow "2.卸载"
read -r -p "请选择:" selectType
case ${ selectType } in
1)
setVMessWSTLSUnblockStreamingMediaOutbounds
; ;
2)
removeVMessWSTLSUnblockStreamingMedia
; ;
esac
}
# 设置VMess+WS+TLS解锁Netflix【仅出站】
setVMessWSTLSUnblockStreamingMediaOutbounds( ) {
read -r -p "请输入解锁流媒体VMess+WS+TLS的地址:" setVMessWSTLSAddress
echoContent red "=============================================================="
echoContent yellow "# 注意事项\n"
echoContent yellow "1.规则仅支持预定义域名列表[https://github.com/v2fly/domain-list-community]"
echoContent yellow "2.详细文档[https://www.v2fly.org/config/routing.html]"
echoContent yellow "3.如内核启动失败请检查域名后重新添加域名"
echoContent yellow "4.不允许有特殊字符,注意逗号的格式"
echoContent yellow "5.每次添加都是重新添加,不会保留上次域名"
echoContent yellow "6.录入示例:netflix,disney,hulu\n"
read -r -p "请按照上面示例录入域名:" domainList
if [ [ -z ${ domainList } ] ] ; then
echoContent red " ---> 域名不可为空"
setVMessWSTLSUnblockStreamingMediaOutbounds
fi
if [ [ -n " ${ setVMessWSTLSAddress } " ] ] ; then
unInstallOutbounds VMess-out
echo
read -r -p "请输入VMess+WS+TLS的端口:" setVMessWSTLSPort
echo
if [ [ -z " ${ setVMessWSTLSPort } " ] ] ; then
echoContent red " ---> 端口不可为空"
fi
read -r -p "请输入VMess+WS+TLS的UUID:" setVMessWSTLSUUID
echo
if [ [ -z " ${ setVMessWSTLSUUID } " ] ] ; then
echoContent red " ---> UUID不可为空"
fi
read -r -p "请输入VMess+WS+TLS的Path路径:" setVMessWSTLSPath
echo
if [ [ -z " ${ setVMessWSTLSPath } " ] ] ; then
echoContent red " ---> 路径不可为空"
fi
outbounds = $( jq -r " .outbounds += [{\"tag\":\"VMess-out\",\"protocol\":\"vmess\",\"streamSettings\":{\"network\":\"ws\",\"security\":\"tls\",\"tlsSettings\":{\"allowInsecure\":false},\"wsSettings\":{\"path\":\" ${ setVMessWSTLSPath } \"}},\"mux\":{\"enabled\":true,\"concurrency\":8},\"settings\":{\"vnext\":[{\"address\":\" ${ setVMessWSTLSAddress } \",\"port\": ${ setVMessWSTLSPort } ,\"users\":[{\"id\":\" ${ setVMessWSTLSUUID } \",\"security\":\"auto\",\"alterId\":0}]}]}}] " ${ configPath } 10_ipv4_outbounds.json)
echo " ${ outbounds } " | jq . >${ configPath } 10_ipv4_outbounds.json
if [ [ -f " ${ configPath } 09_routing.json " ] ] ; then
unInstallRouting VMess-out outboundTag
local routing
routing = $( jq -r " .routing.rules += [{\"type\":\"field\",\"domain\":[\"ip.sb\",\"geosite: ${ domainList //,/ \" , \" geosite : } \"],\"outboundTag\":\"VMess-out\"}] " ${ configPath } 09_routing.json)
echo " ${ routing } " | jq . >${ configPath } 09_routing.json
else
cat <<EOF >${ configPath } 09_routing.json
{
"routing" : {
"rules" : [
{
"type" : "field" ,
"domain" : [
"ip.sb" ,
" geosite: ${ domainList //,/ \" , \" geosite : } "
] ,
"outboundTag" : "VMess-out"
}
]
}
}
EOF
fi
reloadCore
echoContent green " ---> 添加出站解锁成功"
exit 0
fi
echoContent red " ---> 地址不可为空"
setVMessWSTLSUnblockStreamingMediaOutbounds
}
2021-03-04 16:15:53 +08:00
# 设置任意门解锁Netflix【出站】
2021-12-16 16:55:28 +08:00
setDokodemoDoorUnblockStreamingMediaOutbounds( ) {
read -r -p "请输入解锁流媒体 vps的IP:" setIP
echoContent red "=============================================================="
echoContent yellow "# 注意事项\n"
echoContent yellow "1.规则仅支持预定义域名列表[https://github.com/v2fly/domain-list-community]"
echoContent yellow "2.详细文档[https://www.v2fly.org/config/routing.html]"
echoContent yellow "3.如内核启动失败请检查域名后重新添加域名"
echoContent yellow "4.不允许有特殊字符,注意逗号的格式"
echoContent yellow "5.每次添加都是重新添加,不会保留上次域名"
echoContent yellow "6.录入示例:netflix,disney,hulu\n"
read -r -p "请按照上面示例录入域名:" domainList
2022-02-03 21:45:03 +08:00
if [ [ -z ${ domainList } ] ] ; then
echoContent red " ---> 域名不可为空"
setDokodemoDoorUnblockStreamingMediaOutbounds
fi
2021-03-04 16:15:53 +08:00
if [ [ -n " ${ setIP } " ] ] ; then
2021-06-21 17:36:04 +08:00
2021-12-16 16:55:28 +08:00
unInstallOutbounds streamingMedia-80
unInstallOutbounds streamingMedia-443
2021-06-21 17:36:04 +08:00
2021-12-16 16:55:28 +08:00
outbounds = $( jq -r " .outbounds += [{\"tag\":\"streamingMedia-80\",\"protocol\":\"freedom\",\"settings\":{\"domainStrategy\":\"AsIs\",\"redirect\":\" ${ setIP } :22387\"}},{\"tag\":\"streamingMedia-443\",\"protocol\":\"freedom\",\"settings\":{\"domainStrategy\":\"AsIs\",\"redirect\":\" ${ setIP } :22388\"}}] " ${ configPath } 10_ipv4_outbounds.json)
2021-06-21 17:36:04 +08:00
2021-09-03 15:19:21 +08:00
echo " ${ outbounds } " | jq . >${ configPath } 10_ipv4_outbounds.json
2021-06-21 17:36:04 +08:00
2021-09-03 15:19:21 +08:00
if [ [ -f " ${ configPath } 09_routing.json " ] ] ; then
2021-12-16 16:55:28 +08:00
unInstallRouting streamingMedia-80 outboundTag
unInstallRouting streamingMedia-443 outboundTag
2021-06-15 16:27:56 +08:00
2021-09-03 15:19:21 +08:00
local routing
2021-12-16 16:55:28 +08:00
routing = $( jq -r " .routing.rules += [{\"type\":\"field\",\"port\":80,\"domain\":[\"ip.sb\",\"geosite: ${ domainList //,/ \" , \" geosite : } \"],\"outboundTag\":\"streamingMedia-80\"},{\"type\":\"field\",\"port\":443,\"domain\":[\"ip.sb\",\"geosite: ${ domainList //,/ \" , \" geosite : } \"],\"outboundTag\":\"streamingMedia-443\"}] " ${ configPath } 09_routing.json)
2021-09-03 15:19:21 +08:00
echo " ${ routing } " | jq . >${ configPath } 09_routing.json
2021-06-15 16:27:56 +08:00
else
cat <<EOF >${ configPath } 09_routing.json
2021-02-24 15:57:51 +08:00
{
2021-03-04 16:15:53 +08:00
"routing" : {
"domainStrategy" : "AsIs" ,
"rules" : [
{
"type" : "field" ,
"port" : 80,
"domain" : [
"ip.sb" ,
2021-12-16 16:55:28 +08:00
" geosite: ${ domainList //,/ \" , \" geosite : } "
2021-03-04 16:15:53 +08:00
] ,
2021-12-16 16:55:28 +08:00
"outboundTag" : "streamingMedia-80"
2021-03-04 16:15:53 +08:00
} ,
{
"type" : "field" ,
"port" : 443,
"domain" : [
"ip.sb" ,
2021-12-16 16:55:28 +08:00
" geosite: ${ domainList //,/ \" , \" geosite : } "
2021-03-04 16:15:53 +08:00
] ,
2021-12-16 16:55:28 +08:00
"outboundTag" : "streamingMedia-443"
2021-03-04 16:15:53 +08:00
}
]
}
2021-02-24 15:57:51 +08:00
}
EOF
2021-06-15 16:27:56 +08:00
fi
2021-03-04 16:15:53 +08:00
reloadCore
2021-12-16 16:55:28 +08:00
echoContent green " ---> 添加出站解锁成功"
2021-03-12 15:38:33 +08:00
exit 0
2021-03-04 16:15:53 +08:00
fi
echoContent red " ---> ip不可为空"
}
2021-02-24 15:57:51 +08:00
2021-03-04 16:15:53 +08:00
# 设置任意门解锁Netflix【入站】
2021-12-16 16:55:28 +08:00
setDokodemoDoorUnblockStreamingMediaInbounds( ) {
2021-05-28 16:01:49 +08:00
echoContent skyBlue " \n功能 1/ ${ totalProgress } : 任意门添加入站 "
echoContent red "\n=============================================================="
echoContent yellow "# 注意事项\n"
2021-12-16 16:55:28 +08:00
echoContent yellow "1.规则仅支持预定义域名列表[https://github.com/v2fly/domain-list-community]"
echoContent yellow "2.详细文档[https://www.v2fly.org/config/routing.html]"
echoContent yellow "3.如内核启动失败请检查域名后重新添加域名"
echoContent yellow "4.不允许有特殊字符,注意逗号的格式"
echoContent yellow "5.每次添加都是重新添加,不会保留上次域名"
echoContent yellow "6.ip录入示例:1.1.1.1,1.1.1.2"
echoContent yellow "7.下面的域名一定要和出站的vps一致"
2022-04-21 17:07:44 +08:00
# echoContent yellow "8.如有防火墙请手动开启22387、22388端口"
echoContent yellow "8.域名录入示例:netflix,disney,hulu\n"
2021-12-16 16:55:28 +08:00
read -r -p "请输入允许访问该解锁 vps的IP:" setIPs
2021-05-28 16:01:49 +08:00
if [ [ -n " ${ setIPs } " ] ] ; then
2021-12-16 16:55:28 +08:00
read -r -p "请按照上面示例录入域名:" domainList
2022-04-21 17:07:44 +08:00
allowPort 22387
allowPort 22388
2021-12-16 16:55:28 +08:00
2021-04-08 17:53:19 +08:00
cat <<EOF >${ configPath } 01_netflix_inbounds.json
2021-03-04 16:15:53 +08:00
{
"inbounds" : [
{
"listen" : "0.0.0.0" ,
"port" : 22387,
"protocol" : "dokodemo-door" ,
"settings" : {
"address" : "0.0.0.0" ,
"port" : 80,
"network" : "tcp" ,
"followRedirect" : false
} ,
"sniffing" : {
"enabled" : true,
"destOverride" : [
"http"
]
} ,
2021-12-16 16:55:28 +08:00
"tag" : "streamingMedia-80"
2021-03-04 16:15:53 +08:00
} ,
{
"listen" : "0.0.0.0" ,
"port" : 22388,
"protocol" : "dokodemo-door" ,
"settings" : {
"address" : "0.0.0.0" ,
"port" : 443,
"network" : "tcp" ,
"followRedirect" : false
} ,
"sniffing" : {
"enabled" : true,
"destOverride" : [
"tls"
]
} ,
2021-12-16 16:55:28 +08:00
"tag" : "streamingMedia-443"
2021-03-04 16:15:53 +08:00
}
]
}
2021-05-28 16:01:49 +08:00
EOF
2021-09-03 15:19:21 +08:00
cat <<EOF >${ configPath } 10_ipv4_outbounds.json
2021-05-28 16:01:49 +08:00
{
2021-06-15 16:27:56 +08:00
"outbounds" :[
{
"protocol" :"freedom" ,
"settings" :{
"domainStrategy" :"UseIPv4"
} ,
"tag" :"IPv4-out"
} ,
{
"protocol" :"freedom" ,
"settings" :{
"domainStrategy" :"UseIPv6"
} ,
"tag" :"IPv6-out"
} ,
{
"protocol" :"blackhole" ,
"tag" :"blackhole-out"
}
]
2021-05-28 16:01:49 +08:00
}
2021-03-04 16:15:53 +08:00
EOF
2021-12-16 16:55:28 +08:00
if [ [ -f " ${ configPath } 09_routing.json " ] ] ; then
unInstallRouting streamingMedia-80 inboundTag
unInstallRouting streamingMedia-443 inboundTag
2021-09-03 15:19:21 +08:00
2021-12-16 16:55:28 +08:00
local routing
routing = $( jq -r " .routing.rules += [{\"source\":[\" ${ setIPs //,/ \" , \" } \"],\"type\":\"field\",\"inboundTag\":[\"streamingMedia-80\",\"streamingMedia-443\"],\"outboundTag\":\"direct\"},{\"domains\":[\"geosite: ${ domainList //,/ \" , \" geosite : } \"],\"type\":\"field\",\"inboundTag\":[\"streamingMedia-80\",\"streamingMedia-443\"],\"outboundTag\":\"blackhole-out\"}] " ${ configPath } 09_routing.json)
2021-09-03 15:19:21 +08:00
echo " ${ routing } " | jq . >${ configPath } 09_routing.json
2021-12-16 16:55:28 +08:00
else
cat <<EOF >${ configPath } 09_routing.json
{
"routing" : {
"rules" : [
{
"source" : [
" ${ setIPs //,/ \" , \" } "
] ,
"type" : "field" ,
"inboundTag" : [
"streamingMedia-80" ,
"streamingMedia-443"
] ,
"outboundTag" : "direct"
} ,
{
"domains" : [
" geosite: ${ domainList //,/ \" , \" geosite : } "
] ,
"type" : "field" ,
"inboundTag" : [
"streamingMedia-80" ,
"streamingMedia-443"
] ,
"outboundTag" : "blackhole-out"
}
]
}
}
EOF
fi
2021-09-03 15:19:21 +08:00
2021-03-04 16:15:53 +08:00
reloadCore
2021-12-16 16:55:28 +08:00
echoContent green " ---> 添加落地机入站解锁成功"
2021-03-12 15:38:33 +08:00
exit 0
2021-02-24 15:57:51 +08:00
fi
2021-03-04 16:15:53 +08:00
echoContent red " ---> ip不可为空"
2021-02-24 15:57:51 +08:00
}
2021-03-04 16:15:53 +08:00
# 移除任意门解锁Netflix
2021-12-16 16:55:28 +08:00
removeDokodemoDoorUnblockStreamingMedia( ) {
unInstallOutbounds streamingMedia-80
unInstallOutbounds streamingMedia-443
unInstallRouting streamingMedia-80 inboundTag
unInstallRouting streamingMedia-443 inboundTag
unInstallRouting streamingMedia-80 outboundTag
unInstallRouting streamingMedia-443 outboundTag
2021-03-18 17:13:16 +08:00
2021-05-28 16:01:49 +08:00
rm -rf ${ configPath } 01_netflix_inbounds.json
2021-03-08 16:02:09 +08:00
2021-03-04 16:15:53 +08:00
reloadCore
echoContent green " ---> 卸载成功"
}
2022-05-02 01:03:05 +08:00
# 移除VMess+WS+TLS解锁流媒体
removeVMessWSTLSUnblockStreamingMedia( ) {
unInstallOutbounds VMess-out
unInstallRouting VMess-out outboundTag
reloadCore
echoContent green " ---> 卸载成功"
}
2021-03-04 16:15:53 +08:00
# 重启核心
reloadCore( ) {
2021-02-24 15:57:51 +08:00
if [ [ " ${ coreInstallType } " = = "1" ] ] ; then
handleXray stop
handleXray start
elif [ [ " ${ coreInstallType } " = = "2" || " ${ coreInstallType } " = = "3" ] ] ; then
handleV2Ray stop
handleV2Ray start
fi
2022-11-08 15:04:46 +08:00
if [ [ -n " ${ hysteriaConfigPath } " ] ] ; then
handleHysteria stop
handleHysteria start
fi
2021-03-04 16:15:53 +08:00
}
2021-02-24 15:57:51 +08:00
2021-03-04 17:35:55 +08:00
# dns解锁Netflix
dnsUnlockNetflix( ) {
2021-11-29 15:47:39 +08:00
if [ [ -z " ${ configPath } " ] ] ; then
echoContent red " ---> 未安装,请使用脚本安装"
menu
exit 0
fi
echoContent skyBlue " \n功能 1/ ${ totalProgress } : DNS解锁流媒体 "
2021-03-04 17:35:55 +08:00
echoContent red "\n=============================================================="
echoContent yellow "1.添加"
echoContent yellow "2.卸载"
read -r -p "请选择:" selectType
case ${ selectType } in
1)
setUnlockDNS
; ;
2)
removeUnlockDNS
; ;
esac
}
# 设置dns
setUnlockDNS( ) {
2021-11-29 15:47:39 +08:00
read -r -p "请输入解锁流媒体DNS:" setDNS
2021-03-04 17:35:55 +08:00
if [ [ -n ${ setDNS } ] ] ; then
2021-11-29 15:47:39 +08:00
echoContent red "=============================================================="
echoContent yellow "# 注意事项\n"
echoContent yellow "1.规则仅支持预定义域名列表[https://github.com/v2fly/domain-list-community]"
echoContent yellow "2.详细文档[https://www.v2fly.org/config/routing.html]"
echoContent yellow "3.如内核启动失败请检查域名后重新添加域名"
echoContent yellow "4.不允许有特殊字符,注意逗号的格式"
echoContent yellow "5.每次添加都是重新添加,不会保留上次域名"
echoContent yellow "6.录入示例:netflix,disney,hulu"
echoContent yellow "7.默认方案请输入1, 默认方案包括以下内容"
echoContent yellow "netflix,bahamut,hulu,hbo,disney,bbc,4chan,fox,abema,dmm,niconico,pixiv,bilibili,viu"
read -r -p "请按照上面示例录入域名:" domainList
2021-12-26 16:36:27 +08:00
if [ [ " ${ domainList } " = = "1" ] ] ; then
2021-11-29 15:47:39 +08:00
cat <<EOF >${ configPath } 11_dns.json
{
"dns" : {
"servers" : [
{
"address" : " ${ setDNS } " ,
"port" : 53,
"domains" : [
"geosite:netflix" ,
"geosite:bahamut" ,
"geosite:hulu" ,
"geosite:hbo" ,
"geosite:disney" ,
"geosite:bbc" ,
"geosite:4chan" ,
"geosite:fox" ,
"geosite:abema" ,
"geosite:dmm" ,
"geosite:niconico" ,
"geosite:pixiv" ,
"geosite:bilibili" ,
"geosite:viu"
]
} ,
"localhost"
]
}
}
2021-03-04 17:35:55 +08:00
EOF
2021-12-16 16:55:28 +08:00
elif [ [ -n " ${ domainList } " ] ] ; then
2021-11-29 15:47:39 +08:00
cat <<EOF >${ configPath } 11_dns.json
{
"dns" : {
"servers" : [
{
"address" : " ${ setDNS } " ,
"port" : 53,
"domains" : [
" geosite: ${ domainList //,/ \" , \" geosite : } "
]
} ,
"localhost"
]
}
}
EOF
fi
2021-04-03 18:46:11 +08:00
reloadCore
2021-03-04 17:35:55 +08:00
echoContent yellow "\n ---> 如还无法观看可以尝试以下两种方案"
echoContent yellow " 1.重启vps"
echoContent yellow " 2.卸载dns解锁后, 修改本地的[/etc/resolv.conf]DNS设置并重启vps\n"
else
echoContent red " ---> dns不可为空"
fi
2021-03-12 15:38:33 +08:00
exit 0
2021-03-04 17:35:55 +08:00
}
# 移除Netflix解锁
removeUnlockDNS( ) {
2021-04-08 17:53:19 +08:00
cat <<EOF >${ configPath } 11_dns.json
2021-03-04 17:35:55 +08:00
{
"dns" : {
"servers" : [
"localhost"
]
}
}
EOF
2021-04-03 18:46:11 +08:00
reloadCore
2021-03-04 17:35:55 +08:00
echoContent green " ---> 卸载成功"
2021-03-12 15:38:33 +08:00
exit 0
2021-03-04 17:35:55 +08:00
}
2020-11-27 14:27:36 +08:00
# v2ray-core个性化安装
2021-01-14 17:28:13 +08:00
customV2RayInstall( ) {
echoContent skyBlue "\n========================个性化安装============================"
2021-12-24 16:29:54 +08:00
echoContent yellow "VLESS前置, 默认安装0, 如果只需要安装0, 则只选择0即可"
echoContent yellow "0.VLESS+TLS/XTLS+TCP"
2021-01-14 17:28:13 +08:00
echoContent yellow "1.VLESS+TLS+WS[CDN]"
2021-12-24 16:29:54 +08:00
echoContent yellow "2.Trojan+TLS+gRPC[CDN]"
2021-01-14 17:28:13 +08:00
echoContent yellow "3.VMess+TLS+WS[CDN]"
2021-06-25 15:57:37 +08:00
echoContent yellow "4.Trojan"
2021-06-10 14:24:36 +08:00
echoContent yellow "5.VLESS+TLS+gRPC[CDN]"
2021-01-14 17:28:13 +08:00
read -r -p "请选择[多选], [例如:123]:" selectCustomInstallType
echoContent skyBlue "--------------------------------------------------------------"
if [ [ -z ${ selectCustomInstallType } ] ] ; then
selectCustomInstallType = 0
fi
2021-06-10 14:24:36 +08:00
if [ [ " ${ selectCustomInstallType } " = ~ ^[ 0-5] +$ ] ] ; then
2021-01-14 17:28:13 +08:00
cleanUp xrayClean
totalProgress = 17
installTools 1
# 申请tls
initTLSNginxConfig 2
installTLS 3
handleNginx stop
# 随机path
2021-01-15 14:27:19 +08:00
if echo ${ selectCustomInstallType } | grep -q 1 || echo ${ selectCustomInstallType } | grep -q 3 || echo ${ selectCustomInstallType } | grep -q 4; then
2021-01-14 17:28:13 +08:00
randomPathFunction 5
customCDNIP 6
fi
nginxBlog 7
updateRedirectNginxConf
handleNginx start
# 安装V2Ray
installV2Ray 8
installV2RayService 9
initV2RayConfig custom 10
cleanUp xrayDel
installCronTLS 14
handleV2Ray stop
handleV2Ray start
# 生成账号
checkGFWStatue 15
showAccounts 16
else
echoContent red " ---> 输入不合法"
customV2RayInstall
fi
2020-11-20 17:57:50 +08:00
}
2020-11-25 17:06:40 +08:00
2020-11-27 14:27:36 +08:00
# Xray-core个性化安装
2021-01-14 17:28:13 +08:00
customXrayInstall( ) {
echoContent skyBlue "\n========================个性化安装============================"
echoContent yellow "VLESS前置, 默认安装0, 如果只需要安装0, 则只选择0即可"
echoContent yellow "0.VLESS+TLS/XTLS+TCP"
echoContent yellow "1.VLESS+TLS+WS[CDN]"
2021-07-01 00:04:12 +08:00
echoContent yellow "2.Trojan+TLS+gRPC[CDN]"
2021-01-14 17:28:13 +08:00
echoContent yellow "3.VMess+TLS+WS[CDN]"
2021-06-25 15:57:37 +08:00
echoContent yellow "4.Trojan"
2021-04-28 16:26:40 +08:00
echoContent yellow "5.VLESS+TLS+gRPC[CDN]"
2021-01-14 17:28:13 +08:00
read -r -p "请选择[多选], [例如:123]:" selectCustomInstallType
echoContent skyBlue "--------------------------------------------------------------"
if [ [ -z ${ selectCustomInstallType } ] ] ; then
echoContent red " ---> 不可为空"
customXrayInstall
2021-04-28 16:26:40 +08:00
elif [ [ " ${ selectCustomInstallType } " = ~ ^[ 0-5] +$ ] ] ; then
2021-01-14 17:28:13 +08:00
cleanUp v2rayClean
totalProgress = 17
installTools 1
# 申请tls
initTLSNginxConfig 2
2022-10-11 16:02:05 +08:00
handleXray stop
handleNginx start
checkIP
2021-01-14 17:28:13 +08:00
installTLS 3
handleNginx stop
# 随机path
2021-07-01 21:09:17 +08:00
if echo " ${ selectCustomInstallType } " | grep -q 1 || echo " ${ selectCustomInstallType } " | grep -q 2 || echo " ${ selectCustomInstallType } " | grep -q 3 || echo " ${ selectCustomInstallType } " | grep -q 5; then
2021-01-14 17:28:13 +08:00
randomPathFunction 5
customCDNIP 6
fi
nginxBlog 7
updateRedirectNginxConf
handleNginx start
# 安装V2Ray
installXray 8
installXrayService 9
initXrayConfig custom 10
cleanUp v2rayDel
2021-06-25 14:36:57 +08:00
2021-01-14 17:28:13 +08:00
installCronTLS 14
handleXray stop
handleXray start
# 生成账号
checkGFWStatue 15
showAccounts 16
else
echoContent red " ---> 输入不合法"
customXrayInstall
fi
2020-11-27 14:27:36 +08:00
}
2021-01-14 17:28:13 +08:00
2021-08-13 11:25:56 +08:00
# 选择核心安装---v2ray-core、xray-core
2021-01-14 17:28:13 +08:00
selectCoreInstall( ) {
echoContent skyBlue " \n功能 1/ ${ totalProgress } : 选择核心安装 "
echoContent red "\n=============================================================="
echoContent yellow "1.Xray-core"
echoContent yellow "2.v2ray-core"
echoContent red "=============================================================="
2021-09-20 01:51:28 +08:00
read -r -p "请选择:" selectCoreType
2021-01-14 17:28:13 +08:00
case ${ selectCoreType } in
2021-05-26 17:27:52 +08:00
1)
2021-01-14 17:28:13 +08:00
if [ [ " ${ selectInstallType } " = = "2" ] ] ; then
customXrayInstall
else
xrayCoreInstall
fi
; ;
2021-05-26 17:27:52 +08:00
2)
2021-01-14 17:28:13 +08:00
v2rayCoreVersion =
if [ [ " ${ selectInstallType } " = = "2" ] ] ; then
customV2RayInstall
else
v2rayCoreInstall
fi
; ;
2021-05-26 17:27:52 +08:00
3)
2021-01-14 17:28:13 +08:00
v2rayCoreVersion = v4.32.1
if [ [ " ${ selectInstallType } " = = "2" ] ] ; then
customV2RayInstall
else
v2rayCoreInstall
fi
; ;
*)
echoContent red ' ---> 选择错误,重新选择'
selectCoreInstall
; ;
esac
2020-11-25 17:06:40 +08:00
}
2020-11-20 17:57:50 +08:00
# v2ray-core 安装
2021-01-14 17:28:13 +08:00
v2rayCoreInstall( ) {
cleanUp xrayClean
selectCustomInstallType =
2021-08-12 18:18:36 +08:00
totalProgress = 13
2021-01-14 17:28:13 +08:00
installTools 2
# 申请tls
initTLSNginxConfig 3
2022-10-11 16:02:05 +08:00
handleV2Ray stop
handleNginx start
checkIP
2021-01-14 17:28:13 +08:00
installTLS 4
handleNginx stop
2021-09-03 15:19:21 +08:00
# initNginxConfig 5
2021-08-12 18:18:36 +08:00
randomPathFunction 5
2021-01-14 17:28:13 +08:00
# 安装V2Ray
2021-08-12 18:18:36 +08:00
installV2Ray 6
installV2RayService 7
customCDNIP 8
initV2RayConfig all 9
2021-01-14 17:28:13 +08:00
cleanUp xrayDel
2021-08-12 18:18:36 +08:00
installCronTLS 10
nginxBlog 11
2021-01-14 17:28:13 +08:00
updateRedirectNginxConf
handleV2Ray stop
sleep 2
handleV2Ray start
handleNginx start
# 生成账号
2021-08-12 18:18:36 +08:00
checkGFWStatue 12
showAccounts 13
2020-11-20 17:57:50 +08:00
}
2020-10-17 00:13:20 +08:00
2020-11-20 17:57:50 +08:00
# xray-core 安装
2021-01-14 17:28:13 +08:00
xrayCoreInstall( ) {
cleanUp v2rayClean
selectCustomInstallType =
2021-08-12 18:18:36 +08:00
totalProgress = 13
2021-01-14 17:28:13 +08:00
installTools 2
# 申请tls
initTLSNginxConfig 3
2022-10-11 16:02:05 +08:00
handleXray stop
handleNginx start
checkIP
2021-01-14 17:28:13 +08:00
installTLS 4
handleNginx stop
2021-08-12 18:18:36 +08:00
randomPathFunction 5
2021-01-14 17:28:13 +08:00
# 安装Xray
2021-09-17 17:46:07 +08:00
# handleV2Ray stop
2021-08-12 18:18:36 +08:00
installXray 6
installXrayService 7
customCDNIP 8
initXrayConfig all 9
2021-01-14 17:28:13 +08:00
cleanUp v2rayDel
2021-08-12 18:18:36 +08:00
installCronTLS 10
nginxBlog 11
2021-01-14 17:28:13 +08:00
updateRedirectNginxConf
handleXray stop
sleep 2
handleXray start
handleNginx start
# 生成账号
2021-08-12 18:18:36 +08:00
checkGFWStatue 12
showAccounts 13
2020-11-20 17:57:50 +08:00
}
2022-11-08 15:04:46 +08:00
# Hysteria安装
hysteriaCoreInstall( ) {
if [ [ -z " ${ coreInstallType } " ] ] ; then
echoContent red "\n ---> 由于环境依赖, 如安装hysteria, 请先安装Xray/V2ray"
menu
exit 0
fi
totalProgress = 5
installHysteria 1
initHysteriaConfig 2
installHysteriaService 3
2022-11-09 14:10:28 +08:00
handleHysteria stop
2022-11-08 15:04:46 +08:00
handleHysteria start
showAccounts 5
}
# 卸载 hysteria
unInstallHysteriaCore( ) {
if [ [ -z " ${ hysteriaConfigPath } " ] ] ; then
echoContent red "\n ---> 未安装"
exit 0
fi
handleHysteria stop
rm -rf /etc/v2ray-agent/hysteria/*
rm -rf /etc/systemd/system/hysteria.service
echoContent green " ---> 卸载完成"
}
2020-11-30 16:34:43 +08:00
# 核心管理
2021-01-14 17:28:13 +08:00
coreVersionManageMenu( ) {
if [ [ -z " ${ coreInstallType } " ] ] ; then
echoContent red "\n ---> 没有检测到安装目录,请执行脚本安装内容"
menu
exit 0
fi
if [ [ " ${ coreInstallType } " = = "1" ] ] ; then
xrayVersionManageMenu 1
elif [ [ " ${ coreInstallType } " = = "2" ] ] ; then
v2rayCoreVersion =
v2rayVersionManageMenu 1
elif [ [ " ${ coreInstallType } " = = "3" ] ] ; then
v2rayCoreVersion = v4.32.1
v2rayVersionManageMenu 1
fi
2020-11-30 16:34:43 +08:00
}
2021-01-11 17:56:57 +08:00
# 定时任务检查证书
2021-01-14 17:28:13 +08:00
cronRenewTLS( ) {
if [ [ " ${ renewTLS } " = = "RenewTLS" ] ] ; then
renewalTLS
exit 0
fi
2021-01-11 17:56:57 +08:00
}
2021-01-18 17:11:48 +08:00
# 账号管理
manageAccount( ) {
echoContent skyBlue " \n功能 1/ ${ totalProgress } : 账号管理 "
echoContent red "\n=============================================================="
2022-11-08 15:04:46 +08:00
echoContent yellow "# 每次删除、添加账号后,需要重新查看订阅生成订阅"
echoContent yellow "# 如安装了Hysteria, 账号会同时添加到Hysteria\n"
2021-01-18 17:11:48 +08:00
echoContent yellow "1.查看账号"
2021-01-18 17:59:35 +08:00
echoContent yellow "2.查看订阅"
2021-01-27 16:24:23 +08:00
echoContent yellow "3.添加用户"
echoContent yellow "4.删除用户"
2021-01-18 17:11:48 +08:00
echoContent red "=============================================================="
read -r -p "请输入:" manageAccountStatus
if [ [ " ${ manageAccountStatus } " = = "1" ] ] ; then
showAccounts 1
elif [ [ " ${ manageAccountStatus } " = = "2" ] ] ; then
subscribe 1
2021-01-27 16:24:23 +08:00
elif [ [ " ${ manageAccountStatus } " = = "3" ] ] ; then
addUser
elif [ [ " ${ manageAccountStatus } " = = "4" ] ] ; then
removeUser
2021-01-18 17:11:48 +08:00
else
2021-01-27 16:24:23 +08:00
echoContent red " ---> 选择错误"
2021-01-18 17:11:48 +08:00
fi
}
2021-01-19 11:47:16 +08:00
2021-01-18 17:11:48 +08:00
# 订阅
subscribe( ) {
2021-01-19 11:47:16 +08:00
if [ [ -n " ${ configPath } " ] ] ; then
2021-03-12 15:38:33 +08:00
echoContent skyBlue "-------------------------备注---------------------------------"
2021-01-27 16:24:23 +08:00
echoContent yellow "# 查看订阅时会重新生成订阅"
echoContent yellow "# 每次添加、删除账号需要重新查看订阅"
2021-01-19 11:47:16 +08:00
rm -rf /etc/v2ray-agent/subscribe/*
2021-01-25 15:32:32 +08:00
rm -rf /etc/v2ray-agent/subscribe_tmp/*
2021-01-19 11:47:16 +08:00
showAccounts >/dev/null
2021-01-25 15:32:32 +08:00
mv /etc/v2ray-agent/subscribe_tmp/* /etc/v2ray-agent/subscribe/
2021-09-06 11:53:02 +08:00
if [ [ -n $( ls /etc/v2ray-agent/subscribe/) ] ] ; then
2021-12-24 16:29:54 +08:00
find /etc/v2ray-agent/subscribe/* | while read -r email; do
2022-05-02 17:36:06 +08:00
email = $( echo " ${ email } " | awk -F "[b][e][/]" '{print $2}' )
2021-09-03 15:19:21 +08:00
local base64Result
base64Result = $( base64 -w 0 " /etc/v2ray-agent/subscribe/ ${ email } " )
echo " ${ base64Result } " >" /etc/v2ray-agent/subscribe/ ${ email } "
2021-01-19 11:47:16 +08:00
echoContent skyBlue "--------------------------------------------------------------"
2022-05-02 22:08:21 +08:00
echoContent yellow " email: ${ email } \n "
2022-04-15 16:35:41 +08:00
local currentDomain = ${ currentHost }
if [ [ -n " ${ currentDefaultPort } " && " ${ currentDefaultPort } " != "443" ] ] ; then
currentDomain = " ${ currentHost } : ${ currentDefaultPort } "
fi
echoContent yellow " url:https:// ${ currentDomain } /s/ ${ email } \n "
echoContent yellow " 在线二维码:https://api.qrserver.com/v1/create-qr-code/?size=400x400&data=https:// ${ currentDomain } /s/ ${ email } \n "
echo " https:// ${ currentDomain } /s/ ${ email } " | qrencode -s 10 -m 1 -t UTF8
2021-01-19 11:47:16 +08:00
echoContent skyBlue "--------------------------------------------------------------"
done
fi
2021-01-18 17:59:35 +08:00
else
2021-01-19 11:47:16 +08:00
echoContent red " ---> 未安装"
2021-01-18 17:59:35 +08:00
fi
2021-01-18 17:11:48 +08:00
}
2021-01-18 17:59:35 +08:00
2021-09-17 17:46:07 +08:00
# 切换alpn
switchAlpn( ) {
echoContent skyBlue " \n功能 1/ ${ totalProgress } : 切换alpn "
if [ [ -z ${ currentAlpn } ] ] ; then
echoContent red " ---> 无法读取alpn, 请检查是否安装"
exit 0
fi
echoContent red "\n=============================================================="
2022-03-24 17:23:03 +08:00
echoContent green " 当前alpn首位为: ${ currentAlpn } "
2021-09-17 17:46:07 +08:00
echoContent yellow " 1.当http/1.1首位时, trojan可用, gRPC部分客户端可用【客户端支持手动选择alpn的可用】"
echoContent yellow " 2.当h2首位时, gRPC可用, trojan部分客户端可用【客户端支持手动选择alpn的可用】"
echoContent yellow " 3.如客户端不支持手动更换alpn, 建议使用此功能更改服务端alpn顺序, 来使用相应的协议"
echoContent red "=============================================================="
if [ [ " ${ currentAlpn } " = = "http/1.1" ] ] ; then
echoContent yellow "1.切换alpn h2 首位"
elif [ [ " ${ currentAlpn } " = = "h2" ] ] ; then
echoContent yellow "1.切换alpn http/1.1 首位"
else
echoContent red '不符合'
fi
echoContent red "=============================================================="
read -r -p "请选择:" selectSwitchAlpnType
if [ [ " ${ selectSwitchAlpnType } " = = "1" && " ${ currentAlpn } " = = "http/1.1" ] ] ; then
2021-09-20 01:51:28 +08:00
local frontingTypeJSON
frontingTypeJSON = $( jq -r ".inbounds[0].streamSettings.xtlsSettings.alpn = [\"h2\",\"http/1.1\"]" ${ configPath } ${ frontingType } .json)
2021-09-17 17:46:07 +08:00
echo " ${ frontingTypeJSON } " | jq . >${ configPath } ${ frontingType } .json
elif [ [ " ${ selectSwitchAlpnType } " = = "1" && " ${ currentAlpn } " = = "h2" ] ] ; then
2021-09-20 01:51:28 +08:00
local frontingTypeJSON
frontingTypeJSON = $( jq -r ".inbounds[0].streamSettings.xtlsSettings.alpn =[\"http/1.1\",\"h2\"]" ${ configPath } ${ frontingType } .json)
2021-09-17 17:46:07 +08:00
echo " ${ frontingTypeJSON } " | jq . >${ configPath } ${ frontingType } .json
else
echoContent red " ---> 选择错误"
2021-09-20 01:51:28 +08:00
exit 0
2021-09-17 17:46:07 +08:00
fi
reloadCore
}
2022-11-08 15:04:46 +08:00
# hysteria管理
manageHysteria( ) {
2022-11-08 17:49:30 +08:00
2022-11-08 15:04:46 +08:00
echoContent skyBlue "\n进度 1/1 : Hysteria管理"
echoContent red "\n=============================================================="
2022-11-08 17:49:30 +08:00
local hysteriaStatus =
if [ [ -n " ${ hysteriaConfigPath } " ] ] ; then
echoContent yellow "1.重新安装"
echoContent yellow "2.卸载"
echoContent yellow "3.更新core"
hysteriaStatus = true
else
echoContent yellow "1.安装"
fi
2022-11-08 15:04:46 +08:00
echoContent red "=============================================================="
read -r -p "请选择:" installHysteriaStatus
if [ [ " ${ installHysteriaStatus } " = = "1" ] ] ; then
hysteriaCoreInstall
2022-11-08 17:49:30 +08:00
elif [ [ " ${ installHysteriaStatus } " = = "2" && " ${ hysteriaStatus } " = = "true" ] ] ; then
2022-11-08 15:04:46 +08:00
unInstallHysteriaCore
2022-11-08 17:49:30 +08:00
elif [ [ " ${ installHysteriaStatus } " = = "3" && " ${ hysteriaStatus } " = = "true" ] ] ; then
2022-11-08 15:04:46 +08:00
installHysteria 1
handleHysteria start
fi
}
2020-11-25 17:06:40 +08:00
# 主菜单
2021-01-14 17:28:13 +08:00
menu( ) {
cd " $HOME " || exit
echoContent red "\n=============================================================="
2022-03-24 17:23:03 +08:00
echoContent green "作者:mack-a"
2022-11-09 14:10:28 +08:00
echoContent green "当前版本:v2.6.8"
2022-03-24 17:23:03 +08:00
echoContent green "Github:https://github.com/mack-a/v2ray-agent"
echoContent green "描述:八合一共存脚本\c"
2021-03-23 15:06:17 +08:00
showInstallStatus
2021-04-09 17:12:16 +08:00
echoContent red "\n=============================================================="
2022-07-04 15:47:57 +08:00
echoContent red " 推广区 "
2022-06-20 17:22:45 +08:00
echoContent green "AFF捐赠: https://github.com/mack-a/v2ray-agent/blob/master/documents/donation_aff.md\n"
echoContent green "虚拟币捐赠: 0xB08b731653515b083deE362fefFc45d5eb96c35d\n"
echoContent green "推广可联系TG: https://t.me/mackaff"
echoContent red "=============================================================="
2021-03-23 15:06:17 +08:00
if [ [ -n " ${ coreInstallType } " ] ] ; then
echoContent yellow "1.重新安装"
else
echoContent yellow "1.安装"
fi
2021-01-14 17:28:13 +08:00
echoContent yellow "2.任意组合安装"
2021-07-02 11:29:43 +08:00
if echo ${ currentInstallProtocolType } | grep -q trojan; then
echoContent yellow "3.切换VLESS[XTLS]"
2021-09-03 15:19:21 +08:00
elif echo ${ currentInstallProtocolType } | grep -q 0; then
2021-07-02 11:29:43 +08:00
echoContent yellow "3.切换Trojan[XTLS]"
fi
2021-09-17 17:46:07 +08:00
2022-11-08 15:04:46 +08:00
echoContent yellow "4.Hysteria管理"
2021-01-14 17:28:13 +08:00
echoContent skyBlue "-------------------------工具管理-----------------------------"
2022-11-08 15:04:46 +08:00
echoContent yellow "5.账号管理"
echoContent yellow "6.更换伪装站"
echoContent yellow "7.更新证书"
echoContent yellow "8.更换CDN节点"
echoContent yellow "9.IPv6分流"
echoContent yellow "10.WARP分流"
echoContent yellow "11.流媒体工具"
echoContent yellow "12.添加新端口"
echoContent yellow "13.BT下载管理"
echoContent yellow "14.切换alpn"
echoContent yellow "15.域名黑名单"
2021-01-14 17:28:13 +08:00
echoContent skyBlue "-------------------------版本管理-----------------------------"
2022-11-08 15:04:46 +08:00
echoContent yellow "16.core管理"
echoContent yellow "17.更新脚本"
echoContent yellow "18.安装BBR、DD脚本"
2021-01-14 17:28:13 +08:00
echoContent skyBlue "-------------------------脚本管理-----------------------------"
2022-11-08 15:04:46 +08:00
echoContent yellow "19.查看日志"
echoContent yellow "20.卸载脚本"
2021-01-14 17:28:13 +08:00
echoContent red "=============================================================="
mkdirTools
aliasInstall
read -r -p "请选择:" selectInstallType
case ${ selectInstallType } in
1)
selectCoreInstall
; ;
2)
selectCoreInstall
; ;
3)
2021-07-01 22:48:51 +08:00
initXrayFrontingConfig 1
2021-01-14 17:28:13 +08:00
; ;
4)
2022-11-08 15:04:46 +08:00
manageHysteria
2021-01-14 17:28:13 +08:00
; ;
5)
2022-11-08 15:04:46 +08:00
manageAccount 1
2021-01-14 17:28:13 +08:00
; ;
6)
2022-11-08 15:04:46 +08:00
updateNginxBlog 1
2021-01-14 17:28:13 +08:00
; ;
7)
2022-11-08 15:04:46 +08:00
renewalTLS 1
2021-01-14 17:28:13 +08:00
; ;
2021-01-27 16:24:23 +08:00
8)
2022-11-08 15:04:46 +08:00
updateV2RayCDN 1
2021-01-14 17:28:13 +08:00
; ;
2021-08-11 17:09:26 +08:00
9)
2022-11-08 15:04:46 +08:00
ipv6Routing 1
2021-08-11 17:09:26 +08:00
; ;
2021-01-27 16:24:23 +08:00
10)
2022-11-08 15:04:46 +08:00
warpRouting 1
2021-01-14 17:28:13 +08:00
; ;
2021-01-27 16:24:23 +08:00
11)
2022-11-08 15:04:46 +08:00
streamingToolbox 1
2021-07-01 22:48:51 +08:00
; ;
12)
2022-11-08 15:04:46 +08:00
addCorePort 1
2021-01-14 17:28:13 +08:00
; ;
2021-07-01 22:48:51 +08:00
13)
2022-11-08 15:04:46 +08:00
btTools 1
2021-02-24 15:57:51 +08:00
; ;
2021-07-01 22:48:51 +08:00
14)
2022-11-08 15:04:46 +08:00
switchAlpn 1
2021-03-11 17:47:35 +08:00
; ;
2021-07-01 22:48:51 +08:00
15)
2022-11-08 15:04:46 +08:00
blacklist 1
2021-06-21 17:36:04 +08:00
; ;
2021-07-01 22:48:51 +08:00
16)
2022-11-08 15:04:46 +08:00
coreVersionManageMenu 1
2021-07-16 17:09:55 +08:00
; ;
17)
2022-11-08 15:04:46 +08:00
updateV2RayAgent 1
2021-09-17 17:46:07 +08:00
; ;
18)
2022-11-08 15:04:46 +08:00
bbrInstall
2022-01-29 18:06:56 +08:00
; ;
19)
2022-11-08 15:04:46 +08:00
checkLog 1
; ;
20)
2021-01-14 17:28:13 +08:00
unInstall 1
; ;
esac
2020-11-20 17:57:50 +08:00
}
2021-01-12 14:58:45 +08:00
cronRenewTLS
2020-10-15 14:19:02 +08:00
menu