| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 | #!/bin/bashDIR=$(dirname `readlink -f $0`). $DIR/../testing.conf. $DIR/function.shSWANDIR=${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"running_any $STRONGSWANHOSTS && die "Please stop test environment before running $0"[ -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 bindfsload_qemu_nbdmkdir -p $LOOPDIRmkdir -p $IMGDIRcase "$2" in"")	log_action "Connecting root image to NBD device $NBDEV"	execute "qemu-nbd -c $NBDEV $ROOTIMG"	;;*)	echo $STRONGSWANHOSTS | grep -q "\b$2\b" || die "Guest $2 not found"	GUESTIMG="$IMGDIR/$2.$IMGEXT"	[ -f "$GUESTIMG" ] || die "Guest image $GUESTIMG not found"	log_action "Connecting guest image to NBD device $NBDEV"	execute "qemu-nbd -c $NBDEV $GUESTIMG"	;;esacdo_on_exit qemu-nbd -d $NBDEVpartprobe $NBDEVlog_action "Mounting $NBDPARTITION to $LOOPDIR"execute "mount $NBDPARTITION $LOOPDIR"do_on_exit umount $LOOPDIRlog_action "Mounting proc filesystem to $LOOPDIR/proc"execute "mount -t proc none $LOOPDIR/proc"do_on_exit umount $LOOPDIR/procmkdir -p $LOOPDIR/root/sharedlog_action "Mounting $SHAREDDIR as /root/shared"execute "mount -o bind $SHAREDDIR $LOOPDIR/root/shared"do_on_exit umount $LOOPDIR/root/sharedmkdir -p $LOOPDIR/root/strongswanlog_action "Mounting $SWANDIR as /root/strongswan"execute "bindfs -u $SRCUID -g $SRCGID --create-for-user=$SRCUID --create-for-group=$SRCGID $SWANDIR $LOOPDIR/root/strongswan"do_on_exit umount $LOOPDIR/root/strongswanlog_action "Copy /etc/resolv.conf"execute "cp /etc/resolv.conf $LOOPDIR/etc/resolv.conf"do_on_exit rm $LOOPDIR/etc/resolv.conflog_action "Remove SWID tags of previous versions"execute_chroot "find /usr/local/share -path '*strongswan*' -name *.swidtag -delete"echo "Building and installing strongSwan"log_action "Determine strongSwan version"desc=`git -C $SWANDIR describe --dirty`if [ $? -eq 0 ]; then	SWANVERSION="$desc (`git -C $SWANDIR rev-parse --abbrev-ref HEAD`)"else	SWANVERSION="`cat $SWANDIR/configure.ac | sed -n '/^AC_INIT/{ s/.*,\[\(.*\)\])$/\1/p }'`"fiecho "$SWANVERSION" > $SHAREDDIR/.strongswan-versionlog_status 0log_action "Preparing source tree"execute_chroot 'autoreconf -i /root/strongswan'RECPDIR=$DIR/recipesRECIPE=`ls $RECPDIR/*strongswan.mk | xargs -n1 basename`mkdir -p $SHAREDDIR/build-strongswancp $RECPDIR/$RECIPE $SHAREDDIR/build-strongswanlog_action "Installing from recipe $RECIPE"execute_chroot "make SRCDIR=/root/strongswan BUILDDIR=/root/shared/build-strongswan -f /root/shared/build-strongswan/$RECIPE"# rebuild the guest images after we modified the root imageif [ -z "$2" ]; then	# cleanup before mounting guest images	on_exit	# building the guest images without certificates fails on winnetou	if [ ! -f "$DIR/../hosts/winnetou/etc/ca/strongswanCert.pem" ]; then		# this also re-builds the guest images		$DIR/build-certs	else		$DIR/build-guestimages	fifi
 |