feat: add optional x-ui-updategeo.timer and .service files

This commit is contained in:
Nebulosa 2026-02-02 13:46:36 +03:00
parent 5d1ae6be16
commit 5b18d1b018
2 changed files with 110 additions and 105 deletions

View file

@ -858,47 +858,36 @@ install_x-ui() {
else else
# Install systemd service file # Install systemd service file
service_installed=false service_installed=false
case "${release}" in
if [ -f "x-ui.service" ]; then ubuntu | debian | armbian)
echo -e "${green}Found x-ui.service in extracted files, installing...${plain}" if [ -f "x-ui.service.debian" ]; then
cp -f x-ui.service ${xui_service}/ >/dev/null 2>&1 echo -e "${green}Found x-ui.service.debian in extracted files, installing...${plain}"
if [[ $? -eq 0 ]]; then cp -f x-ui.service.debian ${xui_service}/x-ui.service >/dev/null 2>&1
service_installed=true if [[ $? -eq 0 ]]; then
fi service_installed=true
fi
if [ "$service_installed" = false ]; then
case "${release}" in
ubuntu | debian | armbian)
if [ -f "x-ui.service.debian" ]; then
echo -e "${green}Found x-ui.service.debian in extracted files, installing...${plain}"
cp -f x-ui.service.debian ${xui_service}/x-ui.service >/dev/null 2>&1
if [[ $? -eq 0 ]]; then
service_installed=true
fi
fi fi
;; fi
arch | manjaro | parch) ;;
if [ -f "x-ui.service.arch" ]; then arch | manjaro | parch)
echo -e "${green}Found x-ui.service.arch in extracted files, installing...${plain}" if [ -f "x-ui.service.arch" ]; then
cp -f x-ui.service.arch ${xui_service}/x-ui.service >/dev/null 2>&1 echo -e "${green}Found x-ui.service.arch in extracted files, installing...${plain}"
if [[ $? -eq 0 ]]; then cp -f x-ui.service.arch ${xui_service}/x-ui.service >/dev/null 2>&1
service_installed=true if [[ $? -eq 0 ]]; then
fi service_installed=true
fi fi
;; fi
*) ;;
if [ -f "x-ui.service.rhel" ]; then *)
echo -e "${green}Found x-ui.service.rhel in extracted files, installing...${plain}" if [ -f "x-ui.service.rhel" ]; then
cp -f x-ui.service.rhel ${xui_service}/x-ui.service >/dev/null 2>&1 echo -e "${green}Found x-ui.service.rhel in extracted files, installing...${plain}"
if [[ $? -eq 0 ]]; then cp -f x-ui.service.rhel ${xui_service}/x-ui.service >/dev/null 2>&1
service_installed=true if [[ $? -eq 0 ]]; then
fi service_installed=true
fi fi
;; fi
esac ;;
fi esac
# If service file not found in tar.gz, download from GitHub # If service file not found in tar.gz, download from GitHub
if [ "$service_installed" = false ]; then if [ "$service_installed" = false ]; then
echo -e "${yellow}Service files not found in tar.gz, downloading from GitHub...${plain}" echo -e "${yellow}Service files not found in tar.gz, downloading from GitHub...${plain}"
@ -932,8 +921,45 @@ install_x-ui() {
echo -e "${red}Failed to install x-ui.service file${plain}" echo -e "${red}Failed to install x-ui.service file${plain}"
exit 1 exit 1
fi fi
#Installing Update geo timer and service files.
geoupdate_installed=false
if [ -f "x-ui-updategeo.timer" ] && [ -f "x-ui-updategeo.service"]; then
echo -e "${green}Found x-ui-updategeo.timer and .service in extracted files, installing...${plain}"
cp -f x-ui-updategeo.{timer,service} -t ${xui_service} >/dev/null 2>&1
if [[ $? -eq 0 ]]; then
geoupdate_installed=true
fi
fi
# If geo service and timer files not found in tar.gz, download from GitHub
if [ "$geoupdate_installed" = false ]; then
echo -e "${yellow}Update geo files service and timer files not found in tar.gz, downloading from GitHub...${plain}"
curl -4fLRo ${xui_service}/x-ui-updategeo.timer https://raw.githubusercontent.com/MHSanaei/3x-ui/main/x-ui-updategeo.timer >/dev/null 2>&1
if [[ $? -ne 0 ]]; then
echo -e "${red}Failed to install x-ui-updategeo.timer from GitHub${plain}"
exit 1
fi
curl -4fLRo ${xui_service}/x-ui-updategeo.service https://raw.githubusercontent.com/MHSanaei/3x-ui/main/x-ui-updategeo.service >/dev/null 2>&1
if [[ $? -ne 0 ]]; then
echo -e "${red}Failed to install x-ui-updategeo.service from GitHub${plain}"
exit 1
fi
geoupdate_installed=true
fi
if [ "$geoupdate_installed" = true ]; then
chown root:root ${xui_service}/x-ui-updategeo.{timer,service} >/dev/null 2>&1
chmod 644 ${xui_service}/x-ui-updategeo.{timer,service} >/dev/null 2>&1
systemctl daemon-reload
echo -e "${green}Optional: you could enable the x-ui-updategeo.timer after installing, by running:${plain}"
echo -e "${green} systemctl enable --now x-ui-updategeo.timer${plain}"
else
echo -e "${red}Failed to install x-ui-updategeo.timer and .service file${plain}"
exit 1
fi
fi fi
echo -e "${green}x-ui ${tag_version}${plain} installation finished, it is running now..." echo -e "${green}x-ui ${tag_version}${plain} installation finished, it is running now..."
echo -e "" echo -e ""
echo -e "┌───────────────────────────────────────────────────────┐ echo -e "┌───────────────────────────────────────────────────────┐

111
update.sh
View file

@ -787,8 +787,12 @@ update_x-ui() {
if [ -f "${xui_service}/x-ui.service" ]; then if [ -f "${xui_service}/x-ui.service" ]; then
systemctl stop x-ui >/dev/null 2>&1 systemctl stop x-ui >/dev/null 2>&1
systemctl disable x-ui >/dev/null 2>&1 systemctl disable x-ui >/dev/null 2>&1
if [ -f "${xui_service}/x-ui-updategeo.timer"] && [ -f "${xui_service}/x-ui-updategeo.service"]; then
systemctl stop x-ui-updategeo.timer >/dev/null 2>&1
systemctl disable x-ui-updategeo.timer >/dev/null 2>&1
echo -e "${green}Removing old systemd unit version...${plain}" echo -e "${green}Removing old systemd unit version...${plain}"
rm ${xui_service}/x-ui.service -f >/dev/null 2>&1 rm ${xui_service}/x-ui.service -f >/dev/null 2>&1
rm ${xui_service}/x-ui-updategeo.{timer,service} -f >/dev/null 2>&1
systemctl daemon-reload >/dev/null 2>&1 systemctl daemon-reload >/dev/null 2>&1
else else
rm x-ui-linux-$(arch).tar.gz -f >/dev/null 2>&1 rm x-ui-linux-$(arch).tar.gz -f >/dev/null 2>&1
@ -801,6 +805,7 @@ update_x-ui() {
rm ${xui_folder}/x-ui.service.debian -f >/dev/null 2>&1 rm ${xui_folder}/x-ui.service.debian -f >/dev/null 2>&1
rm ${xui_folder}/x-ui.service.arch -f >/dev/null 2>&1 rm ${xui_folder}/x-ui.service.arch -f >/dev/null 2>&1
rm ${xui_folder}/x-ui.service.rhel -f >/dev/null 2>&1 rm ${xui_folder}/x-ui.service.rhel -f >/dev/null 2>&1
rm ${xui_folder}/x-ui-updategeo.{timer,service} -f >/dev/null 2>&1
rm ${xui_folder}/x-ui -f >/dev/null 2>&1 rm ${xui_folder}/x-ui -f >/dev/null 2>&1
rm ${xui_folder}/x-ui.sh -f >/dev/null 2>&1 rm ${xui_folder}/x-ui.sh -f >/dev/null 2>&1
echo -e "${green}Removing old xray version...${plain}" echo -e "${green}Removing old xray version...${plain}"
@ -851,87 +856,61 @@ update_x-ui() {
if [[ $release == "alpine" ]]; then if [[ $release == "alpine" ]]; then
echo -e "${green}Downloading and installing startup unit x-ui.rc...${plain}" echo -e "${green}Downloading and installing startup unit x-ui.rc...${plain}"
${curl_bin} -fLRo /etc/init.d/x-ui https://raw.githubusercontent.com/MHSanaei/3x-ui/main/x-ui.rc >/dev/null 2>&1
${curl_bin} -4fLRo /etc/init.d/x-ui https://raw.githubusercontent.com/MHSanaei/3x-ui/main/x-ui.rc >/dev/null 2>&1
if [[ $? -ne 0 ]]; then if [[ $? -ne 0 ]]; then
${curl_bin} -4fLRo /etc/init.d/x-ui https://raw.githubusercontent.com/MHSanaei/3x-ui/main/x-ui.rc >/dev/null 2>&1 _fail "ERROR: Failed to download startup unit x-ui.rc, please be sure that your server can access GitHub"
if [[ $? -ne 0 ]]; then exit 1
_fail "ERROR: Failed to download startup unit x-ui.rc, please be sure that your server can access GitHub"
fi
fi fi
chmod +x /etc/init.d/x-ui >/dev/null 2>&1 chmod +x /etc/init.d/x-ui >/dev/null 2>&1
chown root:root /etc/init.d/x-ui >/dev/null 2>&1 chown root:root /etc/init.d/x-ui >/dev/null 2>&1
rc-update add x-ui >/dev/null 2>&1 rc-update add x-ui >/dev/null 2>&1
rc-service x-ui start >/dev/null 2>&1 rc-service x-ui start >/dev/null 2>&1
else else
if [ -f "x-ui.service" ]; then echo -e "${green}Downloading and installing startup service x-ui...${plain}"
echo -e "${green}Installing systemd unit...${plain}" case "${release}" in
cp -f x-ui.service ${xui_service}/ >/dev/null 2>&1 ubuntu | debian | armbian)
if [[ $? -ne 0 ]]; then ${curl_bin} -4fLRo ${xui_service}/x-ui.service https://raw.githubusercontent.com/MHSanaei/3x-ui/main/x-ui.service.debian >/dev/null 2>&1
echo -e "${red}Failed to copy x-ui.service${plain}" ;;
exit 1 arch | manjaro | parch)
fi ${curl_bin} -4fLRo ${xui_service}/x-ui.service https://raw.githubusercontent.com/MHSanaei/3x-ui/main/x-ui.service.arch >/dev/null 2>&1
else ;;
service_installed=false *)
case "${release}" in ${curl_bin} -4fLRo ${xui_service}/x-ui.service https://raw.githubusercontent.com/MHSanaei/3x-ui/main/x-ui.service.rhel >/dev/null 2>&1
ubuntu | debian | armbian) ;;
if [ -f "x-ui.service.debian" ]; then esac
echo -e "${green}Installing debian-like systemd unit...${plain}" if [[ $? -ne 0 ]]; then
cp -f x-ui.service.debian ${xui_service}/x-ui.service >/dev/null 2>&1 echo -e "${red}Failed to install x-ui.service from GitHub${plain}"
if [[ $? -eq 0 ]]; then _fail "ERROR: Failed to download startup service file, please be sure that your server can access GitHub"
service_installed=true
fi exit 1
fi
;;
arch | manjaro | parch)
if [ -f "x-ui.service.arch" ]; then
echo -e "${green}Installing arch-like systemd unit...${plain}"
cp -f x-ui.service.arch ${xui_service}/x-ui.service >/dev/null 2>&1
if [[ $? -eq 0 ]]; then
service_installed=true
fi
fi
;;
*)
if [ -f "x-ui.service.rhel" ]; then
echo -e "${green}Installing rhel-like systemd unit...${plain}"
cp -f x-ui.service.rhel ${xui_service}/x-ui.service >/dev/null 2>&1
if [[ $? -eq 0 ]]; then
service_installed=true
fi
fi
;;
esac
# If service file not found in tar.gz, download from GitHub
if [ "$service_installed" = false ]; then
echo -e "${yellow}Service files not found in tar.gz, downloading from GitHub...${plain}"
case "${release}" in
ubuntu | debian | armbian)
${curl_bin} -4fLRo ${xui_service}/x-ui.service https://raw.githubusercontent.com/MHSanaei/3x-ui/main/x-ui.service.debian >/dev/null 2>&1
;;
arch | manjaro | parch)
${curl_bin} -4fLRo ${xui_service}/x-ui.service https://raw.githubusercontent.com/MHSanaei/3x-ui/main/x-ui.service.arch >/dev/null 2>&1
;;
*)
${curl_bin} -4fLRo ${xui_service}/x-ui.service https://raw.githubusercontent.com/MHSanaei/3x-ui/main/x-ui.service.rhel >/dev/null 2>&1
;;
esac
if [[ $? -ne 0 ]]; then
echo -e "${red}Failed to install x-ui.service from GitHub${plain}"
exit 1
fi
fi
fi fi
chown root:root ${xui_service}/x-ui.service >/dev/null 2>&1 chown root:root ${xui_service}/x-ui.service >/dev/null 2>&1
chmod 644 ${xui_service}/x-ui.service >/dev/null 2>&1 chmod 644 ${xui_service}/x-ui.service >/dev/null 2>&1
systemctl daemon-reload >/dev/null 2>&1 systemctl daemon-reload >/dev/null 2>&1
systemctl enable x-ui >/dev/null 2>&1 systemctl enable x-ui >/dev/null 2>&1
systemctl start x-ui >/dev/null 2>&1 systemctl start x-ui >/dev/null 2>&1
echo -e "${green}Downloading and installing geo files update timer...${plain}"
curl -4fLRo ${xui_service}/x-ui-updategeo.timer https://raw.githubusercontent.com/MHSanaei/3x-ui/main/x-ui-updategeo.timer >/dev/null 2>&1
if [[ $? -ne 0 ]]; then
_fail "ERROR: Failed to install x-ui-updategeo.timer from GitHub"
exit 1
fi
curl -4fLRo ${xui_service}/x-ui-updategeo.service https://raw.githubusercontent.com/MHSanaei/3x-ui/main/x-ui-updategeo.service >/dev/null 2>&1
if [[ $? -ne 0 ]]; then
_fail "ERROR: Failed to install x-ui-updategeo.service from GitHub"
exit 1
fi
chown root:root ${xui_service}/x-ui-updategeo.{timer,service} >/dev/null 2>&1
chmod 644 ${xui_service}/x-ui-updategeo.{timer,service} >/dev/null 2>&1
systemctl daemon-reload
echo -e "${green}Optional: you could enable the x-ui-updategeo.timer after installing, by running:${plain}"
echo -e "${green} systemctl enable --now x-ui-updategeo.timer${plain}"
fi fi
config_after_update config_after_update
echo -e "${green}x-ui ${tag_version}${plain} updating finished, it is running now..." echo -e "${green}x-ui ${tag_version}${plain} updating finished, it is running now..."
echo -e "" echo -e ""
echo -e "┌───────────────────────────────────────────────────────┐ echo -e "┌───────────────────────────────────────────────────────┐