#!/bin/bash -e

CONFIGFILE=/etc/webmin/ldap-users/config
CONFOPT="secret server rootdn basedn \
         homeprefix mailprefix sambasync \
         passwd_capital passwd_lowercase passwd_number \
         passwd_length"

# load the library
. /usr/share/debconf/confmodule

db_version 2.0

# check whether we need to continue
if [ "$AUTO_GEN"x = "nx" ]
then
    db_input low webmin-ldap-skolelinux/no-auto-config
    db_go
else # Do autoconfig
    
    if [ -e $CONFIGFILE ] 
	then
	. $CONFIGFILE || true
	
        # Store values from config file into debconf db.
	for i in $CONFOPT; do
	    eval "j=$(echo \$$i)"
	    if [ "$j"x != x  ] ; then
		eval "db_set webmin-ldap-skolelinux/$i  \$$i || true "
	    fi
	done
    fi
    
# ask what we need to know.
    
    if [ -z $secret ]
	then
	secret=`dd if=/dev/urandom count=20 bs=1 2>/dev/null | md5sum | cut -c1-32`
	db_set webmin-ldap-skolelinux/secret $secret || true
    fi
    
    for i in $CONFOPT; do
	eval "db_input low webmin-ldap-skolelinux/$i || true"
    done
    db_go || true
fi
#DEBHELPER#
