]> git.ipfire.org Git - thirdparty/strongswan.git/blob - testing/scripts/build-baseimage
testing: Support build with Debian stretch base image
[thirdparty/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,less
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,libltdl-dev,liblog4cxx10-dev
19 INC=$INC,libboost-thread-dev,libboost-system-dev,git-core,iperf,htop,screen
20 INC=$INC,gnat,gprbuild,acpid,acpi-support-base,libldns-dev,libunbound-dev
21 INC=$INC,dnsutils,libsoup2.4-dev,ca-certificates,unzip,libsystemd-dev
22 INC=$INC,python,python-setuptools,python-dev,python-pip,apt-transport-https
23 INC=$INC,libjson-c-dev,libxslt1-dev,libapache2-mod-wsgi,iptables-dev
24 INC=$INC,libxerces-c-dev,libgcrypt20-dev
25 case "$BASEIMGSUITE" in
26 jessie)
27 INC=$INC,libahven4-dev,libxmlada5-dev,libgmpada5-dev
28 INC=$INC,libalog1-dev
29 ;;
30 stretch)
31 INC=$INC,libahven5-dev,libxmlada-schema6-dev,libgmpada6-dev
32 INC=$INC,libalog2-dev
33 ;;
34 *)
35 echo_warn "Package list for '$BASEIMGSUITE' might has to be updated"
36 esac
37 SERVICES="apache2 dbus isc-dhcp-server slapd bind9"
38 INC=$INC,${SERVICES// /,}
39
40 CACHEDIR=$BUILDDIR/cache
41 APTCACHE=$LOOPDIR/var/cache/apt/archives
42
43 mkdir -p $LOOPDIR
44 mkdir -p $CACHEDIR
45 mkdir -p $IMGDIR
46 rm -f $BASEIMG
47
48 echo "`date`, building $BASEIMG" >>$LOGFILE
49
50 load_qemu_nbd
51
52 log_action "Creating base image $BASEIMG"
53 execute "qemu-img create -f $IMGEXT $BASEIMG ${BASEIMGSIZE}M"
54
55 log_action "Connecting image to NBD device $NBDEV"
56 execute "qemu-nbd -c $NBDEV $BASEIMG"
57 do_on_exit qemu-nbd -d $NBDEV
58
59 log_action "Partitioning disk"
60 sfdisk /dev/nbd0 >>$LOGFILE 2>&1 << EOF
61 ;
62 EOF
63 if [ $? != 0 ]
64 then
65 log_status 1
66 exit 1
67 else
68 log_status 0
69 fi
70 partprobe $NBDEV
71
72 log_action "Creating ext3 filesystem"
73 execute "mkfs.ext3 $NBDPARTITION"
74
75 log_action "Mounting $NBDPARTITION to $LOOPDIR"
76 execute "mount $NBDPARTITION $LOOPDIR"
77 do_on_exit graceful_umount $LOOPDIR
78
79 log_action "Using $CACHEDIR as archive for apt"
80 mkdir -p $APTCACHE
81 execute "mount -o bind $CACHEDIR $APTCACHE"
82 do_on_exit graceful_umount $APTCACHE
83
84 log_action "Running debootstrap ($BASEIMGSUITE, $BASEIMGARCH)"
85 execute "debootstrap --arch=$BASEIMGARCH --include=$INC $BASEIMGSUITE $LOOPDIR $BASEIMGMIRROR"
86
87 execute "mount -t proc none $LOOPDIR/proc" 0
88 do_on_exit graceful_umount $LOOPDIR/proc
89
90 log_action "Downloading signing key for custom apt repo"
91 execute_chroot "wget -q $BASEIMGEXTKEY -O /tmp/key"
92 log_action "Installing signing key for custom apt repo"
93 execute_chroot "apt-key add /tmp/key"
94
95 log_action "Enabling custom apt repo"
96 cat > $LOOPDIR/etc/apt/sources.list.d/strongswan.list << EOF
97 deb $BASEIMGEXTREPO $BASEIMGSUITE main
98 EOF
99 log_status $?
100
101 log_action "Prioritize custom apt repo"
102 cat > $LOOPDIR/etc/apt/preferences.d/strongswan.pref << EOF
103 Package: *
104 Pin: origin "$BASEIMGEXTREPOHOST"
105 Pin-Priority: 1001
106 EOF
107 log_status $?
108
109 log_action "Update package sources"
110 execute_chroot "apt-get update"
111 log_action "Install packages from custom repo"
112 execute_chroot "apt-get -y upgrade"
113
114 for service in $SERVICES
115 do
116 log_action "Disabling service $service"
117 execute_chroot "systemctl disable $service"
118 done
119
120 log_action "Disabling root password"
121 execute_chroot "passwd -d root"