#!/bin/sh
# cloud-setup-vm is part of autopkgtest
# autopkgtest is a tool for testing Debian binary packages
#
# autopkgtest is Copyright (C) 2006-2015 Canonical Ltd.
#
# --setup-commands script for cloud instances to prepare them for running
# autopkgtests. This is similar to adt-setup-vm, but won't configure serial
# console or networking.

# go-faster apt/dpkg
echo "Acquire::Languages \"none\";" > /etc/apt/apt.conf.d/90nolanguages
echo 'force-unsafe-io' > /etc/dpkg/dpkg.cfg.d/autopkgtest

# some tests use a lot of /dev/random, avoid hangs
EXTRA_PKGS="haveged"

# provides kmods like scsi_debug or mac80211_hwsim on Ubuntu
if grep -q buntu /etc/os-release /etc/lsb-release; then
    EXTRA_PKGS="$EXTRA_PKGS linux-generic"
fi
apt-get install -y $EXTRA_PKGS

# clean up some unnecessary packages
for p in accountsservice apt-xapian-index cryptsetup landscape-client \
    landscape-common open-vm-tools w3m vim-runtime aptitude-common \
    command-not-found-data manpages ntfs-3g sosreport \
    ubuntu-release-upgrader-core cloud-init libcpan-changes-perl git \
    cgmanager lxd-client; do
    apt-get --auto-remove -y purge $p || true
done

# bump vmalloc on i386, necessary for tests like udisks2
if [ $(dpkg --print-architecture) = i386 ]; then
    if [ -d /etc/default/grub.d ]; then
        sed -i '/CMDLINE_LINUX_DEFAULT/ s/"$/ vmalloc=512M"/' /etc/default/grub.d/*.cfg
    else
        # fallback for Ubuntu 12.04
        sed -i '/CMDLINE_LINUX_DEFAULT/ s/"$/ vmalloc=512M"/' /etc/default/grub
    fi
    update-grub
fi
