mirror of
https://github.com/community-scripts/ProxmoxVE.git
synced 2026-03-03 16:15:54 +00:00
* Standardize exit codes and add mappings Replace generic exit 1 usages with specific numeric exit codes and add corresponding explanations to the error lookup. This commit updates multiple misc/* scripts to return distinct codes for validation, Proxmox/LXC, networking, download and curl errors (e.g. 103-123, 64, 107-120, 206, 0 for explicit user cancels). It also updates curl error handling to propagate the original curl exit code and adds new entries in explain_exit_code and the error handler to improve diagnostics. * Set exit code 115 for update_os errors Change exit status from 6 to 115 in misc/alpine-install.func's update_os() error handlers when failing to download tools.func or when the expected functions are missing. This gives a distinct exit code for these specific failure cases. * Add tools/addon exit codes and use them Introduce exit codes 232-238 for Tools & Addon scripts in misc/api.func and misc/error_handler.func. Update addon scripts (tools/addon/adguardhome-sync.sh, tools/addon/copyparty.sh, tools/addon/cronmaster.sh) to return specific codes instead of generic exit 1: 238 for unsupported OS and 233 when the application is not installed/upgrade prerequisites are missing. This makes failures more descriptive and aligns scripts with the central error explanations. * Standardize exit codes in exporter addons Unify exit codes across exporter addon scripts: return 238 for unsupported OS detections and 233 when an update is requested but the exporter is not installed. Applied to nextcloud-exporter.sh, pihole-exporter.sh, prometheus-paperless-ngx-exporter.sh, and qbittorrent-exporter.sh to make failure modes distinguishable for callers/automation. * Use specific exit codes in addon scripts Replace generic exit 1 with distinct exit codes across multiple addon scripts to enable finer-grained error handling in automation. Exit codes introduced: 10 for Docker/Compose missing or user-declined Docker install, 233 for "nothing to update" cases, and 238 for unsupported OS cases. Affected files: tools/addon/arcane.sh, coolify.sh, dockge.sh, dokploy.sh, filebrowser-quantum.sh, filebrowser.sh, immich-public-proxy.sh, jellystat.sh, runtipi.sh. * Use specific exit codes in addon scripts Replace generic exit 1 with specific exit codes across multiple addon scripts to improve error signaling and handling. Files updated: tools/addon/add-netbird-lxc.sh (exit 238 on unsupported distro), tools/addon/add-tailscale-lxc.sh (treat user cancel as exit 0), tools/addon/glances.sh (exit 233 when not installed), tools/addon/komodo.sh (distinct exits for missing compose, legacy DB, backup/download failures, docker checks), tools/addon/netdata.sh (distinct exits for unsupported PVE versions, OS/codename detection, repo lookups), and tools/addon/phpmyadmin.sh (distinct exits for unsupported OS, network/download issues, package install/start failures, and invalid input). These changes make failures easier to identify and automate recovery or reporting. * Use specific exit codes in PVE scripts Replace generic exit 1 with distinct exit codes across tools/pve scripts to provide clearer failure signals for callers. post-pve-install.sh now returns 105 for unsupported Proxmox versions; pve-privilege-converter.sh uses 104 for non-root, 234 when no containers, and 235 for backup/conversion failures; update-apps.sh maps backup failures to 235, missing containers/selections to 234 (and UI cancellations to 0), missing backup storage to 119, and returns the actual container update exit code on failure. These changes improve diagnostics and allow external tooling to react to specific error conditions. * Standardize exit codes and behaviors Adjust exit codes and abort handling across multiple PVE helper scripts to provide clearer outcomes for automation and interactive flows. Changes include: - container-restore-from-backup.sh, core-restore-from-backup.sh: return 235 when no backups found (was 1). - fstrim.sh: treat user cancellation of non-ext4 warning as non-error (exit 0 instead of 1). - kernel-clean.sh: treat no selection or user abort as non-error (exit 0 instead of 1). - lxc-delete.sh: return 234 when no containers are present; treat no selection as non-error (exit 0). - nic-offloading-fix.sh: use specific non-zero codes for root check and tool install failures (exit 104, 237) and 236 when no matching interfaces (was 1). - pbs_microcode.sh, post-pmg-install.sh, post-pbs-install.sh: use distinct exit codes (232 and 105) for detected VM/PVE/unsupported distro conditions instead of generic 1. These modifications make scripts return distinct codes for different failure modes and ensure user-initiated aborts or benign conditions exit with 0 where appropriate. * Use exit 105 for unsupported PVE versions Standardize error handling by replacing generic exit 1 with exit 105 in pve_check() across multiple VM template scripts to indicate unsupported Proxmox VE versions. Also add API exit code 226 message for "Proxmox: VM disk import or post-creation setup failed" in misc/api.func. Affected files include misc/api.func and various vm/*-vm.sh scripts. * Use specific exit codes in VM scripts Replace generic exit 1 with distinct exit codes across vm/*.sh to make failures more actionable for callers. Changes include: use 226 for missing imported-disk references, 237 for pv installation failures, 115 for download/extract/ISO-related failures, 214 for insufficient disk space during FreeBSD decompression, and 119 for missing storage detection. Updated scripts: archlinux-vm.sh, docker-vm.sh, haos-vm.sh, openwrt-vm.sh, opnsense-vm.sh, truenas-vm.sh, umbrel-os-vm.sh.
328 lines
11 KiB
Bash
328 lines
11 KiB
Bash
#!/usr/bin/env bash
|
|
|
|
# Copyright (c) 2021-2026 community-scripts ORG
|
|
# Author: thost96 (thost96)
|
|
# License: MIT | https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE
|
|
|
|
header_info() {
|
|
clear
|
|
cat <<"EOF"
|
|
____ __ _________ ____ __ ____ __ ____
|
|
/ __ \/ |/ / ____/ / __ \____ _____/ /_ / _/___ _____/ /_____ _/ / /
|
|
/ /_/ / /|_/ / / __ / /_/ / __ \/ ___/ __/ / // __ \/ ___/ __/ __ `/ / /
|
|
/ ____/ / / / /_/ / / ____/ /_/ (__ ) /_ _/ // / / (__ ) /_/ /_/ / / /
|
|
/_/ /_/ /_/\____/ /_/ \____/____/\__/ /___/_/ /_/____/\__/\__,_/_/_/
|
|
|
|
EOF
|
|
}
|
|
|
|
RD=$(echo "\033[01;31m")
|
|
YW=$(echo "\033[33m")
|
|
GN=$(echo "\033[1;92m")
|
|
CL=$(echo "\033[m")
|
|
BFR="\\r\\033[K"
|
|
HOLD="-"
|
|
CM="${GN}✓${CL}"
|
|
CROSS="${RD}✗${CL}"
|
|
|
|
set -euo pipefail
|
|
shopt -s inherit_errexit nullglob
|
|
|
|
msg_info() {
|
|
local msg="$1"
|
|
echo -ne " ${HOLD} ${YW}${msg}..."
|
|
}
|
|
|
|
msg_ok() {
|
|
local msg="$1"
|
|
echo -e "${BFR} ${CM} ${GN}${msg}${CL}"
|
|
}
|
|
|
|
msg_error() {
|
|
local msg="$1"
|
|
echo -e "${BFR} ${CROSS} ${RD}${msg}${CL}"
|
|
}
|
|
|
|
# Telemetry
|
|
source <(curl -fsSL https://raw.githubusercontent.com/community-scripts/ProxmoxVE/main/misc/api.func) 2>/dev/null || true
|
|
declare -f init_tool_telemetry &>/dev/null && init_tool_telemetry "post-pmg-install" "pve"
|
|
|
|
if ! grep -q "Proxmox Mail Gateway" /etc/issue 2>/dev/null; then
|
|
msg_error "This script is only intended for Proxmox Mail Gateway"
|
|
exit 232
|
|
fi
|
|
|
|
repo_state() {
|
|
# $1 = repo name (e.g. pmg-enterprise, pmg-no-subscription, pmgtest)
|
|
local repo="$1"
|
|
local file=""
|
|
local state="missing"
|
|
for f in /etc/apt/sources.list /etc/apt/sources.list.d/*.list; do
|
|
[[ -f "$f" ]] || continue
|
|
if grep -q "$repo" "$f"; then
|
|
file="$f"
|
|
if grep -qE "^[^#].*${repo}" "$f"; then
|
|
state="active"
|
|
elif grep -qE "^#.*${repo}" "$f"; then
|
|
state="disabled"
|
|
fi
|
|
break
|
|
fi
|
|
done
|
|
echo "$state $file"
|
|
}
|
|
|
|
start_routines() {
|
|
header_info
|
|
VERSION="$(awk -F'=' '/^VERSION_CODENAME=/{ print $NF }' /etc/os-release)"
|
|
|
|
# ---- SOURCES ----
|
|
CHOICE=$(whiptail --backtitle "Proxmox VE Helper Scripts" --title "PMG SOURCES" --menu \
|
|
"This will set the correct Debian sources for Proxmox Mail Gateway.\n\nCorrect sources?" 14 58 2 \
|
|
"yes" " " \
|
|
"no" " " 3>&2 2>&1 1>&3)
|
|
case $CHOICE in
|
|
yes)
|
|
msg_info "Correcting Debian Sources"
|
|
cat <<EOF >/etc/apt/sources.list
|
|
deb http://deb.debian.org/debian ${VERSION} main contrib
|
|
deb http://deb.debian.org/debian ${VERSION}-updates main contrib
|
|
deb http://security.debian.org/debian-security ${VERSION}-security main contrib
|
|
EOF
|
|
msg_ok "Corrected Debian Sources"
|
|
;;
|
|
no) msg_error "Selected no to Correcting Debian Sources" ;;
|
|
esac
|
|
|
|
# ---- PMG-ENTERPRISE ----
|
|
read -r state file <<<"$(repo_state pmg-enterprise)"
|
|
case $state in
|
|
active)
|
|
CHOICE=$(whiptail --backtitle "Proxmox VE Helper Scripts" --title "PMG-ENTERPRISE" \
|
|
--menu "'pmg-enterprise' repository is currently ENABLED.\n\nWhat do you want to do?" 14 58 3 \
|
|
"keep" "Keep as is" \
|
|
"disable" "Comment out (disable)" \
|
|
"delete" "Delete repo file" \
|
|
3>&2 2>&1 1>&3)
|
|
case $CHOICE in
|
|
keep) msg_ok "Kept 'pmg-enterprise' repository" ;;
|
|
disable)
|
|
msg_info "Disabling 'pmg-enterprise' repository"
|
|
sed -i "s/^[^#].*pmg-enterprise/# &/" "$file"
|
|
msg_ok "Disabled 'pmg-enterprise' repository"
|
|
;;
|
|
delete)
|
|
msg_info "Deleting 'pmg-enterprise' repository file"
|
|
rm -f "$file"
|
|
msg_ok "Deleted 'pmg-enterprise' repository file"
|
|
;;
|
|
esac
|
|
;;
|
|
disabled)
|
|
CHOICE=$(whiptail --backtitle "Proxmox VE Helper Scripts" --title "PMG-ENTERPRISE" \
|
|
--menu "'pmg-enterprise' repository is currently DISABLED.\n\nWhat do you want to do?" 14 58 3 \
|
|
"enable" "Uncomment (enable)" \
|
|
"keep" "Keep disabled" \
|
|
"delete" "Delete repo file" \
|
|
3>&2 2>&1 1>&3)
|
|
case $CHOICE in
|
|
enable)
|
|
msg_info "Enabling 'pmg-enterprise' repository"
|
|
sed -i "s/^#.*pmg-enterprise/deb/" "$file"
|
|
msg_ok "Enabled 'pmg-enterprise' repository"
|
|
;;
|
|
keep) msg_ok "Kept 'pmg-enterprise' repository disabled" ;;
|
|
delete)
|
|
msg_info "Deleting 'pmg-enterprise' repository file"
|
|
rm -f "$file"
|
|
msg_ok "Deleted 'pmg-enterprise' repository file"
|
|
;;
|
|
esac
|
|
;;
|
|
missing)
|
|
CHOICE=$(whiptail --backtitle "Proxmox VE Helper Scripts" --title "PMG-ENTERPRISE" \
|
|
--menu "Add 'pmg-enterprise' repository?\n\nOnly for subscription customers." 14 58 2 \
|
|
"no" " " \
|
|
"yes" " " \
|
|
--default-item "no" \
|
|
3>&2 2>&1 1>&3)
|
|
case $CHOICE in
|
|
yes)
|
|
msg_info "Adding 'pmg-enterprise' repository"
|
|
cat >/etc/apt/sources.list.d/pmg-enterprise.list <<EOF
|
|
deb https://enterprise.proxmox.com/debian/pmg ${VERSION} pmg-enterprise
|
|
EOF
|
|
msg_ok "Added 'pmg-enterprise' repository"
|
|
;;
|
|
no) msg_error "Selected no to Adding 'pmg-enterprise' repository" ;;
|
|
esac
|
|
;;
|
|
esac
|
|
|
|
# ---- PMG-NO-SUBSCRIPTION ----
|
|
read -r state file <<<"$(repo_state pmg-no-subscription)"
|
|
case $state in
|
|
active)
|
|
CHOICE=$(whiptail --backtitle "Proxmox VE Helper Scripts" --title "PMG-NO-SUBSCRIPTION" \
|
|
--menu "'pmg-no-subscription' repository is currently ENABLED.\n\nWhat do you want to do?" 14 58 3 \
|
|
"keep" "Keep as is" \
|
|
"disable" "Comment out (disable)" \
|
|
"delete" "Delete repo file" \
|
|
3>&2 2>&1 1>&3)
|
|
case $CHOICE in
|
|
keep) msg_ok "Kept 'pmg-no-subscription' repository" ;;
|
|
disable)
|
|
msg_info "Disabling 'pmg-no-subscription' repository"
|
|
sed -i "s/^[^#].*pmg-no-subscription/# &/" "$file"
|
|
msg_ok "Disabled 'pmg-no-subscription' repository"
|
|
;;
|
|
delete)
|
|
msg_info "Deleting 'pmg-no-subscription' repository file"
|
|
rm -f "$file"
|
|
msg_ok "Deleted 'pmg-no-subscription' repository file"
|
|
;;
|
|
esac
|
|
;;
|
|
disabled)
|
|
CHOICE=$(whiptail --backtitle "Proxmox VE Helper Scripts" --title "PMG-NO-SUBSCRIPTION" \
|
|
--menu "'pmg-no-subscription' repository is currently DISABLED.\n\nWhat do you want to do?" 14 58 3 \
|
|
"enable" "Uncomment (enable)" \
|
|
"keep" "Keep disabled" \
|
|
"delete" "Delete repo file" \
|
|
3>&2 2>&1 1>&3)
|
|
case $CHOICE in
|
|
enable)
|
|
msg_info "Enabling 'pmg-no-subscription' repository"
|
|
sed -i "s/^#.*pmg-no-subscription/deb/" "$file"
|
|
msg_ok "Enabled 'pmg-no-subscription' repository"
|
|
;;
|
|
keep) msg_ok "Kept 'pmg-no-subscription' repository disabled" ;;
|
|
delete)
|
|
msg_info "Deleting 'pmg-no-subscription' repository file"
|
|
rm -f "$file"
|
|
msg_ok "Deleted 'pmg-no-subscription' repository file"
|
|
;;
|
|
esac
|
|
;;
|
|
missing)
|
|
CHOICE=$(whiptail --backtitle "Proxmox VE Helper Scripts" --title "PMG-NO-SUBSCRIPTION" \
|
|
--menu "Add 'pmg-no-subscription' repository?" 14 58 2 \
|
|
"yes" " " \
|
|
"no" " " \
|
|
3>&2 2>&1 1>&3)
|
|
case $CHOICE in
|
|
yes)
|
|
msg_info "Adding 'pmg-no-subscription' repository"
|
|
cat >/etc/apt/sources.list.d/pmg-install-repo.list <<EOF
|
|
deb http://download.proxmox.com/debian/pmg ${VERSION} pmg-no-subscription
|
|
EOF
|
|
msg_ok "Added 'pmg-no-subscription' repository"
|
|
;;
|
|
no) msg_error "Selected no to Adding 'pmg-no-subscription' repository" ;;
|
|
esac
|
|
;;
|
|
esac
|
|
|
|
# ---- PMG-TEST ----
|
|
read -r state file <<<"$(repo_state pmgtest)"
|
|
case $state in
|
|
active) msg_ok "'pmgtest' repository already active (skipped)" ;;
|
|
disabled) msg_ok "'pmgtest' repository already disabled (skipped)" ;;
|
|
missing)
|
|
CHOICE=$(whiptail --backtitle "Proxmox VE Helper Scripts" --title "PMG TEST" \
|
|
--menu "The 'pmgtest' repository can give advanced users access to new features early.\n\nAdd (disabled) 'pmgtest' repository?" 14 58 2 \
|
|
"yes" " " \
|
|
"no" " " 3>&2 2>&1 1>&3)
|
|
case $CHOICE in
|
|
yes)
|
|
msg_info "Adding 'pmgtest' repository (disabled)"
|
|
cat >/etc/apt/sources.list.d/pmgtest-for-beta.list <<EOF
|
|
# deb http://download.proxmox.com/debian/pmg ${VERSION} pmgtest
|
|
EOF
|
|
msg_ok "Added 'pmgtest' repository"
|
|
;;
|
|
no) msg_error "Selected no to Adding 'pmgtest' repository" ;;
|
|
esac
|
|
;;
|
|
esac
|
|
|
|
# ---- SUBSCRIPTION NAG ----
|
|
CHOICE=$(whiptail --backtitle "Proxmox VE Helper Scripts" --title "SUBSCRIPTION NAG" --menu \
|
|
"Disable subscription nag in PMG UI?" 14 58 2 "yes" " " "no" " " 3>&2 2>&1 1>&3)
|
|
case $CHOICE in
|
|
yes)
|
|
whiptail --backtitle "Proxmox VE Helper Scripts" --msgbox --title "Support Subscriptions" \
|
|
"Supporting the software's development team is essential.\nPlease consider buying a subscription." 10 58
|
|
msg_info "Disabling subscription nag"
|
|
cat >/etc/apt/apt.conf.d/no-nag-script <<'EOF'
|
|
DPkg::Post-Invoke { "if [ -s /usr/share/javascript/proxmox-widget-toolkit/proxmoxlib.js ] && ! grep -q -F 'NoMoreNagging' /usr/share/javascript/proxmox-widget-toolkit/proxmoxlib.js; then sed -i '/data\.status/{s/\!//;s/active/NoMoreNagging/}' /usr/share/javascript/proxmox-widget-toolkit/proxmoxlib.js; fi"; };
|
|
EOF
|
|
|
|
cat >/etc/apt/apt.conf.d/no-nag-script-pmgmanagerlib-mobile <<'EOF'
|
|
DPkg::Post-Invoke { "if [ -s /usr/share/javascript/pmg-gui/js/pmgmanagerlib-mobile.js ] && ! grep -q -F 'NoMoreNagging' /usr/share/javascript/pmg-gui/js/pmgmanagerlib-mobile.js; then sed -i '/data\.status/{s/\!//;s/active/NoMoreNagging/}' /usr/share/javascript/pmg-gui/js/pmgmanagerlib-mobile.js; fi"; };
|
|
EOF
|
|
msg_ok "Disabled subscription nag (clear browser cache!)"
|
|
;;
|
|
no)
|
|
msg_error "Selected no to Disabling subscription nag"
|
|
rm -f /etc/apt/apt.conf.d/no-nag-script 2>/dev/null
|
|
;;
|
|
esac
|
|
apt --reinstall install proxmox-widget-toolkit pmg-gui &>/dev/null || msg_error "Widget toolkit reinstall failed"
|
|
|
|
# ---- UPDATE ----
|
|
CHOICE=$(whiptail --backtitle "Proxmox VE Helper Scripts" --title "UPDATE" --menu \
|
|
"Update Proxmox Mail Gateway now?" 11 58 2 "yes" " " "no" " " 3>&2 2>&1 1>&3)
|
|
case $CHOICE in
|
|
yes)
|
|
msg_info "Updating Proxmox Mail Gateway (Patience)"
|
|
apt update &>/dev/null || msg_error "apt update failed"
|
|
apt -y dist-upgrade &>/dev/null || msg_error "apt dist-upgrade failed"
|
|
msg_ok "Updated Proxmox Mail Gateway"
|
|
;;
|
|
no) msg_error "Selected no to updating Proxmox Mail Gateway" ;;
|
|
esac
|
|
|
|
# ---- REMINDER ----
|
|
whiptail --backtitle "Proxmox VE Helper Scripts" --title "Post-Install Reminder" --msgbox \
|
|
"IMPORTANT:
|
|
|
|
Please run this script on every PMG node individually if you have multiple nodes.
|
|
|
|
After completing these steps, it is strongly recommended to REBOOT your node.
|
|
|
|
After the upgrade or post-install routines, always clear your browser cache or perform a hard reload (Ctrl+Shift+R) before using the PMG Web UI to avoid UI display issues." 20 80
|
|
|
|
# ---- REBOOT ----
|
|
CHOICE=$(whiptail --backtitle "Proxmox VE Helper Scripts" --title "REBOOT" --menu \
|
|
"Reboot Proxmox Mail Gateway now? (recommended)" 11 58 2 "yes" " " "no" " " 3>&2 2>&1 1>&3)
|
|
case $CHOICE in
|
|
yes)
|
|
msg_info "Rebooting Proxmox Mail Gateway"
|
|
sleep 2
|
|
msg_ok "Completed Post Install Routines"
|
|
reboot
|
|
;;
|
|
no)
|
|
msg_error "Selected no to reboot (Reboot recommended)"
|
|
msg_ok "Completed Post Install Routines"
|
|
;;
|
|
esac
|
|
}
|
|
|
|
header_info
|
|
echo -e "\nThis script will Perform Post Install Routines.\n"
|
|
while true; do
|
|
read -rp "Start the Proxmox Mail Gateway Post Install Script (y/n)? " yn
|
|
case $yn in
|
|
[Yy]*) break ;;
|
|
[Nn]*)
|
|
clear
|
|
exit
|
|
;;
|
|
*) echo "Please answer yes or no." ;;
|
|
esac
|
|
done
|
|
|
|
start_routines
|