[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

[PATCH] autopkgtest-build-lxc: accept a customization script



---
 tools/autopkgtest-build-lxc   | 17 +++++++++++++++--
 tools/autopkgtest-build-lxc.1 |  5 +++++
 2 files changed, 20 insertions(+), 2 deletions(-)

diff --git a/tools/autopkgtest-build-lxc b/tools/autopkgtest-build-lxc
index 7a8e637..ee778de 100755
--- a/tools/autopkgtest-build-lxc
+++ b/tools/autopkgtest-build-lxc
@@ -27,7 +27,7 @@ set -e
 DISTRO="$1"
 RELEASE="$2"
 if [ -z "$1" ] || [ -z "$2" ]; then
-    echo "Usage: $0 debian|ubuntu <release> [arch]" >&2
+    echo "Usage: $0 debian|ubuntu <release> [arch] [script]" >&2
     exit 1
 fi
 
@@ -48,6 +48,12 @@ else
     NAME="autopkgtest-${RELEASE}${ARCH:+-$ARCH}"
 fi
 
+SCRIPT=${4:-}
+if [ -n "$SCRIPT" -a ! -r "$SCRIPT" ]; then
+    echo "ERROR: can't read customization script $SCRIPT" >&2
+    exit 1
+fi
+
 # fall back for older LXC option name
 LXCDIR=`lxc-config lxc.lxcpath` || LXCDIR=`lxc-config lxcpath` || LXCDIR=/var/lib/lxc
 
@@ -130,6 +136,13 @@ setup() {
             break
         fi
     done
+
+    # run customize script
+    if [ -n "$SCRIPT" ]; then
+        echo "Running customization script $SCRIPT..."
+        cat "$SCRIPT" | lxc-attach --name=$1 env MIRROR=${MIRROR:-} sh
+    fi
+
     lxc-stop --name=$1
 }
 
@@ -142,7 +155,7 @@ if [ ! -e $LXCDIR/$NAME ]; then
 else
     # remove LXC rootfs caches; on btrfs this might be a subvolume, otherwise
     # rm it
-    btrfs subvolume delete /var/cache/lxc/$RELEASE/rootfs-* 2>/dev/null || rm -rf /var/cache/lxc/$RELEASE/rootfs-*
+    btrfs subvolume delete /var/cache/lxc/$DISTRO/$RELEASE/rootfs-* 2>/dev/null || rm -rf /var/cache/lxc/$DISTRO/$RELEASE/rootfs-*
     # create a new rootfs in a temp container
     $LXC_CREATE_PREFIX lxc-create -B best --name=${NAME}.new $LXC_ARGS
     setup ${NAME}.new
diff --git a/tools/autopkgtest-build-lxc.1 b/tools/autopkgtest-build-lxc.1
index 24c2d3d..8a1ade1 100644
--- a/tools/autopkgtest-build-lxc.1
+++ b/tools/autopkgtest-build-lxc.1
@@ -6,6 +6,7 @@ autopkgtest-build-lxc \- Create or update autopkgtest container for autopkgtest-
 .B autopkgtest-build-lxc
 .I distribution release
 .RI [ architecture ]
+.RI [ script ]
 
 .SH DESCRIPTION
 .B autopkgtest-build-lxc
@@ -29,6 +30,10 @@ apt sources, and runs
 It defaults to the native architecture, but you can specify a different one as
 third parameter.
 
+The path to a script to be executed inside the container to customize the
+container can be passed as the fourth parameter. The script must be a POSIX
+shell script, and should not depend on bash-specific features.
+
 If the container already exists, it updates it as unintrusively as possible by
 first creating a new temporary container \fBautopkgtest-\fIrelease\fB.new\fR, and then
 rsyncing its root file system back to the existing \fBautopkgtest-\fIrelease\fR. Note
-- 
2.8.1




Reply to: