Files
ProxMenux/menu

197 lines
8.0 KiB
Plaintext
Raw Normal View History

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
menu: self-heal broken monitor unit on launch (belt-and-suspenders for #222) The installer fix in this PR rewrites the systemd unit on every v1.2.2.x update, which catches every user once they accept the update prompt. But the prompt in `menu` uses `--defaultno` so a user who presses Enter by reflex stays on the broken state and opens a fresh issue, which is the scenario unfolding in #222. Add a tiny `auto_repair_monitor_unit` function that runs before `check_updates` on every menu launch. It only touches anything when the bug's exact fingerprint is present: 1. /etc/systemd/system/proxmenux-monitor.service exists 2. Its ExecStart points at /usr/local/share/proxmenux/ProxMenux-Monitor.AppImage 3. The extracted AppRun is already on disk at /usr/local/share/proxmenux/monitor-app/AppRun When all three are true the function rewrites the unit, reloads systemd, restarts the service, and logs a single msg_ok line. For healthy installs and for hosts that never had the Monitor at all, it returns immediately without touching anything — safe to ship unconditionally. Verified on .55 by simulating the broken unit (ExecStart on the bare AppImage → 203/EXEC + activating loop) and running the new menu script: unit rewritten to AppRun, service active, single "ProxMenux Monitor unit repaired and restarted" line printed. CHANGELOG entries (EN+ES) updated to mention the auto-repair so users on the broken state know the simpler recovery is now "just run menu". Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
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
if whiptail --title "$(translate 'Update Available')" \
--yesno "$(translate 'New version available') ($REMOTE_VERSION)\n\n$(translate 'Do you want to update now?')" \
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"
# 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"
# 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
menu: self-heal broken monitor unit on launch (belt-and-suspenders for #222) The installer fix in this PR rewrites the systemd unit on every v1.2.2.x update, which catches every user once they accept the update prompt. But the prompt in `menu` uses `--defaultno` so a user who presses Enter by reflex stays on the broken state and opens a fresh issue, which is the scenario unfolding in #222. Add a tiny `auto_repair_monitor_unit` function that runs before `check_updates` on every menu launch. It only touches anything when the bug's exact fingerprint is present: 1. /etc/systemd/system/proxmenux-monitor.service exists 2. Its ExecStart points at /usr/local/share/proxmenux/ProxMenux-Monitor.AppImage 3. The extracted AppRun is already on disk at /usr/local/share/proxmenux/monitor-app/AppRun When all three are true the function rewrites the unit, reloads systemd, restarts the service, and logs a single msg_ok line. For healthy installs and for hosts that never had the Monitor at all, it returns immediately without touching anything — safe to ship unconditionally. Verified on .55 by simulating the broken unit (ExecStart on the bare AppImage → 203/EXEC + activating loop) and running the new menu script: unit rewritten to AppRun, service active, single "ProxMenux Monitor unit repaired and restarted" line printed. CHANGELOG entries (EN+ES) updated to mention the auto-repair so users on the broken state know the simpler recovery is now "just run menu". Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
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