#!/bin/sh
################################################################################
#                                  makeldif                                    #
################################################################################
#
# Maximilian Wilhelm <max@skolelinux.de>
# Frank Matthiess <frankm@skolelinux.de>
#
# Last changed Sun, 24 Aug 2003 19:23:42 +0200
#

# specify path to shadow file
SHADOWPATH=""

################################################################################

# make sure, we have enough data
if [ $# -ne 3 ]; then
	echo "Usage: $0 [UID] [account name] [real name]";
	exit 1;
fi

# make sure we have a shadow file and it exists
if [ -z ${SHADOWPATH} ]; then
	echo "Specify path to your shadow file in $0."
	exit 1;
fi

# make sure the user is listed in the shadow file
if [ -z $( cat ${SHADOWPATH} | cut -d: -f1 |  grep $2 ) ]; then
	echo "Error: user $2 not listed in ${SHADOWPATH}";
	exit 1;
fi



# temporary variables
USERID=$1;
USERNAME=$2;
REALNAME=$(echo $3 | sed -e 's/"//g');
USNAME=$(echo ${REALNAME}| cut -f$(echo $USERNAME | wc -w) -d " ");

#
# Generate LDIF entry for user and personal group
#

cat << EOF | ldapadd -x -h localhost -W -D cn=admin,ou=ldap-access,dc=skole,dc=skolelinux,dc=no

dn: uid=${USERNAME},ou=people,dc=skole,dc=skolelinux,dc=no
objectClass: posixAccount
objectClass: imapUser
cn: ${REALNAME}
uid: ${USERNAME}
uidNumber: ${USERID}
gidNumber: ${USERID}
homeDirectory: /skole/tjener/home0/${USERNAME}
mailMessageStore: /var/lib/maildirs/${USERNAME}
loginShell: /bin/bash
userPassword: {crypt}$(grep ${USERNAME} ${SHADOWPATH} | cut -d: -f2 )

dn: cn=${USERNAME},ou=group,dc=skole,dc=skolelinux,dc=no
objectClass: top
objectClass: posixGroup
objectClass: lisGroup
groupType: private
description: dontcare
cn: ${USERNAME}
gidNumber: ${USERID}

EOF

