summaryrefslogtreecommitdiff
path: root/upgrade-containers.sh
blob: dd4bba2c8456555ef2ae4f175283cc53f8df412f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/bin/sh -euf

usage() (
	echo "upgrade-containers.sh"
	echo
	echo "Upgrade currently running LXC containers."
	echo "Uses apt-get for Debian and apk for Alpine."
	echo
)

upgrade_container() (
	NAME="$1"

	RELEASE_FILE="/var/lib/lxc/$NAME/rootfs/etc/os-release"

	if grep -q "ID=debian" "$RELEASE_FILE"; then
		lxc-attach -n "$NAME" -- apt-get update
		lxc-attach -n "$NAME" -- apt-get upgrade -y
	elif grep -q "ID=alpine" "$RELEASE_FILE"; then
		lxc-attach -n "$NAME" -- apk update
		lxc-attach -n "$NAME" -- apk upgrade
	fi
)

upgrade_running_containers() (
	for CONTAINER in $(lxc-ls --running); do
		upgrade_container "$CONTAINER"
	done
)

case "${1:-run}" in
	"help")	usage;;
	"run")	upgrade_running_containers;;
esac