aboutsummaryrefslogtreecommitdiffstats
path: root/ci.d/lxc
diff options
context:
space:
mode:
Diffstat (limited to 'ci.d/lxc')
-rw-r--r--ci.d/lxc44
1 files changed, 44 insertions, 0 deletions
diff --git a/ci.d/lxc b/ci.d/lxc
new file mode 100644
index 0000000..c0c5ed2
--- /dev/null
+++ b/ci.d/lxc
@@ -0,0 +1,44 @@
+#!/usr/bin/env sh
+
+# $NAME must be set to the name of the container.
+if [ -z "$NAME" ]; then
+ echo 'Error: $NAME is empty or not set.' 1>&2
+ exit 1
+fi
+
+# lxc_create dist release arch
+lxc_create() {
+ lxc-create -n $NAME -t download -B btrfs -- --dist $1 --release $2 --arch $3
+ echo "lxc.start.auto = 1" >> /home/lxc/$NAME/config
+ echo "lxc.environment = HOME=/root" >> /home/lxc/$NAME/config
+ lxc-start -n $NAME
+ lxc-wait -n $NAME -s RUNNING
+}
+
+# lxc_destroy
+lxc_destroy() {
+ lxc-stop -n $NAME -k || true
+ lxc-destroy -n $NAME || true
+}
+
+# lxc_do
+lxc_do() {
+ lxc-attach -n $NAME --clear-env -- "$@"
+}
+
+# lxc_restart
+lxc_restart() {
+ lxc-stop -n $NAME
+ lxc-start -n $NAME
+ lxc_wait_for_ip
+ lxc-ls -f $NAME
+}
+
+# lxc_wait_for_ip
+lxc_wait_for_ip() {
+ until lxc-info -n $NAME -i | grep IP:
+ do
+ echo -n .
+ sleep 1
+ done
+}