Files
dock/xu
2025-12-20 11:11:27 +08:00

147 lines
4.8 KiB
Bash
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/bash
# =========================================================
# X-UI 多架构全自动增强版 - 咸鱼咆哮优化
# 特点:多源下载备份、强制环境修复、自动容错
# =========================================================
set -e
# 1. 变量定义与多源地址 [cite: 1, 2, 11]
PANEL_PORT="8443"
PANEL_USERNAME="3344"
PANEL_PASSWORD="3344"
# 下载源 A (你的私服) 与 下载源 B (GitHub 镜像或备用)
BASE_URL_A="https://g1.vps7k7k.xyz/xui"
BASE_URL_B="https://ghproxy.com/https://github.com/MHSanaei/3x-ui/releases/latest/download" # 备用示例
# 2. 基础环境强力自愈 (解决“系统啥都没装”的问题) [cite: 21, 26, 29]
prepare_env() {
echo -e "\033[32m[1/6] 检查基础组件...\033[0m"
# 自动识别包管理器并更新 [cite: 26, 29, 31]
if command -v apt-get >/dev/null 2>&1; then
apt-get update -y && apt-get install -y wget curl tar gzip ca-certificates || true
elif command -v yum >/dev/null 2>&1; then
yum install -y wget curl tar gzip ca-certificates || true
fi
}
# 3. 架构精准识别 [cite: 9, 10, 88]
get_arch() {
echo -e "\033[32m[2/6] 检测系统架构...\033[0m"
local raw_arch=$(uname -m)
case "$raw_arch" in
x86_64) ARCH="amd64" ;;
aarch64|arm64) ARCH="arm64" ;;
i386|i486|i586|i686) ARCH="386" ;;
armv7l) ARCH="armv7" ;;
s390x) ARCH="s390x" ;;
*) echo "不支持的架构: $raw_arch"; exit 1 ;;
esac
}
# 4. 智能多级下载 (方案1失败自动切换方案2) [cite: 36, 37, 39, 44]
download_package() {
echo -e "\033[32m[3/6] 开始下载安装包 (多线备选)...\033[0m"
local file="x-ui-linux-${ARCH}.tar.gz"
local success=false
# 方案 1: 主站下载 [cite: 37, 39]
echo "尝试主下载源: $BASE_URL_A"
if wget --no-check-certificate -O "$file" "${BASE_URL_A}/${file}" || \
curl -L -k -o "$file" "${BASE_URL_A}/${file}"; then
success=true
fi
# 方案 2: 备用源 (如果方案1失败且是arm64尝试特殊后缀) [cite: 44, 45, 48]
if [ "$success" = false ] && [ "$ARCH" = "arm64" ]; then
echo "主源失败,尝试 ARM64 特殊备份名..."
wget --no-check-certificate -O "$file" "${BASE_URL_A}/x-ui-linux-arm64%20(1).tar.gz" && success=true
fi
if [ "$success" = false ]; then
echo -e "\033[31m[错误] 所有下载源均失效!请检查网络。\033[0m"
exit 1
fi
}
# 5. 双引擎解压与部署 [cite: 52, 53, 58, 60]
install_files() {
echo -e "\033[32m[4/6] 部署文件 (双引擎解压)...\033[0m"
local file="x-ui-linux-${ARCH}.tar.gz"
rm -rf /usr/local/x-ui /usr/bin/x-ui
# 尝试方式 A: 标准解压 [cite: 52]
if ! tar -zxf "$file" -C /usr/local/; then
# 尝试方式 B: 兼容解压 [cite: 53]
gunzip -c "$file" | tar x -C /usr/local/
fi
# 结构标准化 [cite: 58, 60]
cd /usr/local/x-ui
chmod +x x-ui bin/xray-linux-* 2>/dev/null || true
ln -sf /usr/local/x-ui/x-ui /usr/bin/x-ui [cite: 63, 68]
}
# 6. 服务配置与自动防火墙 [cite: 64, 73, 75]
setup_service() {
echo -e "\033[32m[5/6] 启动服务与端口开放...\033[0m"
# 写入 systemd 服务 [cite: 64]
cat > /etc/systemd/system/x-ui.service <<EOF
[Unit]
Description=x-ui Service
After=network.target
[Service]
Type=simple
User=root
WorkingDirectory=/usr/local/x-ui/
ExecStart=/usr/local/x-ui/x-ui
Restart=on-failure
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
systemctl enable x-ui
systemctl restart x-ui [cite: 77]
# 尝试多种防火墙开放端口
if command -v ufw >/dev/null; then ufw allow ${PANEL_PORT}/tcp; fi
if command -v iptables >/dev/null; then iptables -I INPUT -p tcp --dport ${PANEL_PORT} -j ACCEPT; fi
}
# 7. 自动初始化配置 [cite: 69, 70, 71]
init_config() {
echo -e "\033[32m[6/6] 配置面板信息...\033[0m"
sleep 3
# 使用 x-ui 自带指令修改端口、账号、密码 [cite: 70, 71]
echo -e "9\n${PANEL_PORT}\ny" | x-ui >/dev/null 2>&1 || true
echo -e "6\ny\n${PANEL_USERNAME}\n${PANEL_PASSWORD}\ny" | x-ui >/dev/null 2>&1 || true
# 最后验证 [cite: 81]
if systemctl is-active --quiet x-ui; then
echo -e "\033[36m"
echo "================================================="
echo "🎊 X-UI 多架构安装成功!"
echo "🌐 面板: http://$(curl -s ipv4.icanhazip.com):${PANEL_PORT}"
echo "👤 账号: ${PANEL_USERNAME}"
echo "🔑 密码: ${PANEL_PASSWORD}"
echo "================================================="
echo -e "\033[0m"
else
echo -e "\033[31m服务启动失败请检查运行日志: journalctl -u x-ui\033[0m" [cite: 78]
fi
}
# 顺序执行
prepare_env
get_arch
download_package
install_files
setup_service
init_config