This repository has been archived on 2025-02-14. You can view files and clone it, but cannot push or open issues or pull requests.
pyinfra-lxd/files/lxd-containers-upgrade.sh
2021-10-02 14:22:45 +09:00

25 lines
775 B
Bash

#!/usr/bin/env bash
set -euo pipefail
for i in $(lxc list --format csv -c n); do
lxc snapshot "$i"
if lxc exec "$i" -- which apt >/dev/null 2>&1; then
echo "Upgrading Debian/Ubuntu $i"
lxc exec "$i" -- apt update
lxc exec "$i" -- apt upgrade -y
lxc exec "$i" -- apt auto-remove -y
fi
if lxc exec "$i" -- which pacman >/dev/null 2>&1; then
echo "Upgrading ArchLinux $i"
lxc exec "$i" -- sudo -u benpro yay -Sc --noconfirm
lxc exec "$i" -- sudo -u benpro yay -Syu --noconfirm
fi
if lxc exec "$i" -- which apk >/dev/null 2>&1; then
echo "Upgrading Alpine $i"
lxc exec "$i" -- apk update
lxc exec "$i" -- apk add --upgrade apk-tools
lxc exec "$i" -- apk upgrade
fi
lxc exec "$i" -- sync
lxc exec "$i" -- reboot
done