Add auto hostname setting

This commit is contained in:
Donald Burr 2015-02-17 22:41:20 -08:00
parent 4b799bb44b
commit ca552ae331
3 changed files with 18 additions and 18 deletions

View file

@ -1,17 +1,16 @@
#!/bin/bash
if grep -q raspberrypi /etc/hostname; then
echo "You still have the default hostname set. We recommend changing the"
echo "hostname so that your Pi can be uniquely identified."
echo "If you wish to change it, enter a new hostname now, otherwise"
echo -n "just press Return: "
read NEW_HOSTNAME
if [ ! -z "$NEW_HOSTNAME" ]; then
echo "$NEW_HOSTNAME" > /tmp/HOSTNAME.$$
sudo rm -f /etc/hostname
sudo mv /tmp/HOSTNAME.$$ /etc/hostname
sudo chown root:root /etc/hostname
sudo chmod 644 /etc/hostname
sudo /etc/init.d/hostname.sh
fi
fi
MAC=`ifconfig eth0 | grep -o -E '([[:xdigit:]]{1,2}:){5}[[:xdigit:]]{1,2}' | tr '[A-Z]' '[a-z]'`
if grep -q $MAC HOSTS; then
HOSTNAME=`grep $MAC HOSTS | cut -d\| -f1`
echo "setting hostname to $HOSTNAME"
echo "$HOSTNAME" > /tmp/HOSTNAME.$$
sudo rm -f /etc/hostname
sudo mv /tmp/HOSTNAME.$$ /etc/hostname
sudo chown root:root /etc/hostname
sudo chmod 644 /etc/hostname
sudo /etc/init.d/hostname.sh
else
echo "cannot determine hostname"
fi
exit 1