[debian-edu-commits] r79527 - branches/wheezy/debian-edu-config/share/ltsp

schweer-guest at alioth.debian.org schweer-guest at alioth.debian.org
Thu Mar 28 23:09:22 UTC 2013


Author: schweer-guest
Date: 2013-03-28 23:09:21 +0000 (Thu, 28 Mar 2013)
New Revision: 79527

Added:
   branches/wheezy/debian-edu-config/share/ltsp/get-ldap-ltsp-config
Log:
Add forgotten file get-ldap-ltsp-config


Added: branches/wheezy/debian-edu-config/share/ltsp/get-ldap-ltsp-config
===================================================================
--- branches/wheezy/debian-edu-config/share/ltsp/get-ldap-ltsp-config	                        (rev 0)
+++ branches/wheezy/debian-edu-config/share/ltsp/get-ldap-ltsp-config	2013-03-28 23:09:21 UTC (rev 79527)
@@ -0,0 +1,127 @@
+#!/bin/sh
+# Store as /opt/ltsp/$arch/usr/share/ltsp/get-ldap-ltsp-config
+#
+# Fetch LTSP client settings from LDAP based on MAC address
+#
+# Uses ethernet address as stored in the dhcpHost objectclass using
+# the dhcpHWAddress attribute or as stored in the ieee802Device
+# objectclass with the macAddress attribute.
+#
+# This module is written to be schema agnostic, and only depend on the
+# existence of attribute names.
+#
+# The LTSP configuration variables are saved directly using a
+# ltspConfig attribute.  To set the SERVER variable, set a ltspConfig
+# attribute to 'SERVER=value'.
+#
+# Some LDAP schema should be created with all the relevant
+# configuration settings.  Something like this should work:
+#
+# attributetype ( some-OID NAME 'ltspConfig'
+#    DESC 'LTSP config setting'
+#    SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )
+#
+# objectclass ( some-OID NAME 'ltspClientConfigAux'
+#    DESC 'LTSP client configuration attributes'
+#    SUP top
+#    AUXILIARY
+#    MAY ( ltspConfig ))
+#
+# objectclass ( some-OID NAME 'ltspClientConfig'
+#    DESC 'LTSP client configuration attributes'
+#    SUP top
+#    STRUCTURAL
+#    MUST ( cn )
+#    MAY ( ltspConfig ))
+#
+# Example LDAP object:
+#
+# dn: cn=ltspConfigDefault,ou=somewhere
+# objectclass: device
+# objectclass: ltspClientConfigAux
+# cn=ltspConfigDefault
+# ltspConfig: SERVER=ltspserver.somewhere
+# ltspConfig: SOUND=N
+#
+# dn: cn=hostname,ou=somewhere
+# objectclass: ieee802Device
+# objectclass: domainRelatedObject
+# objectclass: ltspClientConfigAux
+# cn=hostname
+# macAddress: 00:01:02:03:04:05
+# associatedDomain: hostname.somewhere
+# ltspConfig: SOUND=N
+
+#
+# GOSA also have a LDAP approach for the tftp content (PXE arguments),
+# searching for
+#
+# filter => "(&(macAddress=$mac)(objectClass=gotoTerminal))",
+# attrs => [ 'gotoTerminalPath', 'gotoBootKernel',
+#            'gotoKernelParameters', 'gotoLdapServer', 'cn' ] );
+#
+# See the fts-ltsp-ldap package for this.  The gotoTerminal object
+# class is auxiliary, allowing it to be combined with other
+# objectclasses.
+
+echo "Fetching ltsp config from ldap"
+
+#LDAP_HOST=tjener.intern
+#BASE_DN=dc=skole,dc=skolelinux,dc=no
+cachefile=/var/cache/ltsp/ltsp_config_edu
+envfile=/var/cache/ltsp/ltsp_config_env
+PATH=/bin:/usr/bin:/usr/sbin
+
+setup_from_ldap() {
+    filter="(&(ltspConfig=*)$1)"
+    config="$(ldapsearch -h "$LDAP_HOST" -b "$BASE_DN" -x "$filter" ltspConfig | \
+	    awk '/^ltspConfig: [^=]*=[^;]*$/ { print $2 }')"
+    if [ "$config" ] ; then
+	if eval "$config" ; then
+            echo "$config" >> $cachefile
+	else
+	    logger -t ltsp-ldap "got invalid LTSP config from LDAP: '$config'"
+	fi
+	foundinldap=true
+    fi
+}
+
+lookup_mac_addrs() {
+    PATH=/sbin:$PATH LANG=C ifconfig 2>/dev/null | grep -i hwaddr | awk '{print $5}' | sort -u
+}
+
+# Only check LDAP when the result can be cached
+if touch $cachefile && touch $envfile; then
+    if [ -z "$LDAP_HOST" ] ; then
+	LDAP_HOST=$(debian-edu-ldapserver || :)
+    fi
+    if [ "$LDAP_HOST" ] && ping -W2 -c2 "$LDAP_HOST" > /dev/null 2>&1 ; then
+        if [ -z "$BASE_DN" ] ; then
+            BASE_DN=$(debian-edu-ldapserver -s "$LDAP_HOST" -b || :)
+        fi
+
+        if [ "$BASE_DN" ] ; then
+            # First set default values if found
+            setup_from_ldap '(cn=ltspConfigDefault)'
+
+            # Next, look up the host MAC address(es).
+            foundinldap=false
+            if [ -e /proc/net/dev ] ; then
+                for MAC in $(lookup_mac_addrs) ; do
+                    filter="(|(dhcpHWAddress=ethernet $MAC)(macAddress=$MAC))"
+                    setup_from_ldap "$filter"
+                done
+            fi
+            # If the HW MAC address was not found, look for the host name
+            # instead.
+            if [ false = "$foundinldap" ] ; then
+                fqdn=$(hostname -f)
+                # No use checking if it isn't set up yet
+                if [ "(none)" != "$fqdn" ] ; then
+                    setup_from_ldap "(associatedDomain=$fqdn)"
+                fi
+            fi
+        fi
+    fi
+fi
+echo "Fetching ltsp config from ldap done"


Property changes on: branches/wheezy/debian-edu-config/share/ltsp/get-ldap-ltsp-config
___________________________________________________________________
Added: svn:executable
   + *




More information about the debian-edu-commits mailing list