-
Notifications
You must be signed in to change notification settings - Fork 146
Expand file tree
/
Copy pathmenu
More file actions
196 lines (166 loc) · 8.03 KB
/
Copy pathmenu
File metadata and controls
196 lines (166 loc) · 8.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
#!/bin/bash
# ==========================================================
# ProxMenux - A menu-driven script for Proxmox VE management
# ==========================================================
# Author : MacRimi
# 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
# ==========================================================
# Description:
# 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.
# ==========================================================
# ── Configuration ──────────────────────────────────────────
BASE_DIR="/usr/local/share/proxmenux"
LOCAL_SCRIPTS="$BASE_DIR/scripts"
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"
BETA_VERSION_FILE="$BASE_DIR/beta_version.txt"
VENV_PATH="/opt/googletrans-env"
REPO_MAIN="https://raw.githubusercontent.com/MacRimi/ProxMenux/main"
REPO_DEVELOP="https://raw.githubusercontent.com/MacRimi/ProxMenux/develop"
# ── Load utilities ─────────────────────────────────────────
[[ -f "$UTILS_FILE" ]] && source "$UTILS_FILE"
: "${LOCAL_SCRIPTS:=/usr/local/share/proxmenux/scripts}"
# ── 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" ]]
}
# ── 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
}
# ── Check for updates ──────────────────────────────────────
check_updates() {
if is_beta; then
check_updates_beta
else
check_updates_stable
fi
}
# ── 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"
[[ ! -f "$LOCAL_VERSION_FILE" ]] && return 0
local REMOTE_VERSION LOCAL_VERSION
REMOTE_VERSION="$(curl -fsSL "$VERSION_URL" 2>/dev/null | head -n 1)"
[[ -z "$REMOTE_VERSION" ]] && return 0
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?')" \
10 60 --defaultno; then
msg_warn "$(translate 'Starting ProxMenux update...')"
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
fi
fi
}
# ── Beta-mode update check (main + develop) ───────────────
# 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.
check_updates_beta() {
# 1. Stable release on main — reuse the non-beta path.
check_updates_stable
# 2. Beta build on develop.
[[ ! -f "$BETA_VERSION_FILE" ]] && return 0
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
if whiptail --title "Beta Update Available" \
--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
msg_warn "Updating to beta build $REMOTE_BETA ..."
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
else
msg_error "Could not download the beta installer from the develop branch."
fi
fi
}
# ── Main ───────────────────────────────────────────────────
main_menu() {
local MAIN_MENU="$LOCAL_SCRIPTS/menus/main_menu.sh"
exec bash "$MAIN_MENU"
}
load_language
initialize_cache
auto_repair_monitor_unit
check_updates
main_menu