Files
dock/xu1
2026-02-27 18:37:25 +08:00

278 lines
9.9 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 自动安装脚本 (咸V咆哮双模式版)
# 更新1. 模式一:纯净官方安装 (不下载数据库)
# 2. 模式二:自定义数据库 (1.db) + 密码防护
# 3. 架构直链:完全使用指定的附件链接
# ==========================================
# --- 颜色配置 ---
Red="\033[31m"
Green="\033[32m"
Yellow="\033[33m"
Blue="\033[36m"
Font="\033[0m"
# --- 核心配置 ---
# 配置二的自定义数据库链接
DB_URL="https://git.77582585.xyz/3344/dock/releases/download/3xui1/1.db"
# 配置二的专属授权码 (在这里修改你的密码)
PRIVATE_AUTH_CODE="7758258"
# 面板默认账号设置 (安装完成后,统一重置为此账号以防无法登录)
INSTALL_PATH="/usr/local/x-ui"
BIN_LINK="/usr/bin/x-ui"
DB_PATH="/etc/x-ui/x-ui.db"
SET_USER="3344"
SET_PASS="3344"
SET_PORT="8443"
# ==========================================
# 1. 模式选择与安全验证
# ==========================================
clear
echo -e "${Blue}#################################################${Font}"
echo -e "${Blue}# X-UI 自动安装脚本 (咸V咆哮专属) #${Font}"
echo -e "${Blue}#################################################${Font}"
echo -e "${Yellow}请选择安装模式:${Font}"
echo -e "-------------------------------------------------"
echo -e "1. ${Green}官方纯净安装${Font} (不使用自定义数据库)"
echo -e "2. ${Red}加载自定义库${Font} (使用预设数据库,需授权码)"
echo -e "-------------------------------------------------"
read -p "请输入数字 [1-2] (默认1): " INSTALL_MODE
[[ -z "$INSTALL_MODE" ]] && INSTALL_MODE="1"
# 密码验证逻辑 (仅模式二触发)
if [ "$INSTALL_MODE" == "2" ]; then
echo -e "-------------------------------------------------"
read -s -p "请输入配置二专属授权码: " INPUT_PWD
echo "" # 换行
if [ "$INPUT_PWD" != "$PRIVATE_AUTH_CODE" ]; then
echo -e "${Red}!! 授权码错误:拒绝安装,脚本已终止 !!${Font}"
exit 1
else
echo -e "${Green}>> 授权通过,准备部署自定义配置...${Font}"
fi
echo -e "-------------------------------------------------"
fi
# ==========================================
# 2. 网络环境智能检测
# ==========================================
echo -e "${Yellow}>> [1/6] 正在检测网络环境...${Font}"
HAS_IPV4=0
HAS_IPV6=0
if curl -s4m2 https://www.google.com/generate_204 >/dev/null 2>&1 || curl -s4m2 https://www.baidu.com >/dev/null 2>&1; then
HAS_IPV4=1
fi
if curl -s6m2 https://www.google.com/generate_204 >/dev/null 2>&1; then
HAS_IPV6=1
fi
if [[ $HAS_IPV4 -eq 1 ]]; then
echo -e "${Green}检测到 IPv4 网络,将优先使用 IPv4 通道${Font}"
NET_OPT="-4"
elif [[ $HAS_IPV6 -eq 1 ]]; then
echo -e "${Green}检测到纯 IPv6 网络,将自动切换至 IPv6 通道${Font}"
NET_OPT="-6"
else
echo -e "${Red}错误:未检测到任何可用网络!${Font}"
exit 1
fi
# ==========================================
# 3. 系统环境与依赖处理
# ==========================================
echo -e "${Yellow}>> [2/6] 安装基础依赖...${Font}"
PM="apt"
if [[ -f /etc/redhat-release ]] || command -v yum >/dev/null 2>&1; then PM="yum"; fi
if [ "$PM" == "apt" ]; then
pgrep -x "apt" && killall apt apt-get dpkg >/dev/null 2>&1
rm -rf /var/lib/apt/lists/lock /var/lib/dpkg/lock*
dpkg --configure -a >/dev/null 2>&1
apt-get update -o Acquire::http::Timeout="20" || echo -e "${Red}源更新超时,尝试继续...${Font}"
apt-get install -y curl wget tar ca-certificates bc sqlite3
if ! apt-get install -y ntpdate >/dev/null 2>&1; then
apt-get install -y ntpsec-ntpdate >/dev/null 2>&1
fi
else
yum install -y epel-release >/dev/null 2>&1
yum install -y curl wget tar bc sqlite3 ntpdate >/dev/null 2>&1
fi
# ==========================================
# 4. 时间校准与架构匹配 (严格使用附件直链)
# ==========================================
echo -e "${Yellow}>> [3/6] 校准时间与识别架构...${Font}"
rm -f /etc/localtime
ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
if command -v ntpdate >/dev/null 2>&1; then
ntpdate pool.ntp.org >/dev/null 2>&1
else
date -s "$(curl -sI g.cn | grep Date | cut -d' ' -f3-6)Z" >/dev/null 2>&1
fi
ARCH=$(uname -m)
DOWNLOAD_URL=""
FILE_NAME=""
case $ARCH in
x86_64)
FILE_NAME="x-ui-linux-amd64.tar.gz"
DOWNLOAD_URL="https://git.77582585.xyz/attachments/40eeb013-5006-423f-ad74-a0541ab340f4"
;;
aarch64|armv8)
FILE_NAME="x-ui-linux-arm64.tar.gz"
DOWNLOAD_URL="https://git.77582585.xyz/attachments/4ab708d5-6bc8-42c0-8494-ef5efe03e074"
;;
i386|i686)
FILE_NAME="x-ui-linux-386.tar.gz"
DOWNLOAD_URL="https://git.77582585.xyz/attachments/d1604006-c6b7-4c7c-9652-b42b229ef4cb"
;;
armv5*)
FILE_NAME="x-ui-linux-armv5.tar.gz"
DOWNLOAD_URL="https://git.77582585.xyz/attachments/8a5c678c-4ae4-43c4-910d-7e47f7c21c22"
;;
armv6*)
FILE_NAME="x-ui-linux-armv6.tar.gz"
DOWNLOAD_URL="https://git.77582585.xyz/attachments/0e7c7fd7-192e-44b3-9739-785a5fb1b51f"
;;
armv7*)
FILE_NAME="x-ui-linux-armv7.tar.gz"
DOWNLOAD_URL="https://git.77582585.xyz/attachments/9d1bf416-afb6-4e9f-b46b-ab3a1913a998"
;;
s390x)
FILE_NAME="x-ui-linux-s390x.tar.gz"
DOWNLOAD_URL="https://git.77582585.xyz/attachments/18784828-0d20-4bc5-908c-15f91bcf8eb5"
;;
*)
echo -e "${Red}不支持或无法识别的架构: $ARCH${Font}"
exit 1
;;
esac
echo -e "${Green}检测到架构: $ARCH${Font}"
echo -e "${Green}匹配安装包: $FILE_NAME${Font}"
# ==========================================
# 5. 本地基础下载逻辑
# ==========================================
download_manager() {
local url=$1
local file=$2
rm -f "$file"
echo -e "${Yellow}>> 尝试使用 Wget 下载...${Font}"
if wget $NET_OPT --no-check-certificate --timeout=30 --tries=3 -O "$file" "$url"; then return 0; fi
echo -e "${Yellow}>> Wget 失败,尝试使用 Curl 兜底...${Font}"
curl $NET_OPT -L -k --connect-timeout 30 --retry 3 -o "$file" "$url"
}
echo -e "${Yellow}>> [4/6] 下载安装包 (Mode: $NET_OPT)...${Font}"
mkdir -p /usr/local/
cd /usr/local/
download_manager "$DOWNLOAD_URL" "$FILE_NAME"
if ! tar -tzf "$FILE_NAME" >/dev/null 2>&1; then
echo -e "${Red}严重错误:安装包下载失败或文件损坏!${Font}"
exit 1
fi
# ==========================================
# 6. 安装与配置 (双模式逻辑)
# ==========================================
echo -e "${Yellow}>> [5/6] 解压与配置数据库...${Font}"
systemctl stop x-ui >/dev/null 2>&1
killall x-ui >/dev/null 2>&1
rm -rf x-ui
tar zxvf "$FILE_NAME" >/dev/null
cd x-ui
chmod +x x-ui x-ui.sh bin/xray-linux-*
ln -sf "$INSTALL_PATH/x-ui.sh" "$BIN_LINK"
mkdir -p /etc/x-ui/
rm -f "$DB_PATH"
if [ "$INSTALL_MODE" == "1" ]; then
echo -e "${Yellow}>> [模式一] 启用官方纯净数据库...${Font}"
# 直接将自带的初始数据库拷贝过去
cp /usr/local/x-ui/bin/x-ui.db "$DB_PATH"
else
echo -e "${Yellow}>> [模式二] 正在拉取自定义数据库...${Font}"
download_manager "$DB_URL" "$DB_PATH"
# 错误网页校验防护
if [ ! -s "$DB_PATH" ] || [ $(stat -c%s "$DB_PATH") -lt 10240 ]; then
echo -e "${Red}警告:自定义数据库下载异常,已回退为官方纯净数据库!${Font}"
cp /usr/local/x-ui/bin/x-ui.db "$DB_PATH"
else
echo -e "${Green}自定义数据库配置拉取成功!${Font}"
fi
fi
echo -e "${Yellow}>> 正在重置账户权限与面板端口...${Font}"
chmod 777 "$DB_PATH" >/dev/null 2>&1
RESET_SUCCESS=0
if command -v sqlite3 >/dev/null 2>&1; then
sqlite3 -cmd ".timeout 2000" "$DB_PATH" "UPDATE settings SET value='/' WHERE key='webBasePath';"
sqlite3 -cmd ".timeout 2000" "$DB_PATH" "UPDATE settings SET value='$SET_PORT' WHERE key='webPort';"
sqlite3 -cmd ".timeout 2000" "$DB_PATH" "UPDATE users SET username='$SET_USER', password='$SET_PASS' WHERE id=1;"
CURRENT_PASS=$(sqlite3 "$DB_PATH" "SELECT password FROM users WHERE id=1;")
if [ "$CURRENT_PASS" == "$SET_PASS" ]; then
RESET_SUCCESS=1
fi
fi
if [ $RESET_SUCCESS -eq 0 ]; then
./x-ui setting -username "$SET_USER" -password "$SET_PASS" -port "$SET_PORT" >/dev/null 2>&1
fi
chmod 644 "$DB_PATH" >/dev/null 2>&1
# ==========================================
# 7. 启动与防火墙放行
# ==========================================
echo -e "${Yellow}>> [6/6] 启动服务与防火墙放行...${Font}"
cat > /etc/systemd/system/x-ui.service <<EOF
[Unit]
Description=x-ui Service
After=network.target
[Service]
Type=simple
User=root
WorkingDirectory=$INSTALL_PATH
ExecStart=$INSTALL_PATH/x-ui
Restart=on-failure
RestartSec=5s
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
systemctl enable x-ui
systemctl restart x-ui
sleep 2
if command -v ufw >/dev/null 2>&1; then ufw allow $SET_PORT/tcp >/dev/null 2>&1; fi
if command -v firewall-cmd >/dev/null 2>&1; then
firewall-cmd --zone=public --add-port=$SET_PORT/tcp --permanent >/dev/null 2>&1
firewall-cmd --reload >/dev/null 2>&1
fi
iptables -I INPUT -p tcp --dport $SET_PORT -j ACCEPT 2>/dev/null
IP=$(curl -s4m5 ip.sb)
[ -z "$IP" ] && IP=$(curl -s6m5 ip.sb)
echo -e "\n${Blue}#################################################${Font}"
echo -e "${Green} X-UI 安装部署完成 ${Font}"
echo -e "${Blue}#################################################${Font}"
echo -e "访问地址 ${Green}http://$IP:$SET_PORT${Font}"
echo -e "用户名 ${Green}$SET_USER${Font}"
echo -e "密码 ${Green}$SET_PASS${Font}"
echo -e "当前模式 ${Yellow}$([ "$INSTALL_MODE" == "1" ] && echo "官方纯净模式" || echo "自定义数据库模式")${Font}"
echo -e "${Blue}#################################################${Font}"