Guest User

Untitled

a guest
Aug 23rd, 2019
84
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2.  
  3. # Update the system, cleans out all of the cloud-init cache, disable and remove cloud-init customisations
  4. sudo apt update
  5. sudo apt upgrade -y
  6. sudo apt autoremove -y
  7. echo "Housekeeping done"
  8.  
  9. # cleanup current ssh keys so templated VMs get fresh key
  10. sudo rm -f /etc/ssh/ssh_host_*
  11. echo "SSH host keys cleared"
  12.  
  13. # add check for ssh keys on reboot...regenerate if neccessary
  14. sudo tee /etc/rc.local >/dev/null <<EOL
  15. #!/bin/sh -e
  16. #
  17. # rc.local
  18. #
  19. # This script is executed at the end of each multiuser runlevel.
  20. # Make sure that the script will "" on success or any other
  21. # value on error.
  22. #
  23. # In order to enable or disable this script just change the execution
  24. # bits.
  25. #
  26.  
  27. # By default this script does nothing.
  28. test -f /etc/ssh/ssh_host_dsa_key || dpkg-reconfigure openssh-server
  29. exit 0
  30. EOL
  31.  
  32. # make the script executable
  33. sudo chmod +x /etc/rc.local
  34. echo "SSH host keys regen script added"
  35.  
  36. # cleanup apt
  37. sudo apt clean
  38. echo "Apt cleaned"
  39.  
  40. # reset the machine-id (DHCP leases in 18.04 are generated based on this... not MAC...)
  41. echo "" | sudo tee /etc/machine-id >/dev/null
  42. echo "Machine-id reset"
  43.  
  44. # disable swap for K8s
  45. sudo swapoff --all
  46. sudo sed -ri '/\sswap\s/s/^#?/#/' /etc/fstab
  47. echo "Swap disabled"
  48.  
  49. # cleanup shell history and shutdown for templating
  50. history -c
  51. history -w
  52. echo "History cleaned"
  53.  
  54. sudo shutdown -h now
RAW Paste Data