Update menu

This commit is contained in:
MacRimi 2025-07-04 19:40:38 +02:00
parent a1f7fb57d9
commit 196c29da17
3 changed files with 157 additions and 60 deletions

62
menu
View File

@ -6,8 +6,8 @@
# Author : MacRimi # Author : MacRimi
# Copyright : (c) 2024 MacRimi # Copyright : (c) 2024 MacRimi
# License : MIT (https://raw.githubusercontent.com/MacRimi/ProxMenux/main/LICENSE) # License : MIT (https://raw.githubusercontent.com/MacRimi/ProxMenux/main/LICENSE)
# Version : 1.0 # Version : 1.1
# Last Updated: 28/01/2025 # Last Updated: 04/07/2025
# ========================================================== # ==========================================================
# Description: # Description:
# This script serves as the main entry point for ProxMenux, # This script serves as the main entry point for ProxMenux,
@ -29,6 +29,7 @@
# for managing Proxmox VE using ProxMenux. # for managing Proxmox VE using ProxMenux.
# ========================================================== # ==========================================================
# Configuration ============================================ # Configuration ============================================
REPO_URL="https://raw.githubusercontent.com/MacRimi/ProxMenux/main" REPO_URL="https://raw.githubusercontent.com/MacRimi/ProxMenux/main"
BASE_DIR="/usr/local/share/proxmenux" BASE_DIR="/usr/local/share/proxmenux"
@ -41,95 +42,48 @@ VENV_PATH="/opt/googletrans-env"
if [[ -f "$UTILS_FILE" ]]; then if [[ -f "$UTILS_FILE" ]]; then
source "$UTILS_FILE" source "$UTILS_FILE"
fi fi
# ==========================================================
#show_proxmenux_logo
# Initialize language configuration
initialize_config() {
# Check if config file exists and has language field
if [ ! -f "$CONFIG_FILE" ] || [ -z "$(jq -r '.language // empty' "$CONFIG_FILE")" ]; then
show_proxmenux_logo
sleep 2
LANGUAGE=$(whiptail --title "$(translate "Select Language")" --menu "$(translate "Choose a language for the menu:")" 20 60 12 \
"en" "$(translate "English (Recommended)")" \
"es" "$(translate "Spanish")" \
"fr" "$(translate "French")" \
"de" "$(translate "German")" \
"it" "$(translate "Italian")" \
"pt" "$(translate "Portuguese")" 3>&1 1>&2 2>&3)
if [ -z "$LANGUAGE" ]; then
msg_error "$(translate "No language selected. Exiting.")"
exit 1
fi
if [ -f "$CONFIG_FILE" ]; then
# Update existing config file with new language
tmp=$(mktemp)
jq --arg lang "$LANGUAGE" '. + {language: $lang}' "$CONFIG_FILE" > "$tmp" && mv "$tmp" "$CONFIG_FILE"
else
# Create new config file if it doesn't exist
echo "{\"language\": \"$LANGUAGE\"}" > "$CONFIG_FILE"
fi
msg_ok "$(translate "Initial language set to:") $LANGUAGE"
fi
}
# =========================================================
check_updates() { check_updates() {
local INSTALL_SCRIPT="$BASE_DIR/install_proxmenux.sh" local INSTALL_SCRIPT="$BASE_DIR/install_proxmenux.sh"
# Fetch the remote version
local REMOTE_VERSION local REMOTE_VERSION
REMOTE_VERSION=$(curl -fsSL "$REPO_URL/version.txt" | head -n 1) REMOTE_VERSION=$(curl -fsSL "$REPO_URL/version.txt" | head -n 1)
# Exit silently if unable to fetch the remote version
if [ -z "$REMOTE_VERSION" ]; then if [ -z "$REMOTE_VERSION" ]; then
return 0 return 0
fi fi
# Read the local version
local LOCAL_VERSION local LOCAL_VERSION
LOCAL_VERSION=$(head -n 1 "$LOCAL_VERSION_FILE") LOCAL_VERSION=$(head -n 1 "$LOCAL_VERSION_FILE")
# If the local version matches the remote version, no update is needed
[ "$LOCAL_VERSION" = "$REMOTE_VERSION" ] && return 0 [ "$LOCAL_VERSION" = "$REMOTE_VERSION" ] && return 0
# Prompt the user for update confirmation
if whiptail --title "$(translate "Update Available")" \ if whiptail --title "$(translate "Update Available")" \
--yesno "$(translate "New version available") ($REMOTE_VERSION)\n\n$(translate "Do you want to update now?")" \ --yesno "$(translate "New version available") ($REMOTE_VERSION)\n\n$(translate "Do you want to update now?")" \
10 60 --defaultno; then 10 60 --defaultno; then
msg_warn "$(translate "Starting ProxMenu update...")" msg_warn "$(translate "Starting ProxMenu update...")"
# Download the installation script
if wget -qO "$INSTALL_SCRIPT" "$REPO_URL/install_proxmenux.sh"; then if wget -qO "$INSTALL_SCRIPT" "$REPO_URL/install_proxmenux.sh"; then
chmod +x "$INSTALL_SCRIPT" chmod +x "$INSTALL_SCRIPT"
# Execute the script directly in the current environment
source "$INSTALL_SCRIPT" source "$INSTALL_SCRIPT"
fi fi
else else
msg_warn "$(translate "Update postponed. You can update later from the menu.")" msg_warn "$(translate "Update postponed. You can update later from the menu.")"
fi fi
} }
main_menu() { main_menu() {
exec bash <(curl -fsSL "$REPO_URL/scripts/menus/main_menu.sh") exec bash <(curl -fsSL "$REPO_URL/scripts/menus/main_menu.sh")
} }
# Main flow
initialize_config
load_language load_language
initialize_cache initialize_cache
check_updates check_updates

136
menu_ Normal file
View File

@ -0,0 +1,136 @@
#!/bin/bash
# ==========================================================
# ProxMenu - A menu-driven script for Proxmox VE management
# ==========================================================
# Author : MacRimi
# Copyright : (c) 2024 MacRimi
# License : MIT (https://raw.githubusercontent.com/MacRimi/ProxMenux/main/LICENSE)
# Version : 1.0
# Last Updated: 28/01/2025
# ==========================================================
# Description:
# This script serves as the main entry point for ProxMenux,
# a menu-driven tool designed for Proxmox VE management.
#
# - Displays the ProxMenu logo on startup.
# - Loads necessary configurations and language settings.
# - Checks for available updates and installs them if confirmed.
# - Downloads and executes the latest main menu script.
#
# Key Features:
# - Ensures ProxMenu is always up-to-date by fetching the latest version.
# - Uses whiptail for interactive menus and language selection.
# - Loads utility functions and translation support.
# - Maintains a cache system to improve performance.
# - Executes the ProxMenux main menu dynamically from the repository.
#
# This script ensures a streamlined and automated experience
# for managing Proxmox VE using ProxMenux.
# ==========================================================
# Configuration ============================================
REPO_URL="https://raw.githubusercontent.com/MacRimi/ProxMenux/main"
BASE_DIR="/usr/local/share/proxmenux"
CONFIG_FILE="$BASE_DIR/config.json"
CACHE_FILE="$BASE_DIR/cache.json"
UTILS_FILE="$BASE_DIR/utils.sh"
LOCAL_VERSION_FILE="$BASE_DIR/version.txt"
VENV_PATH="/opt/googletrans-env"
if [[ -f "$UTILS_FILE" ]]; then
source "$UTILS_FILE"
fi
# ==========================================================
#show_proxmenux_logo
# Initialize language configuration
initialize_config() {
# Check if config file exists and has language field
if [ ! -f "$CONFIG_FILE" ] || [ -z "$(jq -r '.language // empty' "$CONFIG_FILE")" ]; then
show_proxmenux_logo
sleep 2
LANGUAGE=$(whiptail --title "$(translate "Select Language")" --menu "$(translate "Choose a language for the menu:")" 20 60 12 \
"en" "$(translate "English (Recommended)")" \
"es" "$(translate "Spanish")" \
"fr" "$(translate "French")" \
"de" "$(translate "German")" \
"it" "$(translate "Italian")" \
"pt" "$(translate "Portuguese")" 3>&1 1>&2 2>&3)
if [ -z "$LANGUAGE" ]; then
msg_error "$(translate "No language selected. Exiting.")"
exit 1
fi
if [ -f "$CONFIG_FILE" ]; then
# Update existing config file with new language
tmp=$(mktemp)
jq --arg lang "$LANGUAGE" '. + {language: $lang}' "$CONFIG_FILE" > "$tmp" && mv "$tmp" "$CONFIG_FILE"
else
# Create new config file if it doesn't exist
echo "{\"language\": \"$LANGUAGE\"}" > "$CONFIG_FILE"
fi
msg_ok "$(translate "Initial language set to:") $LANGUAGE"
fi
}
check_updates() {
local INSTALL_SCRIPT="$BASE_DIR/install_proxmenux.sh"
# Fetch the remote version
local REMOTE_VERSION
REMOTE_VERSION=$(curl -fsSL "$REPO_URL/version.txt" | head -n 1)
# Exit silently if unable to fetch the remote version
if [ -z "$REMOTE_VERSION" ]; then
return 0
fi
# Read the local version
local LOCAL_VERSION
LOCAL_VERSION=$(head -n 1 "$LOCAL_VERSION_FILE")
# If the local version matches the remote version, no update is needed
[ "$LOCAL_VERSION" = "$REMOTE_VERSION" ] && return 0
# Prompt the user for update confirmation
if whiptail --title "$(translate "Update Available")" \
--yesno "$(translate "New version available") ($REMOTE_VERSION)\n\n$(translate "Do you want to update now?")" \
10 60 --defaultno; then
msg_warn "$(translate "Starting ProxMenu update...")"
# Download the installation script
if wget -qO "$INSTALL_SCRIPT" "$REPO_URL/install_proxmenux.sh"; then
chmod +x "$INSTALL_SCRIPT"
# Execute the script directly in the current environment
source "$INSTALL_SCRIPT"
fi
else
msg_warn "$(translate "Update postponed. You can update later from the menu.")"
fi
}
main_menu() {
exec bash <(curl -fsSL "$REPO_URL/scripts/menus/main_menu.sh")
}
# Main flow
initialize_config
load_language
initialize_cache
check_updates
main_menu

View File

@ -193,15 +193,22 @@ msg_error() {
# Initialize cache # Initialize cache
initialize_cache() { initialize_cache() {
if [[ "$LANGUAGE" != "en" ]]; then
if [ ! -f "$CACHE_FILE" ]; then if [ ! -f "$CACHE_FILE" ]; then
mkdir -p "$(dirname "$CACHE_FILE")" mkdir -p "$(dirname "$CACHE_FILE")"
echo "{}" > "$CACHE_FILE" echo "{}" > "$CACHE_FILE"
fi fi
fi
} }
# Load language
load_language() { load_language() {
LANGUAGE="en"
if [ -f "$CONFIG_FILE" ]; then if [ -f "$CONFIG_FILE" ]; then
LANGUAGE=$(jq -r '.language' "$CONFIG_FILE") lang_candidate=$(jq -r '.language // empty' "$CONFIG_FILE" 2>/dev/null)
if [[ -n "$lang_candidate" && "$lang_candidate" != "null" ]]; then
LANGUAGE="$lang_candidate"
fi
fi fi
} }