#!/bin/bash
### BEGIN BOOT SCRIPT INFO
#Long-Name: p50em
### END BOOT SCRIPT INFO
### BEGIN BOOT SCRIPT INSTALLATION DEFAULTS
#Launch-Mode: terminal-only
### END BOOT SCRIPT INSTALLATION DEFAULTS
#
#This script uses a standard run scriptlet called RUN_P50EM, which should
#end with a call to run_p50em (which passes its options to p50em).
#$PRIMOS_VERSION should be set to the PRIMOS version (for the screen session
#name). Some versions of PRIMOS may require helper scripts, which should be run
#before calling run_p50em.
#
#This script runs p50em in screen with a session attached to the terminal.
#Setting $P50EM_DETACH before running the boot script will instead start with
#the screen session detached. This should not be set in RUN_P50EM, in order to
#allow the user to choose whether to detach on startup.

. bootscriptfunctions.sh

if [ ! "$_DEFAULT_P50EM" ]
then
	_DEFAULT_P50EM=p50em
fi

if [ ! "$_P50EM" ]
then
	_P50EM=$_DEFAULT_P50EM
fi

SCRIPT_ARGS=("$@")

run_p50em()
{

	LOG=logs/console.log.`date +%Y-%m-%d_%H:%M:%S`
	touch $LOG
	rm -f console.log
	ln $LOG console.log
	exec screen -h 1000 $SCREENMODE -m -S p50em"$PRIMOS_VERSION" "$_P50EM" \
		"${SCRIPT_ARGS[@]}" \
		"$@"
}

if [ "$P50EM_DETACH" ]
then
        SCREENMODE="-d"
fi

call_run_scriptlet p50em
