Created
March 17, 2018 22:22
-
-
Save mnebuerquo/5443532036af8b48995547e2817dba85 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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