#!/bin/sh
# $Id: hosts41to40shared,v 1.2.12.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

# Script hosts41to40shared (NOTE) Name was keep and the proto files
# will install it as hosts42to40shared
#
# Convert 4.2 version 4 format back to a 4.0 version 3 format for all
# shared filesystems that were found for this server. If the conversion
# is successful for a filesystem, the hosts.xx.42 file is removed. If
# all conversions are successful, the hosts.master.42 is removed. The 
# hosts.info.41 file will remain in order to show a history of the
# filesystems that were converted.

HOSTNAME=`hostname`
if [ ! -f /etc/opt/SUNWsamfs/hosts.master.42 ]; then
	echo No shared filesystems host files to convert from 42 to 40 format
	echo for server $HOSTNAME
	exit 0
fi

OFILE=/etc/opt/SUNWsamfs/hosts.info1.42
DATE=`/usr/bin/date +%m%d%y-%H%M`
echo Output from hosts42to40shared for server $HOSTNAME > $OFILE
echo hosts42to40shared was run on $DATE >> $OFILE
echo " " >> $OFILE
echo Filesystems that will be converted are the following: >> $OFILE
echo " " >> $OFILE
cat /etc/opt/SUNWsamfs/hosts.master.42 >> $OFILE
echo " " >> $OFILE
echo Results from hosts42to40shared script >> $OFILE
echo " " >> $OFILE

for file in `cat /etc/opt/SUNWsamfs/hosts.master.42`
do
	echo Running samsharefs to convert from 42 to 40 format on filesystem - $file >>$OFILE
	if [ -f /etc/opt/SUNWsamfs/hosts.$file ]; then
		mv /etc/opt/SUNWsamfs/hosts.$file /etc/opt/SUNWsamfs/hosts.$file.orig
		mv /etc/opt/SUNWsamfs/hosts.$file.42 /etc/opt/SUNWsamfs/hosts.$file
		samsharefs -Ru $file >/dev/null
		if [ $? != 0 ]; then
			echo samsharefs command failed for filesystem $file >> $OFILE
			echo $file >/etc/opt/SUNWsamfs/hosts.master.40
			cp /etc/opt/SUNWsamfs/hosts.$file /etc/opt/SUNWsamfs/hosts.$file.42
		fi
		mv /etc/opt/SUNWsamfs/hosts.$file.orig /etc/opt/SUNWsamfs/hosts.$file
	else
		mv /etc/opt/SUNWsamfs/hosts.$file.42 /etc/opt/SUNWsamfs/hosts.$file
		samsharefs -Ru $file >/dev/null
		if [ $? != 0 ]; then
			echo samsharefs command failed for filesystem $file >> $OFILE
			echo $file >/etc/opt/SUNWsamfs/hosts.master.40
			cp /etc/opt/SUNWsamfs/hosts.$file /etc/opt/SUNWsamfs/hosts.$file.42
		fi
		rm /etc/opt/SUNWsamfs/hosts.$file
	fi
done

echo " " >> $OFILE
if [ -f /etc/opt/SUNWsamfs/hosts.master.40 ]; then
	echo samsharefs failed for the following shared filesystems >> $OFILE
	cat /etc/opt/SUNWsamfs/hosts.master.40 >> $OFILE
	echo You will need to determine the reason for the failure and rerun the >> $OFILE
	echo hosts42to40shared script to complete the conversion >> $OFILE
	mv /etc/opt/SUNWsamfs/hosts.master.40 /etc/opt/SUNWsamfs/hosts.master.42
else
	echo Conversions of all shared filesystems completed successfully >> $OFILE
	rm /etc/opt/SUNWsamfs/hosts.master.42
	rm /etc/opt/SUNWsamfs/hosts42to40shared
fi

cat $OFILE
echo " " >> /etc/opt/SUNWsamfs/hosts.info.42
cat $OFILE >> /etc/opt/SUNWsamfs/hosts.info.42
rm $OFILE
