#!/bin/sh

ORACLE_HOME=/usr/lib/oracle/xe/app/oracle/product/10.2.0/server
ORACLE_OWNER=oracle
ORACLE_SID=XE
SQLPLUS=$ORACLE_HOME/bin/sqlplus
LSNR=$ORACLE_HOME/bin/lsnrctl
export ORACLE_HOME
export ORACLE_SID
export PATH=$ORACLE_HOME/bin:$PATH
export LD_LIBRARY_PATH=$ORACLE_HOME/lib

case "$1" in 
start)
	echo -n "Starting Oracle Database 10g Express Edition Instance..."
	pmon=`ps -U $ORACLE_OWNER | egrep pmon_$ORACLE_SID'\>' | grep -v grep`
	if [ "$pmon" = "" ];
	then
	    su -s $ORACLE_OWNER -c "$LSNR start" > /dev/null 2>&1
	    su -s $ORACLE_OWNER -c "$SQLPLUS -s /nolog @$ORACLE_HOME/config/scripts/startdb.sql" > /dev/null 2>&1
	fi
	echo "Done"
	;;
stop)
	echo -n "Stopping Oracle Database 10g Express Edition Instance..."
	pmon=`ps -U $ORACLE_OWNER | egrep pmon_$ORACLE_SID'\>' | grep -v grep`
	if [ "$pmon" != "" ];
	then
	    su -s $ORACLE_OWNER -c "$SQLPLUS -s /nolog @$ORACLE_HOME/config/scripts/stopdb.sql" > /dev/null 2>&1
	fi
	echo "Done"
	;;
*)
        echo "Usage: `basename $0` {start|stop}"
        ;;
esac

exit 0

