#!/usr/bin/env bash

export DEBIAN_FRONTEND=noninteractive
export UCF_FORCE_CONFFNEW=1
export APT="DEBIAN_FRONTEND=noninteractive apt-get -y -q -o Dpkg::Options::=--force-confnew"

sudo $APT autoremove --purge

sudo $APT --auto-remove purge \
  awscli \
  gcc-6-base \
  initscripts \
  insserv \
  linux-image-4.9.* \
  nano \
  python2 \
  startpar \
  sysv-rc \
  || :

while [ "$(deborphan)" ]; do
  sudo $APT --auto-remove purge $(deborphan)
done

if [ "$(dpkg -l | grep ^rc | awk '{ print $2 }')" ]; then
  dpkg -l | grep ^rc | awk '{ print $2 }' | sudo dpkg -P
fi

exit 0
