Skip to content

Instantly share code, notes, and snippets.

@mnebuerquo
Created March 17, 2018 22:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mnebuerquo/5443532036af8b48995547e2817dba85 to your computer and use it in GitHub Desktop.
Save mnebuerquo/5443532036af8b48995547e2817dba85 to your computer and use it in GitHub Desktop.
#!/bin/sh
if [ $(id -u) -ne 0 ]; then
echo "Nope. Simon didn't say so!"
exit 1;
fi
if [ -z "$1" ]; then
echo "What's my name? Say my name, bitch!"
exit 1
fi
newname=$1
# set server name
echo $newname > /etc/hostname
hostname $newname
# ensure name is in /etc/hosts, but only once
if grep -q "$newname" /etc/hosts; then
echo "$newname already in /etc/hosts"
else
echo "127.0.0.1 $newname" >> /etc/hosts;
fi
echo "Changed hostname to ${newname}!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment