#!	/bin/csh -f
#
#	@(#)mkconfig	13.1 (RC International) 91/02/02
#

if ( $#argv != 0 && $1 == -l ) then
        set local = -l
        shift
else
        set local =
endif

if ( $#argv != 0 && ( $#argv != 1 || $1 != -check ) ) then
	echo "usage:  `basename $0`  [ -l ]  [ -check ]"
	exit  1
endif

set check =
if ( $#argv == 1 ) then
	set check = 1
endif

set puname = `/bin/puname`
set exit_code = 0
onintr cleanup
set cur_dir = `pwd`
set mkconfdir = /$puname/tmp/mkconfdir$$
mkdir $mkconfdir
cp *[a-z]tab $mkconfdir
if ( $status ) goto cleanup
cd $mkconfdir
/$puname/etc/mk_config $local
if ( $status ) then
	if ( $check ) then
		echo Error"(s)" encountered
	else
		echo Error"(s)" encountered - no update
	endif

	set exit_code = 1
else
	if ( $check ) then
		echo ===== done - check OK
	else
		cp state_* *_tab $cur_dir
		if ( $status ) then
			echo Unsuccessful update - database may be inconsistent
			set exit_code = 1
		else
			echo ===== done - update OK
		endif
	endif
endif

cleanup:
cd $cur_dir
rm -rf $mkconfdir >& /dev/null
exit $exit_code
