#!/usr/bin/qsh
#
# All Rights Reserved * Licensed Materials - Property of IBM
# 5724-I63, 5724-H88, 5655-N01, 5733-W61 (C) COPYRIGHT International Business Machines Corp., 1997,2007
# US Government Users Restricted Rights - Use, duplication or disclosure
# restricted by GSA ADP Schedule Contract with IBM Corp.
. $(/usr/bin/dirname $0)/setupCmdLine

if [ -e ${USER_INSTALL_ROOT}/configuration/config.ini ]; then
  rm ${USER_INSTALL_ROOT}/configuration/config.ini
fi

${JAVA_HOME}/bin/java ${JAVA_PARM} \
  ${OSGI_INSTALL} \
  ${OSGI_CFG}  \
  -classpath ${WAS_CLASSPATH} \
  org.eclipse.core.launcher.Main -clean -nosplash -application com.ibm.ws.debug.osgi.Noop

RETCODE=$?

# First test to see if the default (OSGI_CFG) is the $WAS_HOME/configuration directory - if so skip this --
# else test to see if there is any cached data (look to see if the org.eclipse.core.runtime
# OR org.eclipse.osgi directory exists)  If so clean the cache.
if [ "${OSGI_CFG}" != "-Dosgi.configuration.area=${WAS_HOME}/configuration" ] &&
   ( [ -d ${WAS_INSTALL_ROOT}/configuration/org.eclipse.core.runtime ] ||
     [ -d ${WAS_INSTALL_ROOT}/configuration/org.eclipse.osgi ]
   ) ;
then
        OSGI_INSTALL="-Dosgi.install.area=${WAS_INSTALL_ROOT}"
        OSGI_CFG="-Dosgi.configuration.area=${WAS_INSTALL_ROOT}/configuration"
        export OSGI_INSTALL OSGI_CFG

	${JAVA_HOME}/bin/java ${JAVA_PARM} \
          ${OSGI_INSTALL} \
	  ${OSGI_CFG}  \
  	  -classpath ${WAS_CLASSPATH} \
          org.eclipse.core.launcher.Main -clean -nosplash -application com.ibm.ws.debug.osgi.Noop
        rc=$?

        if [ ${RETCODE} = "0" ] ;
        then RETCODE=$rc ;
        fi
fi


if [ -e ${USER_INSTALL_ROOT}/configuration ]; then
  chmod -R o=rwx ${USER_INSTALL_ROOT}/configuration
  chown -R QEJBSVR ${USER_INSTALL_ROOT}/configuration
else
  if [ -e ${WAS_INSTALL_ROOT}/configuration ]; then
    chmod -R o=rwx ${WAS_INSTALL_ROOT}/configuration
    chown -R QEJBSVR ${WAS_INSTALL_ROOT}/configuration
  fi
fi
if [ -e ${USER_INSTALL_ROOT}/temp/osgi_instance_location ]; then
  chmod -R o=rwx ${USER_INSTALL_ROOT}/temp/osgi_instance_location
  chown -R QEJBSVR ${USER_INSTALL_ROOT}/temp/osgi_instance_location
fi
if [ -e ${WAS_INSTALL_ROOT}/temp/osgi_instance_location ]; then
  chmod -R o=rwx ${WAS_INSTALL_ROOT}/temp/osgi_instance_location
  chown -R QEJBSVR ${WAS_INSTALL_ROOT}/temp/osgi_instance_location
fi


exit $RETCODE