#!/bin/bash

# run this as:
# history -c && ./cleanvm.sh

sudo apt-get -qq update
sudo apt-get -y dist-upgrade
sudo apt-get -y purge --auto-remove
sudo apt-get --purge remove
sudo apt-get clean

sudo rm /etc/udev/rules.d/70-persistent-net.rules
sudo rm -rf /root/.ssh
sudo rm /root/.bash_history
sudo touch /root/.bash_history

if [ -e /usr/local/bety ]; then
  sudo rm /usr/local/bety/log/*.log
  sudo touch /usr/local/bety/log/production.log
  sudo touch /usr/local/bety/log/development.log
  sudo chmod 0666 /usr/local/bety/log/production.log

  if [ -e /var/log/mysql ]; then
    mysql -u bety -pbety bety -e 'delete from runs'
  fi
  if [ -e /var/log/postgresql ]; then
    psql -U bety bety -c 'delete from runs'
  fi
fi

sudo find /var/log -type f -exec rm {} \;
sudo touch /var/log/wtmp /var/log/btmp
sudo chown root.utmp /var/log/wtmp /var/log/btmp

sudo rm /etc/ssh/ssh_host*key*

history -c

rm ${HOME}/testrun.ed.r*/history.xml ${HOME}/testrun.ed.r*/analysis*.h5
rm ${HOME}/testrun.sipnet/niwot_tutorial.out
rm -rf ${HOME}/testrun.pecan/pecan
rm -rf ${HOME}/dump

rm -rf ${HOME}/{.cache,.bash_history,.bzr.log,.mysql_history,.psql_history,.sudo_as_admin_successful,.viminfo}

rm -f ${HOME}/.ssh/known_hosts
touch ${HOME}/.bash_history

sudo shutdown -h now

