#!/bin/bash : <<'IRANUX_METADATA' { "standard": { "name": "iranux-script-metadata", "schema_version": "1.2" }, "script": { "id": "x-ui-alireza-installer", "name": "x-ui Alireza Installer", "version": "1.1.0", "description": "Installs or updates the alireza0/x-ui panel: updates system packages, downloads the selected release, installs the systemd service, migrates settings, and can restore a backup left by a failed installation. On a new installation it sets the admin login (the password is created by the platform and shown on the result page) and a random port and panel path.", "estimated_minutes": 5, "i18n": { "fa": { "name": "نصب پنل x-ui (Alireza)", "description": "پنل alireza0/x-ui را نصب یا به‌روزرسانی می‌کند: بسته‌های سیستم را به‌روزرسانی می‌کند، نسخه‌ی انتخاب‌شده را دانلود می‌کند، سرویس systemd را نصب می‌کند، تنظیمات را منتقل می‌کند و می‌تواند نسخه‌ی پشتیبانِ مانده از یک نصب ناموفق را بازیابی کند. در نصب جدید، نام کاربری و رمز عبور را از پارامترها تنظیم می‌کند (رمز را پلتفرم می‌سازد و در صفحه‌ی نتیجه نشان می‌دهد) و پورت و مسیر پنل را تصادفی می‌سازد." } } }, "risk": { "level": "high" }, "requirements": { "requires_root": true, "requires_internet": true, "supported_os": [ "ubuntu", "debian", "armbian", "centos", "almalinux", "rocky", "ol", "fedora", "amzn", "arch", "manjaro", "parch", "opensuse-tumbleweed" ], "required_commands": [ "systemctl" ] }, "ui": { "category": { "id": "proxy-management", "name": "Proxy Management" }, "action": { "id": "management-panel-installers", "name": "Management Panel Installers" }, "icon": { "library": "mdi", "name": "view-dashboard-outline" } } } IRANUX_METADATA : <<'IRANUX_PARAM' { "name": "target_version", "label": "Version", "description": "Enter the x-ui release to install, for example v1.8.0. Leave empty to install the latest release.", "type": "string", "required": false, "placeholder": "v1.8.0", "group": "Download Settings", "level": "advanced", "i18n": { "fa": { "label": "نسخه", "description": "نسخه‌ی x-ui را که می‌خواهید نصب شود وارد کنید، مثلاً v1.8.0. برای نصب آخرین نسخه، خالی بگذارید." } } } IRANUX_PARAM : <<'IRANUX_PARAM' { "name": "restore_backup", "label": "Restore backup of a failed installation", "description": "If a backup from a failed installation exists in /usr/local/x-ui-backup, choose whether to restore it instead of installing again. If you choose No, that backup is deleted after the new installation.", "type": "enum", "required": true, "default": "N", "options": [ { "label": "Yes", "value": "Y" }, { "label": "No", "value": "N" } ], "group": "Recovery Settings", "i18n": { "fa": { "label": "بازیابی نسخه‌ی پشتیبان نصب ناموفق", "description": "اگر نسخه‌ی پشتیبانی از یک نصب ناموفق در /usr/local/x-ui-backup وجود دارد، انتخاب کنید که به‌جای نصب دوباره، بازیابی شود یا نه. اگر «خیر» را انتخاب کنید، آن نسخه‌ی پشتیبان بعد از نصب جدید حذف می‌شود." } } } IRANUX_PARAM : <<'IRANUX_PARAM' { "name": "customize_panel_port", "label": "Choose the panel port", "description": "Choose whether to use your own panel port on a new installation. If you choose No, a random port is used.", "type": "enum", "required": true, "default": "N", "options": [ { "label": "Yes", "value": "Y" }, { "label": "No", "value": "N" } ], "group": "Panel Settings", "i18n": { "fa": { "label": "انتخاب پورت پنل", "description": "انتخاب کنید که در نصب جدید، پورت دلخواه شما برای پنل استفاده شود یا نه. اگر «خیر» را انتخاب کنید، یک پورت تصادفی استفاده می‌شود." } } } IRANUX_PARAM : <<'IRANUX_PARAM' { "name": "panel_port", "label": "Panel port", "description": "Enter the port the panel listens on. Used only when Choose the panel port is Yes. Leave empty to get a random port.", "type": "port", "required": false, "example": 54321, "group": "Panel Settings", "generate": "port", "i18n": { "fa": { "label": "پورت پنل", "description": "پورتی را که پنل روی آن کار می‌کند وارد کنید. فقط وقتی استفاده می‌شود که «انتخاب پورت پنل» روی «بله» باشد. برای گرفتن یک پورت تصادفی، خالی بگذارید." } } } IRANUX_PARAM : <<'IRANUX_PARAM' { "name": "admin_username", "label": "Admin username", "description": "Enter the username for signing in to the panel. Used when the panel still has the default login (a new installation). Leave empty to use admin.", "type": "string", "required": false, "default": "admin", "placeholder": "admin", "group": "Admin Settings", "i18n": { "fa": { "label": "نام کاربری مدیر", "description": "نام کاربری برای ورود به پنل را وارد کنید. وقتی پنل هنوز ورود پیش‌فرض دارد (نصب تازه) استفاده می‌شود. برای استفاده از admin خالی بگذارید." } } } IRANUX_PARAM : <<'IRANUX_PARAM' { "name": "admin_password", "label": "Admin password", "description": "The platform creates a strong password unless you type one. It is shown on the result page. Used when the panel still has the default login (a new installation).", "type": "password", "required": true, "generate": "password", "group": "Admin Settings", "i18n": { "fa": { "label": "رمز عبور مدیر", "description": "اگر رمزی وارد نکنید، پلتفرم یک رمز قوی می‌سازد و در صفحه‌ی نتیجه نشان می‌دهد. وقتی پنل هنوز ورود پیش‌فرض دارد (نصب تازه) استفاده می‌شود." } } } IRANUX_PARAM red='\033[0;31m' green='\033[0;32m' yellow='\033[0;33m' plain='\033[0m' cur_dir=$(pwd) # Iranux: JSON string escaping for the IRANUX_RESULT line (specification Appendix C). iranux_json_string() { local s="$1" s="${s//\\/\\\\}" s="${s//\"/\\\"}" s="${s//$'\t'/\\t}" s="${s//$'\r'/\\r}" s="${s//$'\n'/\\n}" printf '"%s"' "$s" } # Iranux: values reported in the IRANUX_RESULT line (empty values are left out). iranux_result_panel_port="" iranux_result_panel_path="" iranux_result_username="" iranux_result_password_set=0 iranux_outputs="" iranux_add_output() { # $1 key, $2 English label, $3 value, $4 type, $5 Persian label [[ -n "$3" ]] || return 0 [[ -z "$iranux_outputs" ]] || iranux_outputs+="," iranux_outputs+="{\"key\":\"$1\",\"label\":\"$2\",\"value\":$(iranux_json_string "$3"),\"type\":\"$4\",\"i18n\":{\"fa\":{\"label\":\"$5\"}}}" } iranux_print_result() { iranux_add_output "panel_port" "Panel port" "$iranux_result_panel_port" "text" "پورت پنل" iranux_add_output "panel_path" "Panel path" "$iranux_result_panel_path" "text" "مسیر پنل" iranux_add_output "admin_username" "Admin username" "$iranux_result_username" "copy" "نام کاربری مدیر" iranux_add_output "installed_version" "Installed version" "$last_version" "text" "نسخه‌ی نصب‌شده" local iranux_show="" [[ "$iranux_result_password_set" == "1" ]] && iranux_show=",\"show_generated\":[\"admin_password\"]" echo "IRANUX_RESULT {\"outputs\":[${iranux_outputs}]${iranux_show}}" } # check root [[ $EUID -ne 0 ]] && echo -e "${red}Fatal error: ${plain} Please run this script with root privilege \n " && exit 1 # Check OS and set release variable if [[ -f /etc/os-release ]]; then source /etc/os-release release=$ID elif [[ -f /usr/lib/os-release ]]; then source /usr/lib/os-release release=$ID else echo "Failed to check the system OS, please contact the author!" >&2 exit 1 fi echo "The OS release is: $release" arch() { 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' ;; *) echo -e "${green}Unsupported CPU architecture! ${plain}" && rm -f install.sh && exit 1 ;; esac } echo "arch: $(arch)" install_dependencies() { case "${release}" in ubuntu | debian | armbian) apt-get update && apt-get install -y -q wget curl tar tzdata cron ;; centos | almalinux | rocky | ol) yum -y update && yum install -y -q wget curl tar tzdata cronie ;; fedora | amzn) dnf -y update && dnf install -y -q wget curl tar tzdata cronie ;; arch | manjaro | parch) pacman -Syu && pacman -Syu --noconfirm wget curl tar tzdata cronie ;; opensuse-tumbleweed) zypper refresh && zypper -q install -y wget curl tar timezone cron ;; *) apt-get update && apt install -y -q wget curl tar tzdata cron ;; esac } gen_random_string() { local length="$1" local random_string=$(LC_ALL=C tr -dc 'a-zA-Z0-9'