#!/bin/sh
# BEGIN COPYRIGHT BLOCK
# Copyright (C) 2001 Sun Microsystems, Inc.  Used by permission.
# Copyright (C) 2005 Red Hat, Inc.
# All rights reserved.
#
# 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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
#

# END COPYRIGHT BLOCK

# This script sets up the environment for the httpd server and starts it.
# There are two parameters which must be replaced - sroot and httpd
# for httpd, on RHEL, this will typically be something like /usr/sbin/httpd.worker
# On HP-UX, this may be /opt/hpws/apache/bin/httpd.

SERVER_ROOT=%%%sroot%%% ; export SERVER_ROOT
NETSITE_ROOT=$SERVER_ROOT ; export NETSITE_ROOT
ADMSERV_ROOT=$SERVER_ROOT/admin-serv ; export ADMSERV_ROOT

unset PASSWORD_PIPE

LD_LIBRARY_PATH=${SERVER_ROOT}/bin/admin/lib:${SERVER_ROOT}/lib:${LD_LIBRARY_PATH};export LD_LIBRARY_PATH
LIBPATH=${LD_LIBRARY_PATH}:${LIBPATH}:/usr/threads/lib:/usr/ibmcxx/lib:/usr/lib:/lib; export LIBPATH
SHLIB_PATH=${LD_LIBRARY_PATH}:${SHLIB_PATH}; export SHLIB_PATH

NS_SERVER_HOME=${SERVER_ROOT}; export NS_SERVER_HOME
PATH=${SERVER_ROOT}/bin/admin/bin:${PATH}; export PATH

HTTPD=%%%httpd%%%

# see if httpd is linked with the openldap libraries - we need to override them
OS=`uname -s`
if [ $OS = "Linux" ]; then
    hasol=0

    /usr/bin/ldd $HTTPD 2>&1 | grep libldap > /dev/null 2>&1 && hasol=1

    if [ $hasol -eq 1 ] ; then
        LD_PRELOAD="${SERVER_ROOT}/bin/admin/lib/libssl3.so ${SERVER_ROOT}/bin/admin/lib/libldap50.so"
        export LD_PRELOAD
    fi
fi

$HTTPD -k start -d $ADMSERV_ROOT -f $ADMSERV_ROOT/config/httpd.conf "$@"
