build openssl-fips in KVM root-image
[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
11 check_commands debootstrap mkfs.ext3 partprobe qemu-img qemu-nbd sfdisk
12
13 # package includes/excludes
14 INC=build-essential,gperf,libgmp-dev,libldap2-dev,libcurl4-openssl-dev,ethtool
15 INC=$INC,libxml2-dev,libtspi-dev,libsqlite3-dev,openssh-server,tcpdump,psmisc
16 INC=$INC,openssl,vim,sqlite3,conntrack,gdb,cmake,libxerces-c2-dev,libltdl-dev
17 INC=$INC,liblog4cxx10-dev,libboost-thread-dev,libboost-system-dev,git-core
18 INC=$INC,less,acpid,acpi-support-base,libldns-dev,libunbound-dev,dnsutils,screen
19 INC=$INC,gnat,gprbuild,libahven3-dev,libxmlada4.1-dev,libgmpada3-dev
20 INC=$INC,libalog0.4.1-base-dev,hostapd,libsoup2.4-dev
21 SERVICES="apache2 dbus isc-dhcp-server slapd bind9"
22 INC=$INC,${SERVICES// /,}
23
24 CACHEDIR=$BUILDDIR/cache
25 APTCACHE=$LOOPDIR/var/cache/apt/archives
26
27 mkdir -p $LOOPDIR
28 mkdir -p $CACHEDIR
29 mkdir -p $IMGDIR
30 rm -f $BASEIMG
31
32 echo "`date`, building $BASEIMG" >>$LOGFILE
33
34 load_qemu_nbd
35
36 log_action "Creating base image $BASEIMG"
37 execute "qemu-img create -f $IMGEXT $BASEIMG ${BASEIMGSIZE}M"
38
39 log_action "Connecting image to NBD device $NBDEV"
40 execute "qemu-nbd -c $NBDEV $BASEIMG"
41 do_on_exit qemu-nbd -d $NBDEV
42
43 log_action "Partitioning disk"
44 sfdisk /dev/nbd0 -D -uM >>$LOGFILE 2>&1 << EOF
45 ;
46 EOF
47 if [ $? != 0 ]
48 then
49         log_status 1
50         exit 1
51 else
52         log_status 0
53 fi
54 partprobe $NBDEV
55
56 log_action "Creating ext3 filesystem"
57 execute "mkfs.ext3 $NBDPARTITION"
58
59 log_action "Mounting $NBDPARTITION to $LOOPDIR"
60 execute "mount $NBDPARTITION $LOOPDIR"
61 do_on_exit graceful_umount $LOOPDIR
62
63 log_action "Using $CACHEDIR as archive for apt"
64 mkdir -p $APTCACHE
65 execute "mount -o bind $CACHEDIR $APTCACHE"
66 do_on_exit graceful_umount $APTCACHE
67
68 log_action "Running debootstrap ($BASEIMGSUITE, $BASEIMGARCH)"
69 execute "debootstrap --arch=$BASEIMGARCH --include=$INC $BASEIMGSUITE $LOOPDIR $BASEIMGMIRROR"
70
71 execute "mount -t proc none $LOOPDIR/proc"
72 do_on_exit graceful_umount $LOOPDIR/proc
73
74 for service in $SERVICES
75 do
76         log_action "Stopping service $service"
77         execute_chroot "/etc/init.d/$service stop"
78         log_action "Disabling service $service"
79         execute_chroot "update-rc.d -f $service remove"
80 done
81
82 log_action "Disabling root password"
83 execute_chroot "passwd -d root"