#!/bin/sh
#################################################################
#                                                               #
#       Copyright 2010,2013 Fidelity Information Services, Inc  #
#                                                               #
#       This source code contains the intellectual property     #
#       of its copyright holder(s), and is made available       #
#       under a license.  If you do not know the terms of       #
#       the license, please stop and do not read further.       #
#                                                               #
#################################################################
if [ ! -f "GTMDIST"/gtmprofile ] ; then echo Cannot find file "GTMDIST"/gtmprofile to source
else
    . "GTMDIST"/gtmprofile
    timestamp=`date -u +%Y%m%d%H%M%S`"UTC"
    ( cd `dirname $gtmgbldir` ; \
	$gtm_dist/mupip journal -recover -backward "*" 2>$gtm_tmp/"$USER"_$timestamp"_mupip_recover" && \
	$gtm_dist/mupip set -journal="on,before" -region "*" 2>$gtm_tmp/"$USER"_$timestamp"_mupip_set" && \
	find . -name \*.mjl_\* -mtime +$gtm_retention -exec rm -vf {} \; )
    if [ 0 = $# ] ; then
	$gtm_dist/mumps -direct
    elif [ "-help" = "$1" -o "-h" = "$1" -o "-?" = "$1" ] ; then
	echo "gtm -dir[ect] to enter direct mode (halt returns to shell)"
	echo "gtm -run <entryref> to start executing at an entryref"
	echo "gtm -help / gtm -h / gtm -? to display this text"
    else
	$gtm_dist/mumps $*
    fi
    ( cd `dirname $gtmgbldir` \
	$gtm_dist/mupip rundown -region "*" 2>$gtm_tmp/"$USER"_$timestamp"-"`date -u +%Y%m%d%H%M%S`"UTC_mupip_rundown" )
    find $gtm_tmp -name "$USER"_\* -mtime +$gtm_retention -exec rm -f {} \;
fi
