#!/bin/sh
#
# Copyright (c) 2001 by Sun Microsystems, Inc.
# All rights reserved.
#
# ident	"@(#)postpatch	1.0	01/10/16 SMI"
#
# postpatch script for ttymux point patch 111406
#

# Only run this script if this is a Netra ct machine.

if [ `uname -i` != "SUNW,UltraSPARC-IIi-Netract" ] 
then
        exit 0
fi

# Determine if installation is via jumpstart

echo $BASEDIR | grep '^\/a' > /dev/null
if [ $? = 0 ]
    then
        JUMPSTART=1
    else
        JUMPSTART=0
fi

if [ "$JUMPSTART" = 1 ]
then
        RDIR="$BASEDIR"
else
        RDIR="$ROOTDIR"
fi

# Add ttymux entry in /etc/iu.ap

if $RDIR/bin/fgrep -s "	ttymux	-1	0	ldterm ttcompat" $RDIR/etc/iu.ap ; then
    echo "/etc/iu.ap already has ttymux entry"
else
    cp $RDIR/etc/iu.ap /tmp/iu.ap
    echo "	ttymux	-1	0	ldterm ttcompat" >> $RDIR/etc/iu.ap
    if [ $? != 0 ] ; then
        echo "/etc/iu.ap file modification failed"
        mv /tmp/iu.ap $RDIR/etc/iu.ap
        exit 1
    else
        echo "/etc/iu.ap file successfully modified"
    fi

fi

# Add ttymux entry in /etc/dacf.conf

if $RDIR/bin/fgrep -s "driver-minorname=\"ttymux:con\" ttymux_dacf:ttymux_config post-attach -" $RDIR/etc/dacf.conf ; then
    echo "/etc/dacf.conf already has ttymux entry"
else
    cp $RDIR/etc/dacf.conf /tmp/dacf.conf
    echo "driver-minorname=\"ttymux:con\" ttymux_dacf:ttymux_config post-attach -" >> $RDIR/etc/dacf.conf
    if [ $? != 0 ] ; then
        echo "/etc/dacf.conf file modification failed"
        mv /tmp/dacf.conf $RDIR/etc/dacf.conf
        exit 1
    else
        echo "/etc/dacf.conf file successfully modified"
    fi

fi

# Load ttymux driver

not_installed() {
	driver=$1
	grep "^${driver} " ${RDIR}/etc/name_to_major > /dev/null 2>&1
	return $?
}

EXIT=0

not_installed ttymux || add_drv -b ${RDIR} -i '"multiplexer"' -n  ttymux || EXIT=1

exit $EXIT
