2024-12-20 19:03:49 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
2025-02-02 22:59:06 +01:00
|
|
|
# ==========================================================
|
2025-09-10 18:47:55 +02:00
|
|
|
# ProxMenux - A menu-driven script for Proxmox VE management
|
2025-02-02 22:59:06 +01:00
|
|
|
# ==========================================================
|
|
|
|
|
# Author : MacRimi
|
2026-03-18 21:15:34 +01:00
|
|
|
# Copyright : (c) 2024-2025 MacRimi
|
|
|
|
|
# License : GPL-3.0 (https://github.com/MacRimi/ProxMenux/blob/main/LICENSE)
|
|
|
|
|
# Version : 1.2
|
|
|
|
|
# Last Updated: 18/03/2026
|
2025-02-02 22:59:06 +01:00
|
|
|
# ==========================================================
|
|
|
|
|
# Description:
|
2026-03-18 21:15:34 +01:00
|
|
|
# Main entry point for ProxMenux.
|
|
|
|
|
# - Loads configuration and utility functions.
|
|
|
|
|
# - Detects if running in Beta Program mode (develop branch).
|
|
|
|
|
# - Checks for updates from the appropriate branch (main or develop).
|
|
|
|
|
# - In beta mode: compares beta_version.txt; notifies when a stable
|
|
|
|
|
# release is available and prompts the user to switch.
|
|
|
|
|
# - Launches the main menu.
|
2025-02-02 22:59:06 +01:00
|
|
|
# ==========================================================
|
|
|
|
|
|
2026-03-18 21:15:34 +01:00
|
|
|
# ── Configuration ──────────────────────────────────────────
|
2024-12-20 21:44:51 +01:00
|
|
|
BASE_DIR="/usr/local/share/proxmenux"
|
2025-11-15 23:58:26 +01:00
|
|
|
LOCAL_SCRIPTS="$BASE_DIR/scripts"
|
2025-02-02 22:59:06 +01:00
|
|
|
CONFIG_FILE="$BASE_DIR/config.json"
|
|
|
|
|
CACHE_FILE="$BASE_DIR/cache.json"
|
|
|
|
|
UTILS_FILE="$BASE_DIR/utils.sh"
|
2024-12-20 21:44:51 +01:00
|
|
|
LOCAL_VERSION_FILE="$BASE_DIR/version.txt"
|
2026-03-18 21:15:34 +01:00
|
|
|
BETA_VERSION_FILE="$BASE_DIR/beta_version.txt"
|
2025-02-02 22:59:06 +01:00
|
|
|
VENV_PATH="/opt/googletrans-env"
|
2024-12-20 20:41:25 +01:00
|
|
|
|
2026-03-18 21:15:34 +01:00
|
|
|
REPO_MAIN="https://raw.githubusercontent.com/MacRimi/ProxMenux/main"
|
|
|
|
|
REPO_DEVELOP="https://raw.githubusercontent.com/MacRimi/ProxMenux/develop"
|
2025-11-16 01:04:16 +01:00
|
|
|
|
2026-03-18 21:15:34 +01:00
|
|
|
# ── Load utilities ─────────────────────────────────────────
|
|
|
|
|
[[ -f "$UTILS_FILE" ]] && source "$UTILS_FILE"
|
2025-11-15 23:58:26 +01:00
|
|
|
|
|
|
|
|
: "${LOCAL_SCRIPTS:=/usr/local/share/proxmenux/scripts}"
|
2024-12-20 19:03:49 +01:00
|
|
|
|
2026-03-18 21:15:34 +01:00
|
|
|
# ── Detect beta mode ───────────────────────────────────────
|
|
|
|
|
# Returns 0 (true) if this install is part of the beta program.
|
|
|
|
|
is_beta() {
|
|
|
|
|
[[ -f "$CONFIG_FILE" ]] || return 1
|
|
|
|
|
local beta_flag
|
|
|
|
|
beta_flag=$(jq -r '.beta_program.status // empty' "$CONFIG_FILE" 2>/dev/null)
|
|
|
|
|
[[ "$beta_flag" == "active" ]]
|
|
|
|
|
}
|
2025-11-14 20:38:07 +01:00
|
|
|
|
2026-06-02 20:39:47 +02:00
|
|
|
# ── Recover broken Monitor unit before anything else ──────
|
|
|
|
|
#
|
|
|
|
|
# v1.2.2 changed the AppImage layout: the binary is extracted to
|
|
|
|
|
# /usr/local/share/proxmenux/monitor-app/ and the systemd unit
|
|
|
|
|
# executes AppRun out of that directory. The install_proxmenux.sh
|
|
|
|
|
# update path before v1.2.2.1 only rewrote the unit on fresh installs,
|
|
|
|
|
# so every user updating from v1.2.1 stable inherited the old unit
|
|
|
|
|
# whose ExecStart still pointed at the bare AppImage. On PVE 9.x /
|
|
|
|
|
# Debian 13 that bare AppImage hits status=203/EXEC immediately and
|
|
|
|
|
# the service enters the activating loop reported in #222.
|
|
|
|
|
#
|
|
|
|
|
# Re-running the new installer fixes it permanently, but the update
|
|
|
|
|
# prompt below uses --defaultno so a user pressing Enter by reflex
|
|
|
|
|
# stays broken. Patch the unit defensively at every menu launch: if
|
|
|
|
|
# the bug's exact fingerprint is present (unit ExecStart matches the
|
|
|
|
|
# bare AppImage path AND the extracted AppRun already exists) we
|
|
|
|
|
# silently rewrite the unit and bounce the service. The check is a
|
|
|
|
|
# no-op for healthy installs and for hosts that never installed the
|
|
|
|
|
# Monitor at all, so it's safe to run unconditionally.
|
|
|
|
|
auto_repair_monitor_unit() {
|
|
|
|
|
local unit_file="/etc/systemd/system/proxmenux-monitor.service"
|
|
|
|
|
local extracted_runtime="/usr/local/share/proxmenux/monitor-app"
|
|
|
|
|
local apprun="$extracted_runtime/AppRun"
|
|
|
|
|
local bare_appimage="/usr/local/share/proxmenux/ProxMenux-Monitor.AppImage"
|
|
|
|
|
|
|
|
|
|
[[ -f "$unit_file" && -x "$apprun" ]] || return 0
|
|
|
|
|
grep -q "^ExecStart=${bare_appimage}\$" "$unit_file" || return 0
|
|
|
|
|
|
|
|
|
|
local port working_dir
|
|
|
|
|
port=$(awk -F'"' '/^Environment="PORT=/ {print $2; exit}' "$unit_file" 2>/dev/null \
|
|
|
|
|
| sed 's/^PORT=//')
|
|
|
|
|
[[ -z "$port" ]] && port="8008"
|
|
|
|
|
working_dir=$(awk -F'=' '/^WorkingDirectory=/ {print $2; exit}' "$unit_file" 2>/dev/null)
|
|
|
|
|
[[ -z "$working_dir" ]] && working_dir="/usr/local/share/proxmenux"
|
|
|
|
|
|
|
|
|
|
cat > "$unit_file" <<EOF
|
|
|
|
|
[Unit]
|
|
|
|
|
Description=ProxMenux Monitor - Web Dashboard
|
|
|
|
|
After=network.target
|
|
|
|
|
|
|
|
|
|
[Service]
|
|
|
|
|
Type=simple
|
|
|
|
|
User=root
|
|
|
|
|
WorkingDirectory=$working_dir
|
|
|
|
|
ExecStart=$apprun
|
|
|
|
|
Restart=on-failure
|
|
|
|
|
RestartSec=10
|
|
|
|
|
Environment="PORT=$port"
|
|
|
|
|
|
|
|
|
|
[Install]
|
|
|
|
|
WantedBy=multi-user.target
|
|
|
|
|
EOF
|
|
|
|
|
|
|
|
|
|
systemctl daemon-reload >/dev/null 2>&1
|
|
|
|
|
systemctl restart proxmenux-monitor.service >/dev/null 2>&1
|
|
|
|
|
sleep 2
|
|
|
|
|
|
|
|
|
|
if systemctl is-active --quiet proxmenux-monitor.service 2>/dev/null; then
|
|
|
|
|
type msg_ok >/dev/null 2>&1 \
|
|
|
|
|
&& msg_ok "$(translate 'ProxMenux Monitor unit repaired and restarted')" \
|
|
|
|
|
|| echo "[ProxMenux] Monitor unit repaired and restarted"
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-18 21:15:34 +01:00
|
|
|
# ── Check for updates ──────────────────────────────────────
|
2025-01-09 21:06:51 +01:00
|
|
|
check_updates() {
|
2026-03-18 21:15:34 +01:00
|
|
|
if is_beta; then
|
|
|
|
|
check_updates_beta
|
|
|
|
|
else
|
|
|
|
|
check_updates_stable
|
|
|
|
|
fi
|
|
|
|
|
}
|
2025-11-14 21:30:58 +01:00
|
|
|
|
2026-03-18 21:15:34 +01:00
|
|
|
# ── Stable update check (main branch) ─────────────────────
|
|
|
|
|
check_updates_stable() {
|
|
|
|
|
local VERSION_URL="$REPO_MAIN/version.txt"
|
|
|
|
|
local INSTALL_URL="$REPO_MAIN/install_proxmenux.sh"
|
|
|
|
|
local INSTALL_SCRIPT="$BASE_DIR/install_proxmenux.sh"
|
2025-11-16 01:04:16 +01:00
|
|
|
|
2025-11-16 00:23:14 +01:00
|
|
|
[[ ! -f "$LOCAL_VERSION_FILE" ]] && return 0
|
2025-11-16 00:13:52 +01:00
|
|
|
|
2026-03-18 21:15:34 +01:00
|
|
|
local REMOTE_VERSION LOCAL_VERSION
|
2025-11-16 00:23:14 +01:00
|
|
|
REMOTE_VERSION="$(curl -fsSL "$VERSION_URL" 2>/dev/null | head -n 1)"
|
|
|
|
|
[[ -z "$REMOTE_VERSION" ]] && return 0
|
2025-01-12 17:06:16 +01:00
|
|
|
|
2025-11-16 00:23:14 +01:00
|
|
|
LOCAL_VERSION="$(head -n 1 "$LOCAL_VERSION_FILE" 2>/dev/null)"
|
|
|
|
|
[[ -z "$LOCAL_VERSION" ]] && return 0
|
|
|
|
|
[[ "$LOCAL_VERSION" = "$REMOTE_VERSION" ]] && return 0
|
|
|
|
|
|
2026-06-09 00:13:24 +02:00
|
|
|
# Extract the translated prompt strings into variables FIRST so the
|
|
|
|
|
# whiptail line below is trivially parseable. A user on the 1.2.2
|
|
|
|
|
# update path hit:
|
|
|
|
|
# menu: line 138: syntax error near unexpected token `$REMOTE_VERSION'
|
|
|
|
|
# The original inline form was technically valid bash, but a
|
|
|
|
|
# translate() return that contains a stray quote or paren is enough
|
|
|
|
|
# to confuse a partially-rewritten file (race during update) or a
|
|
|
|
|
# corrupted download. Splitting the strings out closes the entire
|
|
|
|
|
# parsing-risk surface for zero behavioural change.
|
|
|
|
|
local PROMPT_TITLE PROMPT_AVAIL PROMPT_ASK
|
|
|
|
|
PROMPT_TITLE="$(translate 'Update Available')"
|
|
|
|
|
PROMPT_AVAIL="$(translate 'New version available')"
|
|
|
|
|
PROMPT_ASK="$(translate 'Do you want to update now?')"
|
|
|
|
|
|
|
|
|
|
if whiptail --title "$PROMPT_TITLE" \
|
|
|
|
|
--yesno "$PROMPT_AVAIL ($REMOTE_VERSION)\n\n$PROMPT_ASK" \
|
2025-02-02 22:59:06 +01:00
|
|
|
10 60 --defaultno; then
|
2025-11-14 21:30:58 +01:00
|
|
|
|
2025-11-16 00:23:14 +01:00
|
|
|
msg_warn "$(translate 'Starting ProxMenux update...')"
|
2025-11-16 00:17:22 +01:00
|
|
|
|
2026-04-18 00:58:25 +02:00
|
|
|
if curl -fsSL "$INSTALL_URL" -o "$INSTALL_SCRIPT"; then
|
|
|
|
|
chmod +x "$INSTALL_SCRIPT"
|
2026-05-14 14:33:27 +02:00
|
|
|
# Replace this shell before the installer refreshes /usr/local/bin/menu.
|
|
|
|
|
exec bash "$INSTALL_SCRIPT" --update
|
2026-04-18 00:58:25 +02:00
|
|
|
fi
|
2026-03-18 21:15:34 +01:00
|
|
|
fi
|
|
|
|
|
}
|
2025-11-16 01:21:07 +01:00
|
|
|
|
2026-04-18 01:20:39 +02:00
|
|
|
# ── Beta-mode update check (main + develop) ───────────────
|
2026-04-18 18:48:33 +02:00
|
|
|
# When the beta program is active, check BOTH channels. The stable check
|
|
|
|
|
# is delegated to check_updates_stable (same prompt, same installer). After
|
|
|
|
|
# that we only need the beta-specific part: develop vs beta_version.txt.
|
2026-03-18 21:15:34 +01:00
|
|
|
check_updates_beta() {
|
2026-04-18 18:48:33 +02:00
|
|
|
# 1. Stable release on main — reuse the non-beta path.
|
|
|
|
|
check_updates_stable
|
2025-01-12 18:10:37 +01:00
|
|
|
|
2026-04-18 18:48:33 +02:00
|
|
|
# 2. Beta build on develop.
|
2026-04-18 00:58:25 +02:00
|
|
|
[[ ! -f "$BETA_VERSION_FILE" ]] && return 0
|
|
|
|
|
|
2026-04-18 01:20:39 +02:00
|
|
|
local REMOTE_BETA LOCAL_BETA
|
|
|
|
|
REMOTE_BETA="$(curl -fsSL "$REPO_DEVELOP/beta_version.txt" 2>/dev/null | head -n 1)"
|
|
|
|
|
LOCAL_BETA="$(head -n 1 "$BETA_VERSION_FILE" 2>/dev/null)"
|
|
|
|
|
[[ -z "$REMOTE_BETA" || -z "$LOCAL_BETA" || "$LOCAL_BETA" = "$REMOTE_BETA" ]] && return 0
|
|
|
|
|
[[ "$(printf '%s\n%s\n' "$LOCAL_BETA" "$REMOTE_BETA" | sort -V | tail -1)" = "$REMOTE_BETA" ]] || return 0
|
2026-04-18 00:58:25 +02:00
|
|
|
|
|
|
|
|
if whiptail --title "Beta Update Available" \
|
2026-04-18 01:20:39 +02:00
|
|
|
--yesno "A new beta build is available!\n\nInstalled beta : $LOCAL_BETA\nNew beta build : $REMOTE_BETA\n\nDo you want to update now?" \
|
|
|
|
|
12 64 --defaultno; then
|
2026-04-18 00:58:25 +02:00
|
|
|
|
2026-04-18 01:20:39 +02:00
|
|
|
msg_warn "Updating to beta build $REMOTE_BETA ..."
|
2026-04-18 00:58:25 +02:00
|
|
|
|
2026-04-18 01:20:39 +02:00
|
|
|
local INSTALL_BETA_SCRIPT="$BASE_DIR/install_proxmenux_beta.sh"
|
|
|
|
|
if curl -fsSL "$REPO_DEVELOP/install_proxmenux_beta.sh" -o "$INSTALL_BETA_SCRIPT"; then
|
|
|
|
|
chmod +x "$INSTALL_BETA_SCRIPT"
|
2026-05-14 14:33:27 +02:00
|
|
|
# Replace this shell before the installer refreshes /usr/local/bin/menu.
|
|
|
|
|
exec bash "$INSTALL_BETA_SCRIPT" --update
|
2026-04-18 00:58:25 +02:00
|
|
|
else
|
|
|
|
|
msg_error "Could not download the beta installer from the develop branch."
|
2026-03-18 21:15:34 +01:00
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
}
|
2025-11-16 01:04:16 +01:00
|
|
|
|
2026-03-18 21:15:34 +01:00
|
|
|
# ── Main ───────────────────────────────────────────────────
|
2025-02-02 22:59:06 +01:00
|
|
|
main_menu() {
|
2025-11-15 23:58:26 +01:00
|
|
|
local MAIN_MENU="$LOCAL_SCRIPTS/menus/main_menu.sh"
|
|
|
|
|
exec bash "$MAIN_MENU"
|
2024-12-20 20:26:52 +01:00
|
|
|
}
|
|
|
|
|
|
2025-01-09 21:50:31 +01:00
|
|
|
load_language
|
2025-02-02 22:59:06 +01:00
|
|
|
initialize_cache
|
2026-06-02 20:39:47 +02:00
|
|
|
auto_repair_monitor_unit
|
2025-11-14 20:38:07 +01:00
|
|
|
check_updates
|
2025-11-14 20:48:38 +01:00
|
|
|
main_menu
|