mirror of
https://github.com/community-scripts/ProxmoxVE.git
synced 2026-03-06 02:45:55 +01:00
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.
This commit is contained in:
@@ -88,19 +88,19 @@ main() {
|
||||
if [[ "$PVE_MAJOR" == "8" ]]; then
|
||||
if ((PVE_MINOR < 0 || PVE_MINOR > 9)); then
|
||||
msg_error "Unsupported Proxmox 8 version"
|
||||
exit 1
|
||||
exit 105
|
||||
fi
|
||||
start_routines_8
|
||||
elif [[ "$PVE_MAJOR" == "9" ]]; then
|
||||
if ((PVE_MINOR < 0 || PVE_MINOR > 1)); then
|
||||
msg_error "Only Proxmox 9.0-9.1.x is currently supported"
|
||||
exit 1
|
||||
exit 105
|
||||
fi
|
||||
start_routines_9
|
||||
else
|
||||
msg_error "Unsupported Proxmox VE major version: $PVE_MAJOR"
|
||||
echo -e "Supported: 8.0–8.9.x and 9.0–9.1.x"
|
||||
exit 1
|
||||
exit 105
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ header_info "$APP"
|
||||
check_root() {
|
||||
if [[ $EUID -ne 0 ]]; then
|
||||
msg_error "Script must be run as root"
|
||||
exit 1
|
||||
exit 104
|
||||
fi
|
||||
}
|
||||
|
||||
@@ -63,7 +63,7 @@ select_container() {
|
||||
|
||||
if [[ ${#lxc_list[@]} -eq 0 ]]; then
|
||||
msg_error "No containers found"
|
||||
exit 1
|
||||
exit 234
|
||||
fi
|
||||
|
||||
PS3="Enter number of container to convert: "
|
||||
@@ -101,7 +101,7 @@ backup_container() {
|
||||
if [ -z "$BACKUP_PATH" ] || ! grep -q "Backup job finished successfully" "$vzdump_output"; then
|
||||
rm "$vzdump_output"
|
||||
msg_error "Backup failed"
|
||||
exit 1
|
||||
exit 235
|
||||
fi
|
||||
rm "$vzdump_output"
|
||||
msg_ok "Backup complete: $BACKUP_PATH"
|
||||
@@ -126,7 +126,7 @@ perform_conversion() {
|
||||
msg_ok "Conversion successful"
|
||||
else
|
||||
msg_error "Conversion failed"
|
||||
exit 1
|
||||
exit 235
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
@@ -140,7 +140,7 @@ function backup_container() {
|
||||
msg_ok "Backup created"
|
||||
else
|
||||
msg_error "Backup failed for container $1"
|
||||
exit 1
|
||||
exit 235
|
||||
fi
|
||||
}
|
||||
|
||||
@@ -183,7 +183,7 @@ containers=$(pct list | tail -n +2 | awk '{print $0 " " $4}')
|
||||
|
||||
if [ -z "$containers" ]; then
|
||||
whiptail --title "LXC Container Update" --msgbox "No LXC containers available!" 10 60
|
||||
exit 1
|
||||
exit 234
|
||||
fi
|
||||
|
||||
menu_items=()
|
||||
@@ -242,7 +242,7 @@ if [[ -n "$var_container" ]]; then
|
||||
|
||||
if [[ -z "$CHOICE" ]]; then
|
||||
msg_error "No containers matched the selection criteria: $var_container ${var_tags:-community-script|proxmox-helper-scripts}"
|
||||
exit 1
|
||||
exit 234
|
||||
fi
|
||||
msg_ok "Selected containers: $CHOICE"
|
||||
else
|
||||
@@ -253,7 +253,7 @@ else
|
||||
if [ -z "$CHOICE" ]; then
|
||||
whiptail --title "LXC Container Update" \
|
||||
--msgbox "No containers selected!" 10 60
|
||||
exit 1
|
||||
exit 0
|
||||
fi
|
||||
fi
|
||||
|
||||
@@ -284,7 +284,7 @@ if [ "$BACKUP_CHOICE" == "yes" ]; then
|
||||
|
||||
if [ -z "$STORAGES" ]; then
|
||||
msg_error "No storage with 'backup' support found!"
|
||||
exit 1
|
||||
exit 119
|
||||
fi
|
||||
|
||||
# Determine storage based on var_backup_storage
|
||||
@@ -296,7 +296,7 @@ if [ "$BACKUP_CHOICE" == "yes" ]; then
|
||||
else
|
||||
msg_error "Specified backup storage '$var_backup_storage' not found or doesn't support backups!"
|
||||
msg_info "Available storages: $(echo $STORAGES | tr '\n' ' ')"
|
||||
exit 1
|
||||
exit 119
|
||||
fi
|
||||
else
|
||||
MENU_ITEMS=()
|
||||
@@ -308,7 +308,7 @@ if [ "$BACKUP_CHOICE" == "yes" ]; then
|
||||
|
||||
if [ -z "$STORAGE_CHOICE" ]; then
|
||||
msg_error "No storage selected!"
|
||||
exit 1
|
||||
exit 0
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
@@ -436,11 +436,11 @@ for container in $CHOICE; do
|
||||
msg_ok "Restored LXC from backup"
|
||||
else
|
||||
msg_error "Restored LXC from backup failed"
|
||||
exit 1
|
||||
exit 235
|
||||
fi
|
||||
else
|
||||
msg_error "Update failed for container $container. Exiting"
|
||||
exit 1
|
||||
exit "$exit_code"
|
||||
fi
|
||||
done
|
||||
|
||||
|
||||
Reference in New Issue
Block a user