#!/bin/sh
#
# Copyright (c) AT&T 1999. All rights reserved.
#
# @(#)regupgrade.sh	1.16	6/29/99
#
# regupgrade.sh - script to build regini.path
#
# verify that this is running as root
#
ID="`id | cut -d\( -f1`"
if [ "${ID}" != "uid=0" ]
then
        echo "${0} must be run as root!"
        exit 1
fi
#
# '.' in the lmpaths configuration file
#
LMPATHS="`/bin/dirname $0`/../lib/lmpaths"

if [ -f ${LMPATHS} ]
then
    . ${LMPATHS}
else
    . lmpaths
fi

#
# verify that lanman.ini file exists
#
if [ ! -r ${LANMAN_INI_PATH} ]
then
	echo "error: ${LANMAN_INI_PATH} not found."
	exit 3
fi
#
# verify that reg.ini file exists
#
if [ ! -r ${REG_INI_PATH} ]
then
	echo "error: ${REG_INI_PATH} not found."
	exit 4
fi
#
# import things from lanman.ini if upgrading
#
TMP=/tmp/regupdate.tmp
TMP2=/tmp/regupdate.tmp2
rm -f ${TMP} ${TMP2}
for parameter in listenname
do
	grep "^${parameter}=" ${LANMAN_INI_PATH} > ${TMP}
	if [ $? -eq 0 ]
	then
		echo "Upgrading <${parameter}>..."
		cp ${REG_INI_PATH} ${TMP2}
		grep -v "^${parameter}" ${TMP2} > ${REG_INI_PATH}
		cat ${TMP} >> ${REG_INI_PATH}
	fi
done
#
# upgrade things from lanman.old
#
if [ -f "${LANMAN_OLD_PATH}" ]
then
	#
	# grab values that have the same datatype
	#
	for parameter in \
		accessalert \
		bigendian_luid_compatibility \
		qsched \
		uniquesuffixlength \
		namespacemapping \
		autodisconnect \
		erroralert \
		logonalert \
		srvannounce \
		enablesoftcompat \
		maxfilesize \
		maxzerofillkb\
		country \
		feabufsize \
		sparesrvtime \
		locale \
		adminuserid \
		admingroupid \
		guardtime \
		logon \
		random \
		repl_dirowner \
		repl_dirgroup \
		repl_fileowner \
		repl_filegroup \
		maxruns \
		masterupdate \
		backupupdate \
		backuprecovery \
		maxapplog \
		maxerrlog \
		maxauditlog \
		exclude \
		maxclisess \
		maxsrvsess \
		logonquery \
		querydelay \
		ssipasswdage \
		relogondelay \
		randomize \
		scripts \
		powertime \
		cntsharecache \
		cntsharereads \
		appretention \
		errorretention \
		auditretention \
		fileperms \
		dirperms \
		eafileprefix \
		grpupdate \
		hashsize \
		ustructs \
		ipcreads \
		locknap \
		mailslothold \
		maxdirbufsize \
		maxlocknap \
		maxrawsize \
		maxmsgsize \
		maxsvcwait \
		newusershell \
		nonexistusers \
		nosendtime \
		oplocktimeout \
		rdatrend \
		qnamelen \
		unixdirchk \
		uxclosecount \
		interval
	do
		grep "^${parameter}=" ${LANMAN_OLD_PATH} >> ${REG_INI_PATH}
	done

	#
	# fixup string values
	#
	for parameter in \
		srvcomment \
		mappingseparator \
		powermessage \
		poweraddr \
		usrcomment \
		userpath \
		runpath \
		adminpath \
		userremark \
		exportlist \
		exportpath \
		importlist \
		importpath
	do
		VALUE="`grep ${parameter}= ${LANMAN_OLD_PATH} | cut -d'=' -f2`"
		if [ -n "${VALUE}" ]
		then 
			echo "${parameter}='${VALUE}'" >> ${REG_INI_PATH}
		fi
	done

	#
	# fixup multi-string values
	#
	for parameter in \
		alertnames \
		enable_soft_file_ext
	do
		VALUE="`grep ${parameter}= ${LANMAN_OLD_PATH} | cut -d'=' -f2`"
		if [ -n "${VALUE}" ]
		then 
			echo "${parameter}='	${VALUE}'" | sed 's/[ ,]/,	/g' | tr ',' '\012' >> ${REG_INI_PATH}
		fi
	done

	#
	# for values that were yes/no in lanman.ini, but are now DWORDs,
	# we must do some extra work...
	#
	for parameter in \
		stoponcore \
		unixquotas \
		mixedcasesupport \
		truncatedextensions \
		srvhidden \
		useoplock \
		keepadmshares \
		sbstelladmin \
		sbstelluser \
		spareserver \
		createunixuser \
		synchomedir \
		fileflush \
		forcediracl \
		forcefileacl \
		tryuser \
		nfsroot \
		ntfs \
		lmannounce \
		forceunique \
		ignoresigpwr \
		sharemkdir \
		coreok \
		byemessage \
		memorymap \
		syncaclfile \
		msgheader \
		nfslocks \
		ignoreunix \
		write_behind \
		unixlocks \
		morelog \
		update
	do
		VALUE="`grep ${parameter}= ${LANMAN_OLD_PATH} | cut -d'=' -f2`"
		if [ -n "${VALUE}" ]
		then 
			if [ 	"${VALUE}" = "yes" 	-o \
				"${VALUE}" = 'y'	-o \
				"${VALUE}" = 'si'	-o \
				"${VALUE}" = 'da'	-o \
				"${VALUE}" = 'oui'	-o \
				"${VALUE}" = 'nai'	-o \
				"${VALUE}" = 'ya'	-o \
			 	"${VALUE}" = "YES" 	-o \
				"${VALUE}" = 'Y'	-o \
				"${VALUE}" = 'SI'	-o \
				"${VALUE}" = 'DA'	-o \
				"${VALUE}" = 'OUI'	-o \
				"${VALUE}" = 'NAI'	-o \
				"${VALUE}" = 'YA'		]
			then
				echo "${parameter}=1" >> ${REG_INI_PATH}
			else
				echo "${parameter}=0" >> ${REG_INI_PATH}
			fi
		fi
	done
	#
	# upgrade 'replicate' flag
	# if none of the above, use the default value
	#
	REPLICATE="`grep replicate ${LANMAN_OLD_PATH} | cut -d'=' -f2`"
	if [ "${REPLICATE}" = "EXPORT" -o "${REPLICATE}" = "export" ]
	then
		echo "replicate=1" >> ${REG_INI_PATH}
	elif [ "${REPLICATE}" = "IMPORT" -o "${REPLICATE}" = "import" ]
	then
		echo "replicate=2" >> ${REG_INI_PATH}
	elif [ "${REPLICATE}" = "BOTH" -o "${REPLICATE}" = "both" ]
	then
		echo "replicate=3" >> ${REG_INI_PATH}
	fi

	# update replicator pulse parameter
	echo "pulse=`$OLDSRVCONFIG_PATH -g replicator,pulse`" >> ${REG_INI_PATH}

	# update netlogon pulse parameter
	echo "NetlogonPulse=`$OLDSRVCONFIG_PATH -g netlogon,pulse`" >> ${REG_INI_PATH}
fi
#
# done...
#
echo "${REG_INI_NAME} upgraded successfully"
rm -f ${TMP} ${TMP2}
exit 0
# end of file
