#!/bin/sh
#
#  Script:		set_server_mode
#  Instance:		1
#  Description:		puts nici in a server mode. This is bundled with the 
#			installation pacakge
#  %created_by:		svedula %
#  %date_created:	Wed May 04 13:53:04 2005 %

#############################################################################
# Sets NICI in server mode. By default NICI is installed in client mode.
# Run this script only if you understand the difference between client and 
# server mode. Putting NICI in server mode is the responsibility of the 
# application.
#############################################################################

#############################################################################
# Please note that a nicifk file is bundled with the NICI installation and 
# copied into the /var/opt/novell/nici directory under the name nicifk.new
# This script relies on the existence of the nicifk.new file to put NICI in
# server mode.  This script should be part of the application's install 
# package. It should never be put into the product directory.
#
# This script does the following --
# 1. Check if NICI is already in a server mode, if so we just bail out. We do
#    not change the nicifk file on the box.
# 2. If NICI is in client mode or if the wks and nfk files do not exist, copy 
#    the nicifk.new file into the nicifk file and run primenici.
# 3. If the nicifk.new file does not exist, we bail out giving an error.
#
##############################################################################

##############################################################################
# Return Values :
# 0 - Successfully put NICI in server mode.
# 1 - Could not put NICI in server mode.(The nicifk.new file does not exist)
##############################################################################
ret=0
if [ -s /var/opt/novell/nici/nicifk.new ]
then
    if [ -s /var/opt/novell/nici/nicifk ]
    then
	echo "set_server_mode: NICI already in server mode. Running primenici"
	/var/opt/novell/nici/primenici
	ret=`expr $ret + $?`
    else
	cp /var/opt/novell/nici/nicifk.new /var/opt/novell/nici/nicifk
	chmod 644 /var/opt/novell/nici/nicifk
	/var/opt/novell/nici/primenici
	echo "set_server_mode: NICI set in server mode"
	ret=`expr $ret + $?`
    fi
else
    echo "set_server_mode: A copy of nicifk.new does not exist"
    if [ -s /var/opt/novell/nici/nicifk ]
    then
	echo "set_server_mode: The nicifk file exists already."
	echo "set_server_mode: NICI already in server mode. Running primenici"
	/var/opt/novell/nici/primenici
	ret=`expr $ret + $?`
    else
	echo "set_server_mode: Error! NICI Mode not changed"
	ret=1
    fi
fi

exit $ret
