Update duoxray.sh
This commit is contained in:
@@ -1,17 +1,16 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
# 检查并安装 jq(如果未安装)
|
|
||||||
install_jq() {
|
install_jq() {
|
||||||
if ! command -v jq &> /dev/null; then
|
if ! command -v jq &> /dev/null; then
|
||||||
echo "jq 未安装,正在安装 jq..."
|
echo "jq 未安装,正在安装 jq..."
|
||||||
if [[ -f /etc/debian_version ]]; then
|
if [[ -f /etc/debian_version ]]; then
|
||||||
sudo apt-get update
|
sudo apt-get update
|
||||||
sudo apt-get install -y jq
|
sudo apt-get install -yq jq
|
||||||
elif [[ -f /etc/redhat-release ]]; then
|
elif [[ -f /etc/redhat-release ]]; then
|
||||||
sudo yum install -y epel-release
|
sudo yum install -y epel-release
|
||||||
sudo yum install -y jq
|
sudo yum install -y jq
|
||||||
else
|
else
|
||||||
echo "无法确定系统发行版,手动安装 jq。"
|
echo "无法确定系统发行版,请手动安装 jq。"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
@@ -19,7 +18,6 @@ install_jq() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# 检查并安装 Xray core(如果未安装)
|
|
||||||
install_xray() {
|
install_xray() {
|
||||||
if ! command -v xray &> /dev/null; then
|
if ! command -v xray &> /dev/null; then
|
||||||
echo "Xray 未安装,正在安装 Xray..."
|
echo "Xray 未安装,正在安装 Xray..."
|
||||||
@@ -33,12 +31,10 @@ install_xray() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# 获取所有公网 IPv4 地址
|
|
||||||
get_public_ipv4() {
|
get_public_ipv4() {
|
||||||
ip -4 addr show | grep inet | grep -vE "127\.|10\.|172\.(1[6-9]|2[0-9]|3[0-1])\.|192\.168\.|169\.254" | awk '{print $2}' | cut -d'/' -f1
|
ip -4 addr show | grep inet | grep -vE "127\.|10\.|172\.(1[6-9]|2[0-9]|3[0-1])\.|192\.168\.|169\.254" | awk '{print $2}' | cut -d'/' -f1
|
||||||
}
|
}
|
||||||
|
|
||||||
# 打印节点链接
|
|
||||||
print_node_links() {
|
print_node_links() {
|
||||||
local port=$1
|
local port=$1
|
||||||
local id=$2
|
local id=$2
|
||||||
@@ -47,7 +43,6 @@ print_node_links() {
|
|||||||
echo -e "\033[32m端口: $port, 节点链接: $link\033[0m"
|
echo -e "\033[32m端口: $port, 节点链接: $link\033[0m"
|
||||||
}
|
}
|
||||||
|
|
||||||
# 配置 Xray 配置文件
|
|
||||||
configure_xray() {
|
configure_xray() {
|
||||||
public_ips=($(get_public_ipv4))
|
public_ips=($(get_public_ipv4))
|
||||||
|
|
||||||
@@ -58,10 +53,8 @@ configure_xray() {
|
|||||||
|
|
||||||
echo "找到的公网 IPv4 地址: ${public_ips[@]}"
|
echo "找到的公网 IPv4 地址: ${public_ips[@]}"
|
||||||
|
|
||||||
# Xray 配置文件路径
|
|
||||||
config_file="/usr/local/etc/xray/config.json"
|
config_file="/usr/local/etc/xray/config.json"
|
||||||
|
|
||||||
# 基础配置
|
|
||||||
cat > $config_file <<EOF
|
cat > $config_file <<EOF
|
||||||
{
|
{
|
||||||
"inbounds": [],
|
"inbounds": [],
|
||||||
@@ -77,10 +70,8 @@ EOF
|
|||||||
for ip in "${public_ips[@]}"; do
|
for ip in "${public_ips[@]}"; do
|
||||||
echo "正在配置 IP: $ip 端口: $port"
|
echo "正在配置 IP: $ip 端口: $port"
|
||||||
|
|
||||||
# 生成 UUID
|
|
||||||
id=$(uuidgen)
|
id=$(uuidgen)
|
||||||
|
|
||||||
# 使用一次 jq 完成 inbounds 和 outbounds 的更新
|
|
||||||
jq --argjson port "$port" --arg ip "$ip" --arg id "$id" '.inbounds += [{
|
jq --argjson port "$port" --arg ip "$ip" --arg id "$id" '.inbounds += [{
|
||||||
"port": $port,
|
"port": $port,
|
||||||
"protocol": "vmess",
|
"protocol": "vmess",
|
||||||
@@ -108,17 +99,14 @@ EOF
|
|||||||
"outboundTag": "out-\($port)"
|
"outboundTag": "out-\($port)"
|
||||||
}]' "$config_file" > temp.json && mv temp.json "$config_file"
|
}]' "$config_file" > temp.json && mv temp.json "$config_file"
|
||||||
|
|
||||||
# 打印节点链接
|
|
||||||
print_node_links "$port" "$id" "$ip"
|
print_node_links "$port" "$id" "$ip"
|
||||||
|
|
||||||
# 端口递增
|
|
||||||
port=$((port + 1))
|
port=$((port + 1))
|
||||||
done
|
done
|
||||||
|
|
||||||
echo "Xray 配置完成。"
|
echo "Xray 配置完成。"
|
||||||
}
|
}
|
||||||
|
|
||||||
# 重启 Xray 服务
|
|
||||||
restart_xray() {
|
restart_xray() {
|
||||||
echo "正在重启 Xray 服务..."
|
echo "正在重启 Xray 服务..."
|
||||||
if ! systemctl restart xray; then
|
if ! systemctl restart xray; then
|
||||||
@@ -129,7 +117,6 @@ restart_xray() {
|
|||||||
echo "Xray 服务已重启。"
|
echo "Xray 服务已重启。"
|
||||||
}
|
}
|
||||||
|
|
||||||
# 主函数
|
|
||||||
main() {
|
main() {
|
||||||
install_jq
|
install_jq
|
||||||
install_xray
|
install_xray
|
||||||
@@ -138,5 +125,4 @@ main() {
|
|||||||
echo "部署完成。"
|
echo "部署完成。"
|
||||||
}
|
}
|
||||||
|
|
||||||
# 执行主函数
|
|
||||||
main
|
main
|
||||||
|
|||||||
Reference in New Issue
Block a user