testing: Add a script to build the current (or an arbitrary) source tree
This allows to (relatively) quickly (re-)build and install the current or an arbitrary strongSwan source tree within the root image. bindfs is used to bind mount the source directory using the regular user and group (only works if sudo is used to run the script) so that newly created files are not owned by root. As with building the root image in general the guests must not be running while executing this script. The guest images are automatically rebuilt after the root image has been updated so configuration files and other modifications in guests will be lost.
This commit is contained in:
parent
f376503f41
commit
82136aa2cf
|
@ -0,0 +1,65 @@
|
|||
#!/bin/bash
|
||||
|
||||
echo "Preparing root image"
|
||||
|
||||
DIR=$(dirname `readlink -f $0`)
|
||||
. $DIR/../testing.conf
|
||||
. $DIR/function.sh
|
||||
|
||||
SWANDIR=${1:+$(readlink -f $1)}
|
||||
: ${SWANDIR:=$(readlink -f $DIR/../..)}
|
||||
|
||||
[ `id -u` -eq 0 ] || die "You must be root to run $0"
|
||||
[ -f "$BASEIMG" ] || die "Base image $BASEIMG not found"
|
||||
[ -f "$ROOTIMG" ] || die "Root image $ROOTIMG not found"
|
||||
|
||||
[ -f $SWANDIR/src/libstrongswan/asn1/oid.txt ] || die "strongSwan not found in $SWANDIR"
|
||||
|
||||
SRCUID=${SUDO_UID:-$(id -u)}
|
||||
SRCGID=${SUDO_GID:-$(id -g)}
|
||||
|
||||
check_commands partprobe qemu-img qemu-nbd bindfs
|
||||
|
||||
load_qemu_nbd
|
||||
|
||||
mkdir -p $LOOPDIR
|
||||
mkdir -p $IMGDIR
|
||||
|
||||
log_action "Connecting root image to NBD device $NBDEV"
|
||||
execute "qemu-nbd -c $NBDEV $ROOTIMG"
|
||||
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
|
||||
|
||||
mkdir -p $LOOPDIR/root/strongswan
|
||||
log_action "Mounting $SWANDIR as /root/strongswan"
|
||||
execute "bindfs -u $SRCUID -g $SRCGID $SWANDIR $LOOPDIR/root/strongswan"
|
||||
do_on_exit umount $LOOPDIR/root/strongswan
|
||||
|
||||
echo "Building and installing strongSwan"
|
||||
log_action "Preparing source tree"
|
||||
execute_chroot 'autoreconf -i /root/strongswan'
|
||||
|
||||
RECPDIR=$DIR/recipes
|
||||
RECIPE=`ls $RECPDIR/*strongswan.mk | xargs -n1 basename`
|
||||
mkdir -p $SHAREDDIR/build-strongswan
|
||||
cp $RECPDIR/$RECIPE $SHAREDDIR/build-strongswan
|
||||
log_action "Installing from recipe $RECIPE"
|
||||
execute_chroot "make SRCDIR=/root/strongswan BUILDDIR=/root/shared/build-strongswan -f /root/shared/build-strongswan/$RECIPE"
|
||||
|
||||
# cleanup before mounting guest images
|
||||
on_exit
|
||||
|
||||
$DIR/build-guestimages
|
Loading…
Reference in New Issue