#!/bin/sh
### BEGIN INIT INFO
# Provides:          iceweasel-ldapconf
# Required-Start:    $remote_fs
# Required-Stop:     $remote_fs
# Should-Start:      $network $syslog $named slapd fetch-ldap-cert
# Default-Start:     2 3 4 5
# Default-Stop:
# Short-Description: Update iceweasel configuration from LDAP
# Description:
#   Update default iceweasel default setup (currently only start page)
#   from LDAP.  Check LDAP every boot to see if the default start page
#   should be changed or not.
### END INIT INFO
#
# Author: Petter Reinholdtsen <pere@hungry.com>
# Date:   2011-12-31

set -e

. /lib/lsb/init-functions

if [ -e /etc/debian-edu/config ] ; then
    . /etc/debian-edu/config
fi

do_start() {
    # Skip this on LTSP chroots
    if [ -e /etc/ltsp_chroot ] ; then
        return
    fi

    # Only networked profiles use LDAP
    if echo "$PROFILE" | egrep -q 'Main-Server|Workstation|Roaming-Workstation|Thin-Client-Server|Minimal' ; then
	/usr/share/debian-edu-config/tools/update-iceweasel-homepage ldap:homepage
    fi

    if echo "$PROFILE" | grep -q Thin-Client-Server  && [ -d /opt/ltsp ] ; then
	for ltsp_chroot in `find /opt/ltsp/ -mindepth 1 -maxdepth 1 -type d`; do
	    chroot $ltsp_chroot /usr/share/debian-edu-config/tools/update-iceweasel-homepage ldap:homepage
	done
    fi
}

case "$1" in
    start)
	do_start
	;;
    stop)
	;;
    restart|force-reload)
	;;
    *)
	echo "Usage: $0 {start|stop|restart|force-reload}"
	exit 2
esac
exit 0
