| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 | #!/bin/bash# Create guest root image## Copyright (C) 2004  Eric Marchionni, Patrik Rayo# Zuercher Hochschule Winterthur## This program is free software; you can redistribute it and/or modify it# under the terms of the GNU General Public License as published by the# Free Software Foundation; either version 2 of the License, or (at your# option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.## This program is distributed in the hope that it will be useful, but# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY# or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License# for more details.echo "Building root image"DIR=$(dirname `readlink -f $0`). $DIR/../testing.conf. $DIR/function.sh[ `id -u` -eq 0 ] || die "You must be root to run $0"[ -f "$BASEIMG" ] || die "Base image $BASEIMG not found"running_any $STRONGSWANHOSTS && die "Please stop test environment before running $0"check_commands partprobe qemu-img qemu-nbdload_qemu_nbdmkdir -p $LOOPDIRmkdir -p $SHAREDDIR/compilemkdir -p $IMGDIRlog_action "Creating root image $ROOTIMG"execute "qemu-img create -b $BASEIMG -f $IMGEXT $ROOTIMG"log_action "Connecting root image to NBD device $NBDEV"execute "qemu-nbd -c $NBDEV $ROOTIMG"do_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/sharedecho "Installing software from source"RECPDIR=$DIR/recipesif [ -d "$RECPDIR/patches" ]then	execute "cp -r $RECPDIR/patches $LOOPDIR/root/shared/compile" 0fiRECIPES=`ls $RECPDIR/*.mk | xargs -n1 basename`for r in $RECIPESdo	cp $RECPDIR/$r ${LOOPDIR}/root/shared/compile	log_action "Installing from recipe $r"	execute_chroot "make SWANVERSION=$SWANVERSION -C /root/shared/compile -f $r"donelog_action "Removing /etc/resolv.conf"execute "rm -f $LOOPDIR/etc/resolv.conf"
 |