testing: Updated all swanctl scenarios and added some new ones
[strongswan.git] / testing / scripts / build-baseimage
1 #!/bin/bash
2
3 echo "Building base image"
4
5 DIR=$(dirname `readlink -f $0`)
6 . $DIR/../testing.conf
7 . $DIR/function.sh
8
9 [ `id -u` -eq 0 ] || die "You must be root to run $0"
10 running_any $STRONGSWANHOSTS && die "Please stop test environment before running $0"
11
12 check_commands debootstrap mkfs.ext3 partprobe qemu-img qemu-nbd sfdisk
13
14 # package includes/excludes
15 INC=automake,autoconf,libtool,bison,flex,gperf,pkg-config,gettext
16 INC=$INC,build-essential,libgmp-dev,libldap2-dev,libcurl4-openssl-dev,ethtool
17 INC=$INC,libxml2-dev,libtspi-dev,libsqlite3-dev,openssh-server,tcpdump,psmisc
18 INC=$INC,openssl,vim,sqlite3,conntrack,gdb,cmake,libxerces-c2-dev,libltdl-dev
19 INC=$INC,liblog4cxx10-dev,libboost-thread-dev,libboost-system-dev,git-core,iperf
20 INC=$INC,less,acpid,acpi-support-base,libldns-dev,libunbound-dev,dnsutils,screen
21 INC=$INC,gnat,gprbuild,libahven3-dev,libxmlada4.1-dev,libgmpada3-dev,htop
22 INC=$INC,libalog0.4.1-base-dev,hostapd,libsoup2.4-dev,ca-certificates,unzip
23 INC=$INC,python,python-setuptools,python-dev,python-pip
24 INC=$INC,libjson0-dev,libxslt1-dev,libapache2-mod-wsgi,iptables-dev
25 SERVICES="apache2 dbus isc-dhcp-server slapd bind9"
26 INC=$INC,${SERVICES// /,}
27
28 CACHEDIR=$BUILDDIR/cache
29 APTCACHE=$LOOPDIR/var/cache/apt/archives
30
31 mkdir -p $LOOPDIR
32 mkdir -p $CACHEDIR
33 mkdir -p $IMGDIR
34 rm -f $BASEIMG
35
36 echo "`date`, building $BASEIMG" >>$LOGFILE
37
38 load_qemu_nbd
39
40 log_action "Creating base image $BASEIMG"
41 execute "qemu-img create -f $IMGEXT $BASEIMG ${BASEIMGSIZE}M"
42
43 log_action "Connecting image to NBD device $NBDEV"
44 execute "qemu-nbd -c $NBDEV $BASEIMG"
45 do_on_exit qemu-nbd -d $NBDEV
46
47 log_action "Partitioning disk"
48 sfdisk /dev/nbd0 -D -uM >>$LOGFILE 2>&1 << EOF
49 ;
50 EOF
51 if [ $? != 0 ]
52 then
53         log_status 1
54         exit 1
55 else
56         log_status 0
57 fi
58 partprobe $NBDEV
59
60 log_action "Creating ext3 filesystem"
61 execute "mkfs.ext3 $NBDPARTITION"
62
63 log_action "Mounting $NBDPARTITION to $LOOPDIR"
64 execute "mount $NBDPARTITION $LOOPDIR"
65 do_on_exit graceful_umount $LOOPDIR
66
67 log_action "Using $CACHEDIR as archive for apt"
68 mkdir -p $APTCACHE
69 execute "mount -o bind $CACHEDIR $APTCACHE"
70 do_on_exit graceful_umount $APTCACHE
71
72 log_action "Running debootstrap ($BASEIMGSUITE, $BASEIMGARCH)"
73 execute "debootstrap --arch=$BASEIMGARCH --include=$INC $BASEIMGSUITE $LOOPDIR $BASEIMGMIRROR"
74
75 execute "mount -t proc none $LOOPDIR/proc" 0
76 do_on_exit graceful_umount $LOOPDIR/proc
77
78 for service in $SERVICES
79 do
80         log_action "Stopping service $service"
81         execute_chroot "/etc/init.d/$service stop"
82         log_action "Disabling service $service"
83         execute_chroot "update-rc.d -f $service remove"
84 done
85
86 log_action "Disabling root password"
87 execute_chroot "passwd -d root"