2025-09-28 12:00:45 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
|
|
red='\033[0;31m'
|
|
|
|
|
green='\033[0;32m'
|
|
|
|
|
blue='\033[0;34m'
|
|
|
|
|
yellow='\033[0;33m'
|
|
|
|
|
plain='\033[0m'
|
|
|
|
|
|
2026-05-11 04:20:49 +00:00
|
|
|
cur_dir=$(pwd)
|
|
|
|
|
|
2026-01-03 02:57:19 +00:00
|
|
|
xui_folder="${XUI_MAIN_FOLDER:=/usr/local/x-ui}"
|
|
|
|
|
xui_service="${XUI_SERVICE:=/etc/systemd/system}"
|
|
|
|
|
|
2026-05-11 04:20:49 +00:00
|
|
|
GITHUB_MIRROR_DEFAULT="https://gh.kejilion.pro"
|
|
|
|
|
GITHUB_RAW_DEFAULT="https://raw.githubusercontent.com"
|
2025-09-28 12:00:45 +00:00
|
|
|
|
2026-05-11 05:28:05 +00:00
|
|
|
REPO_OWNER="ruyawwj"
|
|
|
|
|
REPO_NAME="3x-ui"
|
|
|
|
|
|
2026-05-11 04:20:49 +00:00
|
|
|
[[ $EUID -ne 0 ]] && echo -e "${red}Fatal error: ${plain} Please run this script with root privilege \n " && exit 1
|
2025-09-28 12:00:45 +00:00
|
|
|
|
|
|
|
|
if [[ -f /etc/os-release ]]; then
|
2025-12-03 20:40:49 +00:00
|
|
|
source /etc/os-release
|
|
|
|
|
release=$ID
|
2026-05-04 11:20:24 +00:00
|
|
|
elif [[ -f /usr/lib/os-release ]]; then
|
2025-12-03 20:40:49 +00:00
|
|
|
source /usr/lib/os-release
|
|
|
|
|
release=$ID
|
2025-09-28 12:00:45 +00:00
|
|
|
else
|
2026-05-11 04:20:49 +00:00
|
|
|
echo "Failed to check the system OS, please contact the author!" >&2
|
|
|
|
|
exit 1
|
2025-09-28 12:00:45 +00:00
|
|
|
fi
|
|
|
|
|
echo "The OS release is: $release"
|
|
|
|
|
|
|
|
|
|
arch() {
|
2025-12-03 20:40:49 +00:00
|
|
|
case "$(uname -m)" in
|
|
|
|
|
x86_64 | x64 | amd64) echo 'amd64' ;;
|
|
|
|
|
i*86 | x86) echo '386' ;;
|
|
|
|
|
armv8* | armv8 | arm64 | aarch64) echo 'arm64' ;;
|
|
|
|
|
armv7* | armv7 | arm) echo 'armv7' ;;
|
|
|
|
|
armv6* | armv6) echo 'armv6' ;;
|
|
|
|
|
armv5* | armv5) echo 'armv5' ;;
|
|
|
|
|
s390x) echo 's390x' ;;
|
2026-05-11 04:20:49 +00:00
|
|
|
*) echo -e "${green}Unsupported CPU architecture! ${plain}" && rm -f update.sh && exit 1 ;;
|
2025-12-03 20:40:49 +00:00
|
|
|
esac
|
2025-09-28 12:00:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
echo "Arch: $(arch)"
|
|
|
|
|
|
2026-05-11 04:20:49 +00:00
|
|
|
get_github_mirror() {
|
|
|
|
|
local custom_mirror="${GITHUB_MIRROR:-}"
|
|
|
|
|
if [[ -n "$custom_mirror" ]]; then
|
|
|
|
|
echo "$custom_mirror"
|
2025-12-27 23:03:33 +00:00
|
|
|
else
|
2026-05-11 04:20:49 +00:00
|
|
|
echo "$GITHUB_MIRROR_DEFAULT"
|
2025-12-27 23:03:33 +00:00
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-11 04:20:49 +00:00
|
|
|
get_github_raw() {
|
|
|
|
|
local mirror=$(get_github_mirror)
|
|
|
|
|
if [[ "$mirror" == "$GITHUB_MIRROR_DEFAULT" ]]; then
|
|
|
|
|
echo "$GITHUB_RAW_DEFAULT"
|
2026-01-05 04:28:02 +00:00
|
|
|
else
|
2026-05-11 04:20:49 +00:00
|
|
|
echo "$mirror"
|
2026-01-05 04:28:02 +00:00
|
|
|
fi
|
2025-12-27 23:03:33 +00:00
|
|
|
}
|
2026-01-05 04:28:02 +00:00
|
|
|
|
2026-05-11 04:20:49 +00:00
|
|
|
update_x-ui() {
|
|
|
|
|
cd ${xui_folder%/x-ui}/
|
2025-12-27 23:03:33 +00:00
|
|
|
|
2026-05-11 04:20:49 +00:00
|
|
|
local github_raw=$(get_github_raw)
|
2025-12-27 23:03:33 +00:00
|
|
|
|
2026-05-11 04:20:49 +00:00
|
|
|
if [ $# == 0 ]; then
|
2026-05-11 05:28:05 +00:00
|
|
|
tag_version=$(curl -4 -Ls "https://api.github.com/repos/${REPO_OWNER}/${REPO_NAME}/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/')
|
2026-05-11 04:20:49 +00:00
|
|
|
if [[ ! -n "$tag_version" ]]; then
|
|
|
|
|
echo -e "${yellow}Failed to fetch x-ui version, it may be due to GitHub API restrictions, please try it later${plain}"
|
|
|
|
|
exit 1
|
2026-04-17 10:19:45 +00:00
|
|
|
fi
|
2026-05-11 04:20:49 +00:00
|
|
|
echo -e "Got x-ui latest version: ${tag_version}, beginning the installation..."
|
2026-05-11 05:28:05 +00:00
|
|
|
curl -4fLRo ${xui_folder}-linux-$(arch).tar.gz https://github.com/${REPO_OWNER}/${REPO_NAME}/releases/download/${tag_version}/x-ui-linux-$(arch).tar.gz
|
2026-05-11 04:20:49 +00:00
|
|
|
if [[ $? -ne 0 ]]; then
|
|
|
|
|
echo -e "${red}Downloading x-ui failed, please be sure that your server can access GitHub ${plain}"
|
|
|
|
|
exit 1
|
2026-04-17 10:19:45 +00:00
|
|
|
fi
|
2025-12-27 23:03:33 +00:00
|
|
|
else
|
2026-05-11 04:20:49 +00:00
|
|
|
tag_version=$1
|
|
|
|
|
tag_version_numeric=${tag_version#v}
|
|
|
|
|
min_version="2.3.5"
|
2025-12-27 23:03:33 +00:00
|
|
|
|
2026-05-11 04:20:49 +00:00
|
|
|
if [[ "$(printf '%s\n' "$min_version" "$tag_version_numeric" | sort -V | head -n1)" != "$min_version" ]]; then
|
|
|
|
|
echo -e "${red}Please use a newer version (at least v2.3.5). Exiting installation.${plain}"
|
|
|
|
|
exit 1
|
2025-12-27 23:03:33 +00:00
|
|
|
fi
|
2026-05-04 11:20:24 +00:00
|
|
|
|
2026-05-11 05:28:05 +00:00
|
|
|
url="https://github.com/${REPO_OWNER}/${REPO_NAME}/releases/download/${tag_version}/x-ui-linux-$(arch).tar.gz"
|
2026-05-11 04:20:49 +00:00
|
|
|
echo -e "Beginning to install x-ui $1"
|
|
|
|
|
curl -4fLRo ${xui_folder}-linux-$(arch).tar.gz ${url}
|
|
|
|
|
if [[ $? -ne 0 ]]; then
|
|
|
|
|
echo -e "${red}Download x-ui $1 failed, please check if the version exists ${plain}"
|
|
|
|
|
exit 1
|
2025-12-27 23:03:33 +00:00
|
|
|
fi
|
|
|
|
|
fi
|
2026-05-04 11:20:24 +00:00
|
|
|
|
2026-05-11 05:28:05 +00:00
|
|
|
curl -4fLRo /usr/bin/x-ui-temp ${github_raw}/${REPO_OWNER}/${REPO_NAME}/main/x-ui.sh
|
2025-12-03 20:40:49 +00:00
|
|
|
if [[ $? -ne 0 ]]; then
|
2026-05-11 04:20:49 +00:00
|
|
|
echo -e "${red}Failed to download x-ui.sh${plain}"
|
|
|
|
|
exit 1
|
2025-12-03 20:40:49 +00:00
|
|
|
fi
|
2026-05-04 11:20:24 +00:00
|
|
|
|
2026-01-03 02:57:19 +00:00
|
|
|
if [[ -e ${xui_folder}/ ]]; then
|
2025-12-03 20:40:49 +00:00
|
|
|
if [[ $release == "alpine" ]]; then
|
2026-05-11 04:20:49 +00:00
|
|
|
rc-service x-ui stop
|
2025-12-03 20:40:49 +00:00
|
|
|
else
|
2026-05-11 04:20:49 +00:00
|
|
|
systemctl stop x-ui
|
2025-12-03 20:40:49 +00:00
|
|
|
fi
|
2026-05-11 04:20:49 +00:00
|
|
|
rm ${xui_folder}/ -rf
|
2025-12-03 20:40:49 +00:00
|
|
|
fi
|
2026-05-04 11:20:24 +00:00
|
|
|
|
2026-05-11 04:20:49 +00:00
|
|
|
tar zxvf x-ui-linux-$(arch).tar.gz
|
|
|
|
|
rm x-ui-linux-$(arch).tar.gz -f
|
2026-05-04 11:20:24 +00:00
|
|
|
|
2026-05-11 04:20:49 +00:00
|
|
|
cd x-ui
|
|
|
|
|
chmod +x x-ui
|
|
|
|
|
chmod +x x-ui.sh
|
2026-05-04 11:20:24 +00:00
|
|
|
|
2026-05-11 04:20:49 +00:00
|
|
|
if [[ $(arch) == "armv5" || $(arch) == "armv6" || $(arch) == "armv7" ]]; then
|
|
|
|
|
mv bin/xray-linux-$(arch) bin/xray-linux-arm
|
|
|
|
|
chmod +x bin/xray-linux-arm
|
2025-12-03 20:40:49 +00:00
|
|
|
fi
|
2026-05-11 04:20:49 +00:00
|
|
|
chmod +x x-ui bin/xray-linux-$(arch)
|
2026-05-04 11:20:24 +00:00
|
|
|
|
2026-05-11 04:20:49 +00:00
|
|
|
mv -f /usr/bin/x-ui-temp /usr/bin/x-ui
|
|
|
|
|
chmod +x /usr/bin/x-ui
|
2026-05-04 11:20:24 +00:00
|
|
|
|
2026-05-11 04:20:49 +00:00
|
|
|
mkdir -p /var/log/x-ui
|
2026-05-04 11:20:24 +00:00
|
|
|
|
2025-12-03 20:40:49 +00:00
|
|
|
if [[ $release == "alpine" ]]; then
|
2026-05-11 04:20:49 +00:00
|
|
|
rc-service x-ui start
|
2025-12-03 20:40:49 +00:00
|
|
|
else
|
2026-05-11 04:20:49 +00:00
|
|
|
systemctl start x-ui
|
2025-12-03 20:40:49 +00:00
|
|
|
fi
|
2026-05-04 11:20:24 +00:00
|
|
|
|
2026-05-11 04:20:49 +00:00
|
|
|
echo -e "${green}x-ui ${tag_version}${plain} update finished, it is running now..."
|
2025-12-03 20:40:49 +00:00
|
|
|
echo -e ""
|
|
|
|
|
echo -e "┌───────────────────────────────────────────────────────┐
|
2025-09-28 12:00:45 +00:00
|
|
|
│ ${blue}x-ui control menu usages (subcommands):${plain} │
|
2025-12-03 20:40:49 +00:00
|
|
|
│ │
|
2025-09-28 12:00:45 +00:00
|
|
|
│ ${blue}x-ui${plain} - Admin Management Script │
|
|
|
|
|
│ ${blue}x-ui start${plain} - Start │
|
|
|
|
|
│ ${blue}x-ui stop${plain} - Stop │
|
|
|
|
|
│ ${blue}x-ui restart${plain} - Restart │
|
|
|
|
|
│ ${blue}x-ui status${plain} - Current Status │
|
|
|
|
|
│ ${blue}x-ui settings${plain} - Current Settings │
|
|
|
|
|
│ ${blue}x-ui enable${plain} - Enable Autostart on OS Startup │
|
|
|
|
|
│ ${blue}x-ui disable${plain} - Disable Autostart on OS Startup │
|
|
|
|
|
│ ${blue}x-ui log${plain} - Check logs │
|
|
|
|
|
│ ${blue}x-ui banlog${plain} - Check Fail2ban ban logs │
|
|
|
|
|
│ ${blue}x-ui update${plain} - Update │
|
2025-11-07 18:26:43 +00:00
|
|
|
│ ${blue}x-ui legacy${plain} - Legacy version │
|
2025-09-28 12:00:45 +00:00
|
|
|
│ ${blue}x-ui install${plain} - Install │
|
|
|
|
|
│ ${blue}x-ui uninstall${plain} - Uninstall │
|
2025-12-03 23:05:21 +00:00
|
|
|
└───────────────────────────────────────────────────────┘"
|
2025-09-28 12:00:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
echo -e "${green}Running...${plain}"
|
|
|
|
|
update_x-ui $1
|