Lazy unmount guest filesystem after building image, as it still might be busy
[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
21 SERVICES="apache2 dbus isc-dhcp-server slapd bind9"
22 INC=$INC,${SERVICES// /,}
23 EXC=iptables
24
25 CACHEDIR=$BUILDDIR/cache
26 APTCACHE=$LOOPDIR/var/cache/apt/archives
27
28 mkdir -p $LOOPDIR
29 mkdir -p $CACHEDIR
30 mkdir -p $IMGDIR
31 rm -f $BASEIMG
32
33 echo "`date`, building $BASEIMG" >>$LOGFILE
34
35 load_qemu_nbd
36
37 log_action "Creating base image $BASEIMG"
38 execute "qemu-img create -f $IMGEXT $BASEIMG ${BASEIMGSIZE}M"
39
40 log_action "Connecting image to NBD device $NBDEV"
41 execute "qemu-nbd -c $NBDEV $BASEIMG"
42 do_on_exit qemu-nbd -d $NBDEV
43
44 log_action "Partitioning disk"
45 sfdisk /dev/nbd0 -D -uM >>$LOGFILE 2>&1 << EOF
46 ;
47 EOF
48 if [ $? != 0 ]
49 then
50         log_status 1
51         exit 1
52 else
53         log_status 0
54 fi
55 partprobe $NBDEV
56
57 log_action "Creating ext3 filesystem"
58 execute "mkfs.ext3 $NBDPARTITION"
59
60 log_action "Mounting $NBDPARTITION to $LOOPDIR"
61 execute "mount $NBDPARTITION $LOOPDIR"
62 do_on_exit graceful_umount $LOOPDIR
63
64 log_action "Using $CACHEDIR as archive for apt"
65 mkdir -p $APTCACHE
66 execute "mount -o bind $CACHEDIR $APTCACHE"
67 do_on_exit graceful_umount $APTCACHE
68
69 log_action "Running debootstrap ($BASEIMGSUITE, $BASEIMGARCH)"
70 execute "debootstrap --arch=$BASEIMGARCH --include=$INC --exclude $EXC $BASEIMGSUITE $LOOPDIR $BASEIMGMIRROR"
71
72 execute "mount -t proc none $LOOPDIR/proc"
73 do_on_exit graceful_umount $LOOPDIR/proc
74
75 for service in $SERVICES
76 do
77         log_action "Stopping service $service"
78         execute_chroot "/etc/init.d/$service stop"
79         log_action "Disabling service $service"
80         execute_chroot "update-rc.d -f $service remove"
81 done
82
83 log_action "Disabling root password"
84 execute_chroot "passwd -d root"