:
# Configuration script for Clover
#
#  written by Brett M Hogden on 910716
#  modified for server setup by Stephen H. Underwood 9 - 11 - 92 
#
#   Copyright (C) 1991 Free Software Foundation, Inc.
#
#   This file is part of the Clover communications package.
#
#   CCP is free software; you can redistribute it and/or modify it
#   under the terms of the GNU General Public License as published by
#   the Free Software Foundation; either version 1, or (at your option)
#   any later version.  The only constraint imposed upon you by me, this
#   script's author: if I ask you to no longer distribute it, in part or
#   in whole, you may not - in fact, I retain free right to impose any
#   sort of more restrictive copyright at any time in the future, at my
#   discretion.
#
#   CCP is distributed in the hope that it will be useful, but WITHOUT
#   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
#   or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
#   License for more details.
#
#   You should have received a copy of the GNU General Public License
#   along with CCP; see the file COPYING.  If not, write to the Free
#   Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
#
# Shell script to create proper links to machine-dependent files in
# preparation for compiling Clover.
#
# Usage: config.clover [-d] [machine]
#        config.clover -list
#
# If config.clover succeeds, it leaves its status in config.status.
# If config.clover fails after disturbing the status quo, 
#       config.status is removed.
#

# make sure we're running under bourne shell
export PATH || exec sh -c "$0 $*"

# retain original args because some versions of bourne shell mung them
# when functions are called within the script (stupid AIX/370!)
# NOTE: not used, yet
orig_args="$*"

if test -x /bin/basename; then
  prog=`basename $0`
else
  prog=$0
fi

# error function -- echoes to standard error
cc_error()
{
  echo "$prog: $*" >& 2
}

remove="rm -f"
move="mv -f"
server=server
cid=cid

# print usage information
usage()
{
  echo "usage: $prog - setup directory to run server in" >& 2
}

# if the script somehow aborts, cleanup -- including removal of config.status
user_abort()
{
  exit 1
}

# check for a file, skip if missing
skip_if_missing()
{
  if test ! -f $1; then
    cc_error "$1 not found -- skipping that part"
    SIM=
  else
    SIM=$1
  fi
}

# check for a file, abort if missing
abort_if_missing()
{
  if test ! -f $1; then
    cc_error "$1 not found -- aborting"
    user_abort
  fi
}

trap user_abort 1 2 3 15

# handle the arguments:
#  either (1) transform machine name given to a standardised alias,
#      or (2) use all the default settings
#      or (3) give the list of machines and exit,
#      or (4) give an error and exit
# set the defaults, some based on machine name

# try to determine which form of echo to use
case "`echo -n`" in
  -n) echo="echo" ; c="\c" ;;
   *) echo="echo -n" ; c="" ;;
esac

while test -z "$servloc"; do
  echo "The server needs it's own directory to run out of."
  $echo "Where do you want to install the server/other files? $c "
  read tmp
  if test -z "$tmp"; then
    echo "You must enter a valid directory."
  else
    servloc=$tmp
  fi
  if test ! -d $servloc; then
    echo "$servloc does not exist" 
    unset servloc
  fi
done

# enter the port to run on.
while test -z "$port"; do
  echo "The server port number must be >1024 unless you are root."
  $echo "Enter a port number for the server $c "
  read tmp
  if test -z "$tmp"; then
    echo "You must enter a port number."
  else
    port=$tmp
  fi
done

# finally, create the actual CloverID.h file & other files
echo "(cd $servloc;nohup rhysdo $port 1>dump 2>&1 &)" >$servloc/rhystart
cp passwd rhystemp rhysdo $servloc
mkdir $servloc/info
mkdir $servloc/stat
mkdir $servloc/dump.dir
chmod 700 $servloc/rhysdo $servloc/rhystart $servloc/rhystemp
chmod 700 $servloc $servloc/dump.dir $servloc/stat $servloc/info
chmod 600 $servloc/passwd

