From 118ff790598aebf3c3f11a2ed73f0c842ae83e9c Mon Sep 17 00:00:00 2001 From: root Date: Tue, 16 May 2017 23:57:27 +0200 Subject: Add LXC containers upgrade script --- upgrade-containers.sh | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100755 upgrade-containers.sh diff --git a/upgrade-containers.sh b/upgrade-containers.sh new file mode 100755 index 0000000..dd4bba2 --- /dev/null +++ b/upgrade-containers.sh @@ -0,0 +1,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 + -- cgit v1.2.3