c846cda
#!/bin/sh
c846cda
###########################################################################
c846cda
scriptversion="2.1.4 (Debian @DEB_PKG_VERSION@)"
c846cda
###########################################################################
c846cda
##
c846cda
#W gapd                   The SCSCP package             Alexander Konovalov
c846cda
#W                                                             Steve Linton
c846cda
##
c846cda
## gapd [-h host] [-a] [-l] [-u] [-p port] [-t]
c846cda
##
c846cda
## The following options may be used to overwrite the default method to
c846cda
## specify the hostname to run GAP SCSCP server, stated in scscp/config.g :
c846cda
##
c846cda
## 1) if '-h host' is specified, then the server will be started at 'host'.
c846cda
##    'host' may be given as machine name with or without domain or even as
c846cda
##    'localhost', though we have -l option for that purpose
c846cda
##
c846cda
## 2) if '-a' is specified, then the output of the call to 'hostname' will
c846cda
##    be used as the SCSCP server address
c846cda
##
c846cda
## 3) if '-l' is specified, then the server will be started at localhost
c846cda
##    and will not accept any incoming connections from the outside
c846cda
##
c846cda
## 4) if '-u' is specified, the server will be started in a "universal"
c846cda
##    mode and will accept all incoming connections
c846cda
##
c846cda
## The options 1-4 above are incompatible, so in case several of them will
c846cda
## be given, only the option with the biggest number will be used
c846cda
##
c846cda
## If none of the options 1-4 above is stated, the hostname for the server
c846cda
## will be taken from the scscp/config.g file
c846cda
##
c846cda
## Additionally, you may use the following options:
c846cda
##
c846cda
## 5) if '-p port' is specified, this will overwrite the default port for
c846cda
##    the SCSCP server given in scscp/config.g
c846cda
##
c846cda
## 6) if '-t' is specified then the output will be redirected to a
c846cda
##    temporary file, which name will be displayed on screen during
c846cda
##    startup. Otherwise, by default it will be redirected to /dev/null
c846cda
##
c846cda
###########################################################################
c846cda
##
c846cda
##  modified on behalf of Debian by Jerome Benoit <calculus@rezozer.net>
c846cda
##
c846cda
###########################################################################
c846cda
scriptname=${0##*/}
c846cda
###########################################################################
c846cda
##
c846cda
## PART 0. DAEMON VARIABLES
c846cda
##
c846cda
###########################################################################
c846cda
##
c846cda
CONFDIR=/etc/scscp/gap
c846cda
LOGDIR=/var/log/gapd
c846cda
LOGFILE=$LOGDIR/gapd.log
c846cda
##
c846cda
###########################################################################
c846cda
c846cda
###########################################################################
c846cda
## USAGE
c846cda
###########################################################################
c846cda
##
c846cda
## usage string formatted with help2man in mind
c846cda
usage="\
c846cda
Usage: $scriptname [-h HOST|-a|-l|-u] [-p PORT] [-t [MODE]] \
c846cda
[--infolevel[-scscp|-master] LEVEL] [--help] [--version]
c846cda
c846cda
GAP Daemon - GAP SCSCP server daemon
c846cda
c846cda
Options:
c846cda
   -h HOST\tStart at host HOST: HOST may be given as machine name with or
c846cda
          \twithout domain or as 'localhost' (see option -l for that purpose).
c846cda
   -a     \tSet server address to the one given by hostname(1).
c846cda
   -l     \tStart at localhost: reject incoming any connection from the outside.
c846cda
   -u     \tStart in \`universal' mode: accept all incoming connections.
c846cda
c846cda
   -p PORT\tSet server port to PORT, default port set in \`${CONFDIR}/config.g'.
c846cda
c846cda
   -t MODE\tRedirect the server session output according to the following MODEs:
c846cda
          \tMODE=no sink the output to \`/dev/null' (default behaviour);
c846cda
          \tMODE=log redirect the output to \`${LOGFILE}';
c846cda
          \tMODE=yes redirect the output to a temporary file, which name is displayed
c846cda
          \t(and printed to \`${LOGFILE}' for granted users);
c846cda
          \tthe implicit mode is MODE=yes for backward compatibility.
c846cda
c846cda
   --infolevel-scscp LEVEL  \tSet the GAP InfoLevel for SCSCP to LEVEL.
c846cda
   --infolevel-master LEVEL \tSet the GAP InfoLevel for MasterWorker to LEVEL.
c846cda
   --infolevel LEVEL        \tIndiscriminately set the GAP InfoLevel_s to LEVEL.
c846cda
c846cda
   --help    \tPrint this help text and exit.
c846cda
   --version \tOutput version information and exit.
c846cda
c846cda
"
c846cda
##
c846cda
###########################################################################
c846cda
c846cda
###########################################################################
c846cda
##
c846cda
## PART 1. MODIFY PATHS IF NEEDED
c846cda
##
c846cda
###########################################################################
c846cda
##
c846cda
##  Define the local call of GAP and call options, if necessary, for
c846cda
##  example, memory usage, start with the workspace etc. The path may be
c846cda
##  relative (to start from this directory) or absolute.
c846cda
##
c846cda
CGAP=/usr/bin/gap
c846cda
GAP="$CGAP -b -r"
c846cda
##
c846cda
###########################################################################
c846cda
##
c846cda
##  Define the configuration file for the SCSCP server. Note that since GAP
c846cda
##  reads the configuration file immediately before starting SCSCP server,
c846cda
##  you may redefine in it all variables that were set to their default
c846cda
##  values in scscp/config.g and scscp/configpar.g files (explicitly or
c846cda
##  reading your appropriately modified private copies of that files).
c846cda
##  The path may be relative (to start from this directory) or absolute.
c846cda
##
c846cda
SCSCP_CONFIG=${CONFDIR}/server.g
c846cda
##
c846cda
##
c846cda
###########################################################################
c846cda
c846cda
###########################################################################
c846cda
##
c846cda
## PART 2. YOU NEED NOT TO MODIFY ANYTHING BELOW
c846cda
##
c846cda
###########################################################################
c846cda
##
c846cda
##  Parse the arguments.
c846cda
##
c846cda
autohost="no"
c846cda
localhost="no"
c846cda
unimode="no"
c846cda
use_temp_file="no"
c846cda
host=";"
c846cda
port=";"
c846cda
infolevel_scscp=0
c846cda
infolevel_master=0
c846cda
c846cda
option="yes"
c846cda
while [ $option = "yes" ]; do
c846cda
  option="no"
c846cda
  case $1 in
c846cda
    -a) shift; option="yes"; autohost="yes";;
c846cda
    -h) shift; option="yes"; host=":=\""$1"\";"; shift;;
c846cda
    -l) shift; option="yes"; localhost="yes";;
c846cda
    -u) shift; option="yes"; unimode="yes";;
c846cda
    -p) shift; option="yes"; port=":="$1";"; shift;;
c846cda
    -t) shift; option="yes";
c846cda
        if [ 0 -lt $# ]; then
c846cda
          case "$1" in
c846cda
            -*) ;;
c846cda
					  *)
c846cda
              case "$1" in
c846cda
                l|lo|log) use_temp_file="log" ;;
c846cda
                n|no) use_temp_file="no" ;;
c846cda
                y|ye|yes|*) use_temp_file="yes" ;;
c846cda
              esac
c846cda
						  shift
c846cda
              ;;
c846cda
          esac
c846cda
				else
c846cda
				  use_temp_file="yes"
c846cda
				fi
c846cda
				;;
c846cda
		--infolevel-scscp) shift; option="yes"; infolevel_scscp=$1; shift;;
c846cda
		--infolevel-master) shift; option="yes"; infolevel_master=$1; shift;;
c846cda
		--infolevel) shift; option="yes";
c846cda
				infolevel_scscp=$1; shift; infolevel_master=$infolevel_scscp;;
c846cda
		--help) echo "$usage"; exit $?;;
c846cda
		--version) echo "$scriptname $scriptversion"; exit $?;;
c846cda
  esac
c846cda
done
c846cda
eb0b974
if [ -n "${TMPDIR}" -a ! -w "${TMPDIR}" ]; then
c846cda
	unset TMPDIR
c846cda
fi
c846cda
c846cda
case "$use_temp_file" in
c846cda
	log)
c846cda
		OUTFILE=${LOGFILE}
c846cda
		;;
c846cda
	yes)
c846cda
		OUTFILE=$(mktemp --quiet --tmpdir gapd-XXXXXXXXXXX.log)
c846cda
		if [ -w ${LOGFILE} ]; then
c846cda
			cat >> ${LOGFILE} <<- EOM
c846cda
				#############################################################
c846cda
				#D  log: ${OUTFILE}
c846cda
				EOM
c846cda
		fi
c846cda
		echo "Starting SCSCP server with output to ${OUTFILE}"
c846cda
		;;
c846cda
	*)
c846cda
		OUTFILE="/dev/null"
c846cda
		;;
c846cda
esac
c846cda
c846cda
if [ $autohost = "yes" ]; then
c846cda
	host=":=Hostname();"
c846cda
fi;
c846cda
c846cda
if [ $localhost = "yes" ]; then
c846cda
	host=":=false;"
c846cda
fi;
c846cda
c846cda
if [ $unimode = "yes" ]; then
c846cda
	host=":=true;"
c846cda
fi;
c846cda
c846cda
if [ $infolevel_scscp -lt 0 ]; then
c846cda
	infolevel_scscp=0
c846cda
fi;
c846cda
c846cda
if [ $infolevel_master -lt 0 ]; then
c846cda
	infolevel_master=0
c846cda
fi;
c846cda
c846cda
# Check whether ${OUTFILE} is writable
c846cda
if [ -e ${OUTFILE} ]; then
c846cda
	if [ ! -w ${OUTFILE} ]; then
c846cda
		echo "the GAP daemon gapd can not write to the file ${OUTFILE}" 1>&2
c846cda
		exit 2
c846cda
	fi
c846cda
else
c846cda
	OUTFOLDER=$(dirname ${OUTFILE})
c846cda
	if [ ! -w ${OUTFOLDER} ]; then
c846cda
		echo "the GAP daemon gapd can not write into the folder ${OUTFILE}" 1>&2
c846cda
		exit 2
c846cda
	fi
c846cda
fi
c846cda
c846cda
# Check whether the GAP system is available
c846cda
if [ ! -x $CGAP ]; then
c846cda
	echo "the GAP command-line interface $CGAP can not be executed" 1>&2
c846cda
	exit 2
c846cda
fi
c846cda
c846cda
# Check whether the server configuration file is readable
c846cda
if [ ! -r "${SCSCP_CONFIG}" ]; then
c846cda
	echo "the GAP SCSCP server configuration file ${SCSCP_CONFIG} can not be read" 1>&2
c846cda
	exit 2
c846cda
fi
c846cda
c846cda
cat >> ${OUTFILE} <<- EOM
c846cda
	#############################################################
c846cda
	#D  script: ${0} (${scriptversion})
c846cda
	#D  date: $(date -u +%Y%m%dT%H%M%S.%NZ)
c846cda
	#D  host: $(hostname)
c846cda
	#D  user: $(id -un)
c846cda
	#D  infolevel: SCSCP: ${infolevel_scscp}
c846cda
	#D  infolevel: MasterWorker: ${infolevel_master}
c846cda
	#D  TMPDIR: ${TMPDIR}
c846cda
	EOM
c846cda
c846cda
exec $GAP -q >> ${OUTFILE} 2>&1 <<-EOGS &
c846cda
	LoadPackage("scscp");;
c846cda
	SetInfoLevel(InfoSCSCP,${infolevel_scscp});
c846cda
	SetInfoLevel(InfoMasterWorker,${infolevel_master});
c846cda
	SCSCPserverAddress${host};
c846cda
	SCSCPserverPort${port};
c846cda
	Read("${SCSCP_CONFIG}");
c846cda
	if SCSCPserverStatus=fail then
c846cda
			QUIT_GAP();
c846cda
	fi;
c846cda
EOGS
c846cda
c846cda
###########################################################################
c846cda
##
c846cda
#E
c846cda
##