Skip to content

Instantly share code, notes, and snippets.

@Elektordi
Created May 26, 2016 16:10
Show Gist options
  • Save Elektordi/252881cfedd1e72f377d295c0447342f to your computer and use it in GitHub Desktop.
Save Elektordi/252881cfedd1e72f377d295c0447342f to your computer and use it in GitHub Desktop.
#!/bin/bash
# Comment installer le script ?
#
# Copier le contenu dans /etc/network/if-up.d/000-fog-moi-le-hostname
mac=`ifconfig eth0 | grep HWaddr | sed -e "s/.* HWaddr //"`
oldhost=`hostname`
tmp=/tmp/fog-hostname
fogserver=fogserver.plasci.local
(
rm -f $tmp
wget -q -O- http://$fogserver/fog/service/hostname.php?mac=$mac |
while read -r line
do
if echo "$line" | grep -q "!ok"; then
hostname=`echo "$line" | sed -e 's/.*=//'`
if [ -n "$hostname" ]; then
echo $hostname > $tmp
if [ "$hostname" = "$oldhost" ]; then
echo "[PLASCI-FOG] Hostname already $hostname, nothing to change!"
else
echo "[PLASCI-FOG] Hostname was $oldhost, changing to $hostname..."
hostname $hostname
echo $hostname > /etc/hostname
sed -i /etc/hosts -e "s/127\.0\.1\.1.*/127.0.1.1\t`cat $tmp`/"
echo "[PLASCI-FOG] OK, hostname changed!"
fi
exit 0
else
echo "[PLASCI-FOG] Empty hostname received."
fi
fi
done
if [ ! -f $tmp ]; then
echo "[PLASCI-FOG] Cannot find hostname on server. Is network up?"
fi
) | logger
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment