#!/bin/sh
# Copyright 18 Mar 1996 Sun Microsystems, Inc. All Rights Reserved.
#
#pragma ident  "@(#)em_startup	1.36 96/03/18 Sun Microsystems"
#

EM_HOME="${EM_HOME-/opt/SUNWconn/em}"
export EM_HOME
EM_RUNTIME="${EM_RUNTIME-/var/opt/SUNWconn/em}"
SYSTEMID=`/usr/bin/uname -n`
STARTDIR=$EM_HOME/install/em_platform
APP_STARTDIR=$EM_HOME/install/apps
USER_STARTDIR=$EM_RUNTIME/conf
ECHO=/usr/bin/echo

pid=`/usr/bin/ps -e | /usr/bin/grep em_mis |
         /usr/bin/sed -e 's/^  *//' -e 's/ .*//'`

if [ "$pid" -eq 0 ]
then
	$ECHO "Error: MIS server is not running."
        $ECHO "Please run em_mis first."
        exit 1
fi

# For 	1) auto management
# 	2) data collection
# 	3) Access Control initial objects
# 	4) SNM BC object.

$EM_HOME/bin/em_compose_poc \
	autoManagement \
	autoManagementEntry \
	dataCollector \
	dataCollectorEntry \
	targets \
	emAppContainer \
	emGroupContainer \
	emApplication \
	emAppFeature \
		> /dev/null 2> /dev/null
$EM_HOME/bin/em_load_name_bindings \
	autoManagement-emKernel \
	autoManagementEntry-autoManagement \
	dataCollector-emKernel \
	dataCollectorEntry-dataCollector \
	targets-system \
	emAppContainer-emKernel  \
	emApplication-emAppContainer \
	emAppFeature-emApplication \
	emGroupContainer-emKernel \
		> /dev/null 2> /dev/null

$ECHO "\nInitializing ...\c"
$ECHO ".\c"
$EM_HOME/bin/em_objop -s -f $STARTDIR/init_platform

$ECHO ".\c"
$EM_HOME/bin/em_objop -s -f $STARTDIR/.init_access

$ECHO ".\c"
$EM_HOME/bin/em_accesscmd -import $STARTDIR/init_access_em_apps

# Create MAP Application Database and TOPO 

# Check if SUNWembc is installed. If so create MAP Application Database and
# topoTypes to support BC applications, create appropriate links, load other
# third party types. 

/usr/bin/pkginfo -q SUNWembc
if test $? -eq 0  
then
        # SUNWembc installed

        # Support BC Application Installation

        if [ ! -x $EM_HOME/../bin/snm_version ]
        then
            /usr/bin/ln -s $EM_HOME/bin/snm_version $EM_HOME/../bin/snm_version
        fi

        # Load standard topoTypes with BC support

        if [ -f $STARTDIR/init_map_bc ]
        then
            # Patch 4 SUNWembc package installed

	    $ECHO ".\c"
	    $EM_HOME/bin/em_objop -s -f $STARTDIR/init_map_bc
        else
	    $ECHO "\n\nWarning: SUNWembc package is not patched\n"
	    $ECHO "         SNM Backward compatibility may not function"
	    $ECHO "         correctly until this is installed\n"
            
            # Fallback to init_map to allow the system to start

	    $EM_HOME/bin/em_objop -s -f $STARTDIR/init_map
        fi

        # Check if user has installed BC package and wants
        # Ciscoworks and/or Optivity types and icons

        # Ciscoworks

        if [ -f $APP_STARTDIR/ciscoworks ]
        then
            if [ ! -f $EM_HOME/glyphs/cisco-2000.pm ]
            then
                /usr/bin/cp -p $EM_HOME/glyphs/ciscoworks/*.pm $EM_HOME/glyphs
            fi
            $ECHO ".\c"
            $EM_HOME/bin/em_objop -s -f $STARTDIR/cisco_map
        fi

        # Optivity

        if [ -f $APP_STARTDIR/optivity ]
        then
            if [ ! -f $EM_HOME/glyphs/baystack-tr-conc.pm ]
            then
                /usr/bin/cp -p $EM_HOME/glyphs/optivity/*.pm $EM_HOME/glyphs
            fi
            $ECHO ".\c"
            $EM_HOME/bin/em_objop -s -f $STARTDIR/bay_map
        fi

        # Automatically load any topoTypes that the user may have imported via
        # em_snm_db_type_import. Do this last to avoid possible conflicts with
        # delivered types.

        if [ -s $STARTDIR/bc_map ]
        then
            $ECHO ".\c"
            $EM_HOME/bin/em_objop -s -f $STARTDIR/bc_map
        fi
else
        # SUNWembc not installed

        # Load standard topoTypes without BC support

	$ECHO ".\c"
	$EM_HOME/bin/em_objop -s -f $STARTDIR/init_map
fi

# Run user defined init file

$ECHO ".\c"
$EM_HOME/bin/em_objop -s -f $USER_STARTDIR/init_user

$ECHO ".\c"
$EM_HOME/bin/em_accesscmd -import $USER_STARTDIR/init_access_user_apps

$ECHO ".\c"
$EM_HOME/bin/em_accesscmd -import $USER_STARTDIR/init_access_privileges


#
# add the nickname server
#
$ECHO ".\c"
$EM_HOME/bin/em_nnadd -m localhost -n 5594

#
# load nc templates
#
$EM_HOME/bin/em_load_nc_templates

$ECHO ".\n"

exit
