Use do_on_exit() in build scripts for cleanup
[strongswan.git] / testing / scripts / build-baseimage
1 #!/bin/bash
2
3 echo "Building base image"
4
5 . $PWD/scripts/function.sh
6
7 [ `id -u` -eq 0 ] || die "You must be root to run $0"
8
9 # additional packages
10 EXTRAS=build-essential,gperf,libgmp-dev,libldap2-dev,libcurl4-openssl-dev,libxml2-dev,libtspi-dev,libsqlite3-dev,openssh-server,tcpdump,psmisc,openssl,vim,sqlite3,conntrack,gdb,cmake,libxerces-c2-dev,libltdl-dev,liblog4cxx10-dev,libboost-thread-dev,libboost-system-dev,git-core
11 SERVICES="isc-dhcp-server apache2 slapd"
12 PACKAGES=$EXTRAS,${SERVICES// /,}
13 CACHEDIR=$BUILDDIR/cache
14 APTCACHE=$LOOPDIR/var/cache/apt/archives
15
16 mkdir -p $LOOPDIR
17 mkdir -p $BUILDDIR
18 mkdir -p $CACHEDIR
19 rm -f $ROOTFS
20
21 echo "`date`, building $ROOTFS" >>$LOGFILE
22 log_action "Creating image $ROOTFS"
23 execute "dd if=/dev/null of=$ROOTFS bs=1M seek=$ROOTFSSIZE count=1"
24
25 log_action "Creating ext3 filesystem"
26 execute "mkfs.ext3 -F $ROOTFS"
27
28 log_action "Mounting image to $LOOPDIR"
29 execute "mount -o loop $ROOTFS $LOOPDIR"
30
31 log_action "Mounting cache to $CACHEDIR"
32 mkdir -p $APTCACHE
33 execute "mount -o bind $CACHEDIR $APTCACHE"
34
35 do_on_exit umount -l $APTCACHE
36 do_on_exit umount -l $LOOPDIR
37
38 log_action "Running debootstrap ($ROOTFSSUITE, $ROOTFSARCH)"
39 execute "debootstrap --arch=$ROOTFSARCH --include=$PACKAGES $ROOTFSSUITE $LOOPDIR $ROOTFSMIRROR"
40
41 log_action "Disabling root password"
42 execute_chroot "passwd -d root"
43
44 for service in $SERVICES
45 do
46         log_action "Stopping service $service"
47         execute_chroot "/etc/init.d/$service stop"
48         log_action "Disabling service $service"
49         execute_chroot "update-rc.d -f $service remove"
50 done