#!/usr/bin/ksh
#
#
# PatchNum & ROOTDIR are inherited from patch scripts
#
#
# Remove symbolic links in SUNWsclb, SUNWsclbx and SUNWsc
# introduced by the patch.
#
# This is a workaround for a patchrm bug where symlinks do not
# get removed on backout and also handles not to remove them if
# this patch is installed on top of a previous version or
# accumulated version of this patch.  After files have been
# restored on backout, check to see if there is an existing source
# pointed to by the symlink, if so, assume a previous patch
# installed the file.  If no source exists, meaning sym link 
# points to nothing, remove the sym links. 


if [ "$ROOTDIR" != "" ]; then
	CONF_DIR=${ROOTDIR}/etc/opt/SUNWcluster/conf
else
	CONF_DIR=/etc/opt/SUNWcluster/conf
fi

if [ -f ${CONF_DIR}/ccd.database.init ]
then
        chmod 0644 ${CONF_DIR}/ccd.database.init
fi

if [ -f ${CONF_DIR}/ccd.database ]
then
        chmod 0644 ${CONF_DIR}/ccd.database
fi

if [ -f ${CONF_DIR}/ccd.database.shared ]
then
        chmod 0644 ${CONF_DIR}/ccd.database.shared
fi

if [ -f ${CONF_DIR}/ccd.database.shadow ]
then
        chmod 0644 ${CONF_DIR}/ccd.database.shadow
fi

if [ -f ${CONF_DIR}/ccd.database.orig ]
then
        chmod 0644 ${CONF_DIR}/ccd.database.orig
fi   

[ "$ROOTDIR" = / ] && ROOTDIR=""
 
TOP32=$ROOTDIR/opt/SUNWcluster/lib
TOP64=$ROOTDIR/opt/SUNWcluster/lib/sparcv9
LINK_lib=libscutil.so
BIN=/etc/init.d/initpmf

for SYMLINK in $TOP32/$LINK_lib $TOP64/$LINK_lib 
do
         if [ -L $SYMLINK -a ! -a $SYMLINK ]
         then    
            echo "Removing symlink $SYMLINK"
            rm -f $SYMLINK

            if echo $SYMLINK | egrep -s sparcv9
            then
                removef SUNWsclbx $SYMLINK
                removef -f SUNWsclbx
            else
                removef SUNWsclb $SYMLINK
                removef -f SUNWsclb
             fi
        fi
done
exit 0
