Skip to content

Instantly share code, notes, and snippets.

@iComputerfreak
Last active March 21, 2025 18:41
Show Gist options
  • Save iComputerfreak/b1cd5b0e4cedc4463092165370ef225a to your computer and use it in GitHub Desktop.
Save iComputerfreak/b1cd5b0e4cedc4463092165370ef225a to your computer and use it in GitHub Desktop.
Proxmox Ubuntu VM Setup
#!/bin/zsh
set -e
if [ "$EUID" -ne 0 ]; then
echo "Please run this script as root or using sudo."
exit 1
fi
# Questions
short_hostname=""
while [[ -z "$short_hostname" ]]; do
vared -p "What is the shorthand hostname of this machine (e.g., 'titan')? " -c short_hostname
done
vared -p "What is the FQDN hostname of this machine (e.g., 'titan.jonasfrey.eu')? [default: ${short_hostname}.jonasfrey.eu] " -c fqdn_hostname
if [[ -z "$fqdn_hostname" ]]; then
fqdn_hostname="${short_hostname}.jonasfrey.eu"
fi
# Configuration
echo "Configuring hostname '${short_hostname}'..."
sed -i "s/127.0.1.1 .*/127.0.1.1 $fqdn_hostname $short_hostname/g" /etc/hosts
sed -i "s/templatehost.jonasfrey.eu/$fqdn_hostname/g" /etc/postfix/main.cf
sed -i "s/templatehost/$short_hostname/g" /etc/postfix/main.cf
echo "$short_hostname" > /etc/hostname
echo "$fqdn_hostname" > /etc/mailname
echo "Re-generating machine-id..."
rm -f /etc/machine-id
dbus-uuidgen --ensure=/etc/machine-id
echo "Changing user password..."
passwd jonas
# Cleanup
function ask {
vared -p "$* [Yn] " -c yn
if [[ -z "$yn" ]]; then
return 0
fi
case $yn in
([Yy]*) return 0 ;;
([Nn]*) return 1 ;;
esac
}
ask "Remove script?"
if [[ $? ]]; then
echo "Removing script..."
rm -f "$0"
fi
ask "Reboot now?"
if [[ $? ]]; then
echo "Rebooting..."
reboot
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment