#!/bin/bash
# $Header: /cvs/WebShield/wsrc/files/mgmt/systemservices.d/10_nameconf,v 1.5 2004/06/14 15:43:03 bwhittak 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
PATH=$wsPATH:$PATH
option=${1}

machineconf=$XMLCONFDIR/machine.xml
networkconf=$XMLCONFDIR/network.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
[[ -f "$networkconf" ]] || exit 1

start()
{
    # Setup /etc/resolv.conf
    conf=$(xsltproc ${WSMGMT}/resolv.xsl $machineconf)
    if [[ "$conf" != "$(</etc/resolv.conf)" ]]; then
	echo "$conf" >/etc/resolv.conf
	[[ -f $WS_RESTART_LIST ]] && echo syslog >>"$WS_RESTART_LIST"
    fi

    # Setup named.conf
    conf=$(xsltproc ${WSMGMT}/named.xsl $networkconf)
    if [[ "$conf" != "$(</etc/named.conf)" ]]; then
	echo "$conf" >/etc/named.conf
	[[ -f $WS_RESTART_LIST ]] && echo named >>"$WS_RESTART_LIST"
    fi

    # Setup /etc/hosts
    xsltproc ${WSMGMT}/hosts.xsl $machineconf > /etc/hosts

    # Setup /etc/sysconfig/network
    conf=$(xsltproc ${WSMGMT}/network.xsl $machineconf)
    if [[ "$conf" != "$(</etc/sysconfig/network)" ]]; then
	echo "$conf" >/etc/sysconfig/network
	[[ -f $WS_RESTART_LIST ]] && echo network >>"$WS_RESTART_LIST"
    fi
    (
	eval "$conf" || exit
	[[ -n $HOSTNAME ]] && hostname "$HOSTNAME"
	[[ -n $NISDOMAIN ]] && domainname "$NISDOMAIN"
    )
}

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

exit 0

