Created
October 29, 2015 12:46
-
-
Save felixhummel/9bd4252c3823a3305515 to your computer and use it in GitHub Desktop.
/usr/local/bin/vboxhostname
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/bash | |
# If you set the something stupid that's not a valid hostname, then it's your | |
# own fault. :P | |
set -euo pipefail | |
echo 'Ran vboxhostname' > /tmp/x | |
echo '----------------' >> /tmp/x | |
VBoxControl guestproperty get hostname 2>&1 >> /tmp/x | |
vboxhostname=$(VBoxControl guestproperty get hostname | grep Value | awk '{ print $2 }') | |
echo "Got $vboxhostname" >> /tmp/x | |
if [[ -z $vboxhostname ]]; then | |
echo "ERROR: Set hostname via 'vboxmanage guestproperty set <vmname> hostname <hostname>'" | |
exit 1 | |
fi | |
# append as second line | |
sed -i "1 a\ | |
127.0.1.1 $vboxhostname" /etc/hosts | |
echo $vboxhostname > /etc/hostname | |
hostname -F /etc/hostname |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment