#!/bin/bash

set -e

if [ -z "$1" ]; then
    echo "Usage: $0 <new-hostname>"
    exit 1
fi

NEW_HOSTNAME="$1"

echo ""
echo "Changing hostname to '$NEW_HOSTNAME'..."


# !!! IMPORTANT !!!
# double check what are we changing as hostname should end up with *.local
sudo scutil --set HostName "$NEW_HOSTNAME"
sudo scutil --set ComputerName "$NEW_HOSTNAME"
sudo scutil --set LocalHostName "$NEW_HOSTNAME"

echo ""
echo "Hostname has been updated:"
echo "HostName: $(scutil --get HostName)"
echo "ComputerName: $(scutil --get ComputerName)"
echo "LocalHostName: $(scutil --get LocalHostName)"
