#!/sbin/sh
#
#       Subset Control Program for the AFAADVDAEMON subset.

[ `./bin/machine` = alpha ] && . /usr/share/lib/shell/libscp

case $ACT in

M) case $1 in
	-l)	[ `./bin/machine` = "alpha" ] ||
		{
			STL_ScpInit
			Z_BP=`echo $_SUB | sed s/$_VCODE//`

			echo "$Z_BP installs on DEC OSF/1 AXP systems only."
			exit 1
		}
		;;
	esac
	exit 0
	;;

PRE_[LA])
#	if [ `pwd` != "/" -a ! -f ./tmp/fis ]
#	then  echo "The -D option is not supported for this subset."
#	      exit 1
#	fi

	STL_ScpInit
	Z_BP=`echo $_SUB | sed s/$_VCODE//`

	STL_DepInit

	if STL_DepEval AFAADVANCED$_VCODE not
	then
	   echo "For $_SUB to be installed you must first install AFAADVANCED$_VCODE."
	   if STL_DepEval AFAADVANCED???
	   then
	      echo "In order to install AFAADVANCED$_VCODE, you must first"
	      echo "remove the currently installed AFAADVANCED subset."
	      echo "Use the command:"
	      echo "      setld -i | grep AFAADVANCED | grep installed"
	      echo "to determine the name of the subset to delete."
	   fi
	   exit 1
	fi

	if STL_DepEval $Z_BP???
	then
	   if STL_DepEval $_SUB not
	   then
	      echo "You must remove the currently installed $Z_BP subset"
	      echo "before you can install the $_SUB subset."
	      echo "Use the command:"
	      echo "      setld -i | grep $Z_BP | grep installed"
	      echo "to determine the name of the subset to delete."
	      exit 1
	   fi
	fi


	/sbin/rm -f ./etc/services.advfsd.temp
	/usr/bin/awk '
		BEGIN { FS="[ 	][ 	]*"; }

		$1 == "advfsd-snmp" && $2 == "1163/udp" {
			next;
		}
		$1 == "advfsd-snmp-trap" && $2 == "1164/udp" {
			next;
		}
		$1 == "AdvFS" && $2 == "30000/tcp" {
			next;
		}

		$1 != "advfsd-snmp" && $2 == "1163/udp" {
			exit 42;
		}
		$1 != "advfsd-snmp-trap" && $2 == "1164/udp" {
			exit 42;
		}
		$1 != "AdvFS" && $2 == "30000/tcp" {
			exit 42;
		}

		{ print; }
		END { exit; }
		' ./etc/services > ./etc/services.advfsd.temp
	if [ $? -eq 42 ]
	then
		/sbin/rm -f ./etc/services.advfsd.temp
		echo " "
		echo "./etc/services has entries that conflict with what"
		echo "is needed by the AdvFS daemon to run."
		echo " "
		echo "This kit needs ports 1163/udp, 1164/udp, and 30000/tcp"
		echo "to all be free in order to install properly."
		echo " "
		exit 1
	fi
	;;

POST_[AL])
	STL_ScpInit
	Z_BP=`echo $_SUB | sed s/$_VCODE//`

	STL_DepInit

	echo "advfsd-snmp	     1163/udp		# advfs private SNMP request port
advfsd-snmp-trap     1164/udp		# advfs private SNMP trap port
AdvFS		    30000/tcp	advfs	# Added for AdvFS daemon command port" >> ./etc/services.advfsd.temp
	echo "Backing up ./etc/services to ./etc/services.advfsd.back...."
	/sbin/cp ./etc/services ./etc/services.advfsd.back
	if [ $? = 0 ]
	then
		echo "Adding entries to ./etc/services file...."
		/sbin/mv ./etc/services.advfsd.temp ./etc/services
		echo "Added entries to ./etc/services file."
	else
		echo "		Backup failed.  Root filesystem is full.
		./etc/services file not modified.

		Aborting installation...."
		exit 1
	fi

	/sbin/rm -f ./var/opt/advfsd/socket/hosts.allow
#
# The following is usually the hostname of the target system
# but in a dms environment, it is actually the name of the server, 
# thus advfsd will by default permit dtadvfs management from the DMS 
# server as well as from the local host, which is always enabled.
#
	echo `hostname` > ./var/opt/advfsd/socket/hosts.allow
	/sbin/chmod 0500 ./var/opt/advfsd/socket/hosts.allow

	echo " "
	echo "dtadvfs administrative access by host " `hostname` " enabled"
	echo "edit /var/opt/advfsd/socket/hosts.allow to change this if desired."
	echo " "

	if STL_IsDataless
	then
		echo " "
		echo "advfsd will be started when the client system next boots"
		echo " "
	else
		./sbin/init.d/advfsd start
		echo " "
		echo "advfsd started"
		echo " "
	fi

	if STL_DepEval PMGRBASE210
	then
	    /sbin/ln -s ./usr/opt/advfsd/etc/srconf/mgr/advfs_info.dat ./etc/srconf/mgr/advfs_info.dat
	    ./etc/srconf/mgr/Update_snmpinfo.dat ADD ADVFS
	fi

	if STL_DepEval $_SUB
	then
	    echo " "
	    echo "The $_DESC was installed successfully."
	    echo " "
	else
	    echo " "
	    echo "***"
	    echo "*** The $_DESC installation failed."
	    echo "***"
	    echo " "
	fi
        ;;

PRE_D)
#	/sbin/kill -KILL `/sbin/ps ax | /sbin/grep advfsd | /sbin/grep -v grep | /usr/bin/cut -b 1-5`

	if STL_IsDataless
	then
		echo " "
	else
		./sbin/init.d/advfsd stop
		echo " "
		echo "advfsd stopped"
		echo " "
	fi

	/sbin/rm -f ./etc/services.advfsd.temp
	/usr/bin/awk '
		BEGIN { FS="[ 	][ 	]*"; }

		$1 == "advfsd-snmp" && $2 == "1163/udp" {
			next;
		}
		$1 == "advfsd-snmp-trap" && $2 == "1164/udp" {
			next;
		}
		$1 == "AdvFS" && $2 == "30000/tcp" {
			next;
		}

		{ print; }
		END { exit; }
		' ./etc/services > ./etc/services.advfsd.temp

	echo "Backing up ./etc/services to ./etc/services.advfsd.back...."
	/sbin/cp ./etc/services ./etc/services.advfsd.back
	if [ $? = 0 ]
	then
		echo "Removing entries from ./etc/services file...."
		/sbin/mv ./etc/services.advfsd.temp ./etc/services
		echo "Removed entries from ./etc/services file."
	else
		echo "		Backup failed.  Root filesystem is full.
		./etc/services file not modified.  The following lines should
		be removed from ./etc/services:

advfsd-snmp	     1163/udp		# advfs private SNMP request port
advfsd-snmp-trap     1164/udp		# advfs private SNMP trap port
AdvFS		    30000/tcp	advfs	# Added for AdvFS daemon command port

"
	fi

	STL_DepInit
	if STL_DepEval PMGRBASE210
	then
	    ./etc/srconf/mgr/Update_snmpinfo.dat REMOVE ADVFS
	    /sbin/rm ./etc/srconf/mgr/advfs_info.dat
	fi
	;;

POST_D)
	STL_ScpInit
	echo " "
        echo "The $_DESC was deleted successfully."
        echo " "
        ;;

C)
	STL_ScpInit
	case $1 in
	INSTALL)
                echo "
The $_DESC includes support for the License
Management Facility (LMF).  A Product Authorization Key (PAK) is
required to use the file-system utilities.  See the AdvFS Installation
Guide for information on registering and activating the PAK.
"
        ;;
        esac
        ;;

V)
	STL_ScpInit
        echo "
############################################################################
# Copyright  (c)  Digital Equipment Corporation, 1996 All Rights Reserved. #
# Unpublished rights reserved under the copyright  laws  of  the  United   #
# States.   The  software  contained on this media is proprietary to and   #
# embodies the confidential technology of Digital Equipment Corporation.   #
# Possession,  use,  duplication  or  dissemination  of the software and   #
# media is authorized only pursuant to  a  valid  written  license  from   #
# Digital   Equipment   Corporation.    RESTRICTED  RIGHTS  LEGEND  Use,   #
# duplication, or disclosure by  the  U.S.   Government  is  subject  to   #
# restrictions   as  set  forth  in  Subparagraph  (c)(1)(ii)  of  DFARS   #
# 252.227-7013, or  in  FAR  52.227-19,  as  applicable.                   #
############################################################################


This Installation Verification Procedure (IVP) tests the file system
daemon.  You can run the Advanced File System Advanced Utilities
IVP (AFAADVANCED$_VCODE) either before or after running this IVP.
"

FAILED=0

if [ ! -r ./usr/lib/nls/msg/en_US.ISO8859-1/AdvFS_agent.cat ]
then
    echo "./usr/lib/nls/msg/en_US.ISO8859-1/AdvFS_agent.cat is not readable."
    FAILED=1
fi

if [ ! -r ./usr/opt/advfsd/etc/srconf/agt/acl.pty ]
then
    echo "./usr/opt/advfsd/etc/srconf/agt/acl.pty is not readable."
    FAILED=1
fi

if [ ! -r ./usr/opt/advfsd/etc/srconf/agt/advfsd.cnf ]
then
    echo "./usr/opt/advfsd/etc/srconf/agt/advfsd.cnf is not readable."
    FAILED=1
fi

if [ ! -r ./usr/opt/advfsd/etc/srconf/agt/agt.pty ]
then
    echo "./usr/opt/advfsd/etc/srconf/agt/agt.pty is not readable."
    FAILED=1
fi

if [ ! -r ./usr/opt/advfsd/etc/srconf/agt/context.pty ]
then
    echo "./usr/opt/advfsd/etc/srconf/agt/context.pty is not readable."
    FAILED=1
fi

if [ ! -r ./usr/opt/advfsd/etc/srconf/agt/mgr.cnf ]
then
    echo "./usr/opt/advfsd/etc/srconf/agt/mgr.cnf is not readable."
    FAILED=1
fi

if [ ! -r ./usr/opt/advfsd/etc/srconf/agt/view.pty ]
then
    echo "./usr/opt/advfsd/etc/srconf/agt/view.pty is not readable."
    FAILED=1
fi

if [ ! -r ./usr/opt/advfsd/etc/srconf/mgr ]
then
    echo "./usr/opt/advfsd/etc/srconf/mgr is not readable."
    FAILED=1
fi

if [ ! -r ./usr/opt/advfsd/etc/srconf/mgr/acl.pty ]
then
    echo "./usr/opt/advfsd/etc/srconf/mgr/acl.pty is not readable."
    FAILED=1
fi

if [ ! -r ./usr/opt/advfsd/etc/srconf/mgr/advfs_info.dat ]
then
    echo "./usr/opt/advfsd/etc/srconf/mgr/advfs_info.dat is not readable."
    FAILED=1
fi

if [ ! -r ./usr/opt/advfsd/etc/srconf/mgr/advfs_snmpinfo.dat ]
then
    echo "./usr/opt/advfsd/etc/srconf/mgr/advfs_snmpinfo.dat is not readable."
    FAILED=1
fi

if [ ! -r ./usr/opt/advfsd/etc/srconf/mgr/context.pty ]
then
    echo "./usr/opt/advfsd/etc/srconf/mgr/context.pty is not readable."
    FAILED=1
fi

if [ ! -r ./usr/opt/advfsd/etc/srconf/mgr/mgr.cnf ]
then
    echo "./usr/opt/advfsd/etc/srconf/mgr/mgr.cnf is not readable."
    FAILED=1
fi

if [ ! -r ./usr/opt/advfsd/etc/srconf/mgr/mgr.pty ]
then
    echo "./usr/opt/advfsd/etc/srconf/mgr/mgr.pty is not readable."
    FAILED=1
fi

if [ ! -r ./usr/opt/advfsd/etc/srconf/mgr/view.pty ]
then
    echo "./usr/opt/advfsd/etc/srconf/mgr/view.pty is not readable."
    FAILED=1
fi

if [ ! -x ./usr/opt/advfsd/scripts/backup_fstab.sh ]
then
    echo "./usr/opt/advfsd/scripts/backup_fstab.sh is not executable."
    FAILED=1
fi

if [ ! -x ./usr/opt/advfsd/scripts/mount.sh ]
then
    echo "./usr/opt/advfsd/scripts/mount.sh is not executable."
    FAILED=1
fi

if [ ! -x ./usr/opt/advfsd/scripts/renamefdmn.sh ]
then
    echo "./usr/opt/advfsd/scripts/renamefdmn.sh is not executable."
    FAILED=1
fi

if [ ! -x ./usr/opt/advfsd/scripts/renamefset.sh ]
then
    echo "./usr/opt/advfsd/scripts/renamefset.sh is not executable."
    FAILED=1
fi

if [ ! -x ./usr/opt/advfsd/scripts/rmfdmn.sh ]
then
    echo "./usr/opt/advfsd/scripts/rmfdmn.sh is not executable."
    FAILED=1
fi

if [ ! -x ./usr/opt/advfsd/scripts/rmfset.sh ]
then
    echo "./usr/opt/advfsd/scripts/rmfset.sh is not executable."
    FAILED=1
fi

#if [ ! -x ./usr/opt/advfsd/scripts/rmvol.sh ]
#then
#    echo "./usr/opt/advfsd/scripts/rmvol.sh is not executable."
#    FAILED=1
#fi

if [ ! -x ./usr/opt/advfsd/scripts/setalert.sh ]
then
    echo "./usr/opt/advfsd/scripts/setalert.sh is not executable."
    FAILED=1
fi

if [ ! -x ./usr/opt/advfsd/scripts/setalertint.sh ]
then
    echo "./usr/opt/advfsd/scripts/setalertint.sh is not executable."
    FAILED=1
fi

if [ ! -x ./usr/opt/advfsd/scripts/setmonint.sh ]
then
    echo "./usr/opt/advfsd/scripts/setmonint.sh is not executable."
    FAILED=1
fi

if [ ! -x ./usr/opt/advfsd/scripts/unmount.sh ]
then
    echo "./usr/opt/advfsd/scripts/unmount.sh is not executable."
    FAILED=1
fi

if [ ! -x ./usr/opt/advfsd/scripts/unsetalert.sh ]
then
    echo "./usr/opt/advfsd/scripts/unsetalert.sh is not executable."
    FAILED=1
fi

if [ ! -x ./usr/sbin/advfsd ]
then
    echo "./usr/sbin/advfsd is not executable."
    FAILED=1
fi

if [ ! -d ./var/opt/advfsd/logs ]
then
    echo "./var/opt/advfsd/logs is not a directory."
    FAILED=1
fi

if [ ! -d ./var/opt/advfsd/socket ]
then
    echo "./var/opt/advfsd/socket is not a directory."
    FAILED=1
fi

if [ $FAILED -eq 1 ]
then
    echo "
************************************************************************
One or more files, listed above, that were supposed to be installed with
the $_DESC are not correctly installed.

The $_DESC was not successfully installed.
************************************************************************
"

exit 1
fi

echo " "
echo "All files are in the correct locations for the $_DESC."

if STL_IsDataless
then
	echo " "
	echo "You must boot the dataless client to run advfsd."
	echo " "
	echo "The $_DESC ($_SUB) was successfully verified."
else
	echo " "
	echo "Checking to make sure the daemon is running...."

	if ( /sbin/ps ax | /sbin/grep -v grep | /sbin/grep advfsd )
	then
	    echo "The AdvFS daemon is running."
	    echo "The $_DESC ($_SUB) was successfully verified."
	else
	    echo "advfsd is not currently running.  Restarting /usr/sbin/advfsd."
	    echo "This may take up to 30 seconds...."
	    /sbin/init.d/advfsd start

	    sleep 10

	    if ( /sbin/ps ax | /sbin/grep -v grep | /sbin/grep advfsd )
	    then
		echo " "
		echo "Successfully restarted AdvFS daemon."
		echo " " 
		echo "The $_DESC ($_SUB) was successfully verified."
	    else
		echo " "
		echo "***"
		echo "Failed to restart AdvFS daemon.  The $_DESC ($_SUB) was not successfully installed."
		echo "***"
		echo " "
	    fi
        fi
fi

esac
exit 0
#	End of script
