#
# Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
# Use is subject to license terms.
#
# ident	"@(#)postinstall	1.31	06/08/01 SMI"

#
# pkgdefs/SUNWsacom/postinstall
#

#
# Retain original SNMPD configuration file they might have from an
# earlier SunNet Manager installation.
#

if [ -f $BASEDIR/etc/opt/SUNWconn/snm/snmpd.conf ] ; then
    cp $BASEDIR/etc/snmp/conf/snmpd.conf $BASEDIR/etc/snmp/conf/snmpd.conf.original
    echo 'Copying $BASEDIR/etc/opt/SUNWconn/snm/snmpd.conf (existing SNMPD configuration file)'
    echo 'to $BASEDIR/etc/snmp/conf/snmpd.conf'
    cp $BASEDIR/etc/opt/SUNWconn/snm/snmpd.conf $BASEDIR/etc/snmp/conf/snmpd.conf
fi

def_read="public"
def_write="private"
def_desc="Sun SNMP Agent, Company Property Number 123456"
def_cont="System administrator"
def_loc="System administrators office"

READSTR=$def_read
WRITESTR=$def_write

        desc=`/etc/prtconf |/usr/bin/head -5|/usr/bin/grep SUNW |awk -F, '{print $2}'`
	if [ "$desc" = "" ]; then
		desc=`/etc/prtconf |/usr/bin/head -5|/usr/bin/grep SUNW |awk '{print $1}'`
	fi
        def_desc="Sun SNMP Agent, $desc"

DESCSTR=$def_desc
CONTSTR=$def_cont
LOCSTR=$def_loc
export READSTR WRITESTR DESCSTR CONTSTR LOCSTR

# main ()

#
# Update the snmpd.conf file with the default community strings
# for the system on which this is installed.
#

/usr/bin/ed -s $BASEDIR/etc/snmp/conf/snmpd.conf <<SNMPEOF>/dev/null
1,\$s!ALLDESC!$DESCSTR!g
1,\$s!ALLCONT!$CONTSTR!g
1,\$s!ALLLOC!$LOCSTR!g
w
q
SNMPEOF

installf -f $PKGINST

#
# check if snmpdx should be enabled (snmpdx.tmp was set in preinstall)
if [ -f $BASEDIR/var/snmpdx.tmp ]; then
	cat >> $BASEDIR/var/svc/profile/upgrade <<\_SNMPDX
if [ `/sbin/zonename` = global ]; then
	/usr/sbin/svcadm enable svc:/application/management/snmpdx:default
fi
_SNMPDX
	rm -f $BASEDIR/var/snmpdx.tmp
fi

exit 0
