Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # Update the system, cleans out all of the cloud-init cache, disable and remove cloud-init customisations
- sudo apt update
- sudo apt upgrade -y
- sudo apt autoremove -y
- echo "Housekeeping done"
- # cleanup current ssh keys so templated VMs get fresh key
- sudo rm -f /etc/ssh/ssh_host_*
- echo "SSH host keys cleared"
- # add check for ssh keys on reboot...regenerate if neccessary
- sudo tee /etc/rc.local >/dev/null <<EOL
- #!/bin/sh -e
- #
- # rc.local
- #
- # This script is executed at the end of each multiuser runlevel.
- # Make sure that the script will "" on success or any other
- # value on error.
- #
- # In order to enable or disable this script just change the execution
- # bits.
- #
- # By default this script does nothing.
- test -f /etc/ssh/ssh_host_dsa_key || dpkg-reconfigure openssh-server
- exit 0
- EOL
- # make the script executable
- sudo chmod +x /etc/rc.local
- echo "SSH host keys regen script added"
- # cleanup apt
- sudo apt clean
- echo "Apt cleaned"
- # reset the machine-id (DHCP leases in 18.04 are generated based on this... not MAC...)
- echo "" | sudo tee /etc/machine-id >/dev/null
- echo "Machine-id reset"
- # disable swap for K8s
- sudo swapoff --all
- sudo sed -ri '/\sswap\s/s/^#?/#/' /etc/fstab
- echo "Swap disabled"
- # cleanup shell history and shutdown for templating
- history -c
- history -w
- echo "History cleaned"
- sudo shutdown -h now
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement