From ce2a2530536d2b89870ef6f449e6636925d45389 Mon Sep 17 00:00:00 2001 From: "CanbiZ (MickLesk)" <47820557+MickLesk@users.noreply.github.com> Date: Mon, 2 Mar 2026 09:41:03 +0100 Subject: [PATCH] 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. --- misc/alpine-install.func | 4 ++-- misc/api.func | 24 ++++++++++++++++++++++++ misc/build.func | 32 ++++++++++++++++---------------- misc/core.func | 12 ++++++------ misc/error_handler.func | 23 +++++++++++++++++++++++ misc/install.func | 8 ++++---- misc/tools.func | 2 +- misc/vm-core.func | 18 +++++++++--------- 8 files changed, 85 insertions(+), 38 deletions(-) diff --git a/misc/alpine-install.func b/misc/alpine-install.func index a80b2e6d3..5b9043c6d 100644 --- a/misc/alpine-install.func +++ b/misc/alpine-install.func @@ -79,7 +79,7 @@ setting_up_container() { if [ "$(ip addr show | grep 'inet ' | grep -v '127.0.0.1' | awk '{print $2}' | cut -d'/' -f1)" = "" ]; then echo 1>&2 -e "\n${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" echo -e "${NETWORK}Check Network Settings" - exit 1 + exit 121 fi msg_ok "Set up Container OS" msg_ok "Network Connected: ${BL}$(ip addr show | grep 'inet ' | awk '{print $2}' | cut -d'/' -f1 | tail -n1)${CL}" @@ -99,7 +99,7 @@ network_check() { echo -e "${INFO}${RD}Expect Issues Without Internet${CL}" else echo -e "${NETWORK}Check Network Settings" - exit 1 + exit 122 fi fi RESOLVEDIP=$(getent hosts github.com | awk '{ print $1 }') diff --git a/misc/api.func b/misc/api.func index 4d5c0ae86..9507ef2fd 100644 --- a/misc/api.func +++ b/misc/api.func @@ -124,6 +124,7 @@ detect_repo_source # * Generic/Shell errors (1-3, 10, 124-132, 134, 137, 139, 141, 143-146) # * curl/wget errors (4-8, 16, 18, 22-28, 30, 32-36, 39, 44-48, 51-52, 55-57, 59, 61, 63, 75, 78-79, 92, 95) # * Package manager errors (APT, DPKG: 100-102, 255) +# * Script Validation & Setup (103-123) # * BSD sysexits (64-78) # * Systemd/Service errors (150-154) # * Python/pip/uv errors (160-162) @@ -189,6 +190,29 @@ explain_exit_code() { 101) echo "APT: Configuration error (bad sources.list, malformed config)" ;; 102) echo "APT: Lock held by another process (dpkg/apt still running)" ;; + # --- Script Validation & Setup (103-123) --- + 103) echo "Validation: Shell is not Bash" ;; + 104) echo "Validation: Not running as root (or invoked via sudo)" ;; + 105) echo "Validation: Proxmox VE version not supported" ;; + 106) echo "Validation: Architecture not supported (ARM / PiMox)" ;; + 107) echo "Validation: Kernel key parameters unreadable" ;; + 108) echo "Validation: Kernel key limits exceeded" ;; + 109) echo "Proxmox: No available container ID after max attempts" ;; + 110) echo "Proxmox: Failed to apply default.vars" ;; + 111) echo "Proxmox: App defaults file not available" ;; + 112) echo "Proxmox: Invalid install menu option" ;; + 113) echo "LXC: Under-provisioned — user aborted update" ;; + 114) echo "LXC: Storage too low — user aborted update" ;; + 115) echo "Download: install.func download failed or incomplete" ;; + 116) echo "Proxmox: Default bridge vmbr0 not found" ;; + 117) echo "LXC: Container did not reach running state" ;; + 118) echo "LXC: No IP assigned to container after timeout" ;; + 119) echo "Proxmox: No valid storage for rootdir content" ;; + 120) echo "Proxmox: No valid storage for vztmpl content" ;; + 121) echo "LXC: Container network not ready (no IP after retries)" ;; + 122) echo "LXC: No internet connectivity — user declined to continue" ;; + 123) echo "LXC: Local IP detection failed" ;; + # --- BSD sysexits.h (64-78) --- 64) echo "Usage error (wrong arguments)" ;; 65) echo "Data format error (bad input data)" ;; diff --git a/misc/build.func b/misc/build.func index 4233d831c..84736a4dd 100644 --- a/misc/build.func +++ b/misc/build.func @@ -119,7 +119,7 @@ maxkeys_check() { # Exit if kernel parameters are unavailable if [[ "$per_user_maxkeys" -eq 0 || "$per_user_maxbytes" -eq 0 ]]; then msg_error "Unable to read kernel key parameters. Ensure proper permissions." - exit 1 + exit 107 fi # Fetch key usage for user ID 100000 (typical for containers) @@ -148,7 +148,7 @@ maxkeys_check() { # Provide next steps if issues are detected if [[ "$failure" -eq 1 ]]; then msg_error "Kernel key limits exceeded - see suggestions above" - exit 1 + exit 108 fi # Silent success - only show errors if they exist @@ -355,7 +355,7 @@ get_valid_container_id() { attempts=$((attempts + 1)) if [[ $attempts -ge $max_attempts ]]; then msg_error "Could not find available container ID after $max_attempts attempts" - exit 1 + exit 109 fi done @@ -2035,7 +2035,7 @@ advanced_settings() { else whiptail --msgbox "Default bridge 'vmbr0' not found!\n\nPlease configure a network bridge in Proxmox first." 10 58 msg_error "Default bridge 'vmbr0' not found" - exit 1 + exit 116 fi else if result=$(whiptail --backtitle "Proxmox VE Helper Scripts [Step $STEP/$MAX_STEP]" \ @@ -3023,7 +3023,7 @@ install_script() { 3 | mydefaults | MYDEFAULTS | userdefaults | USERDEFAULTS) default_var_settings || { msg_error "Failed to apply default.vars" - exit 1 + exit 110 } defaults_target="/usr/local/community-scripts/default.vars" break @@ -3040,7 +3040,7 @@ install_script() { break else msg_error "No App Defaults available for ${APP}" - exit 1 + exit 111 fi ;; "$SETTINGS_OPTION" | settings | SETTINGS) @@ -3051,7 +3051,7 @@ install_script() { ;; *) msg_error "Invalid option: $CHOICE" - exit 1 + exit 112 ;; esac done @@ -3135,7 +3135,7 @@ check_container_resources() { read -r prompt /dev/null || echo "unknown") msg_error "LXC Container did not reach running state (status: ${ct_status})" - exit 1 + exit 117 fi done @@ -3967,7 +3967,7 @@ EOF echo " • Verify static IP configuration (if using static IP)" echo " • Check Proxmox firewall rules" echo " • If using Tailscale: Disable MagicDNS temporarily" - exit 1 + exit 118 fi # Verify basic connectivity (ping test) @@ -5014,11 +5014,11 @@ create_lxc_container() { # Storage capability check check_storage_support "rootdir" || { msg_error "No valid storage found for 'rootdir' [Container]" - exit 1 + exit 119 } check_storage_support "vztmpl" || { msg_error "No valid storage found for 'vztmpl' [Template]" - exit 1 + exit 120 } # Template storage selection @@ -5296,7 +5296,7 @@ create_lxc_container() { } else msg_custom "🚫" "${YW}" "Installation cancelled" - exit 1 + exit 0 fi else msg_error "No ${PCT_OSTYPE} templates available" diff --git a/misc/core.func b/misc/core.func index 9a4c52f71..e3b9d2cff 100644 --- a/misc/core.func +++ b/misc/core.func @@ -276,7 +276,7 @@ shell_check() { msg_error "Your default shell is currently not set to Bash. To use these scripts, please switch to the Bash shell." echo -e "\nExiting..." sleep 2 - exit 1 + exit 103 fi } @@ -293,7 +293,7 @@ root_check() { msg_error "Please run this script as root." echo -e "\nExiting..." sleep 2 - exit 1 + exit 104 fi } @@ -314,7 +314,7 @@ pve_check() { if ((MINOR < 0 || MINOR > 9)); then msg_error "This version of Proxmox VE is not supported." msg_error "Supported: Proxmox VE version 8.0 – 8.9" - exit 1 + exit 105 fi return 0 fi @@ -325,7 +325,7 @@ pve_check() { if ((MINOR < 0 || MINOR > 1)); then msg_error "This version of Proxmox VE is not yet supported." msg_error "Supported: Proxmox VE version 9.0 – 9.1" - exit 1 + exit 105 fi return 0 fi @@ -333,7 +333,7 @@ pve_check() { # All other unsupported versions msg_error "This version of Proxmox VE is not supported." msg_error "Supported versions: Proxmox VE 8.0 – 8.9 or 9.0 – 9.1" - exit 1 + exit 105 } # ------------------------------------------------------------------------------ @@ -348,7 +348,7 @@ arch_check() { msg_error "This script will not work with PiMox (ARM architecture detected)." msg_warn "Visit https://github.com/asylumexp/Proxmox for ARM64 support." sleep 2 - exit 1 + exit 106 fi } diff --git a/misc/error_handler.func b/misc/error_handler.func index cb89239ac..85b755008 100644 --- a/misc/error_handler.func +++ b/misc/error_handler.func @@ -94,6 +94,29 @@ if ! declare -f explain_exit_code &>/dev/null; then 100) echo "APT: Package manager error (broken packages / dependency problems)" ;; 101) echo "APT: Configuration error (bad sources.list, malformed config)" ;; 102) echo "APT: Lock held by another process (dpkg/apt still running)" ;; + + # --- Script Validation & Setup (103-123) --- + 103) echo "Validation: Shell is not Bash" ;; + 104) echo "Validation: Not running as root (or invoked via sudo)" ;; + 105) echo "Validation: Proxmox VE version not supported" ;; + 106) echo "Validation: Architecture not supported (ARM / PiMox)" ;; + 107) echo "Validation: Kernel key parameters unreadable" ;; + 108) echo "Validation: Kernel key limits exceeded" ;; + 109) echo "Proxmox: No available container ID after max attempts" ;; + 110) echo "Proxmox: Failed to apply default.vars" ;; + 111) echo "Proxmox: App defaults file not available" ;; + 112) echo "Proxmox: Invalid install menu option" ;; + 113) echo "LXC: Under-provisioned — user aborted update" ;; + 114) echo "LXC: Storage too low — user aborted update" ;; + 115) echo "Download: install.func download failed or incomplete" ;; + 116) echo "Proxmox: Default bridge vmbr0 not found" ;; + 117) echo "LXC: Container did not reach running state" ;; + 118) echo "LXC: No IP assigned to container after timeout" ;; + 119) echo "Proxmox: No valid storage for rootdir content" ;; + 120) echo "Proxmox: No valid storage for vztmpl content" ;; + 121) echo "LXC: Container network not ready (no IP after retries)" ;; + 122) echo "LXC: No internet connectivity — user declined to continue" ;; + 123) echo "LXC: Local IP detection failed" ;; 124) echo "Command timed out (timeout command)" ;; 125) echo "Command failed to start (Docker daemon or execution error)" ;; 126) echo "Command invoked cannot execute (permission problem?)" ;; diff --git a/misc/install.func b/misc/install.func index 069eba5ba..94f005b26 100644 --- a/misc/install.func +++ b/misc/install.func @@ -126,7 +126,7 @@ setting_up_container() { if [ "$(hostname -I)" = "" ]; then echo 1>&2 -e "\n${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" echo -e "${NETWORK}Check Network Settings" - exit 1 + exit 121 fi rm -rf /usr/lib/python3.*/EXTERNALLY-MANAGED systemctl disable -q --now systemd-networkd-wait-online.service @@ -177,7 +177,7 @@ network_check() { echo -e "${INFO}${RD}Expect Issues Without Internet${CL}" else echo -e "${NETWORK}Check Network Settings" - exit 1 + exit 122 fi fi @@ -242,12 +242,12 @@ EOF local tools_content tools_content=$(curl -fsSL https://raw.githubusercontent.com/community-scripts/ProxmoxVE/main/misc/tools.func) || { msg_error "Failed to download tools.func" - exit 6 + exit 115 } source /dev/stdin <<<"$tools_content" if ! declare -f fetch_and_deploy_gh_release >/dev/null 2>&1; then msg_error "tools.func loaded but incomplete — missing expected functions" - exit 6 + exit 115 fi } diff --git a/misc/tools.func b/misc/tools.func index 84f5e053b..9f53729d0 100644 --- a/misc/tools.func +++ b/misc/tools.func @@ -5142,7 +5142,7 @@ current_ip="$(get_current_ip)" if [[ -z "$current_ip" ]]; then echo "[ERROR] Could not detect local IP" >&2 - exit 1 + exit 123 fi if [[ -f "$IP_FILE" ]]; then diff --git a/misc/vm-core.func b/misc/vm-core.func index 125f2e79e..852945152 100644 --- a/misc/vm-core.func +++ b/misc/vm-core.func @@ -244,7 +244,7 @@ curl_handler() { if [[ -z "$url" ]]; then msg_error "no valid url or option entered for curl_handler" - exit 1 + exit 64 fi $STD msg_info "Fetching: $url" @@ -273,7 +273,7 @@ curl_handler() { rm -f /tmp/curl_error.log fi __curl_err_handler "$exit_code" "$url" "$curl_stderr" - exit 1 # hard exit if exit_code is not 0 + exit "$exit_code" fi $STD printf "\r\033[K${INFO}${YW}Retry $attempt/$max_retries in ${delay}s...${CL}" >&2 @@ -316,7 +316,7 @@ __curl_err_handler() { esac [[ -n "$curl_msg" ]] && printf "%s\n" "$curl_msg" >&2 - exit 1 + exit "$exit_code" } # ------------------------------------------------------------------------------ @@ -331,7 +331,7 @@ shell_check() { msg_error "Your default shell is currently not set to Bash. To use these scripts, please switch to the Bash shell." echo -e "\nExiting..." sleep 2 - exit + exit 103 fi } @@ -552,7 +552,7 @@ check_root() { msg_error "Please run this script as root." echo -e "\nExiting..." sleep 2 - exit + exit 104 fi } @@ -562,7 +562,7 @@ pve_check() { echo -e "Requires Proxmox Virtual Environment Version 8.1 - 8.4 or 9.0 - 9.1." echo -e "Exiting..." sleep 2 - exit + exit 105 fi } @@ -572,21 +572,21 @@ arch_check() { echo -e "\n ${YWB}Visit https://github.com/asylumexp/Proxmox for ARM64 support. \n" echo -e "Exiting..." sleep 2 - exit + exit 106 fi } exit_script() { clear echo -e "\n${CROSS}${RD}User exited script${CL}\n" - exit + exit 0 } check_hostname_conflict() { local hostname="$1" if qm list | awk '{print $2}' | grep -qx "$hostname"; then msg_error "Hostname $hostname already in use by another VM." - exit 1 + exit 206 fi }