[Pkg-ltsp-devel] Bug#704830: Bug#704830: ltsp-client-core: the init script should provide a hook for code snippets
Wolfgang Schweer
w.schweer at gmx.de
Tue Apr 9 10:41:08 UTC 2013
On Mon, Apr 08, 2013 at 02:44:07PM -0700, Vagrant Cascadian wrote:
> On Sat, Apr 06, 2013 at 03:58:09PM +0200, Wolfgang Schweer wrote:
> > to fetch config values out of LDAP and to add them to those provided on
> > the kernel command line or in lts.conf, code has to be executed inside
> > of the init script. While it is possible to modify the init script in
> > such a way using a script in init-ltsp.d [1], it would be better to have a
> > hook inside of the initscript serching for code in some directory, say
> > ltsp-client-core.d
>
> Or you could also use /usr/share/ltsp/ltsp_config.d...
First location I tried, but it didn't work out for me.
> Why is this better to do it from ltsp-client-core?
Cause then a network connection to the LDAP server is possible.
> > # Save as /usr/share/ltsp/init-ltsp.d/70-edu-client-core
> > # This snippet modifies /etc/init.d/ltsp-client-core on-the-fly.
> > #
> > # Get config stored in LDAP for Debian Edu ltsp clients (thin and fat).
> > #
> > sed -i '/"Starting\ LTSP\ client..."/ a\
> > /usr/share/ltsp/get-ldap-ltsp-config\
> > cat /var/cache/ltsp/ltsp_config_edu >> /var/cache/ltsp/ltsp_config_env\
> > ' /etc/init.d/ltsp-client-core
>
> Why don't you call get-ldap-ltsp-config from ltsp_config.d or init-ltsp.d
> instead?
Tried both locations; init-ltsp.d is far to early. As far as
ltsp_config.d is concerned, it seems to be the same (no connection to
ldap server). So this weird workaround. The script get-ldap-ltsp-config
is attached, maybe you're able to figure our some other way.
Wolfgang
-------------- next part --------------
#!/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"
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.alioth.debian.org/pipermail/pkg-ltsp-devel/attachments/20130409/faa43e1f/attachment.pgp>
More information about the Pkg-ltsp-devel
mailing list