#!/bin/sh
# this little shell script simply attempts to automatically make, and install
# netscript. (this turned into a "portable" shell script, that is why it isn't
# exactly pretty(but, i am not very pretty/clean anyways) -- made to work on
# different platforms)
echo "[ netscript/automake: automation of compiling sequence. ]"
echo "* Attempting to see if gcc is located on this system..."
CHECKGCC=`which gcc 2>/dev/null`
if test -x "$CHECKGCC"
then
 echo "* Found gnu compiler to compile with..."
else
 echo "! no gnu compiler found to compile with."
 exit
fi
echo "* Deleting any old local/global data if possible..."
if test "$UID" = "0"
then
 make cleanall
else
 make clean
fi
echo "* Attempting to use uname to decide what to compile as..."
COMPTYPE=`uname`
if test -z $COMPTYPE
then
 echo "! no operating system found."
 exit
fi
echo "* Attempting to see if GTK is located on this system..."
CHECKGUI=`which gtk-config 2>/dev/null`
if test -x "$CHECKGUI"
then
 CHECKGUI="G"
else
 CHECKGUI=""
fi
echo "* Attempting to use type \"$COMPTYPE\" as compiler type..."
make $CHECKGUI$COMPTYPE
if test "$UID" = "0"
then
 echo "* UID is zero(root), attempting to install to bin directory..."
 make ${CHECKGUI}install
 if test -d "/usr/man/man1/"
 then
  echo "* Installing netscript man page, for informational use..."
  cp -f netscript.1.gz /usr/share/man/man1
  chmod 644 /usr/share/man/man1/netscript.1.gz
  ln -sf /usr/share/man/man1/netscript.1.gz /usr/share/man/man1/gnetscript.1.gz 
  ln -sf /usr/share/man/man1/netscript.1.gz /usr/share/man/man1/ns.1.gz 
 else
  echo "* Could not install man page, man page directory is non-existent..."
 fi
else
 echo "* UID is NOT zero(root), skipping install to bin directory..."
fi
if test -d "modules/"
then
 echo "* Module sub directory exists, attempting to compile..."
 cd modules/
 echo "* Deleting any old module data if possible..."
 make clean
# was using -C with make, but apparently not all versions have -C.  so...
 make $CHECKGUI$COMPTYPE
 cd ..
else
 echo "* Module sub directory does not exist, skipping compile..."
fi
echo "* Done."
