#!/bin/bash

# Remove created files
rm -rf /var/opt/opendof/dof-router-on-aws/db
rm -f /etc/opt/opendof/dof-router-on-aws/*
rm -f /var/opt/opendof/dof-router-on-aws/web/private/[a-z]*
rm -f /var/opt/opendof/dof-router-on-aws/web/public/itunes.png /var/opt/opendof/dof-router-on-aws/web/public/play.png

# Only remove the configuration file if the template is still present.
if [ -e /var/opt/opendof/dof-router-on-aws/web/config.js-template ]; then
  rm -f /var/opt/opendof/dof-router-on-aws/web/config.js
fi

# Shutdown logging and remove logs. Nothing in logs should need to be securely deleted.
/etc/init.d/rsyslog stop
find /var/log -type f -delete

# Remove security-related files, which should be removed securely. Disable login.
passwd -l root
shred -u ~ec2-user/.ssh/authorized_keys
shred -u ~/.ssh/authorized_keys
shred -u /etc/ssh/*_key /etc/ssh/*_key.pub
shred -u ~ec2-user/.*history
shred -u ~/.*history

# Clear the history (preventing writing it to disk) and shutdown
history -c && shutdown -h now
