#!/bin/bash
######################################################################
# perditiondb_ldap_makedb                                     May 2000
# Horms                                             horms@vergenet.net
#
# Sample programme to make an LDAP based popmap
#
# perdition
# Mail retrieval proxy server
# Copyright (C) 1999  Horms
# 
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 2 of the
# License, or (at your option) any later version.
# 
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
# 02111-1307  USA
#
######################################################################


DEFAULT_DC="cn=Manager, dc=my-domain, dc=com"

if [ -z "$(type -path ldapadd)" ]; then
  echo "Could not find ldapadd command. Bailing" >&2
  exit 1
fi



echo
echo "openldap requires a binddn to bind to the LDAP directory"
echo "The default is \"$DEFAULT_DC\". To use this"
echo "hit return, otherwise enter a host to connect to, it should be a"
echo "should be a string-represented DN as defined in RFC 1779."
echo -n "Enter binddn [$DEFAULT_DC]: " >&2
read dc
if [ -z "$dc" ]; then
  dc="$DEFAULT_DC"
fi


echo
echo "You will need to enter the sevrer for the"
echo "binddn: \"$dc\"."
echo "The default mau be \"secret\", you should change"
echo "your ldap configuration if this is the case."
echo -n "Enter the password for \"$dc\": " >&2
stty -echo
read rootpw
stty echo
echo

echo "Initialising LDAP popmap..."

ldapadd -D "$dc" -w "$rootpw" << __EOF__
dn: dc=my-domain, dc=com
dc: my-domain

dn: ou=mailbox, dc=my-domain, dc=com
ou: mailbox

dn: uid=horms, ou=mailbox,  dc=my-domain, dc=com
uid: horms
username: horms
mailhost: localhost
port: 110

dn: uid=tymm, ou=mailbox, dc=my-domain, dc=com
uid: tymm
username: tymm
mailhost: localhost
__EOF__

if [ $? != 0 ]; then
  echo "Error initialising LDAP popmap. Bailing" >&2
  exit 1
fi
echo Done
