#! /bin/sh
#	@(#)postinstall	1.16 98/06/08 

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

RTVC_ALIAS="SUNW,rtvc"
DRV=rtvc
DRVALIASES_EGREP='"SUNW,rtvc"'
DRVALIASES_ADD='"SUNW,rtvc"'
DRVPERM='rtvcctl* 0644 root sys'
DRVPERM1='rtvc[!ctl]* 0666 root sys'

touch ${BASEDIR}/reconfigure

#
# Is the hardware there?
#
hw_exists=0
prtconf -p | egrep -s "${DRVALIASES_EGREP}"
if [ $? -eq 0 ]; then
        hw_exists=1
fi

#
# Select the correct add_drv options to execute.
# Only attempt to attach the driver
# on a running system with the hardware present.
#
if [ "${BASEDIR}" = "/" ]; then
        #
        case ${hw_exists} in
                #
                # On a running system of the relevant arch with *no* hardware,
                # modify the system files only
                #
                0 )
                        ADD_DRV="add_drv -n"
                        ;;
                #
                # On a running system with hardware,
                # modify the system files and attach the driver
                #
                1 )
                        ADD_DRV="add_drv"
                        ;;
        esac
else
        #
        # On a client,
        # modify the system files and touch /reconfigure
        # for reconfigure reboot
        #
        ADD_DRV="add_drv -b ${BASEDIR}"
fi

#
# Make sure add_drv has *not* been previously executed
# before attempting to add the driver.
#

grep "^${DRV} " $BASEDIR/etc/name_to_major > /dev/null 2>&1
if [ $? -ne 0 ]; then
        ${ADD_DRV} -m "${DRVPERM}","${DRVPERM1}" -i "${DRVALIASES_ADD}" ${DRV}
        if [ $? -ne 0 ]; then
                echo "\nFailed add_drv!\n" >&2
                exit 1
        fi
fi


if [ "$BASEDIR" = "/" ]
then
	if /usr/sbin/prtconf -vp | /bin/fgrep -s "$RTVC_ALIAS"
	then
            modnum=`set -- \`modinfo | grep rtvc\`; echo $1`
            if [ "$modnum" ]
            then 
                modunload -i $modnum
            fi
	    /usr/sbin/drvconfig -i rtvc
	    /usr/sbin/devlinks -t /tmp/svdevlink.tab
	    rm -f /tmp/svdevlink.tab
	fi
	rm -f /tmp/svdevlink.tab
#
# it could happen that the user is upgrading and has rtvc-config
# from a previous OS; explicitely remove them since they should
# not be there in Solaris 2.7
#
	rm -f /etc/init.d/rtvc-config
	rm -f /etc/rc2.d/S92rtvc-config
	echo >&2
	echo "NOTE: Reboot your system to load the SunVideo (RTVC) driver." >&2
	echo >&2
fi


installf -f $PKGINST || exit 2

exit 0

