Annotation of embedaddon/strongswan/testing/scripts/build-baseimage, revision 1.1.1.1
1.1 misho 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,locales
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
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,traceroute
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 freeradius"
38: INC=$INC,${SERVICES// /,}
39: # packages to install via APT, for SWIMA tests
40: APT="tmux"
41: # additional services to disable
42: SERVICES="$SERVICES systemd-timesyncd.service"
43:
44: CACHEDIR=$BUILDDIR/cache
45: APTCACHE=$LOOPDIR/var/cache/apt/archives
46:
47: mkdir -p $LOOPDIR
48: mkdir -p $CACHEDIR
49: mkdir -p $IMGDIR
50: rm -f $BASEIMG
51:
52: echo "`date`, building $BASEIMG" >>$LOGFILE
53:
54: load_qemu_nbd
55:
56: log_action "Creating base image $BASEIMG"
57: execute "qemu-img create -f $IMGEXT $BASEIMG ${BASEIMGSIZE}M"
58:
59: log_action "Connecting image to NBD device $NBDEV"
60: execute "qemu-nbd -c $NBDEV $BASEIMG"
61: do_on_exit qemu-nbd -d $NBDEV
62:
63: log_action "Partitioning disk"
64: sfdisk /dev/nbd0 >>$LOGFILE 2>&1 << EOF
65: ;
66: EOF
67: if [ $? != 0 ]
68: then
69: log_status 1
70: exit 1
71: else
72: log_status 0
73: fi
74: partprobe $NBDEV
75:
76: log_action "Creating ext3 filesystem"
77: execute "mkfs.ext3 $NBDPARTITION"
78:
79: log_action "Mounting $NBDPARTITION to $LOOPDIR"
80: execute "mount $NBDPARTITION $LOOPDIR"
81: do_on_exit graceful_umount $LOOPDIR
82:
83: log_action "Using $CACHEDIR as archive for apt"
84: mkdir -p $APTCACHE
85: execute "mount -o bind $CACHEDIR $APTCACHE"
86: do_on_exit graceful_umount $APTCACHE
87:
88: log_action "Running debootstrap ($BASEIMGSUITE, $BASEIMGARCH)"
89: execute "debootstrap --arch=$BASEIMGARCH --include=$INC $BASEIMGSUITE $LOOPDIR $BASEIMGMIRROR"
90:
91: execute "mount -t proc none $LOOPDIR/proc" 0
92: do_on_exit graceful_umount $LOOPDIR/proc
93:
94: log_action "Generating locales"
95: cat > $LOOPDIR/etc/locale.gen << EOF
96: de_CH.UTF-8 UTF-8
97: en_US.UTF-8 UTF-8
98: EOF
99: execute_chroot "locale-gen"
100:
101: log_action "Downloading signing key for custom apt repo"
102: execute_chroot "wget -q $BASEIMGEXTKEY -O /tmp/key"
103: log_action "Installing signing key for custom apt repo"
104: execute_chroot "apt-key add /tmp/key"
105:
106: log_action "Enabling custom apt repo"
107: cat > $LOOPDIR/etc/apt/sources.list.d/strongswan.list << EOF
108: deb $BASEIMGEXTREPO $BASEIMGSUITE main
109: EOF
110: log_status $?
111:
112: log_action "Prioritize custom apt repo"
113: cat > $LOOPDIR/etc/apt/preferences.d/strongswan.pref << EOF
114: Package: *
115: Pin: origin "$BASEIMGEXTREPOHOST"
116: Pin-Priority: 1001
117: EOF
118: log_status $?
119:
120: log_action "Update package sources"
121: execute_chroot "apt-get update"
122: log_action "Install packages via APT"
123: execute_chroot "apt-get -y install $APT"
124: log_action "Install packages from custom repo"
125: execute_chroot "apt-get -y upgrade"
126:
127: for service in $SERVICES
128: do
129: log_action "Disabling service $service"
130: execute_chroot "systemctl disable $service"
131: done
132:
133: log_action "Disabling root password"
134: execute_chroot "passwd -d root"
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>