#! /bin/sh

PATH="/usr/bin:/usr/sbin:${PATH}"
PKG_INSTALL_ROOT=$ROOTDIR
if [ "$PKG_INSTALL_ROOT" = "/" ]; then
	PKG_INSTALL_ROOT=""
fi

REV=`patchadd -p -R "/$PKG_INSTALL_ROOT" | grep \^"Patch: 113432" | cut -f2 -d' ' | cut -f2 -d'-' | sort | tail -1`
if [ "$REV" -ge 04 ]
then
	exit 0
fi

CWD=`pwd`
ALLTOKENS="FJSV,GPUS FJSV,GPUSC-M FJSV,GPUSK"

for TOKENS in $ALLTOKENS
do
    PSBIN_DIR=/usr/platform/$TOKENS/sbin
    if [ ! -h "${PKG_INSTALL_ROOT}${PSBIN_DIR}" ]
    then
	if [ -d "${PKG_INSTALL_ROOT}${PSBIN_DIR}" ]
	then
	    rmdir ${PKG_INSTALL_ROOT}${PSBIN_DIR} > /dev/null 2>&1
	    if [ $? != 0 ]
	    then
		echo ""
		echo "***Warning***"
		echo "Directory ${PKG_INSTALL_ROOT}${PSBIN_DIR} is not empty."
		echo "Cannot restore the ${PKG_INSTALL_ROOT}${PSBIN_DIR} link."
		echo "Please reinstall the \"FJSVcpc[x]\" packages."
		echo "Refer to the proper documentation on how to install"
		echo "packages in Solaris 9."
	    else
		cd ${PKG_INSTALL_ROOT}/usr/platform/$TOKENS
		if [ $? -eq 0 ]
		then
		    ln -s ../sun4us/sbin sbin > /dev/null 2>&1
		fi
		cd $CWD
	    fi
	else
	    echo ""
	    echo "**Warning***"
	    echo "The ${PKG_INSTALL_ROOT}${PSBIN_DIR} directory is missing on your system."
	fi
    fi
done

exit 0
