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