#!/bin/sh

set -e
export DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true

# Reset grub configuration
echo "Setting install device to $( grub-mkdevicemap -m - | head -n 1 | awk '{ print $2 }' )"
echo "debconf grub-pc/install_devices string $( grub-mkdevicemap -m - | head -n 1 | awk '{ print $2 }' )"  | debconf-set-selections

# Prevent "suggested" packages from being installed automatically
echo 'APT::Install-Suggests "0";' > /etc/apt/apt.conf.d/05disable-suggests

# Remove various useless packages
apt-get remove -y memcached postfix postfix-cdb

# Full system update
apt-get update -y
apt-get dist-upgrade -uy
apt-get clean
apt-get autoremove -y

# Install Ansible requirements
apt-get install -y python3-venv python-is-python3

# Create a directory for the provisioning playbook
[ -d /var/cache/provision ] || mkdir -p /var/cache/provision
chown -R vagrant:vagrant /var/cache/provision