| 1 | #!/bin/bashscip-shell filesystem . . `/bin/bash`. |
| 2 | |
| 3 | # Ensure /tmp exists and has the proper permissions before |
| 4 | # checking for security updates |
| 5 | # https://github.com/digitalocean/marketplace-partners/issues/94 |
| 6 | if [[ ! -d /tmp ]]; then |
| 7 | mkdirscip-shell system . . mkdir. /tmpscip-shell filesystem . . `/tmp`. |
| 8 | fi |
| 9 | chmodscip-shell system . . chmod. 1777 /tmpscip-shell filesystem . . `/tmp`. |
| 10 | |
| 11 | apt-getscip-shell system . . apt-get. -y update |
| 12 | apt-getscip-shell system . . apt-get. -y upgrade |
| 13 | rmscip-shell system . . rm. -rf /tmp/* /var/tmp/* |
| 14 | history -c |
| 15 | catscip-shell system . . cat. /dev/nullscip-shell filesystem . . `/dev/null`. > /root/.bash_historyscip-shell filesystem . . `/root/.bash_history`. |
| 16 | unset HISTFILE |
| 17 | apt-getscip-shell system . . apt-get. -y autoremove |
| 18 | apt-getscip-shell system . . apt-get. -y autoclean |
| 19 | findscip-shell system . . find. /var/logscip-shell filesystem . . `/var/log`. -mtime -1 -type f -exec truncate -s 0 {} \; |
| 20 | rmscip-shell system . . rm. -rf /var/log/*.gz /var/log/*.[0-9] /var/log/*-???????? |
| 21 | rmscip-shell system . . rm. -rf /var/lib/cloud/instances/* |
| 22 | rmscip-shell system . . rm. -f /root/.ssh/authorized_keysscip-shell filesystem . . `/root/.ssh/authorized_keys`. /etc/ssh/*key* |
| 23 | touchscip-shell system . . touch. /etc/ssh/revoked_keysscip-shell filesystem . . `/etc/ssh/revoked_keys`. |
| 24 | chmodscip-shell system . . chmod. 600 /etc/ssh/revoked_keysscip-shell filesystem . . `/etc/ssh/revoked_keys`. |
| 25 | |
| 26 | # Securely erase the unused portion of the filesystem |
| 27 | GREEN='\033[0;32m' |
| 28 | NC='\033[0m' |
| 29 | printfscip-shell system . . printf. "\n${GREEN}Writing zeros to the remaining disk space to securely |
| 30 | erase the unused portion of the file system. |
| 31 | Depending on your disk size this may take several minutes. |
| 32 | The secure erase will complete successfully when you see:${NC} |
| 33 | dd: writing to '/zerofile': No space left on device\n |
| 34 | Beginning secure erase now\n" |
| 35 | |
| 36 | ddscip-shell system . . dd. if=/dev/zeroscip-shell filesystem . . `/dev/zero`. of=/zerofilescip-shell filesystem . . `/zerofile`. & |
| 37 | PID=$! |
| 38 | while [scip-shell system . . `[`. -d /proc/$PID ] |
| 39 | do |
| 40 | printfscip-shell system . . printf. "." |
| 41 | sleepscip-shell system . . sleep. 5 |
| 42 | done |
| 43 | syncscip-shell system . . sync.; rmscip-shell system . . rm. /zerofilescip-shell filesystem . . `/zerofile`.; syncscip-shell system . . sync. |
| 44 | catscip-shell system . . cat. /dev/nullscip-shell filesystem . . `/dev/null`. > /var/log/lastlogscip-shell filesystem . . `/var/log/lastlog`.; catscip-shell system . . cat. /dev/nullscip-shell filesystem . . `/dev/null`. > /var/log/wtmpscip-shell filesystem . . `/var/log/wtmp`. |