Skip to content

Instantly share code, notes, and snippets.

@petterpet
Created February 12, 2022 11:54
Show Gist options
  • Save petterpet/0b70cf5f731c7729f4b016abd9786a19 to your computer and use it in GitHub Desktop.
Save petterpet/0b70cf5f731c7729f4b016abd9786a19 to your computer and use it in GitHub Desktop.
Updater for Proxmox
#!/bin/bash
# update all containers and host
# execute on host
echo "[UPDATER] +++ updating host and containers only +++"
echo "[UPDATER] +++ update your VMs separately +++"
echo ""
# Update host
echo "[UPDATER] updateing host"
apt update && DEBIAN_FRONTEND=noninteractive apt upgrade -y && apt autoremove -y
# Update container templates
echo "[UPDATER] updateing container templates"
pveam update
# Update container
echo "[UPDATER] updateing containers"
# list of container IDs we need to iterate through
containers=$(pct list | tail -n +2 | cut -f1 -d' ')
function updateContainer() {
# update single container
container=$1
echo "[UPDATER] Updating $container"
pct exec $container -- bash -c "apt update && apt upgrade -y && apt autoremove -y"
}
for container in $containers
# iterate through containers
do
status=`pct status $container`
if [ "$status" == "status: stopped" ]; then
# start stopped containers for update
echo "[Info] Starting $container"
pct start $container
sleep 5
updateContainer $container
echo "[Info] Shutting down $container"
pct shutdown $container &
elif [ "$status" == "status: running" ]; then
updateContainer $container
fi
done; wait
echo "[UPDATER] finished"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment