# if TR installed
/usr/bin/pkginfo -q SUNWnsmbj
if [ $? -eq 0 ]; then

    # if agent station has already been configured, need to update httpd.conf 
    # config file
    PKG=SUNWnsmat
    /usr/bin/pkginfo -q $PKG
    if [ $? -eq 0 ]; then
	BASEDIR=`/usr/bin/pkginfo -r $PKG 2>&1`
	if [ $? -ne 0 ]; then
	    BASEDIR=/opt
	fi

        PRODUCT_DIR=$BASEDIR/SUNWnsm
        NSMCONF_FILE=$PRODUCT_DIR/etc/sstr.properties
        if [ -f $NSMCONF_FILE ]; then
            echo "Reconfiguring the topology reporter agents..."
            sed_file () {
                src="$1"
                dst="$2"
                regexp="$3"
    
                ftmp=/tmp/nsmsed$$
                /bin/sed "$regexp" "$src" > $ftmp
                if [ $? -ne 0 ]; then
                    return 1
                fi
                mv "$ftmp" "$dst"
                if [ $? -ne 0 ]; then
                    return 1
                fi
                return 0;
            }

            setup_agent_apache () {
                src="$PRODUCT_DIR/util/apache/conf/httpd.conf.default"
                dst="$PRODUCT_DIR/util/apache/conf/httpd.conf"
                regexp="s/NSM_APACHE_PORT/$NSM_APACHE_PORT/g"
                sed_file "$src" "$dst" "$regexp"
                if [ $? -ne 0 ]; then
                    return 1
                fi
    
                regexp="s/NSM_APACHE_SERVERNAME/$NSM_APACHE_SERVERNAME/g"
                sed_file "$dst" "$dst" "$regexp"
                if [ $? -ne 0 ]; then
                    return 1
                fi
    
                regexp="s/NSM_APACHE_SERVERADMIN/$NSM_APACHE_SERVERADMIN/g"
                sed_file "$dst" "$dst" "$regexp"
                if [ $? -ne 0 ]; then
                    return 1
                fi
    
                chown root:other "$dst"
                chmod 644 "$dst"
    
                return 0;
            }

            NSM_REGISTRY_HOST=`/sbin/uname -n`
            . $NSMCONF_FILE
            setup_agent_apache
            if [ $? -ne 0 ]; then
                echo "Reconfigure of the topology reporter agent failed."
                echo "Please reconfigure the agent manually with "
                echo "$BASEDIR/SUNWstm/bin/esmconfig"
            fi
        fi
    fi

    echo "Topology Reporter needs to be restarted with the command"
    echo "\t/etc/init.d/sstrd start\n"
fi

# if CS installed
/usr/bin/pkginfo -q SUNWdm
if [ $? -eq 0 ]; then
    echo "Configuration Service needs to be restarted with the commands:"
    os=`/sbin/uname -r`
    if [ "$os" = "5.8" ]; then
	echo "\t/etc/init.d/prngd start"
    fi
    echo "\t/etc/init.d/sshd start"
    echo "\t/etc/init.d/sscs.wbem start"
    echo "\t/etc/init.d/sscs start\n"
fi

# if DE installed
/usr/bin/pkginfo -q SUNWsade
if [ $? -eq 0 ]; then
    echo "Diagnostic Expert needs to be restarted with the command"
    echo "\t/etc/init.d/init.ssde start\n"
fi
