| 1 | #!/bin/bash
|
|---|
| 2 | # Run this before you save the image
|
|---|
| 3 | # Version 1.0 Edited by James - 7/28/2014
|
|---|
| 4 |
|
|---|
| 5 | # Fix apt stuff
|
|---|
| 6 | apt-get clean
|
|---|
| 7 | apt-get update
|
|---|
| 8 |
|
|---|
| 9 | # Root user stuff to clean
|
|---|
| 10 | CLEAN_ROOT="/root/.ssh /root/.viminfo /root/.lesshst /root/.bash_history"
|
|---|
| 11 |
|
|---|
| 12 | # Tmp stuff to clean
|
|---|
| 13 | CLEAN_TMP="/tmp/* /var/tmp/"
|
|---|
| 14 |
|
|---|
| 15 | # We do not want documentation on our baselines
|
|---|
| 16 | CLEAN_DOC="/usr/doc/* /usr/share/doc/*"
|
|---|
| 17 |
|
|---|
| 18 | # Udev data to clean. Udev likes keeps interface names persistent accross bootups. We
|
|---|
| 19 | # do not want that behaviour because we move the image to different hardware
|
|---|
| 20 | # so we remove the saved rules and the generator rules
|
|---|
| 21 | CLEAN_UDEV="/etc/udev/rules.d/70-persistent-net.rules"
|
|---|
| 22 |
|
|---|
| 23 | #Dump old logs
|
|---|
| 24 | CLEAN_LOGS="/var/log/*"
|
|---|
| 25 |
|
|---|
| 26 | # Detel all the data we want gone
|
|---|
| 27 | CLEAN="$CLEAN_TMP $CLEAN_DOC $CLEAN_UDEV $CLEAN_ROOT"
|
|---|
| 28 | rm -rf $CLEAN
|
|---|
| 29 |
|
|---|
| 30 | #log clean up fix
|
|---|
| 31 | find /var/log -type f -regex ".*\.gz$" -delete
|
|---|
| 32 | find /var/log -type f -regex ".*\.[0-9]$" -delete
|
|---|
| 33 | find /var/log -type f -exec cp /dev/null {} \;
|
|---|
| 34 |
|
|---|
| 35 | # Old logs
|
|---|
| 36 | rm /etc/hostname
|
|---|
| 37 | history -c
|
|---|
| 38 |
|
|---|
| 39 | #Prevent Udev from makeing persistent rules:
|
|---|
| 40 | ln -s /dev/null /etc/udev/rules.d/70-persistent-net.rules
|
|---|
| 41 |
|
|---|
| 42 | #make sure there are no rogue Name resloutions in /etc/hosts
|
|---|
| 43 | ruby -i.bak -ne 'print if not /node\d-\d.*orbit/' /etc/hosts
|
|---|
| 44 |
|
|---|
| 45 | poweroff
|
|---|