feat(脚本): 添加hysteria2

pull/798/head
mack-a 2023-09-27 10:42:13 +03:00
parent e175e4cdc5
commit 72bd755de7
1 changed files with 94 additions and 119 deletions

View File

@ -341,8 +341,7 @@ readInstallType() {
fi fi
if [[ -d "/etc/v2ray-agent/hysteria" && -f "/etc/v2ray-agent/hysteria/hysteria" ]]; then 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" ]]; then
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/ hysteriaConfigPath=/etc/v2ray-agent/hysteria/conf/
fi fi
fi fi
@ -539,11 +538,11 @@ checkFirewalldAllowPort() {
# 读取hysteria网络环境 # 读取hysteria网络环境
readHysteriaConfig() { readHysteriaConfig() {
if [[ -n "${hysteriaConfigPath}" ]]; then if [[ -n "${hysteriaConfigPath}" ]]; then
hysteriaLag=$(jq -r .hysteriaLag <"${hysteriaConfigPath}client_network.json") # hysteriaLag=$(jq -r .hysteriaLag <"${hysteriaConfigPath}client_network.json")
hysteriaClientDownloadSpeed=$(jq -r .hysteriaClientDownloadSpeed <"${hysteriaConfigPath}client_network.json") # hysteriaClientDownloadSpeed=$(jq -r .hysteriaClientDownloadSpeed <"${hysteriaConfigPath}client_network.json")
hysteriaClientUploadSpeed=$(jq -r .hysteriaClientUploadSpeed <"${hysteriaConfigPath}client_network.json") # hysteriaClientUploadSpeed=$(jq -r .hysteriaClientUploadSpeed <"${hysteriaConfigPath}client_network.json")
hysteriaPort=$(jq -r .listen <"${hysteriaConfigPath}config.json" | awk -F "[:]" '{print $2}') hysteriaPort=$(jq -r .listen <"${hysteriaConfigPath}config.json" | awk -F "[:]" '{print $2}')
hysteriaProtocol=$(jq -r .protocol <"${hysteriaConfigPath}config.json") # hysteriaProtocol=$(jq -r .protocol <"${hysteriaConfigPath}config.json")
fi fi
} }
# 读取Tuic配置 # 读取Tuic配置
@ -1903,14 +1902,14 @@ installHysteria() {
if [[ -z "${hysteriaConfigPath}" ]]; then if [[ -z "${hysteriaConfigPath}" ]]; then
version=$(curl -s "https://api.github.com/repos/apernet/hysteria/releases?per_page=10" | jq -r ".[]|select (.prerelease==${prereleaseStatus})|.tag_name" | grep -v "app/v2" | head -1) version=$(curl -s "https://api.github.com/repos/apernet/hysteria/releases?per_page=10" | jq -r ".[]|select (.prerelease==${prereleaseStatus})|.tag_name" | grep "app/" | head -1)
echoContent green " ---> Hysteria版本:${version}" echoContent green " ---> Hysteria版本:${version}"
wget -c -q "${wgetShowProgressStatus}" -P /etc/v2ray-agent/hysteria/ "https://github.com/apernet/hysteria/releases/download/${version}/${hysteriaCoreCPUVendor}" wget -c -q "${wgetShowProgressStatus}" -P /etc/v2ray-agent/hysteria/ "https://github.com/apernet/hysteria/releases/download/${version}/${hysteriaCoreCPUVendor}"
mv "/etc/v2ray-agent/hysteria/${hysteriaCoreCPUVendor}" /etc/v2ray-agent/hysteria/hysteria mv "/etc/v2ray-agent/hysteria/${hysteriaCoreCPUVendor}" /etc/v2ray-agent/hysteria/hysteria
chmod 655 /etc/v2ray-agent/hysteria/hysteria chmod 655 /etc/v2ray-agent/hysteria/hysteria
else else
echoContent green " ---> Hysteria版本:$(/etc/v2ray-agent/hysteria/hysteria --version | awk '{print $3}')" echoContent green " ---> Hysteria版本:$(/etc/v2ray-agent/hysteria/hysteria version | grep "Version:" | awk '{print $2}')"
read -r -p "是否更新、升级?[y/n]:" reInstallHysteriaStatus read -r -p "是否更新、升级?[y/n]:" reInstallHysteriaStatus
if [[ "${reInstallHysteriaStatus}" == "y" ]]; then if [[ "${reInstallHysteriaStatus}" == "y" ]]; then
rm -f /etc/v2ray-agent/hysteria/hysteria rm -f /etc/v2ray-agent/hysteria/hysteria
@ -2305,19 +2304,22 @@ installHysteriaService() {
if [[ -n $(find /bin /usr/bin -name "systemctl") ]]; then if [[ -n $(find /bin /usr/bin -name "systemctl") ]]; then
rm -rf /etc/systemd/system/hysteria.service rm -rf /etc/systemd/system/hysteria.service
touch /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' execStart='/etc/v2ray-agent/hysteria/hysteria server -c /etc/v2ray-agent/hysteria/conf/config.json --log-level debug'
cat <<EOF >/etc/systemd/system/hysteria.service cat <<EOF >/etc/systemd/system/hysteria.service
[Unit] [Unit]
Description=Hysteria Service
Documentation=https://github.com/apernet
After=network.target nss-lookup.target After=network.target nss-lookup.target
[Service] [Service]
User=root User=root
ExecStart=${execStart} WorkingDirectory=/root
CapabilityBoundingSet=CAP_NET_ADMIN CAP_NET_BIND_SERVICE
AmbientCapabilities=CAP_NET_ADMIN CAP_NET_BIND_SERVICE
ExecStart=/etc/v2ray-agent/hysteria/hysteria server -c /etc/v2ray-agent/hysteria/conf/config.json --log-level debug
Restart=on-failure Restart=on-failure
RestartPreventExitStatus=23 RestartSec=10
LimitNPROC=10000 LimitNPROC=512
LimitNOFILE=1000000 LimitNOFILE=infinity
[Install] [Install]
WantedBy=multi-user.target WantedBy=multi-user.target
EOF EOF
@ -2831,38 +2833,43 @@ initHysteriaConfig() {
echoContent skyBlue "\n进度 $1/${totalProgress} : 初始化Hysteria配置" echoContent skyBlue "\n进度 $1/${totalProgress} : 初始化Hysteria配置"
initHysteriaPort initHysteriaPort
initHysteriaProtocol # initHysteriaProtocol
initHysteriaNetwork # initHysteriaNetwork
local uuid= local uuid=
uuid=$(${ctlPath} uuid) uuid=$(${ctlPath} uuid)
getClients "${configPath}${frontingType}.json" true # getClients "${configPath}${frontingType}.json" true
cat <<EOF >/etc/v2ray-agent/hysteria/conf/config.json cat <<EOF >/etc/v2ray-agent/hysteria/conf/config.json
{ {
"listen": ":${hysteriaPort}", "listen":":${hysteriaPort}",
"protocol": "${hysteriaProtocol}", "tls":{
"disable_udp": false, "cert": "/etc/v2ray-agent/tls/${currentHost}.crt",
"cert": "/etc/v2ray-agent/tls/${currentHost}.crt", "key": "/etc/v2ray-agent/tls/${currentHost}.key"
"key": "/etc/v2ray-agent/tls/${currentHost}.key", },
"auth": { "auth":{
"mode": "passwords", "type": "password",
"config": [] "password": "${uuid}"
}, },
"socks5_outbound":{ "resolver":{
"server":"127.0.0.1:31295", "type": "https",
"user":"hysteria_socks5_outbound", "https":{
"password":"${uuid}" "addr": "1.1.1.1:443",
}, "timeout": "10s"
"alpn": "h3", }
"recv_window_conn": 15728640, },
"recv_window_client": 67108864, "outbounds":{
"max_conn_client": 4096, "name": "socks5_outbound",
"disable_mtu_discovery": true, "type": "socks5",
"resolve_preference": "46", "socks5":{
"resolver": "https://8.8.8.8:443/dns-query" "addr": "127.0.0.1:31295",
"username": "hysteria_socks5_outbound",
"password": "${uuid}"
}
}
} }
EOF EOF
addClientsHysteria "/etc/v2ray-agent/hysteria/conf/config.json" true # addClientsHysteria "/etc/v2ray-agent/hysteria/conf/config.json" true
# 添加socks入站 # 添加socks入站
cat <<EOF >${configPath}/02_socks_inbounds_hysteria.json cat <<EOF >${configPath}/02_socks_inbounds_hysteria.json
@ -4058,72 +4065,39 @@ EOF
echoContent green " https://api.qrserver.com/v1/create-qr-code/?size=400x400&data=trojan%3a%2f%2f${id}%40${add}%3a${currentDefaultPort}%3Fencryption%3Dnone%26fp%3Dchrome%26security%3Dtls%26peer%3d${currentHost}%26type%3Dgrpc%26sni%3d${currentHost}%26path%3D${currentPath}trojangrpc%26alpn%3Dh2%26serviceName%3D${currentPath}trojangrpc%23${email}\n" echoContent green " https://api.qrserver.com/v1/create-qr-code/?size=400x400&data=trojan%3a%2f%2f${id}%40${add}%3a${currentDefaultPort}%3Fencryption%3Dnone%26fp%3Dchrome%26security%3Dtls%26peer%3d${currentHost}%26type%3Dgrpc%26sni%3d${currentHost}%26path%3D${currentPath}trojangrpc%26alpn%3Dh2%26serviceName%3D${currentPath}trojangrpc%23${email}\n"
elif [[ "${type}" == "hysteria" ]]; then elif [[ "${type}" == "hysteria" ]]; then
local hysteriaEmail= # local hysteriaEmail=
hysteriaEmail=$(echo "${email}" | awk -F "[-]" '{print $1}')_hysteria # hysteriaEmail=$(echo "${email}" | awk -F "[-]" '{print $1}')_hysteria
echoContent yellow " ---> Hysteria(TLS)" echoContent yellow " ---> Hysteria(TLS)"
local clashMetaPortTmp="port: ${hysteriaPort}"
local v2rayNPortHopping= echoContent green " hysteria2://${id}@${currentHost}:${hysteriaPort}?peer=${currentHost}&insecure=0&sni=${currentHost}&alpn=h3#hysteria2\n"
local mport= # cat <<EOF >>"/etc/v2ray-agent/subscribe_local/default/${user}"
if [[ -n "${portHoppingStart}" ]]; then #hysteria2://${id}@${currentHost}:${hysteriaPort}?peer=${currentHost}&insecure=0&sni=${currentHost}&alpn=h3#hysteria2
mport="mport=${portHoppingStart}-${portHoppingEnd}&" #EOF
clashMetaPortTmp="ports: ${portHoppingStart}-${portHoppingEnd}"
v2rayNPortHopping=",${portHoppingStart}-${portHoppingEnd}"
fi
echoContent green " hysteria://${currentHost}:${hysteriaPort}?${mport}protocol=${hysteriaProtocol}&auth=${id}&peer=${currentHost}&insecure=0&alpn=h3&upmbps=${hysteriaClientUploadSpeed}&downmbps=${hysteriaClientDownloadSpeed}#${hysteriaEmail}\n"
cat <<EOF >>"/etc/v2ray-agent/subscribe_local/default/${user}"
hysteria://${currentHost}:${hysteriaPort}?${mport}protocol=${hysteriaProtocol}&auth=${id}&peer=${currentHost}&insecure=0&alpn=h3&upmbps=${hysteriaClientUploadSpeed}&downmbps=${hysteriaClientDownloadSpeed}#${hysteriaEmail}
EOF
echoContent yellow " ---> v2rayN(hysteria+TLS)" echoContent yellow " ---> v2rayN(hysteria+TLS)"
cat <<EOF >"/etc/v2ray-agent/hysteria/conf/client.json" cat <<EOF >"/etc/v2ray-agent/hysteria/conf/client.json"
{ {
"server": "${currentHost}:${hysteriaPort}${v2rayNPortHopping}", "server": "${currentHost}:${hysteriaPort}",
"protocol": "${hysteriaProtocol}", "socks5": { "listen": "127.0.0.1:10808", "timeout": 300},
"up_mbps": ${hysteriaClientUploadSpeed}, "auth":"${id}",
"down_mbps": ${hysteriaClientDownloadSpeed}, "tls":{
"http": { "listen": "127.0.0.1:10809", "timeout": 300, "disable_udp": false }, "sni":"${currentHost}"
"socks5": { "listen": "127.0.0.1:10808", "timeout": 300, "disable_udp": false }, }
"obfs": "",
"auth_str":"${id}",
"alpn": "h3",
"acl": "acl/routes.acl",
"mmdb": "acl/Country.mmdb",
"server_name": "${currentHost}",
"insecure": false,
"recv_window_conn": 5767168,
"recv_window": 23068672,
"disable_mtu_discovery": true,
"resolver": "https://223.5.5.5/dns-query",
"retry": 3,
"retry_interval": 3,
"quit_on_disconnect": false,
"handshake_timeout": 15,
"idle_timeout": 30,
"fast_open": true,
"hop_interval": 120
} }
EOF EOF
local v2rayNConf= local v2rayNConf=
v2rayNConf="$(cat /etc/v2ray-agent/hysteria/conf/client.json)" v2rayNConf="$(cat /etc/v2ray-agent/hysteria/conf/client.json)"
echoContent green "${v2rayNConf}\n" echoContent green "${v2rayNConf}\n"
cat <<EOF >>"/etc/v2ray-agent/subscribe_local/clashMeta/${user}" # cat <<EOF >>"/etc/v2ray-agent/subscribe_local/clashMeta/${user}"
- name: "${hysteriaEmail}" # - name: hysteria2
type: hysteria # type: hysteria2
server: ${currentHost} # server: ${currentHost}
${clashMetaPortTmp} # port: ${hysteriaPort}
auth_str: ${id} # password: ${id}
alpn: # sni: ${currentHost}
- h3 #EOF
protocol: ${hysteriaProtocol}
up: "${hysteriaClientUploadSpeed}"
down: "${hysteriaClientDownloadSpeed}"
sni: ${currentHost}
EOF
echoContent yellow " ---> 二维码 Hysteria(TLS)" echoContent yellow " ---> 二维码 Hysteria(TLS)"
if [[ -n "${mport}" ]]; then echoContent green " https://api.qrserver.com/v1/create-qr-code/?size=400x400&data=hysteria2%3A%2F%2F${id}%40${currentHost}%3A${hysteriaPort}%3Fpeer%3D${currentHost}%26insecure%3D0%26sni%3D${currentHost}%26alpn%3Dh3%23hysteria2\n"
mport="mport%3D${portHoppingStart}-${portHoppingEnd}%26"
fi
echoContent green " https://api.qrserver.com/v1/create-qr-code/?size=400x400&data=hysteria%3A%2F%2F${currentHost}%3A${hysteriaPort}%3F${mport}protocol%3D${hysteriaProtocol}%26auth%3D${id}%26peer%3D${currentHost}%26insecure%3D0%26alpn%3Dh3%26upmbps%3D${hysteriaClientUploadSpeed}%26downmbps%3D${hysteriaClientDownloadSpeed}%23${hysteriaEmail}\n"
elif [[ "${type}" == "vlessReality" ]]; then elif [[ "${type}" == "vlessReality" ]]; then
echoContent yellow " ---> 通用格式(VLESS+reality+uTLS+Vision)" echoContent yellow " ---> 通用格式(VLESS+reality+uTLS+Vision)"
echoContent green " vless://${id}@$(getPublicIP):${currentRealityPort}?encryption=none&security=reality&type=tcp&sni=${currentRealityServerNames}&fp=chrome&pbk=${currentRealityPublicKey}&sid=6ba85179e30d4fc2&flow=xtls-rprx-vision#${email}\n" echoContent green " vless://${id}@$(getPublicIP):${currentRealityPort}?encryption=none&security=reality&type=tcp&sni=${currentRealityServerNames}&fp=chrome&pbk=${currentRealityPublicKey}&sid=6ba85179e30d4fc2&flow=xtls-rprx-vision#${email}\n"
@ -4369,27 +4343,28 @@ showAccounts() {
fi fi
if echo ${currentInstallProtocolType} | grep -q 6; then if echo ${currentInstallProtocolType} | grep -q 6; then
echoContent skyBlue "\n================================ Hysteria TLS ================================\n" echoContent skyBlue "\n================================ Hysteria TLS ================================\n"
echoContent red "\n --->Hysteria速度依赖与本地的网络环境如果被QoS使用体验会非常差。IDC也有可能认为是攻击请谨慎使用" # echoContent red "\n --->Hysteria速度依赖与本地的网络环境如果被QoS使用体验会非常差。IDC也有可能认为是攻击请谨慎使用"
jq .auth.config ${hysteriaConfigPath}config.json | jq -r '.[]' | while read -r user; do jq -r .auth.password ${hysteriaConfigPath}config.json | while read -r user; do
local defaultUser= # local defaultUser=
local uuidType= # local uuidType=
uuidType=".id" # uuidType=".id"
#
# if [[ "${frontingType}" == "02_trojan_TCP_inbounds" ]]; then
# uuidType=".password"
# fi
if [[ "${frontingType}" == "02_trojan_TCP_inbounds" ]]; then # defaultUser=$(jq '.inbounds[0].settings.clients[]|select('${uuidType}'=="'"${user}"'")' ${configPath}${frontingType}.json)
uuidType=".password" # local email=
fi # email=$(echo "${defaultUser}" | jq -r .email)
# local hysteriaEmail=
# hysteriaEmail=$(echo "${email}" | awk -F "[_]" '{print $1}')_hysteria
defaultUser=$(jq '.inbounds[0].settings.clients[]|select('${uuidType}'=="'"${user}"'")' ${configPath}${frontingType}.json) if [[ -n ${user} ]]; then
local email= # echoContent skyBlue "\n ---> 账号:$(echo "${hysteriaEmail}" | awk -F "[-]" '{print $1"_hysteria"}')"
email=$(echo "${defaultUser}" | jq -r .email) echoContent skyBlue "\n ---> 账号:hysteria2"
local hysteriaEmail=
hysteriaEmail=$(echo "${email}" | awk -F "[_]" '{print $1}')_hysteria
if [[ -n ${defaultUser} ]]; then
echoContent skyBlue "\n ---> 账号:$(echo "${hysteriaEmail}" | awk -F "[-]" '{print $1"_hysteria"}')"
echo echo
defaultBase64Code hysteria "${hysteriaEmail}" "${user}" defaultBase64Code hysteria hysteria2 "${user}"
fi fi
done done
@ -7785,9 +7760,9 @@ manageHysteria() {
if [[ -n "${hysteriaConfigPath}" ]]; then if [[ -n "${hysteriaConfigPath}" ]]; then
echoContent yellow "1.重新安装" echoContent yellow "1.重新安装"
echoContent yellow "2.卸载" echoContent yellow "2.卸载"
echoContent yellow "3.端口跳跃管理" # echoContent yellow "3.端口跳跃管理"
echoContent yellow "4.core管理" echoContent yellow "3.core管理"
echoContent yellow "5.查看日志" echoContent yellow "4.查看日志"
hysteriaStatus=true hysteriaStatus=true
else else
echoContent yellow "1.安装" echoContent yellow "1.安装"
@ -7799,11 +7774,11 @@ manageHysteria() {
hysteriaCoreInstall hysteriaCoreInstall
elif [[ "${installHysteriaStatus}" == "2" && "${hysteriaStatus}" == "true" ]]; then elif [[ "${installHysteriaStatus}" == "2" && "${hysteriaStatus}" == "true" ]]; then
unInstallHysteriaCore unInstallHysteriaCore
# elif [[ "${installHysteriaStatus}" == "3" && "${hysteriaStatus}" == "true" ]]; then
# hysteriaPortHoppingMenu
elif [[ "${installHysteriaStatus}" == "3" && "${hysteriaStatus}" == "true" ]]; then elif [[ "${installHysteriaStatus}" == "3" && "${hysteriaStatus}" == "true" ]]; then
hysteriaPortHoppingMenu
elif [[ "${installHysteriaStatus}" == "4" && "${hysteriaStatus}" == "true" ]]; then
hysteriaVersionManageMenu 1 hysteriaVersionManageMenu 1
elif [[ "${installHysteriaStatus}" == "5" && "${hysteriaStatus}" == "true" ]]; then elif [[ "${installHysteriaStatus}" == "4" && "${hysteriaStatus}" == "true" ]]; then
journalctl -fu hysteria journalctl -fu hysteria
fi fi
} }
@ -7897,7 +7872,7 @@ menu() {
cd "$HOME" || exit cd "$HOME" || exit
echoContent red "\n==============================================================" echoContent red "\n=============================================================="
echoContent green "作者mack-a" echoContent green "作者mack-a"
echoContent green "当前版本v2.10.21" echoContent green "当前版本v2.10.22"
echoContent green "Githubhttps://github.com/mack-a/v2ray-agent" echoContent green "Githubhttps://github.com/mack-a/v2ray-agent"
echoContent green "描述:八合一共存脚本\c" echoContent green "描述:八合一共存脚本\c"
showInstallStatus showInstallStatus