#!/bin/sh

# Don't load core services in professional mode
MWADM_UTILITY=1
export MWADM_UTILITY

# may fail if in enterprise mode and MSC are not running or professional when 
# it fails to start MSC or MWADM_UTILITY
mode=`mwgetmode 2>  /dev/null`

if [ "$mode" = "" ]
	then mode=$MWRT_MODE
fi
if [ "$mode" = "" ]
	then mode=`cat $MWHOME/default.mode 2> /dev/null`
fi
if [ "$mode" = "" ]
	then mode="enterprise"
fi

# We shouldn't get this because in classic mode abort mwadm
# but this may change.
if [ "$mode" = "classic" ] ;then
	echo "Run-time mode       : classic"
	exit 0
fi

if [ "$mode" = "enterprise" ]; then
# get info from the etc file
# If /etc/mainwin.conf doesn't exist some of our tests will fail
# so we'll just report that there are no MSC.
    if [ ! -r "/etc/mainwin.conf" ]; then
	    echo "Enterprise Core Services are not installed on this computer!"
	    exit 1
    fi

	core_path=`grep \^CORE_PATH= /etc/mainwin.conf |cut -f2 -d=` 
	admin=`grep \^CORE_ADMIN= /etc/mainwin.conf | cut -f2 -d=`
	port=`mwsetport`
else
# professional mode
	sub=`echo $mode | cut -f2 -d: -s`
	if [ "$sub" != "" ]
		then core_path=$HOME/.mw/$sub/`hostname`
		else core_path=$HOME/.mw/`hostname`
	fi
	port=$MWRPC_ENDPOINT
	if [ "$port" = "" ]; then
	    port="dynamic"
	fi
fi

mwpingreg
if [ $? -eq 0 ]
	then stat="running"
	else stat="stopped"
fi


echo "Run-time mode       : "$mode
echo "Core Services status: "$stat
echo "Core Data Directory : "$core_path
# Admin is only set (and relevant) in enterprise mode
if [ "$admin" != "" ]; then
	echo "MSC Administrator   : "$admin
fi
echo "RPC Port            : "$port
