#!/bin/bash

OFFISSERVERDIR="/ct/offis"
STORESCPBINARY="/usr/local/dicom/bin/storescp"
#
# default port is 104, but we would need to be root to bind to port 104,
# so we default to 1104 allowing the server to run as an oridinary user.
#
PACSPORT="1104"

cd "$OFFISSERVERDIR" || {
	echo "Can't find directory to run OFFIS storage-scp in."
	echo "Please edit the script $0"
	echo "or create the directory $OFFISSERVERDIR"
	exit 1
}

case "$0" in 
	(*stop_offis*)
		kill `cat offis.pid` && rm offis.pid && \
			echo "Killed Server." && \
			xmessage -center -timeout 5 "DICOM Storage Server stopped." && \
			exit 0
		xmessage -center -timeout 5 "DICOM Storage Server not found."
		exit 0;
		;;
esac

nohup $STORESCPBINARY -ss eccet --exec-on-eostudy "eccet_convert_offis #p" \
		--eostudy-timeout 5 "$PACSPORT" >offis.log 2>offis.err &
echo "$!" >offis.pid
xmessage -center -timeout 5 "DICOM Storage Server started"
