#!/bin/sh
# $Id: backto,v 1.1.2.1 2004/09/10 17:48:13 jp148923 Exp $

#   SAM-QFS_notice_begin
#
#   Solaris 2.x Sun Storage & Archiving Management File System
#
#   Copyright (c) 2004 Sun Microsystems, Inc.
#   All Rights Reserved.
#
#   Government Rights Notice
#   Use, duplication, or disclosure by the U.S. Government is
#   subject to restrictions set forth in the Sun Microsystems,
#   Inc. license agreements and as provided in DFARS 227.7202-1(a)
#   and 227.7202-3(a) (1995), DRAS 252.227-7013(c)(ii) (OCT 1988),
#   FAR 12.212(a)(1995), FAR 52.227-19, or FAR 52.227-14 (ALT III),
#   as applicable.  Sun Microsystems, Inc.
#
#   SAM-QFS_notice_end

ETCDIR=/etc/opt/SUNWsamfs
SBINDIR=/opt/SUNWsamfs/sbin

usage() {

	echo "Usage: backto { 4.0 | 4.1 }"
	exit 1
}
	
echo " "

if [ "$1" = "4.0" ]; then
	if [ -d /var/sadm/pkg/SUNWsamfsr ]; then
		echo "Converting back a SAM-FS/QFS system"

		echo "Renaming files to the 4.0 names."

		# rename rft.cmd to ftp.cmd

		if [ ! -f ${ETCDIR}/ftp.cmd ] ; then
			if [ -f ${ETCDIR}/rft.cmd ] ; then
				/bin/cp ${ETCDIR}/rft.cmd ${ETCDIR}/ftp.cmd
			fi
		fi
	else
		echo "Converting back for a Standalone QFS system"
	fi

	if [ ! -f ${ETCDIR}/LICENSE.4.0 ]; then
		echo " "
		echo "No LICENSE.4.0 file exists copying LICENSE.4.2 to LICENSE.4.0"
		echo " "
		/bin/cp ${ETCDIR}/LICENSE.4.2 ${ETCDIR}/LICENSE.4.0
	else
		/bin/diff ${ETCDIR}/LICENSE.4.2 ${ETCDIR}/LICENSE.4.0 > /dev/null
		if [ $? -ne 0 ]; then
			echo " "
			echo "Your 4.2 License is different from your 4.0 License"
			echo "Leaving both Licenses as they are. Upgrading to 4.2"
			echo "in the future will not run the upgrade scripts because"
			echo "the LICENSE.4.2 file will exist"
			echo " "
		else
			echo " "
			echo "Removing /etc/opt/SUNWsamfs/LICENSE.4.2 file, so a future"
			echo "upgrade will copy all necessary files to the correct locations"
			echo " "
			rm ${ETCDIR}/LICENSE.4.2
		fi
	fi

	echo "Conversion to the 4.0 names complete."

	# Save any hosts information for shared filesystems

	${SBINDIR}/backto40shared

elif [ "$1" = "4.1" ]; then

	echo "Renaming files to the 4.1 names."

	if [ ! -f ${ETCDIR}/LICENSE.4.1 ]; then
		echo " "
		echo "No LICENSE.4.1 file exists, copying LICENSE.4.2 to LICENSE.4.1"
		echo " "
		/bin/cp ${ETCDIR}/LICENSE.4.2 ${ETCDIR}/LICENSE.4.1
	else
		/bin/diff ${ETCDIR}/LICENSE.4.2 ${ETCDIR}/LICENSE.4.1 > /dev/null
		if [ $? -ne 0 ]; then
			echo " "
			echo "Your 4.2 License is different from your 4.1 License"
			echo "Leaving both Licenses as they are. Upgrading to 4.2"
			echo "in the future will not run the upgrade scripts because"
			echo "the LICENSE.4.2 file will exist"
			echo " "
		else
			echo " "
			echo "Removing /etc/opt/SUNWsamfs/LICENSE.4.2 file, so a future"
			echo "upgrade will copy all necessary files to the correct locations"
			echo " "
			rm ${ETCDIR}/LICENSE.4.2
		fi
	fi

	echo "Conversion to the 4.1 names complete."

else
	usage
fi
