aboutsummaryrefslogtreecommitdiffstats
path: root/testing/scripts
diff options
context:
space:
mode:
authorTobias Brunner <tobias@strongswan.org>2015-11-24 11:08:57 +0100
committerTobias Brunner <tobias@strongswan.org>2016-06-15 16:24:43 +0200
commit6466546f81902dc25e7fd52111890ae06c38e014 (patch)
treec2663ed7a4b5f1e6d0b90959795dcc1add21a738 /testing/scripts
parentcac9051eed7aa57f9f3d11f6f17fb4c23fc6dc8c (diff)
downloadstrongswan-6466546f81902dc25e7fd52111890ae06c38e014.tar.bz2
strongswan-6466546f81902dc25e7fd52111890ae06c38e014.tar.xz
testing: Add script to chroot into an image
If changes are made to the base or root image the images depending on these have to be rebuilt.
Diffstat (limited to 'testing/scripts')
-rwxr-xr-xtesting/scripts/chroot67
1 files changed, 67 insertions, 0 deletions
diff --git a/testing/scripts/chroot b/testing/scripts/chroot
new file mode 100755
index 000000000..4f4245515
--- /dev/null
+++ b/testing/scripts/chroot
@@ -0,0 +1,67 @@
+#!/bin/bash
+
+DIR=$(dirname `readlink -f $0`)
+. $DIR/../testing.conf
+. $DIR/function.sh
+
+[ `id -u` -eq 0 ] || die "You must be root to run $0"
+running_any $STRONGSWANHOSTS && die "Please stop test environment before running $0"
+
+[ -n "$1" ] || die "$0 <image to mount: base|root|<guest>>"
+
+check_commands partprobe qemu-nbd
+
+load_qemu_nbd
+
+mkdir -p $LOOPDIR
+mkdir -p $IMGDIR
+mkdir -p $SHAREDDIR
+
+echo "Mounting image"
+
+case "$1" in
+base)
+ [ -f "$BASEIMG" ] || die "Base image $BASEIMG not found"
+ log_action "Connecting base image to NBD device $NBDEV"
+ execute "qemu-nbd -c $NBDEV $BASEIMG"
+ affected="root and guest"
+ ;;
+root)
+ [ -f "$ROOTIMG" ] || die "Root image $ROOTIMG not found"
+ log_action "Connecting root image to NBD device $NBDEV"
+ execute "qemu-nbd -c $NBDEV $ROOTIMG"
+ affected="guest"
+ ;;
+*)
+ echo $STRONGSWANHOSTS | grep -q "\b$1\b" || die "Guest $1 not found"
+ GUESTIMG="$IMGDIR/$1.$IMGEXT"
+ [ -f "$GUESTIMG" ] || die "Guest image $GUESTIMG not found"
+ log_action "Connecting guest image to NBD device $NBDEV"
+ execute "qemu-nbd -c $NBDEV $GUESTIMG"
+ ;;
+esac
+
+do_on_exit qemu-nbd -d $NBDEV
+partprobe $NBDEV
+
+log_action "Mounting $NBDPARTITION to $LOOPDIR"
+execute "mount $NBDPARTITION $LOOPDIR"
+do_on_exit umount $LOOPDIR
+
+log_action "Mounting proc filesystem to $LOOPDIR/proc"
+execute "mount -t proc none $LOOPDIR/proc"
+do_on_exit umount $LOOPDIR/proc
+
+mkdir -p $LOOPDIR/root/shared
+log_action "Mounting $SHAREDDIR as /root/shared"
+execute "mount -o bind $SHAREDDIR $LOOPDIR/root/shared"
+do_on_exit umount $LOOPDIR/root/shared
+
+if [ -n "$affected" ]; then
+echo
+echo "Rebuild the $affected images after making changes to this image!"
+echo
+fi
+
+export debian_chroot="$1"
+chroot $LOOPDIR /bin/bash -i