[debian-edu-commits] r81456 - in branches/wheezy/debian-edu-config: debian etc/dhcp/dhclient-exit-hooks.d
pere at alioth.debian.org
pere at alioth.debian.org
Sun Jul 7 22:10:55 UTC 2013
Author: pere
Date: 2013-07-07 22:10:55 +0000 (Sun, 07 Jul 2013)
New Revision: 81456
Modified:
branches/wheezy/debian-edu-config/debian/changelog
branches/wheezy/debian-edu-config/etc/dhcp/dhclient-exit-hooks.d/hostname
Log:
Change code to set hostname on Workstation, Thin-Client-Server and
Minimal installations, to fall back to unique name generated from
the MAC address, to make it possible to unique identify machines
on the login screen after installation/boot.
Modified: branches/wheezy/debian-edu-config/debian/changelog
===================================================================
--- branches/wheezy/debian-edu-config/debian/changelog 2013-07-07 19:05:08 UTC (rev 81455)
+++ branches/wheezy/debian-edu-config/debian/changelog 2013-07-07 22:10:55 UTC (rev 81456)
@@ -6,6 +6,10 @@
* Adjust setup-ad-client and locate-syslog-collector to handle dns
domain localdomain as no domain the same way sssd-generate-config
do.
+ * Change code to set hostname on Workstation, Thin-Client-Server and
+ Minimal installations, to fall back to unique name generated from
+ the MAC address, to make it possible to unique identify machines
+ on the login screen after installation/boot.
-- Petter Reinholdtsen <pere at debian.org> Sun, 07 Jul 2013 19:58:25 +0200
Modified: branches/wheezy/debian-edu-config/etc/dhcp/dhclient-exit-hooks.d/hostname
===================================================================
--- branches/wheezy/debian-edu-config/etc/dhcp/dhclient-exit-hooks.d/hostname 2013-07-07 19:05:08 UTC (rev 81455)
+++ branches/wheezy/debian-edu-config/etc/dhcp/dhclient-exit-hooks.d/hostname 2013-07-07 22:10:55 UTC (rev 81456)
@@ -8,6 +8,9 @@
# http://nxhelp.com/blog/2013/01/24/automatically-set-hostname-from-dhcp/
#
+PATH=/sbin:$PATH
+export PATH
+
# Should not update hostname on Main-Server, Roaming-Workstation and Standalone
if [ -r /etc/debian-edu/config ] ; then
. /etc/debian-edu/config
@@ -22,6 +25,10 @@
exit 0
fi
+log() {
+ logger -t dhclient-exit-hooks.d/hostname "$1"
+}
+
# Map IP to FQDN
ip2hostname() {
ip=$1
@@ -29,17 +36,40 @@
rev |cut -d '.' -f 2-|rev
}
+# Generate FQDN based on hardware MAC address
+ether2hostname() {
+ # Pick the first MAC address listed by ifconfig, and use it to
+ # generate a unique host name for the machine.
+ mac=$(ifconfig | awk '/Link encap:Ethernet HWaddr/ { print $5; exit}'| \
+ sed 's/[^0-9a-f-]/-/gi')
+ if [ "$mac" ] ; then
+ fqdn="auto-mac-$mac.intern";
+ echo $fqdn
+ fi
+}
+
+sethostname() {
+ hostname="$1"
+ namesource="$2"
+ echo $hostname > /etc/hostname
+ hostname $hostname
+ log "changing hostname to $hostname based on $namesource"
+}
+
case "$reason" in
BOUND|RENEW|REBIND|REBOOT)
+ namesource="DHCP IP address $new_ip_address"
hostname=$(ip2hostname $new_ip_address)
if [ -z "$hostname" ] ; then
- logger -t dhclient-exit-hooks.d/hostname "unable to find hostname from DHCP IP address $new_ip_address, not updating current hostname"
+ namesource="hardware MAC address"
+ hostname=$(ether2hostname)
+ fi
+ if [ -z "$hostname" ] ; then
+ log "unable to find hostname from DHCP IP address $new_ip_address and MAC address, not updating current hostname"
elif [ "$hostname" != "$(uname -n)" ] ; then
echo dhclient-exit-hooks.d/hostname: Dynamic IP address = $new_ip_address
- echo $hostname > /etc/hostname
- hostname $hostname
+ sethostname "$hostname" "$namesource"
echo dhclient-exit-hooks.d/hostname: Dynamic Hostname = $hostname
- logger -t dhclient-exit-hooks.d/hostname "changing hostname to $hostname based on DHCP IP address $new_ip_address"
fi
;;
esac
More information about the debian-edu-commits
mailing list