Annotation of embedaddon/strongswan/testing/scripts/build-baseimage, revision 1.1.1.2

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
1.1.1.2 ! misho      18: INC=$INC,openssl,vim,sqlite3,conntrack,gdb,cmake,libltdl-dev,wget,gnupg,man-db
        !            19: INC=$INC,libboost-thread-dev,libboost-system-dev,git,iperf,htop,valgrind,strace
1.1       misho      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:        ;;
1.1.1.2 ! misho      34: buster)
        !            35:        INC=$INC,libahven7-dev,libxmlada-schema8-dev,libgmpada8-dev
        !            36:        INC=$INC,libalog4-dev,dbus-user-session
        !            37:        ;;
1.1       misho      38: *)
                     39:        echo_warn "Package list for '$BASEIMGSUITE' might has to be updated"
1.1.1.2 ! misho      40:        ;;
1.1       misho      41: esac
                     42: SERVICES="apache2 dbus isc-dhcp-server slapd bind9 freeradius"
                     43: INC=$INC,${SERVICES// /,}
                     44: # packages to install via APT, for SWIMA tests
                     45: APT="tmux"
                     46: # additional services to disable
                     47: SERVICES="$SERVICES systemd-timesyncd.service"
                     48: 
                     49: CACHEDIR=$BUILDDIR/cache
                     50: APTCACHE=$LOOPDIR/var/cache/apt/archives
                     51: 
                     52: mkdir -p $LOOPDIR
                     53: mkdir -p $CACHEDIR
                     54: mkdir -p $IMGDIR
                     55: rm -f $BASEIMG
                     56: 
                     57: echo "`date`, building $BASEIMG" >>$LOGFILE
                     58: 
                     59: load_qemu_nbd
                     60: 
                     61: log_action "Creating base image $BASEIMG"
                     62: execute "qemu-img create -f $IMGEXT $BASEIMG ${BASEIMGSIZE}M"
                     63: 
                     64: log_action "Connecting image to NBD device $NBDEV"
                     65: execute "qemu-nbd -c $NBDEV $BASEIMG"
                     66: do_on_exit qemu-nbd -d $NBDEV
                     67: 
                     68: log_action "Partitioning disk"
                     69: sfdisk /dev/nbd0 >>$LOGFILE 2>&1 << EOF
                     70: ;
                     71: EOF
                     72: if [ $? != 0 ]
                     73: then
                     74:        log_status 1
                     75:        exit 1
                     76: else
                     77:        log_status 0
                     78: fi
                     79: partprobe $NBDEV
                     80: 
                     81: log_action "Creating ext3 filesystem"
                     82: execute "mkfs.ext3 $NBDPARTITION"
                     83: 
                     84: log_action "Mounting $NBDPARTITION to $LOOPDIR"
                     85: execute "mount $NBDPARTITION $LOOPDIR"
                     86: do_on_exit graceful_umount $LOOPDIR
                     87: 
                     88: log_action "Using $CACHEDIR as archive for apt"
                     89: mkdir -p $APTCACHE
                     90: execute "mount -o bind $CACHEDIR $APTCACHE"
                     91: do_on_exit graceful_umount $APTCACHE
                     92: 
                     93: log_action "Running debootstrap ($BASEIMGSUITE, $BASEIMGARCH)"
                     94: execute "debootstrap --arch=$BASEIMGARCH --include=$INC $BASEIMGSUITE $LOOPDIR $BASEIMGMIRROR"
                     95: 
                     96: execute "mount -t proc none $LOOPDIR/proc" 0
                     97: do_on_exit graceful_umount $LOOPDIR/proc
                     98: 
                     99: log_action "Generating locales"
                    100: cat > $LOOPDIR/etc/locale.gen << EOF
                    101: de_CH.UTF-8 UTF-8
                    102: en_US.UTF-8 UTF-8
                    103: EOF
                    104: execute_chroot "locale-gen"
                    105: 
                    106: log_action "Downloading signing key for custom apt repo"
                    107: execute_chroot "wget -q $BASEIMGEXTKEY -O /tmp/key"
                    108: log_action "Installing signing key for custom apt repo"
                    109: execute_chroot "apt-key add /tmp/key"
                    110: 
                    111: log_action "Enabling custom apt repo"
                    112: cat > $LOOPDIR/etc/apt/sources.list.d/strongswan.list << EOF
                    113: deb $BASEIMGEXTREPO $BASEIMGSUITE main
                    114: EOF
                    115: log_status $?
                    116: 
                    117: log_action "Prioritize custom apt repo"
                    118: cat > $LOOPDIR/etc/apt/preferences.d/strongswan.pref << EOF
                    119: Package: *
                    120: Pin: origin "$BASEIMGEXTREPOHOST"
                    121: Pin-Priority: 1001
                    122: EOF
                    123: log_status $?
                    124: 
                    125: log_action "Update package sources"
                    126: execute_chroot "apt-get update"
                    127: log_action "Install packages via APT"
                    128: execute_chroot "apt-get -y install $APT"
                    129: log_action "Install packages from custom repo"
                    130: execute_chroot "apt-get -y upgrade"
                    131: 
                    132: for service in $SERVICES
                    133: do
                    134:        log_action "Disabling service $service"
                    135:        execute_chroot "systemctl disable $service"
                    136: done
                    137: 
1.1.1.2 ! misho     138: case "$BASEIMGSUITE" in
        !           139: buster)
        !           140:        log_action "Switching from iptables-nft to iptables-legacy"
        !           141:        execute_chroot "update-alternatives --set iptables /usr/sbin/iptables-legacy" 0
        !           142:        execute_chroot "update-alternatives --set ip6tables /usr/sbin/ip6tables-legacy" 0
        !           143:        log_status 0
        !           144:        ;;
        !           145: esac
        !           146: 
1.1       misho     147: log_action "Disabling root password"
                    148: execute_chroot "passwd -d root"

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>