#!/bin/sh
# This script OMNotebook is a start script. It launches the Qt based pro-
# gram OMNotebook. Before launching it creates a sub directory in users
# home directory, if launched from GNOME or Debian menu. If launched
# from a console it doesn't create a sub directory in the users home
# directory. The user get a hint, how he or she should start the script
# from the console.
#
# The script OMNotebook should be an interim solution until the Qt
# based program OMNotebook has a setting menu.
#
# The script OMNotebook based on the work of William Spinelli's
# package_builder and changed by Robert Wotzlaw.

OMDIR=OMWorkspace                        # OpenModelica Workspace
PPROC=`which $(ps -p ${PPID} -o comm=)`  # Prog name with path from 
                                         # parent process ID

# No OMWorkspace in user's home dir and not started from terminal console
# or console (bash), then create dir OMWorkspace and change in dir.
if [ ! -e ${HOME}/${OMDIR} ] && [ "${PPROC}" != "${SHELL}" ]
then
   mkdir ${HOME}/${OMDIR}
   cd ${HOME}/${OMDIR}

# OMWorkspace exist and not started from terminal console
# or console (bash), then change directory.
elif [ -d ${HOME}/${OMDIR} ] && [ "${PPROC}" != "${SHELL}" ]
then
   cd ${HOME}/${OMDIR}

# Started from terminal console or console (bash) and current dir is
# user home dir, then give a hint and exit.
elif [ "${PPROC}" = "${SHELL}" ] && [ "`pwd`" = "${HOME}" ]
then
   clear
   echo "   
   Dear user ${USER},
   
   You launched OpenModelica  OMNotebook from Your home directory:
   
   ${HOME}
   
   Please  create a sub  directory and change into the new created
   sub  directory. In the sub directory  launch OMNotebook  again.
   
   Creating and  changing the sub  directory is necessary, because
   OMNotebook  creates  temporary files during the runtime. If You
   not created a sub directory, OMNotebook would clutter Your home
   directory with temporary files.
   
   Thanks
   "
   exit 0
fi

# Set OpenModelica OMNotebook environment variables.
export OPENMODELICAHOME=/usr/lib/omc
export OPENMODELICALIBRARY=/usr/share/omlibrary/modelicalib/
export DRMODELICAHOME=/usr/share/omnotebook/drmodelica/
export QTHOME=${OPENMODELICAHOME}/lib

# Run the Qt based OMNotebook.
exec ${OPENMODELICAHOME}/bin/OMNotebook $*
