#! /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
	/usr/sbin/rem_drv -b $ROOTDIR sppp
fi

if [ ! -f $ROOTDIR/usr/kernel/drv/sppptun ]; then
	/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"
# check for diskless client install. if installing to service area
# continue else exit because we are patching the client's root.

pids=`egrep '^PATCHLIST' $INFO 2> /dev/null | nawk -F= '{print $2}'`
if [ "$pids" = "" ]; then
	exit 0
fi
 
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
