[debian-edu-commits] r81720 - in branches/wheezy/debian-edu-config: debian etc/dhcp/dhclient-exit-hooks.d ldap-tools sbin share/debian-edu-config/d-i

pere at alioth.debian.org pere at alioth.debian.org
Thu Jul 18 11:20:45 UTC 2013


Author: pere
Date: 2013-07-18 11:20:45 +0000 (Thu, 18 Jul 2013)
New Revision: 81720

Modified:
   branches/wheezy/debian-edu-config/debian/changelog
   branches/wheezy/debian-edu-config/etc/dhcp/dhclient-exit-hooks.d/hostname
   branches/wheezy/debian-edu-config/ldap-tools/sitesummary2ldapdhcp
   branches/wheezy/debian-edu-config/sbin/update-hostname-from-ip
   branches/wheezy/debian-edu-config/share/debian-edu-config/d-i/pre-pkgsel
Log:
Adjust our system for setting default hostname to set a unique
generated hostname during installation, fetched either from
reverse DNS lookups or using the MAC address of the interface used
by the default route.  Adjust all code setting the hostname to use
the update-hostname-from-ip script for generating the name.

Modified: branches/wheezy/debian-edu-config/debian/changelog
===================================================================
--- branches/wheezy/debian-edu-config/debian/changelog	2013-07-18 09:00:06 UTC (rev 81719)
+++ branches/wheezy/debian-edu-config/debian/changelog	2013-07-18 11:20:45 UTC (rev 81720)
@@ -13,6 +13,11 @@
     /etc/dhcp/dhclient-exit-hooks.d/hostname called by the
     dispatcher.d script, and it was activated on roaming workstations
     where it should not update the hostname.
+  * Adjust our system for setting default hostname to set a unique
+    generated hostname during installation, fetched either from
+    reverse DNS lookups or using the MAC address of the interface used
+    by the default route.  Adjust all code setting the hostname to use
+    the update-hostname-from-ip script for generating the name.
 
   [ Holger Levsen ]
   * debian/rules: stop calling (obsolete) dh_pysupport, we don't have any

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-18 09:00:06 UTC (rev 81719)
+++ branches/wheezy/debian-edu-config/etc/dhcp/dhclient-exit-hooks.d/hostname	2013-07-18 11:20:45 UTC (rev 81720)
@@ -32,25 +32,6 @@
     logger -t dhclient-exit-hooks.d/hostname "$1"
 }
 
-# Map IP to FQDN
-ip2hostname() {
-    ip=$1
-    host $new_ip_address | grep 'domain name pointer' | cut -d ' ' -f 5 | \
-	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"
@@ -62,17 +43,6 @@
 case "$reason" in
 	BOUND|RENEW|REBIND|REBOOT)
 	namesource="DHCP IP address $new_ip_address"
-	hostname=$(ip2hostname $new_ip_address)
-	if [ -z "$hostname" ] ; then
-		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
-		sethostname "$hostname" "$namesource"
-		echo dhclient-exit-hooks.d/hostname: Dynamic Hostname = $hostname
-	fi
+	/usr/sbin/update-hostname-from-ip -I $new_ip_address
 	;;
 esac

Modified: branches/wheezy/debian-edu-config/ldap-tools/sitesummary2ldapdhcp
===================================================================
--- branches/wheezy/debian-edu-config/ldap-tools/sitesummary2ldapdhcp	2013-07-18 09:00:06 UTC (rev 81719)
+++ branches/wheezy/debian-edu-config/ldap-tools/sitesummary2ldapdhcp	2013-07-18 11:20:45 UTC (rev 81720)
@@ -90,8 +90,8 @@
         $hostinfo{$hostid} = [$fqdn, $ipaddr, $macref, 1];
     } elsif ($opts{a}) {
         my $mac = get_primary_ether_hwaddr($macref);
-        $mac =~ s/[^0-9a-f-]/-/gi;
-        $fqdn = "auto-mac-$mac.intern";
+        # Use -I 127.0.0.1 to disable DNS lookup
+        fqdn=`/usr/sbin/update-hostname-from-ip -m -I 127.0.0.1 -M $mac -n`;
         print "info: Create GOsa machine for $fqdn [$ipaddr] id $hostid.\n";
         $hostinfo{$hostid} = [$fqdn, $ipaddr, $macref, 0];
     } else {

Modified: branches/wheezy/debian-edu-config/sbin/update-hostname-from-ip
===================================================================
--- branches/wheezy/debian-edu-config/sbin/update-hostname-from-ip	2013-07-18 09:00:06 UTC (rev 81719)
+++ branches/wheezy/debian-edu-config/sbin/update-hostname-from-ip	2013-07-18 11:20:45 UTC (rev 81720)
@@ -6,43 +6,132 @@
 # Set current hostname to match the IP address on eth0.  This is
 # useful when getting the IP address from DHCP.
 
-PATH="/sbin:$PATH"
+LC_ALL=C
+export LC_ALL
+QUIET=echo
+USEMAC=false
+onlyprint=false
 
-INTERFACE="$(/sbin/route -n | awk '/^0\.0\.0\.0 / { print $8 }')"
+DNSDOMAIN=intern
 
-if [ "-q" = "$1" ] ; then
-    QUIET=true
-    shift
-else
-    QUIET=false
-fi
+log() {
+    $QUIET "$2"
+    logger -t update-hostname-from-ip "$1"
+}
 
-LC_ALL=C
-export LC_ALL
+# Generate FQDN based on hardware MAC address
+ether2hostname() {
+    if [ "$1" ] ; then
+	mac="$1"
+    else
+	mac=$(ifconfig $INTERFACE | awk '/Link encap:Ethernet  HWaddr/ { print $5; exit}')
+    fi
+    mac=$(echo $mac | sed 's/[^0-9a-f-]/-/gi')
+    if [ "$mac" ] ; then
+       fqdn="auto-mac-$mac.$DNSDOMAIN";
+       echo $fqdn
+    fi
+}
 
+# Map IP to FQDN
+ip2hostname() {
+    ip=$1
+    host $ip | grep 'domain name pointer' | cut -d ' ' -f 5 | \
+	rev |cut -d '.' -f 2-|rev
+}
+
+PATH="/sbin:$PATH"
+
+INTERFACE="$(/sbin/route -n | awk '/^0\.0\.0\.0 / { print $8; exit }')"
+
 if [ -z "$INTERFACE" ] ; then
     INTERFACE=eth0
 fi
 
-# Extract current IP
-IP=`ifconfig $INTERFACE 2>&1 |grep 'inet addr:'|tr a-zA-Z: " "|awk '{print $1}'`
+sethostname() {
+    hostname="$1"
+    namesource="$2"
+    if hostname $hostname ; then
+	echo $hostname > /etc/hostname
+	log "info: changing hostname to $hostname based on $namesource"
+    else
+	log "error: unable to set hostname to $hostname."
+	exit 1
+    fi
+}
 
+# argument parsing
+TEMP=$(getopt -n update-hostname-from-ip -o dmM:nI:q -- "$@")
+
+# Abort when there was a bug
+[ $? = 0 ] || die "error parsing arguments. Try $0 --help"       
+
+eval set -- "$TEMP"
+while true; do     
+    case $1 in 
+        -m)
+            USEMAC=true; shift; continue
+            ;;                                    
+        -M)                            
+            MAC="$2"; shift; shift; continue
+            ;;
+        -I)
+            IP="$2"; shift; shift; continue
+            ;;
+        -q)
+            QUIET=:; shift; continue
+            ;;
+        -n)
+            onlyprint=true; shift; continue
+            ;;
+        --)
+            # no more arguments to parse
+            break
+            ;;
+        *)
+            printf "Unknown option %s\n" "$1"
+            exit 1
+            ;;
+    esac
+done
+
+# Extract current IP if non was provided on the command line
+if [ -z "$IP" ] ; then
+    IP=`ifconfig $INTERFACE 2>&1 |grep 'inet addr:'|tr a-zA-Z: " "|awk '{print $1; exit}'`
+fi
+
+if [ "127.0.0.1" = "$IP" ] ; then
+    IP=""
+fi
+
 if [ "$IP" ] ; then
-    DNSNAME=`getent hosts $IP | awk '{ print $2 }'`
-    if [ "$DNSNAME" ] ; then
-	if hostname $DNSNAME 2>/dev/null ; then
-	    [ true != "$QUIET" ] && echo "info: Setting hostname to DNS name $DNSNAME [$IP]."
-	    echo $DNSNAME > /etc/hostname
-	else
-	    [ true != "$QUIET" ] && echo "error: Unable to set hostname to $DNSNAME."
-	    exit 1
-	fi
+    HOSTNAME=$(ip2hostname $IP)
+    SOURCE="reverse DNS of $IP"
+elif $USEMAC ; then
+    HOSTNAME=$(ether2hostname $MAC)
+    SOURCE="hardware MAC address"
+else
+    exit 1
+fi
+
+if $USEMAC && [ -z "$HOSTNAME" ] ; then
+    HOSTNAME=$(ether2hostname $MAC)
+    SOURCE="hardware MAC address"
+fi
+
+# Already got the correct host name?
+if [ "$HOSTNAME" = "$(uname -n)" ] ; then
+    exit 0
+fi
+
+if [ "$HOSTNAME" ]; then
+    if $onlyprint ; then
+	echo $HOSTNAME
+	exit 0
     else
-	[ true != "$QUIET" ] && echo "error: Unable to look up $IP using DNS."
-	exit 1
+	sethostname "$HOSTNAME" "$SOURCE"
     fi
 else
-    [ true != "$QUIET" ] && echo "error: Unable to determine current IP address."
     exit 1
 fi
 

Modified: branches/wheezy/debian-edu-config/share/debian-edu-config/d-i/pre-pkgsel
===================================================================
--- branches/wheezy/debian-edu-config/share/debian-edu-config/d-i/pre-pkgsel	2013-07-18 09:00:06 UTC (rev 81719)
+++ branches/wheezy/debian-edu-config/share/debian-edu-config/d-i/pre-pkgsel	2013-07-18 11:20:45 UTC (rev 81720)
@@ -181,12 +181,12 @@
         in-target /etc/init.d/hostname.sh start
     fi
 
-    # Update hostname based on reverse DNS entry of current IP, unless
-    # installing main-server.
+    # Update hostname based on reverse DNS entry of current IP or
+    # generate from MAC address, unless installing main-server.
     if echo $PROFILE | grep -q Main-Server ; then
 	:
     elif [ -x /target/usr/sbin/update-hostname-from-ip ] ; then
-	in-target /usr/sbin/update-hostname-from-ip || true
+	in-target /usr/sbin/update-hostname-from-ip -m || true
     fi
 
     # Avoid hardcoding entries on the clients, to make sure IP address




More information about the debian-edu-commits mailing list