#!/usr/bin/env bash
# File: auto-upgrade-proxmox.sh

# Stop on Ctrl-C and treat unset variables as errors
set -u
trap 'printf "\nAborted.\n"; exit 130' INT

# Set PATH for cron compatibility
export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

# ---------- 1. Run the update sequence ----------
if apt update                               \
   && apt dist-upgrade -y                   \
   && apt autoremove   -y                   \
   && apt autoclean                         \
   && sleep 5; then

  # -------- 2-a. All update commands succeeded --------
  echo "The Update-Upgrade on Proxmox VE COMPLETE."

else
  # -------- 2-b. At least one update command failed --------
  echo "The Update-Upgrade on Proxmox VE FAILED."
fi
