aboutsummaryrefslogtreecommitdiffstats
path: root/testing/scripts/build-baseimage
blob: 7e380f80cf85ce547267a25ecb741df5a1cfa433 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/bin/bash

if [ `id -u` != 0 ];
then
	echo "! you must be root to run $0"
	exit
fi

DIR=`dirname $0`

. $DIR/function.sh

[ -f $DIR/../testing.conf ] || die "!! Configuration file 'testing.conf' not found"
. $DIR/../testing.conf

# execute command
# $1 - command to execute
# $2 - whether or not to log command exit status
#      (0 -> disable exit status logging)
execute()
{
	cmd=${1}
	echo $cmd >>$LOGFILE
	$cmd >>$LOGFILE 2>&1
	status=$?
	[ "$2" != 0 ] && log_status $status
	if [ $status != 0 ]; then
		echo "! command $cmd failed, exiting (status $status)"
		echo "! check why here $LOGFILE"
		exit 1
	fi
}

# execute command in chroot
# $1 - command to execute
execute_chroot()
{
	execute "chroot $LOOPDIR $@"
}

# additional packages
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
SERVICES="isc-dhcp-server apache2 slapd"
PACKAGES=$EXTRAS,${SERVICES// /,}
CACHEDIR=$BUILDDIR/cache
APTCACHE=$LOOPDIR/var/cache/apt/archives

mkdir -p $LOOPDIR
mkdir -p $BUILDDIR
mkdir -p $CACHEDIR
rm -f $ROOTFS

echo "`date`, building $ROOTFS" >>$LOGFILE
echo "Building base image"
log_action "Creating image $ROOTFS"
execute "dd if=/dev/null of=$ROOTFS bs=1M seek=$ROOTFSSIZE count=1"

log_action "Creating ext3 filesystem"
execute "mkfs.ext3 -F $ROOTFS"

log_action "Mounting image to $LOOPDIR"
execute "mount -o loop $ROOTFS $LOOPDIR"

log_action "Mounting cache to $CACHEDIR"
mkdir -p $APTCACHE
execute "mount -o bind $CACHEDIR $APTCACHE"

log_action "Running debootstrap ($ROOTFSSUITE, $ROOTFSARCH)"
execute "debootstrap --arch=$ROOTFSARCH --include=$PACKAGES $ROOTFSSUITE $LOOPDIR $ROOTFSMIRROR"

log_action "Disabling root password"
execute_chroot "passwd -d root"

for service in $SERVICES
do
	log_action "Stopping service $service"
	execute_chroot "/etc/init.d/$service stop"
	log_action "Disabling service $service"
	execute_chroot "update-rc.d -f $service remove"
done

execute "umount -l $APTCACHE" 0
execute "umount -l $LOOPDIR" 0