#!/usr/bin/env bash
#
# Copyright (C) 2003 VA Linux Systems Japan, K.K. All rights reserved.
#
# LICENSE NOTICE
#
#  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.
#

set -e

eval `ultrapossum-config init`
trap "eval `ultrapossum-config term`"

if test "x$ULTRAPOSSUM_CONFIG_BACKEND_LDAP_URI" = "x"; then

  if test "x$LDAPSURILIST" != "x"; then
    prot="ldaps"
    if test "x$LDAPSLISTENPORT" != "x"; then
      port=":$LDAPSLISTENPORT"
    fi
  else
    prot="ldap"
    if test "x$LDAPLISTENPORT" != "x"; then
      port=":$LDAPLISTENPORT"
    fi
  fi

  ULTRAPOSSUM_CONFIG_BACKEND_LDAP_URI="$prot://$LDAPMASTER$port/"

fi

if test "x$ULTRAPOSSUM_CONFIG_BACKEND_LDAP_BASEDN" = "x"; then
  ULTRAPOSSUM_CONFIG_BACKEND_LDAP_BASEDN="ou=config,$SUFFIX"
fi

if test "x$ULTRAPOSSUM_CONFIG_BACKEND_LDAP_BINDDN" = "x"; then
  ULTRAPOSSUM_CONFIG_BACKEND_LDAP_BINDDN="$ROOTDN"
fi

if test "x$ULTRAPOSSUM_CONFIG_BACKEND_LDAP_BINDPW" = "x"; then
  ULTRAPOSSUM_CONFIG_BACKEND_LDAP_BINDPW="$ROOTPW"
fi

echo "ULTRAPOSSUM_CONFIG_BACKEND=ldap"
echo "ULTRAPOSSUM_CONFIG_BACKEND_LDAP_URI=$ULTRAPOSSUM_CONFIG_BACKEND_LDAP_URI"
echo "ULTRAPOSSUM_CONFIG_BACKEND_LDAP_BASEDN=$ULTRAPOSSUM_CONFIG_BACKEND_LDAP_BASEDN"
echo "ULTRAPOSSUM_CONFIG_BACKEND_LDAP_BINDDN=$ULTRAPOSSUM_CONFIG_BACKEND_LDAP_BINDDN"
echo "ULTRAPOSSUM_CONFIG_BACKEND_LDAP_BASEDN=$ULTRAPOSSUM_CONFIG_BACKEND_LDAP_BINDPW"



