Skip to content

Instantly share code, notes, and snippets.

@wolfeidau
Last active August 29, 2015 13:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wolfeidau/9998554 to your computer and use it in GitHub Desktop.
Save wolfeidau/9998554 to your computer and use it in GitHub Desktop.
Digital Ocean clean image
#!/bin/bash
#+----------------------------------------------------------------------------------------+
#| This file is used to clean up traces from DigitalOcean *images* before being published.|
#+----------------------------------------------------------------------------------------+
unset HISTFILE
files=(/root/.mysql_history /var/log/lastlog /root/.bash_history /var/log/wtmp /var/log/auth.log /var/log/messages)
for file in ${files[*]}
do
if [[ -f "$file" ]]
then
printf "\t%s\n" $file
cat /dev/null > $file
fi
done
rm -f /var/log/messages.*
rm -f /var/log/*.gz
if [ -f /etc/debian_version ]
then
DEBIAN_FRONTEND=noninteractive
apt-get autoremove -y
apt-get clean -y
fi
printf "\tPowering off.\n"
history -w
history -r
history -c
history -w && poweroff || poweroff

Probaly should have run unset HISTFILE and history -c in the current shell when setting up the image.

root@www:~# history
    1  clear
    2  ls
    3  clear
    4  wget https://kmlnsr.me/cleanimage.sh
    5  rm cleanimage.sh
    6  cd /tmp/
    7  wget https://kmlnsr.me/cleanimage.sh
    8  chmod +x cleanimage.sh
    9  ./cleanimage.sh
   10  cat /etc/issue
   11  vi /etc/rc.local
   12  rm /etc/ssh/ssh_host*
   13  reboot
   14  poweroff
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment