#!/bin/bash

#==================================================
# This shell script is intended to be placed in
# /usr/bin/ and should be run to start a GNUmed
# client.
#
# license: GPL
# Karsten Hilbert, Sebastian Hilbert, Andreas Tille
#--------------------------------------------------

# for debugging this script
# set -x

OPTIONS=$@


# The system-wide configuration file for backend profiles.
SYSCONF="/etc/gnumed/gnumed-client.conf"
if [ ! -e ${SYSCONF} ] ; then
	echo "Global config file ${SYSCONF} missing."
	exit 1
fi


# source systemwide startup extension shell script if it exists
if [ -r /etc/gnumed/gnumed-startup-local.sh ] ; then
	. /etc/gnumed/gnumed-startup-local.sh
fi


# source local startup extension shell script if it exists
if [ -r ${HOME}/.gnumed/scripts/gnumed-startup-local.sh ] ; then
	. ${HOME}/.gnumed/scripts/gnumed-startup-local.sh
fi


# packages which install the GNUmed python modules into a path not
# already accessible for imports via sys.path (say, /usr/share/gnumed/)
# may need to adjust PYTHONPATH appropriately here
#export PYTHONPATH="${PYTHONPATH}:/usr/share/gnumed/"


# now run the client
python -m Gnumed.gnumed ${OPTIONS}


# source systemwide shutdown extension shell script if it exists
if [ -r /etc/gnumed/gnumed-shutdown-local.sh ] ; then
	. /etc/gnumed/gnumed-shutdown-local.sh
fi


# source local shutdown extension shell script if it exists
if [ -r ${HOME}/.gnumed/scripts/gnumed-shutdown-local.sh ] ; then
	. ${HOME}/.gnumed/scripts/gnumed-shutdown-local.sh
fi


# sync the discs just in case so we don't lose log files
sync

#==================================================
