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-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
2025-11-16 00:51:12 +01:00
if curl -fsSL "$INSTALL_URL" -o "$INSTALL_SCRIPT"; then
chmod +x "$INSTALL_SCRIPT"
2025-11-16 01:21:07 +01:00
bash "$INSTALL_SCRIPT" --update
2026-03-18 21:15:34 +01:00
fi
fi
}
2025-11-16 01:21:07 +01:00
2026-03-18 21:15:34 +01:00
# ── Beta update check (develop branch) ────────────────────
check_updates_beta() {
local BETA_VERSION_URL="$REPO_DEVELOP/beta_version.txt"
local STABLE_VERSION_URL="$REPO_MAIN/version.txt"
local INSTALL_BETA_URL="$REPO_DEVELOP/install_proxmenux_beta.sh"
local INSTALL_STABLE_URL="$REPO_MAIN/install_proxmenux.sh"
local INSTALL_SCRIPT="$BASE_DIR/install_proxmenux_beta.sh"
# ── 1. Check if a stable release has superseded the beta ──
# If main's version.txt exists and is newer than local beta_version.txt,
# the beta cycle is over and we invite the user to switch to stable.
local STABLE_VERSION BETA_LOCAL_VERSION
STABLE_VERSION="$(curl -fsSL "$STABLE_VERSION_URL" 2>/dev/null | head -n 1)"
BETA_LOCAL_VERSION="$(head -n 1 "$BETA_VERSION_FILE" 2>/dev/null)"
if [[ -n "$STABLE_VERSION" && -n "$BETA_LOCAL_VERSION" ]]; then
# Simple string comparison is enough if versions follow semver x.y.z
if [[ "$STABLE_VERSION" != "$BETA_LOCAL_VERSION" ]] && \
printf '%s\n' "$BETA_LOCAL_VERSION" "$STABLE_VERSION" | sort -V | tail -1 | grep -qx "$STABLE_VERSION"; then
# Stable is newer — offer migration out of beta
if whiptail --title "🎉 Stable Release Available" \
--yesno "A stable release of ProxMenux is now available!\n\nStable version : $STABLE_VERSION\nYour beta : $BETA_LOCAL_VERSION\n\nThe beta program for this cycle is complete.\nWould you like to switch to the stable release now?\n\n(Choosing 'No' keeps you on the beta for now.)" \
16 68; then
msg_warn "Switching to stable release $STABLE_VERSION ..."
local tmp_installer="/tmp/install_proxmenux_stable_$$.sh"
if curl -fsSL "$INSTALL_STABLE_URL" -o "$tmp_installer"; then
chmod +x "$tmp_installer"
bash "$tmp_installer"
rm -f "$tmp_installer"
else
msg_error "Could not download the stable installer. Try manually:"
echo
echo " bash -c \"\$(wget -qLO - $INSTALL_STABLE_URL)\""
echo
fi
return 0
fi
# User chose to stay on beta — continue normally
2025-11-16 10:19:50 +01:00
return 0
2025-11-16 00:13:52 +01:00
fi
2025-02-02 22:59:06 +01:00
fi
2025-01-12 18:10:37 +01:00
2026-03-18 21:15:34 +01:00
# ── 2. Check for a newer beta build on develop ─────────────
[[ ! -f "$BETA_VERSION_FILE" ]] && return 0
local REMOTE_BETA_VERSION
REMOTE_BETA_VERSION="$(curl -fsSL "$BETA_VERSION_URL" 2>/dev/null | head -n 1)"
[[ -z "$REMOTE_BETA_VERSION" ]] && return 0
[[ "$BETA_LOCAL_VERSION" = "$REMOTE_BETA_VERSION" ]] && return 0
if whiptail --title "Beta Update Available" \
--yesno "A new beta build is available!\n\nInstalled beta : $BETA_LOCAL_VERSION\nNew beta build : $REMOTE_BETA_VERSION\n\nThis is a pre-release build from the develop branch.\nDo you want to update now?" \
13 64 --defaultno; then
2025-11-16 00:02:52 +01:00
2026-03-18 21:15:34 +01:00
msg_warn "Updating to beta build $REMOTE_BETA_VERSION ..."
2025-11-16 00:13:52 +01:00
2026-03-18 21:15:34 +01:00
if curl -fsSL "$INSTALL_BETA_URL" -o "$INSTALL_SCRIPT"; then
chmod +x "$INSTALL_SCRIPT"
bash "$INSTALL_SCRIPT" --update
else
msg_error "Could not download the beta installer from the develop branch."
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
2025-11-14 20:38:07 +01:00
check_updates
2025-11-14 20:48:38 +01:00
main_menu