#! /bin/sh
# This script restores files back to hardlinks. 
#
#
 
if [ "$ROOTDIR" != "" ]; then
	INSTALLF="installf -R ${ROOTDIR}"
        REMOVEF="removef -R ${ROOTDIR}"
else
	INSTALLF="installf"
        REMOVEF="removef"
fi


PATID=116384
NOUNDO=01      # rev when this postbackout was introduced
rmv_links=1

PATH="/bin:/usr/bin:/usr/sbin:${PATH}"
export PATH
EXIT=0

PKG_INSTALL_ROOT=$ROOTDIR
INFO="$PKG_INSTALL_ROOT/var/sadm/pkg/SUNWslpr/pkginfo"

set_old_links() {

# This is needed if installed on top of a previous rev of this patch.
# It's a workaround to restore the hard links and entries in the 
# patch DB if this patch is removed.
 
pkginfo -R $ROOTDIR -q  SUNWslpr
if [ $? -eq 0 ]
then
    ${REMOVEF} SUNWslpr /etc/rc0.d/K41slpd  > /dev/null 2>&1
    ${REMOVEF} SUNWslpr /etc/rc1.d/K41slpd > /dev/null 2>&1
    ${REMOVEF} SUNWslpr /etc/rcS.d/K41slpd  > /dev/null 2>&1
    ${REMOVEF} -f SUNWslpr || exit 2

# Now re-add them back as hard links to /etc/init.d/slpd.

    ${INSTALLF} -c initd SUNWslpr /etc/init.d/slpd e 0744 root sys > /dev/null 2>&1
    ${INSTALLF} -c initd SUNWslpr /etc/rc0.d/K41slpd=../../etc/init.d/slpd l > /dev/null 2>&1
    ${INSTALLF} -c initd SUNWslpr /etc/rc1.d/K41slpd=../../etc/init.d/slpd l > /dev/null 2>&1
    ${INSTALLF} -c initd SUNWslpr /etc/rcS.d/K41slpd=../../etc/init.d/slpd l > /dev/null 2>&1
    ${INSTALLF} -c initd SUNWslpr /etc/rc2.d/S72slpd=../../etc/init.d/slpd l > /dev/null 2>&1
    ${INSTALLF} -f -c initd SUNWslpr || exit 2
     
fi

}



set_new_dblinks() {
 
pkginfo -R $ROOTDIR -q  SUNWslpr
if [ $? -eq 0 ]
then
# Now re-add db entries for new hardlinks /etc/init.d/slpd and original
# link s72slpd.

    ${INSTALLF} -c initd SUNWslpr /etc/init.d/slpd e 0744 root sys > /dev/null 2>&1
    ${INSTALLF} -c initd SUNWslpr /etc/rc0.d/K40slpd=../../etc/init.d/slpd l > /dev/null 2>&1
    ${INSTALLF} -c initd SUNWslpr /etc/rc1.d/K40slpd=../../etc/init.d/slpd l > /dev/null 2>&1
    ${INSTALLF} -c initd SUNWslpr /etc/rcS.d/K40slpd=../../etc/init.d/slpd l > /dev/null 2>&1
    ${INSTALLF} -c initd SUNWslpr /etc/rc2.d/S72slpd=../../etc/init.d/slpd l > /dev/null 2>&1
    ${INSTALLF} -c initd -f SUNWslpr || exit 2
     
fi

}


pids=`egrep '^PATCHLIST' $INFO 2> /dev/null | nawk -F= '{print $2}'` 
for i in `echo $pids`; do
        echo $i | egrep -s $PATID || continue
        rev=`expr //$i : '.*-\(.*\)'`
        #No undo edits for rev-01 or higher
        [ $rev -ge $NOUNDO ] && set_new_dblinks && exit
done

   [ $rmv_links ] && set_old_links 

exit ${EXIT}


