#!/bin/sh
:       '(c) Copyright  Empress Software Inc.   1983, 2004'

if test "$EMPRESSPATH" = ""
then
	echo "EMPRESSPATH must be set"
	exit 1
elif test ! -d $EMPRESSPATH/config
then
        echo "invalid EMPRESSPATH"
        exit 1
fi

ME=`$EMPRESSPATH/common/sys_bin/getuname`

D=$EMPRESSPATH/config

case $1 in
  -unset)	UNSET=true
		;;
esac

if test "$MSDEVUTIL_PATH" != ""
then
	FTYPE=`$MSDEVUTIL_PATH/file_type $D`
	if test "$FTYPE" = "link_dir"
	then
		$MSDEVUTIL_PATH/mkr $D
	fi
fi

cd $D

if test "$UNSET" = "true"
then
	cp netserver.cfg._ netserver.cfg

	cp initfile initfile.v0
	rm initfile
	sed -e 's;MSUSERAUTHCONFIGFILE=.*;MSUSERAUTHCONFIGFILE=;' < initfile.v0 > initfile
	rm initfile.v0

	rm -f userauth.cfg
	rm -f password

else

	#
	#Modify the Administrator to be the login
	#
	rm -f netserver.cfg
	sed -e "
		s/ADMINISTRATOR=.*/ADMINISTRATOR=${ME}/
	" < netserver.cfg._ > netserver.cfg

	#
	# Modify the initfile to reflect the authorization file location
	# 
	cp initfile initfile.v0
	rm initfile
	sed -e 's;MSUSERAUTHCONFIGFILE=.*;MSUSERAUTHCONFIGFILE="userauth.cfg";' < initfile.v0 > initfile
	rm initfile.v0

	#
	# Set up the authrorization file that the user 
	# will use to enable automatic start up.
	#
	test "$HOME" = "" && HOME=`cd; pwd`
	USERDATADIR=$HOME/.empress

	test -d $USERDATADIR || mkdir -p $USERDATADIR

	sed -e "
		s/LOGIN=.*/LOGIN=${ME}/
	" < userauth.cfg._ > $USERDATADIR/userauth.cfg
	chmod 600 $USERDATADIR/userauth.cfg

	rm -f password
	$EMPRESSPATH/bin/emppassword empodbcsv create
	$EMPRESSPATH/bin/emppassword empodbcsv add $ME -c "Administrative User"  -password ""

fi
