You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
1.4 KiB

  1. #!/bin/bash
  2. # Ensure /tmp exists and has the proper permissions before
  3. # checking for security updates
  4. # https://github.com/digitalocean/marketplace-partners/issues/94
  5. if [[ ! -d /tmp ]]; then
  6. mkdir /tmp
  7. fi
  8. chmod 1777 /tmp
  9. export DEBIAN_FRONTEND=noninteractive
  10. apt-get -y update
  11. apt-get -o Dpkg::Options::="--force-confold" upgrade -q -y --force-yes
  12. apt-get purge droplet-agent
  13. rm -rf /opt/digitalocean
  14. apt-get -y autoremove
  15. apt-get -y autoclean
  16. rm -rf /tmp/* /var/tmp/*
  17. history -c
  18. cat /dev/null > /root/.bash_history
  19. unset HISTFILE
  20. find /var/log -mtime -1 -type f -exec truncate -s 0 {} \;
  21. rm -rf /var/log/*.gz /var/log/*.[0-9] /var/log/*-????????
  22. rm -rf /var/lib/cloud/instances/*
  23. rm -f /root/.ssh/authorized_keys /etc/ssh/*key*
  24. touch /etc/ssh/revoked_keys
  25. chmod 600 /etc/ssh/revoked_keys
  26. # Securely erase the unused portion of the filesystem
  27. GREEN='\033[0;32m'
  28. NC='\033[0m'
  29. 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. dd if=/dev/zero of=/zerofile &
  36. PID=$!
  37. while [ -d /proc/$PID ]
  38. do
  39. printf "."
  40. sleep 5
  41. done
  42. sync; rm /zerofile; sync
  43. cat /dev/null > /var/log/lastlog; cat /dev/null > /var/log/wtmp