]>
Commit | Line | Data |
---|---|---|
82136aa2 TB |
1 | #!/bin/bash |
2 | ||
82136aa2 TB |
3 | DIR=$(dirname `readlink -f $0`) |
4 | . $DIR/../testing.conf | |
5 | . $DIR/function.sh | |
6 | ||
7 | SWANDIR=${1:+$(readlink -f $1)} | |
8 | : ${SWANDIR:=$(readlink -f $DIR/../..)} | |
9 | ||
10 | [ `id -u` -eq 0 ] || die "You must be root to run $0" | |
11 | [ -f "$BASEIMG" ] || die "Base image $BASEIMG not found" | |
12 | [ -f "$ROOTIMG" ] || die "Root image $ROOTIMG not found" | |
83efded3 | 13 | running_any $STRONGSWANHOSTS && die "Please stop test environment before running $0" |
82136aa2 TB |
14 | |
15 | [ -f $SWANDIR/src/libstrongswan/asn1/oid.txt ] || die "strongSwan not found in $SWANDIR" | |
16 | ||
17 | SRCUID=${SUDO_UID:-$(id -u)} | |
18 | SRCGID=${SUDO_GID:-$(id -g)} | |
19 | ||
20 | check_commands partprobe qemu-img qemu-nbd bindfs | |
21 | ||
22 | load_qemu_nbd | |
23 | ||
24 | mkdir -p $LOOPDIR | |
25 | mkdir -p $IMGDIR | |
26 | ||
75214fab TB |
27 | case "$2" in |
28 | "") | |
29 | log_action "Connecting root image to NBD device $NBDEV" | |
30 | execute "qemu-nbd -c $NBDEV $ROOTIMG" | |
31 | ;; | |
32 | *) | |
33 | echo $STRONGSWANHOSTS | grep -q "\b$2\b" || die "Guest $2 not found" | |
34 | GUESTIMG="$IMGDIR/$2.$IMGEXT" | |
35 | [ -f "$GUESTIMG" ] || die "Guest image $GUESTIMG not found" | |
36 | log_action "Connecting guest image to NBD device $NBDEV" | |
37 | execute "qemu-nbd -c $NBDEV $GUESTIMG" | |
38 | ;; | |
39 | esac | |
40 | ||
82136aa2 TB |
41 | do_on_exit qemu-nbd -d $NBDEV |
42 | partprobe $NBDEV | |
43 | ||
44 | log_action "Mounting $NBDPARTITION to $LOOPDIR" | |
45 | execute "mount $NBDPARTITION $LOOPDIR" | |
46 | do_on_exit umount $LOOPDIR | |
47 | ||
48 | log_action "Mounting proc filesystem to $LOOPDIR/proc" | |
49 | execute "mount -t proc none $LOOPDIR/proc" | |
50 | do_on_exit umount $LOOPDIR/proc | |
51 | ||
52 | mkdir -p $LOOPDIR/root/shared | |
53 | log_action "Mounting $SHAREDDIR as /root/shared" | |
54 | execute "mount -o bind $SHAREDDIR $LOOPDIR/root/shared" | |
55 | do_on_exit umount $LOOPDIR/root/shared | |
56 | ||
57 | mkdir -p $LOOPDIR/root/strongswan | |
58 | log_action "Mounting $SWANDIR as /root/strongswan" | |
59 | execute "bindfs -u $SRCUID -g $SRCGID $SWANDIR $LOOPDIR/root/strongswan" | |
60 | do_on_exit umount $LOOPDIR/root/strongswan | |
61 | ||
f7234e5e | 62 | log_action "Remove SWID tags of previous versions" |
936db031 | 63 | execute_chroot "find /usr/local/share -path '*strongswan*' -name *.swidtag -delete" |
f7234e5e | 64 | |
82136aa2 | 65 | echo "Building and installing strongSwan" |
aee35392 TB |
66 | |
67 | log_action "Determine strongSwan version" | |
68 | desc=`git -C $SWANDIR describe --dirty` | |
69 | if [ $? -eq 0 ]; then | |
70 | SWANVERSION="$desc (`git -C $SWANDIR rev-parse --abbrev-ref HEAD`)" | |
71 | else | |
72 | SWANVERSION="`cat $SWANDIR/configure.ac | sed -n '/^AC_INIT/{ s/.*,\[\(.*\)\])$/\1/p }'`" | |
73 | fi | |
74 | echo "$SWANVERSION" > $SHAREDDIR/.strongswan-version | |
75 | log_status 0 | |
76 | ||
82136aa2 TB |
77 | log_action "Preparing source tree" |
78 | execute_chroot 'autoreconf -i /root/strongswan' | |
79 | ||
80 | RECPDIR=$DIR/recipes | |
81 | RECIPE=`ls $RECPDIR/*strongswan.mk | xargs -n1 basename` | |
82 | mkdir -p $SHAREDDIR/build-strongswan | |
83 | cp $RECPDIR/$RECIPE $SHAREDDIR/build-strongswan | |
84 | log_action "Installing from recipe $RECIPE" | |
85 | execute_chroot "make SRCDIR=/root/strongswan BUILDDIR=/root/shared/build-strongswan -f /root/shared/build-strongswan/$RECIPE" | |
86 | ||
75214fab TB |
87 | # requild the guest images if we modified the root image |
88 | if [ -z "$2" ]; then | |
89 | # cleanup before mounting guest images | |
90 | on_exit | |
91 | $DIR/build-guestimages | |
92 | fi |