#! /bin/sh
# This script cleans up /etc/driver_aliases, /etc/driver_classes
# and /etc/name_to_major.
#
#
if [ ! -f $ROOTDIR/usr/kernel/drv/sppp ]; then
	$ROOTDIR/usr/sbin/rem_drv -b $ROOTDIR sppp
fi

if [ ! -f $ROOTDIR/usr/kernel/drv/sppptun ]; then
	$ROOTDIR/usr/sbin/rem_drv -b $ROOTDIR sppptun
fi

PATID=108993
NUNDO_REV=14

PKG_INSTALL_ROOT=$ROOTDIR
INFO="$PKG_INSTALL_ROOT/var/sadm/pkg/SUNWcsu/pkginfo"
pids=`egrep '^PATCHLIST' $INFO | nawk -F= '{print $2}'`
 
if [ "$ROOTDIR" != "" ]; then
	INSTALLF="installf -R ${ROOTDIR}"
        REMOVEF="removef -R ${ROOTDIR}"
else
	INSTALLF="installf"
        REMOVEF="removef"
fi

pkginfo -R $ROOTDIR -q  SUNWnisu
if [ $? -eq 0 ]
then
	${INSTALLF} SUNWnisu /usr/sbin/ldap_gen_profile=$ROOTDIR/usr/sbin/ldapclient l > /dev/null 2>&1
        ${INSTALLF} -f SUNWnisu || exit 2
fi

pkginfo -R $ROOTDIR -q SUNWapppr
if [ $? -eq 0 ]
then
        ${INSTALLF} -c initd SUNWapppr /etc/init.d/asppp e \
                       0744 root sys   > /dev/null 2>&1
        ${INSTALLF} -c initd -f SUNWapppr || exit 2
fi

pkginfo -R $ROOTDIR -q SUNWpppdr
if [ $? -eq 0 ]
then
        ${INSTALLF} -c initd SUNWpppdr /etc/init.d/pppd e \
                       0744 root sys  > /dev/null 2>&1
        ${INSTALLF} -c initd -f SUNWpppdr || exit 2
fi


restore_links () {


pkginfo -R $ROOTDIR -q  SUNWnisu
if [ $? -eq 0 ]
then
        ${REMOVEF} SUNWnisu /usr/bin/yppasswd > /dev/null 2>&1
        ${REMOVEF} -f SUNWnisu || exit 2

	${INSTALLF} SUNWnisu /usr/bin/nispasswd=$ROOTDIR/usr/bin/passwd l > /dev/null 2>&1
	${INSTALLF} SUNWnisu /usr/sbin/ldap_gen_profile=$ROOTDIR/usr/sbin/ldapclient l > /dev/null 2>&1
        ${INSTALLF} -f SUNWnisu || exit 2
fi

${INSTALLF} SUNWcsu /usr/bin/yppasswd=$ROOTDIR/usr/bin/passwd l > /dev/null 2>&1
${INSTALLF} -f SUNWcsu || exit 2

}


restore_yppasswd_db () {

${REMOVEF} SUNWcsu /usr/bin/yppasswd > /dev/null 2>&1
${REMOVEF} -f SUNWcsu || exit 2

}


for i in `echo $pids`; do
        echo $i | egrep -s $PATID || continue
        rev=`expr //$i : '.*-\(.*\)'`
        #Don't restore links and reset DB for rev-14 or higher
        [ $rev -ge $NUNDO_REV ] && restore_yppasswd_db && exit
done

restore_links

exit 0
