#!/bin/bash

# init function for the globus/edg gatekeeper, to export some variables

# The first two can be overridden by external definitions of the variables,
# e.g. if the advertised host name should be an alias

GATEKEEPER_HOST=${GATEKEEPER_HOST:-`hostname -f`}
GATEKEEPER_PORT=${GATEKEEPER_PORT:-2119}

GATEKEEPER_LOCKFILE=/var/lock/edg-gatekeeper

# It seems that the lockfile isn't used in more recent configurations,
# so try finding the process and using the /proc/nnn timestamp

GATEKEEPER_PROCDIR=`/bin/ps axwww | awk '/[g]atekeeper/ { print "/proc/"$1 }' | head -n 1`

GLOBUS_SYSCONFIG=${GLOBUS_SYSCONFIG:-/etc/sysconfig/globus}
if [ -f "$GLOBUS_SYSCONFIG" ]; then
    . "$GLOBUS_SYSCONFIG"
fi

GLOBUS_LOCATION=${GLOBUS_LOCATION:-/opt/globus}

GATEKEEPER_SERVICES=`ls -w 255 -m $GLOBUS_LOCATION/etc/grid-services | sed 's/ //g'`

# Write to stdout - will be imported by the info provider

echo GATEKEEPER_PORT=$GATEKEEPER_PORT
echo GATEKEEPER_HOST=$GATEKEEPER_HOST
echo GATEKEEPER_SERVICES=$GATEKEEPER_SERVICES
echo GATEKEEPER_LOCKFILE=$GATEKEEPER_LOCKFILE
echo GATEKEEPER_PROCDIR=$GATEKEEPER_PROCDIR
