Files
dock/xu
2025-12-22 14:40:47 +08:00

175 lines
5.5 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
# ==========================================
# 标题咸v咆哮制作 - X-UI 自动安装脚本
# 功能自动适配架构、下载私有源、配置端口8443、账号密码3344
# ==========================================
# 字体颜色配置
Red="\033[31m"
Green="\033[32m"
Yellow="\033[33m"
Blue="\033[36m"
Font="\033[0m"
# 1. 第一步:显示定制大名
echo -e "${Blue}#################################################${Font}"
echo -e "${Blue}# #${Font}"
echo -e "${Blue}# 咸v咆哮制作 #${Font}"
echo -e "${Blue}# #${Font}"
echo -e "${Blue}#################################################${Font}"
echo -e "${Green}正在初始化安装程序...${Font}"
sleep 2
# 检查是否为Root用户
if [[ $EUID -ne 0 ]]; then
echo -e "${Red}错误:本脚本必须以 root 身份运行!${Font}"
exit 1
fi
# 2. 第二步:更新系统基础软件架构
echo -e "${Yellow}正在更新系统并安装基础组件 (curl, wget, tar)...${Font}"
if [[ -f /etc/redhat-release ]]; then
yum update -y
yum install -y curl wget tar
elif cat /etc/issue | grep -q -E -i "debian"; then
apt-get update -y
apt-get install -y curl wget tar
elif cat /etc/issue | grep -q -E -i "ubuntu"; then
apt-get update -y
apt-get install -y curl wget tar
else
echo -e "${Red}不支持的操作系统,请使用 Debian/Ubuntu/CentOS${Font}"
exit 1
fi
# 3. 第三步:自动判断系统架构并选择下载链接
echo -e "${Yellow}正在检测系统架构...${Font}"
ARCH=$(uname -m)
DOWNLOAD_URL=""
# 你的私有源地址配置
BASE_URL="https://freeyx.vps3344.dpdns.org/xui"
case $ARCH in
x86_64)
echo -e "检测到架构: ${Green}AMD64${Font}"
DOWNLOAD_URL="${BASE_URL}/x-ui-linux-amd64.tar.gz"
;;
aarch64)
echo -e "检测到架构: ${Green}ARM64${Font}"
DOWNLOAD_URL="${BASE_URL}/x-ui-linux-arm64.tar.gz"
;;
i386|i686)
echo -e "检测到架构: ${Green}386 (x86)${Font}"
DOWNLOAD_URL="${BASE_URL}/x-ui-linux-386.tar.gz"
;;
armv5*)
echo -e "检测到架构: ${Green}ARMv5${Font}"
DOWNLOAD_URL="${BASE_URL}/x-ui-linux-armv5.tar.gz"
;;
*)
echo -e "${Red}错误:不支持的架构 $ARCH${Font}"
exit 1
;;
esac
# 4. 第四步:下载并安装
cd /usr/local/
# 清理旧文件
rm -rf /usr/local/x-ui
rm -f /usr/local/x-ui-linux-*.tar.gz
echo -e "${Yellow}开始下载安装包: ${DOWNLOAD_URL}${Font}"
# 下载 (尝试 wget失败则尝试 curl)
wget -N --no-check-certificate -O x-ui-install.tar.gz "$DOWNLOAD_URL"
if [[ $? -ne 0 ]]; then
echo -e "${Red}Wget下载失败尝试使用Curl...${Font}"
curl -L -k -o x-ui-install.tar.gz "$DOWNLOAD_URL"
if [[ $? -ne 0 ]]; then
echo -e "${Red}致命错误:无法从指定源下载安装包,请检查网络或链接有效性。${Font}"
exit 1
fi
fi
echo -e "${Green}下载成功,正在解压安装...${Font}"
tar zxvf x-ui-install.tar.gz
rm x-ui-install.tar.gz
# 确保二进制权限
cd x-ui
chmod +x x-ui bin/xray-linux-* 2>/dev/null
# 5. 第五步:自动修改端口、账号、密码
echo -e "${Yellow}正在配置面板设置 (端口: 8443, 账号: 3344, 密码: 3344)...${Font}"
# 停止可能存在的服务
systemctl stop x-ui 2>/dev/null
# 使用 x-ui 内置命令修改设置
# 注意:这里假设下载的 x-ui 版本支持 setting 命令,这是标准 x-ui 的功能
./x-ui setting -port 8443 -username 3344 -password 3344
if [[ $? -ne 0 ]]; then
echo -e "${Red}配置修改失败!可能安装包版本过旧或不兼容 setting 命令。${Font}"
# 备用方案如果内置命令失败通常需要操作sqlite数据库但通常x-ui都支持命令
else
echo -e "${Green}配置修改成功!${Font}"
fi
# 6. 配置系统服务 (Systemd)
echo -e "${Yellow}配置 Systemd 服务...${Font}"
cat > /etc/systemd/system/x-ui.service <<EOF
[Unit]
Description=x-ui Service
After=network.target
[Service]
Type=simple
User=root
Restart=on-failure
RestartSec=5s
ExecStart=/usr/local/x-ui/x-ui
[Install]
WantedBy=multi-user.target
EOF
# 重载服务并启动
systemctl daemon-reload
systemctl enable x-ui
systemctl restart x-ui
# 7. 防火墙放行 (尝试放行 8443)
echo -e "${Yellow}尝试配置防火墙放行端口 8443...${Font}"
if command -v ufw > /dev/null; then
ufw allow 8443/tcp
ufw reload
elif command -v firewall-cmd > /dev/null; then
firewall-cmd --zone=public --add-port=8443/tcp --permanent
firewall-cmd --reload
else
# iptables 备用
iptables -I INPUT -p tcp --dport 8443 -j ACCEPT 2>/dev/null
fi
# 8. 验证与完成显示
sleep 2
STATUS=$(systemctl is-active x-ui)
if [[ "$STATUS" == "active" ]]; then
IP=$(curl -s4m8 ip.sb)
echo -e ""
echo -e "${Blue}#################################################${Font}"
echo -e "${Green} X-UI 安装配置完成! ${Font}"
echo -e "${Blue}#################################################${Font}"
echo -e "脚本制作:${Yellow}咸v咆哮制作${Font}"
echo -e "运行状态:${Green}已启动${Font}"
echo -e "访问地址:${Green}http://$IP:8443${Font}"
echo -e "用户名 ${Green}3344${Font}"
echo -e "密码 ${Green}3344${Font}"
echo -e "${Blue}#################################################${Font}"
else
echo -e "${Red}安装似乎完成了但服务启动失败请检查日志journalctl -u x-ui${Font}"
fi