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