Scripte/proxmox/update-containers.sh
2025-05-12 21:48:57 +02:00

31 lines
967 B
Bash
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root"
exit 1
fi
for CTID in $(pct list | tail -n+2 | awk '{print $1}'); do
echo "==> Checking container $CTID..."
if pct exec $CTID -- which apt >/dev/null 2>&1; then
echo "-> apt found. Running update & upgrade..."
pct exec $CTID -- apt -qq update
pct exec $CTID -- apt -qq upgrade -y
elif pct exec $CTID -- which apt-get >/dev/null 2>&1; then
echo "-> apt-get found. Running update & upgrade..."
pct exec $CTID -- apt-get -qq update
pct exec $CTID -- apt-get -qq upgrade -y
elif pct exec $CTID -- which dnf >/dev/null 2>&1; then
echo "-> dnf found. Running update..."
pct exec $CTID -- dnf -y upgrade --refresh
elif pct exec $CTID -- which yum >/dev/null 2>&1; then
echo "-> yum found. Running update..."
pct exec $CTID -- yum -y update
else
echo "-> No package manager found in container $CTID skipping."
fi
echo
done