#sccs	"@(#)fndetc/convert:convert	1.16"

#	FILE:  convert                      DATE:  March 7, 1986
#	CREATED BY:  Mark Emmerich
#
#	This program reads the file SPECIAL to determine what
#	to do about each of the programs contained therein.
#	SPECIAL is assumed to have the following format:
#
#	  PATH           S                     or
#	  PATH           C      CONVPROG
#
#	where PATH is the full path name, S indicates that the
#	file is to be "Saved" from the earlier version, C indicates
#	that the file is to be "Converted", and CONVPROG indicates
#	which program to use to perform the conversion.

SAVEDIR=/u/SAVE3.5
CONVDIR=/u/CONV3.5
LISTING=$SAVEDIR/listing
SAVELIST=/tmp/SAVED

export SAVEDIR CONVDIR SAVELIST

#  Begin a new conversion log.

echo `date`"\nCONVERSION TO 3.51 BEGINNING\n\n" > /usr/adm/convert.log

> $SAVELIST

# Perform conversions as specified in the SPECIAL file.

while read FNAME SAVE CONVPROG
do
	if [ \( -s ${SAVEDIR}${FNAME} \) -o \
	     \( -s ${CONVDIR}${FNAME} \) ]
	then
		echo "Converting the file $FNAME ... \c"
		SNAME=`basename $FNAME`
		if [ "$SAVE" = "S" ]
		then
			cp  ${SAVEDIR}${FNAME} ${FNAME}
			rm -r  ${SAVEDIR}${FNAME}
		else
			./${CONVPROG}  ${CONVDIR}${FNAME} ${FNAME}
			rm -r  ${CONVDIR}${FNAME}
		fi
		echo "$FNAME	---- CONVERSION ACCOMPLISHED" \
		   >> /usr/adm/convert.log
		echo "done."
	else
		echo "$FNAME	no file found for conversion" \
		   >> /usr/adm/convert.log
	fi

done < SPECIAL

# The /usr/spool/lp tree is no longer saved due to incompatabilities with
# earlier releases.

##  PROTECT UPDATED VERSIONS OF THE SOFTWARE

while read FILE CHKSUM
do
	if [ ! "$FILE" ]
	then	continue
	fi

	if expr "$FILE" : "#" > /dev/null 2>&1
	then	continue
	fi

	if [ -s "$FILE" ]
	then
		CURSUM=`sum $FILE | cut -f1 -d' '`
		if [ "$CURSUM" = "$CHKSUM" ]
		then
			GOODFILE="/etc/fixes/`basename $FILE`"
			cp $GOODFILE $FILE
			echo "$FILE converted on `date`" >> /etc/.fixedfiles
			echo "$FILE	---- CONVERSION ACCOMPLISHED" \
			   >> /usr/adm/convert.log
		fi
	fi
done < /etc/fixes/.fixedlist

#  Convert the existing 3.0 (System V.0) libraries to 3.51 (System 5.2).
#  arconvert looks for its own libraries (/lib & /usr/lib) and does its
#  duty to them.

#  Commented out 3/18/87 - ELL
#  arconvert

#  Restore saved voice mail software.

if [ -x $SAVEDIR/voicemail ]
then
	mv /bin/mail /bin/oldmail
	rm -f /bin/rmail
	mv $SAVEDIR/voicemail /bin/mail
	chown bin /bin/mail
	chgrp mail /bin/mail
	chmod 2755 /bin/mail
	ln /bin/mail /bin/rmail
	echo "/bin/mail	---- CONVERSION ACCOMPLISHED" \
	   >> /usr/adm/convert.log
fi

#  Change the owner and group for the file /usr/spool/lp/default. This is
#  a bug in earlier versions.

chown lp /usr/spool/lp/default >/dev/null 2>&1
chgrp other /usr/spool/lp/default >/dev/null 2>&1

#  Complete the conversion log.

echo `date`"\nCONVERSION TO 3.51 ACCOMPLISHED\n\n" >> /usr/adm/convert.log

#  Remove old version of masterupd saved by rm3.0stuff for
#  the conversion.

	rm -f $SAVEDIR/masterupd

#  Look for anything left behind.

SREMAIN=`find $SAVEDIR -type f -print` 2> /dev/null
CREMAIN=`find $CONVDIR -type f -print` 2> /dev/null

if [ "${SREMAIN}${CREMAIN}" ]
then
	cat << -END-


All system files have now completed their conversions.  Your
system is effectively a 3.51 system.  There were however, files
on your system which were left over after the conversion.

A copy of these files has been saved in folders:

                  $SAVEDIR      or
                  $CONVDIR

			should you wish to examine them.


-END-
	sleep 18
else
	cat << -END-


Your system files have been converted to 3.51.

A log of the conversion has been saved in /usr/adm/convert.log.


-END-
	sleep 2
fi

if [ -s $SAVELIST ]
then
	cat << -END-
The following files have been replaced by newer versions.  The old
version of each has been renamed, starting with the original file
name and ending with '-old', should you wish to examine them.

     For example, the original file "/etc/shutdown" has been
     renamed to "/etc/shutdown-old".

-END-
	cat $SAVELIST
	echo "\n"
	sleep 20
fi

rm -f $SAVELIST
sleep 2

