#!/bin/sh
# Run this to make sure you set up the INL server correctly

ERR=0

if [ ! -f ./config/system.mk ] ; then
   echo "! ./config/system.mk doesn't exist."
   echo "You need to make a symbolic link from one of the files in the ./config"
   echo "directory to system.mk.  For example, on Ultrix you would do"
   echo "'ln -s ultrix.mk system.mk'.  See ./INSTALL for more details."
   exit 1
fi
CONFIG=./config/system.mk

if [ ! -f ./ntserv/rsa_utilmp.c ] ; then
   echo "! ./ntserv/rsa_utilmp.c doesn't exist."
   echo "If you want to use RSA on this server, you'll have to get that file."
   echo "See ./INSTALL for more details."
   exit 1
fi

if [ ! -f ./ntserv/reserved.c ] ; then
   echo "! ./ntserv/reserved.c doesn't exist."
   echo "You should either make a symbolic link from ./ntserv/reserved.c.shipped"
   echo to "reserved.c or get a \"blessed\" version from somewhere."
   exit 1
fi

XSG=0

if [ ! -d ./xsgd ] ; then
   echo "! ./xsgd does not exist."
   echo "This is not a problem if you don't want to use XSG on this server."
   echo "Otherwise, see ./INSTALL for how to get the INL XSG source."
   echo
else
   if [ ! -r ./xsgd/struct.h ] ; then
      echo "! ./xsgd/struct.h doesn't seem to be linked properly."
      echo "Make sure that file is symbolically linked to the INL ntserv/struct.h"
      ERR=1
   fi
   if [ ! -r ./xsgd/defs.h ] ; then
      echo "! ./xsgd/defs.h doesn't seem to be linked properly."
      echo "Make sure that file is symbolically linked to the INL ntserv/defs.h"
      ERR=1
   fi
   XSG=1
fi

# Warning: dependency on config variables names

BIN="`egrep '^XTREKDIR' $CONFIG | awk -F= '{print $2}'`"

if [ "${BIN}x" = x ] ; then
   echo "! I couldn't find XTREKDIR in $CONFIG."
   ERR=1
else
   if [ ! -d $BIN ] ; then
      echo "! $BIN doesn't exist (XTREKDIR in $CONFIG)."
      echo "You probably need to 'mkdir $BIN'."
      ERR=1
   fi
fi

GMP="`egrep '^GMP' $CONFIG | awk -F= '{print $2}'`"

if [ "${GMP}x" != x ] ; then
   if [ ! -d $GMP ] ; then
      echo "! $GMP doesn't exist (GMP in '$CONFIG')."
      echo "If you plan to use RSA, this directory will be searched for the"
      echo "GNU mp libraries."
      exit 1
   fi
fi

if [ $XSG -eq 1 ] ; then
   X11LIB="`egrep '^X11LIB' $CONFIG | awk -F= '{print $2}'`"
   if [ "${X11LIB}x" = x ] ; then
      echo "! X11LIB hasn't been defined in $CONFIG."
      echo "If you plan to use XSG, this variable should have the compiler"
      echo "flags to allow linking with the X library (-lX11)."
      exit 1
   fi
fi

if [ $ERR -ne 1 ] ; then
   echo "You're all set!"
   echo "Now do 'make depend' and then 'make install'.  If those are sucessful:"
   echo "+ Edit $BIN/.motd "
   echo "  to add local server information."
   echo "+ Check or edit $BIN/.sysdef"
   echo "  for any specific server configuration."
   echo "+ Check or edit $BIN/.ports"
   echo "  if you want to change default ports."
   echo "+ Run $BIN/rsa_getkeys"
   echo "  to initialize the RSA reserved file."
   echo "  If you need to edit rsa_keycap after the previous step do"
   echo "  'rsa_keycomp -o ./RSAreserved rsa_keycap'"
   echo "+ Run $BIN/start_tourney"
   echo
fi
