Added setautostartall.sh script.
authorZoltán Felleg <zoltan.felleg@userrendszerhaz.hu>
Tue, 15 Sep 2020 11:10:07 +0000 (13:10 +0200)
committerZoltán Felleg <zoltan.felleg@userrendszerhaz.hu>
Tue, 15 Sep 2020 11:10:07 +0000 (13:10 +0200)
scripts/setautostartall.sh [new file with mode: 0755]

diff --git a/scripts/setautostartall.sh b/scripts/setautostartall.sh
new file mode 100755 (executable)
index 0000000..626c932
--- /dev/null
@@ -0,0 +1,27 @@
+#!/bin/sh
+
+
+if [ -f /etc/lxc/lxc.conf ]
+then
+    LXC_PATH=$(grep '^lxc.lxcpath' /etc/lxc/lxc.conf \
+               | cut -f 2 -d '=' | tr -d ' ')
+else
+    echo "No lxc system configuration found" >&2
+    exit 1
+fi
+
+read -n 1 -p "Autostart containers? 0/1 " AUTOSTART
+if [ "$AUTOSTART" -eq 1 ]
+then
+    ACTION="Enabling"
+else
+    ACTION="Disabling"
+    AUTOSTART=0
+fi
+
+lxc-ls -1 | while read CONTAINER_NAME
+do
+    echo "$ACTION autostart on $CONTAINER_NAME"
+    CONTAINER_PATH=$LXC_PATH/$CONTAINER_NAME
+    sed --in-place "s/^lxc.start.auto = .$/lxc.start.auto = $AUTOSTART/" $CONTAINER_PATH/config
+done