]> git.ipfire.org Git - thirdparty/strongswan.git/blame - testing/scripts/build-rootimage
testing: Only attempt to copy patches if there are any
[thirdparty/strongswan.git] / testing / scripts / build-rootimage
CommitLineData
997358a6 1#!/bin/bash
8ed98c13 2# Create guest root image
997358a6
MW
3#
4# Copyright (C) 2004 Eric Marchionni, Patrik Rayo
5# Zuercher Hochschule Winterthur
6#
7# This program is free software; you can redistribute it and/or modify it
8# under the terms of the GNU General Public License as published by the
9# Free Software Foundation; either version 2 of the License, or (at your
10# option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
11#
12# This program is distributed in the hope that it will be useful, but
13# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15# for more details.
997358a6 16
bf3ff0e5 17echo "Building root image"
997358a6 18
aafc0a17
RB
19DIR=$(dirname `readlink -f $0`)
20. $DIR/../testing.conf
21. $DIR/function.sh
997358a6 22
bf3ff0e5 23[ `id -u` -eq 0 ] || die "You must be root to run $0"
258cbd40 24[ -f "$BASEIMG" ] || die "Base image $BASEIMG not found"
83efded3 25running_any $STRONGSWANHOSTS && die "Please stop test environment before running $0"
997358a6 26
cbe031d7 27check_commands partprobe qemu-img qemu-nbd
b24d3ed5 28
8ed98c13
RB
29load_qemu_nbd
30
bf3ff0e5 31mkdir -p $LOOPDIR
2c4954ad 32mkdir -p $SHAREDDIR/compile
48ea1d8b 33mkdir -p $IMGDIR
997358a6 34
258cbd40 35log_action "Creating root image $ROOTIMG"
cbe031d7 36execute "qemu-img create -b $BASEIMG -f $IMGEXT $ROOTIMG"
bf3ff0e5 37
258cbd40
RB
38log_action "Connecting root image to NBD device $NBDEV"
39execute "qemu-nbd -c $NBDEV $ROOTIMG"
74c0839a 40do_on_exit qemu-nbd -d $NBDEV
97265aba 41partprobe $NBDEV
8ed98c13
RB
42
43log_action "Mounting $NBDPARTITION to $LOOPDIR"
44execute "mount $NBDPARTITION $LOOPDIR"
74c0839a 45do_on_exit umount $LOOPDIR
8ed98c13 46
bf3ff0e5
RB
47log_action "Mounting proc filesystem to $LOOPDIR/proc"
48execute "mount -t proc none $LOOPDIR/proc"
74c0839a 49do_on_exit umount $LOOPDIR/proc
997358a6 50
2c4954ad
RB
51mkdir -p $LOOPDIR/root/shared
52log_action "Mounting $SHAREDDIR as /root/shared"
53execute "mount -o bind $SHAREDDIR $LOOPDIR/root/shared"
54do_on_exit umount $LOOPDIR/root/shared
0cc40637 55
bf3ff0e5 56echo "Installing software from source"
aafc0a17 57RECPDIR=$DIR/recipes
99f6457e
TB
58if [ -d "$RECPDIR/patches" ]
59then
60 execute "cp -r $RECPDIR/patches $LOOPDIR/root/shared/compile" 0
61fi
e61ce6ee
RB
62RECIPES=`ls $RECPDIR/*.mk | xargs -n1 basename`
63for r in $RECIPES
64do
2c4954ad 65 cp $RECPDIR/$r ${LOOPDIR}/root/shared/compile
bf3ff0e5 66 log_action "Installing from recipe $r"
2c4954ad 67 execute_chroot "make SWANVERSION=$SWANVERSION -C /root/shared/compile -f $r"
e61ce6ee 68done
997358a6 69
bf3ff0e5
RB
70log_action "Removing /etc/resolv.conf"
71execute "rm -f $LOOPDIR/etc/resolv.conf"