fix(configure): toggle install state, scope patching to selected mod

This commit is contained in:
Meliox 2026-06-14 00:42:40 +02:00
parent af6065998b
commit 0ad344fdfe
3 changed files with 71 additions and 22 deletions

View File

@ -102,7 +102,9 @@ if ! command -v patch >/dev/null 2>&1; then
exit 1 exit 1
fi fi
for mod in $(list_modules); do mapfile -t _all_modules < <(list_modules)
_target_modules=("${@:-${_all_modules[@]}}")
for mod in "${_target_modules[@]}"; do
[[ "$(read_conf "$MAIN_CONF" modules "$mod" 0)" == "1" ]] || continue [[ "$(read_conf "$MAIN_CONF" modules "$mod" 0)" == "1" ]] || continue
mod_dir="$PATCHES_DIR/$mod" mod_dir="$PATCHES_DIR/$mod"

View File

@ -11,6 +11,7 @@ CONFD_DIR="/etc/pve-mod/conf.d"
NODE_INFO_CONF="${CONFD_DIR}/node_info.conf" NODE_INFO_CONF="${CONFD_DIR}/node_info.conf"
NAG_SCREEN_CONF="${CONFD_DIR}/nag_screen.conf" NAG_SCREEN_CONF="${CONFD_DIR}/nag_screen.conf"
APPLY_PATCHES="/usr/lib/pve-mod/apply-patches.sh" APPLY_PATCHES="/usr/lib/pve-mod/apply-patches.sh"
REVERT_PATCHES="/usr/lib/pve-mod/revert-patches.sh"
NODES_PM="/usr/share/perl5/PVE/API2/Nodes.pm" NODES_PM="/usr/share/perl5/PVE/API2/Nodes.pm"
KNOWN_CPU_SENSORS=("coretemp-isa-" "k10temp-pci-") KNOWN_CPU_SENSORS=("coretemp-isa-" "k10temp-pci-")
@ -26,10 +27,33 @@ ask() {
echo "$response" echo "$response"
} }
bool() { [[ "$1" == true ]] && echo 1 || echo 0; } bool() { [[ "$1" == true ]] && echo 1 || echo 0; }
mod_status() {
local val="$1" on_label="${2:-[enabled]}" off_label="${3:-[disabled]}"
[[ "$val" == "1" ]] && echo -e "\e[0;32m${on_label}\e[0m" || echo -e "\e[0;33m${off_label}\e[0m"
}
_load_conf() { _load_conf() {
# Load main config (module toggles + pve_trigger)
if [[ -f "$CONF_FILE" ]]; then
local section="" line key val
while IFS= read -r line; do
case "$line" in
'#'*|'') continue ;;
'['*']') section="${line#[}"; section="${section%]}"; continue ;;
esac
[[ "$line" == *=* ]] || continue
key="${line%%=*}"; val="${line#*=}"
case "${section}.${key}" in
modules.node_info) MOD_NODE_INFO="$val" ;;
modules.nag_screen) MOD_NAG_SCREEN="$val" ;;
pve_trigger.enabled) PVE_TRIGGER_ENABLED="$val" ;;
esac
done < "$CONF_FILE"
fi
# Load node_info mod config
[[ -f "$NODE_INFO_CONF" ]] || return 0 [[ -f "$NODE_INFO_CONF" ]] || return 0
local in_debug=0 line key val local in_debug=0 line key val section=""
while IFS= read -r line; do while IFS= read -r line; do
case "$line" in case "$line" in
'#'*|'') continue ;; '#'*|'') continue ;;
@ -569,37 +593,58 @@ main() {
# this run, and all other options retain their previously saved values. # this run, and all other options retain their previously saved values.
msgb "\n=== pve-mod Module Selection ===" msgb "\n=== pve-mod Module Selection ==="
echo "Available options (select one):" echo "Available options (select one):"
echo " [1] Node Info — sensor readings, GPU stats, UPS, system information" echo -e " [1] Node Info $(mod_status "$MOD_NODE_INFO") — sensor readings, GPU stats, UPS, system information"
echo " [2] Nag Screen — remove Proxmox subscription nag screen" echo -e " [2] Nag Screen $(mod_status "$MOD_NAG_SCREEN") — remove Proxmox subscription nag screen"
echo " [3] Auto re-patch on PVE upgrade — automatically re-apply patches when" echo -e " [3] Auto re-patch on PVE upgrade $(mod_status "$PVE_TRIGGER_ENABLED") — automatically re-apply patches when"
echo " pve-manager is upgraded" echo " pve-manager is upgraded"
echo " [n] None / cancel" echo " [n] None / cancel"
local modChoice local modChoice selected_mod="" patching_needed=0
modChoice=$(ask "Select an option to enable (1/2/3/n)") modChoice=$(ask "Select an option (1/2/3/n)")
case "$modChoice" in case "$modChoice" in
1) 1)
MOD_NODE_INFO=1 selected_mod="node_info"
msgb "\n=== Node Info Configuration ===" if [[ "$MOD_NODE_INFO" == "1" ]]; then
configure_node_info MOD_NODE_INFO=0; info "Node Info will be removed."
else
MOD_NODE_INFO=1; patching_needed=1
msgb "\n=== Node Info Configuration ==="
configure_node_info
fi
;; ;;
2) 2)
MOD_NAG_SCREEN=1 selected_mod="nag_screen"
msgb "\n=== Nag Screen ===" if [[ "$MOD_NAG_SCREEN" == "1" ]]; then
info "Subscription nag screen removal will be applied." MOD_NAG_SCREEN=0; info "Nag Screen will be removed."
else
MOD_NAG_SCREEN=1; patching_needed=1
info "Subscription nag screen removal will be applied."
fi
;; ;;
3) 3)
PVE_TRIGGER_ENABLED=1 if [[ "$PVE_TRIGGER_ENABLED" == "1" ]]; then
info "Auto re-patching on PVE upgrade enabled." PVE_TRIGGER_ENABLED=0; info "Auto re-patch disabled."
else
PVE_TRIGGER_ENABLED=1; info "Auto re-patching on PVE upgrade enabled."
fi
;; ;;
[nN]) info "No option selected. Exiting."; exit 0 ;; [nN]) info "No option selected. Exiting."; exit 0 ;;
*) warn "Invalid selection. Exiting."; exit 0 ;; *) warn "Invalid selection. Exiting."; exit 0 ;;
esac esac
# ── Write config and apply ──────────────────────────────────────────────── # ── Write config and apply/revert ─────────────────────────────────────────
write_config write_config
msgb "\n=== Applying patches ===" # For mods with patches: apply if being enabled, revert if being disabled.
"$APPLY_PATCHES" # Option 3 (pve_trigger) has no patches — write_config is sufficient.
if [[ -n "$selected_mod" ]]; then
if [[ "$patching_needed" == "1" ]]; then
msgb "\n=== Applying patches ==="
"$APPLY_PATCHES" "$selected_mod"
else
msgb "\n=== Removing patches ==="
"$REVERT_PATCHES" "$selected_mod"
fi
fi
msgb "\n=== Done ===" msgb "\n=== Done ==="
info "pve-mod is configured and active." info "pve-mod is configured and active."

View File

@ -52,9 +52,11 @@ fi
CHANGED=false CHANGED=false
for mod_dir in "$PATCHES_DIR"/*/; do mapfile -t _all_modules < <(for d in "$PATCHES_DIR"/*/; do [[ -d "$d" ]] && basename "$d"; done)
_target_modules=("${@:-${_all_modules[@]}}")
for mod in "${_target_modules[@]}"; do
mod_dir="$PATCHES_DIR/$mod/"
[[ -d "$mod_dir" ]] || continue [[ -d "$mod_dir" ]] || continue
mod="$(basename "$mod_dir")"
manifest="$mod_dir/patches.list" manifest="$mod_dir/patches.list"
mod_conf="$CONFD_DIR/$mod.conf" mod_conf="$CONFD_DIR/$mod.conf"