#!/bin/bash
# $Header: /cvs/WebShield/wsrc/files/mgmt/systemservices.d/10_nwaconf,v 1.5 2004/06/24 14:37:11 pboyle Exp $
#
# Copyright (C) 2004 Networks Associates Technology Inc. All Rights Reserved
#
if [ -f $NETAWSS/.profile.vars ]; then
 . $NETAWSS/.profile.vars
else
 . /var/NAIENV/.profile.vars
fi
shopt -s nullglob
shopt -s extglob
PATH=$wsPATH:$PATH
option=${1}

machineconf=$XMLCONFDIR/machine.xml

exec </dev/null		# whatever stdin is we don't want it

# not much point if there's no XML config
[[ -f "$machineconf" ]] || exit 1

config='Plugin Path=STRING:/opt/NETAepoagt/bin/libagplugin.so.3.0
SoftwareID=STRING:EPO_CHNL1000
Uninstall Command=STRING:/opt/NETASSOC/EPO_CHNL1000/Uninstall.sh
Product Name=STRING:WebShield pseudo point product
Version=STRING:3.0.0
Language=STRING:English
Installed Path=STRING:/opt/NETASSOC/EPO_CHNL1000'

start()
{

    # Set up writeable directories
    # /opt/NETASSOC
    od=/opt/NETASSOC vd=/var/NETASSOC
    if [[ -d $od ]]; then
	mkdir -p $vd
	if [[ ! $vd -ef $od ]] || umount $od; then
	    # writable version not mounted
	    cp -a $od/. $vd
	    chown -R uucp $vd
	    chmod -R u+wX $vd
	    mkdir -p $vd/EPO_CHNL1000
	    echo "$config" > $vd/EPO_CHNL1000/config
	    mount --bind $vd $od
	fi
    fi
    # /opt/NETAepoagt/scratch
    od=/opt/NETAepoagt/scratch vd=/logs/NETAepoagt
    if [[ -d $od ]]; then
	mkdir -p $vd
	if [[ ! $vd -ef $od ]] || umount $od; then
	    # writable version not mounted
	    cp -a $od/. $vd
	    chown -R uucp $vd
	    chmod -R u+wX $vd
	    mount --bind $vd $od
	fi
    fi

    # Setup /etc/sysconfig/nwa_ws
    conf=$(xsltproc ${WSMGMT}/nwa_conf.xsl $machineconf)
    scfile=/etc/sysconfig/nwa_ws
    if [[ ! -f $scfile || "$conf" != "$(<$scfile)" ]]; then
	echo "$conf" >/etc/sysconfig/nwa_ws
	(#in a subshell in case of accidents with eval
		eval "$conf"
		if [[ -n $EPO_SERVER ]]; then
			chkconfig nwa_ws on
		else
			chkconfig nwa_ws off
			/etc/init.d/nwa_ws stop
		fi
	)
	[[ -f $WS_RESTART_LIST ]] && echo nwa_ws >>"$WS_RESTART_LIST"
    fi
}

case $option in
    (start|restart|reload) start ;;
    (stop|status) : ;;
    (*) echo $"Usage: $0 {start|stop|restart|reload|status}"; exit 1 ;;
esac

exit 0

