#! /bin/sh

# --- INSTALLATION SCRIPT for FWEB ---
# (Try to use ./configure instead.)

# USAGE:  INSTALL.FWEB [d]
#  (d means debugging option)

# THE FOLLOWING DEFINITIONS MUST BE IN ACCORD WITH THOSE IN setup.mk!
# Default FWEB directory structure a la the TAR file:
boot="boot"
demos="demos"
manual="manual"
web="web"

# --- DON'T CHANGE ANYTHING BELOW HERE! ---

# For debugging, say ``ECHO=echo''; for production, say ``ECHO=''
if [ ! "$1" ]
then
 ECHO=
else
 ECHO=echo
fi

# Prompts:
Iprompt=""
Rprompt=">>>"

# Miscellaneous stuff
FWEB_version="1.30"
FWEB_date="June 15, 1993"

Feditor=""
Fprompt=""

# Set up the PWD:
if [ ! "$PWD" ]
then
 PWD=.
fi

# Start-up messages to screen.
clear
echo "--- Welcome to the FWEB old-style installation procedure for Unix systems ---"
echo "                        FWEB Version $FWEB_version ($FWEB_date)"
echo ""

# Check for Makefile present.
isMakefile=y
for mfile in web/Makefile manual/Makefile
do
 if  test ! -f "$mfile"
 then
   echo "ERROR:  Missing $mfile!!!"
   isMakefile=n
 fi
done
if [ $isMakefile = n ]
then
 exit
fi

# Preliminary warnings and instructions.
bootsd=$boot/???
echo "Questions, suggestions, and bug reports to krommes@princeton.edu."
echo ""
echo "[If you want to run this script in debugging mode (commands are merely"
echo "displayed, not executed), type \`\`install.fweb d''.]"
echo ""
echo "IF YOU ARE A UNIX USER, YOU DON'T NEED TO USE THIS SCRIPT."
echo "Rather, type"
echo ""
echo "      ./configure"
echo "      cd web"
echo "      make bootstrap"
echo " [ Log on as root ]"
echo "      make install"
echo ""
echo "(This is equivalent to bootstrap option 0 below.)"
echo "For further discussion, see READ_ME.FWEB."
echo ""
echo "You must worry about several things:"
echo ""
echo " (1)  WARNING:  This script isn't fully error-trapped yet for"
echo "      things like missing files!"
echo ""
echo " (2)  This script will ask you to select a boot subdirectory."
echo "      If you are not using the automatic configuration option 0,"
echo "      it will then copy $bootsd/defaults.mk to web/defaults.mk."
echo "      You may need to change some things in web/defaults.mk such as"
echo "      compiler options to make things work with your system."
echo ""
echo "      For example, users of Cray's scc compiler need to change the"
echo "      default name of cc to scc, and must remove the -o option from the"
echo "      compiler command line."
echo ""
echo "      Also, if your compiler has a switch to force the |char| type to be"
echo "      |unsigned|, you should use that.  For example, FWEB will compile"
echo "      on the DECstation with the ansi bootstrap provided one uses the"
echo "      -unsigned option."
echo ""
echo " (3)  This script will also create $web/custom.h, either by running"
echo "      configure or by copying $bootsd/custom.h to $web/custom.h."
echo "      If the bootstrap doesn't work, you may need to change some things"
echo "      in $web/custom.h.  If you do, please let me know."
echo ""
echo " (4)  The last actions of this script attempt to copy files to system"
echo "      areas.  You must be root to that to succeed."
echo ""
echo "$Rprompt PLEASE TYPE ONE OF THE FOLLOWING:"
echo ""
echo "  y --- PROCEED"
echo "  a --- ABORT"
echo "  i --- SKIP to installation section."
skip_to_install=n
Fprompt=""
while [ ! "$Fprompt" ]
read Fprompt
do
 case "$Fprompt" in
  [yY]) break;;
  [aAnN]) echo "Aborting!"
	exit;;
  [iI]) skip_to_install=y
	break;;
     *) echo "$Rprompt PLEASE TYPE y, a, or i:"
	Fprompt=""
	;;
 esac
done

if [ $skip_to_install = n ]
then

# Select the boot subdirectory.
select_boot=y
while [ $select_boot = y ]
do
 echo "The available BOOT SUBDIRECTORIES are"
 echo ""
 echo " (0) AUTOMATIC UNIX CONFIGURATION"
 echo ""
 echo " (1) $boot/misc/           (miscellaneous unsupported machines)"
 echo ""
 echo "     $boot/ibm/"
 echo " (2)            mvs/      (IBM/MVS)"
 echo " (3)            pc/       (IBM-PC)"
 echo ""
 echo "     $boot/unix/"
 echo " (4)            ansi/     (The PREFERRED, ANSI-C, bootstrap.**)"
 echo " (5)            apollo/   (Nothing's guaranteed here!)"
 echo " (6)            dsu/      (DECstation/ULTRIX)"
 echo " (7)            sgi/      (Silicon Graphics IRIS)"
 echo ""
 echo "                sun/"
 echo " (8)                cc/   (Sun's standard C compiler; DO NOT USE)"
 echo " (9)                gcc/  (GNU's cc; PREFERRED)"
 echo ""
 echo "(10) $boot/vax             (VAX/VMS)"
 echo ""
 echo "** Always use the ANSI bootstrap and GNU's gcc compiler if possible!"
 echo "   For v1.30, many of the other bootstraps have not been tested,"
 echo "   since ANSI compilers are becoming much more widespread."
 echo ""
 copy_boot=y
 echo "$Rprompt PLEASE TYPE THE NUMBER OF YOUR BOOT SUBDIRECTORY (a to abort);"
 read nboot
 auto_conf=n
 while true
 do
  case "$nboot" in
   [aAnN]) echo "Aborting!"
 	exit;;
   0) auto_conf=y
	break;;
   1) bootsd=$boot/misc
	break;;
   2) bootsd=$boot/ibm/mvs
	break;;
   3) bootsd=$boot/ibm/pc
	break;;
   4) bootsd=$boot/unix/ansi
	break;;
   5) bootsd=$boot/unix/apollo
	break;;
   6) bootsd=$boot/unix/dsu
	break;;
   7) bootsd=$boot/unix/sgi
	break;;
   8) bootsd=$boot/unix/sun/cc
	break;;
   9) bootsd=$boot/unix/sun/gcc
	break;;
  10) bootsd=$boot/vax
	break;;
     *) echo "$Rprompt THAT NUMBER IS INVALID!  PLEASE TRY AGAIN:"
	read nboot;;
  esac
 done

 echo ""
 echo "The following will happen:"
 echo ""
if [ $auto_conf = y ]
then
 echo "  ./configure"
else
 echo "  cp $bootsd/custom.h $web"
 echo "  cp $bootsd/defaults.mk $web"
fi
 echo ""
 echo "$Rprompt PLEASE TYPE ONE OF THE FOLLOWING:"
 echo ""
 echo "  y --- PROCEED with the configuration."
 echo "  n --- SELECT another boot subdirectory."
 echo "  0 --- SKIP the configuration commands and PROCEED."
 echo "  a --- ABORT!"
 Fprompt=""
 while [ ! Fprompt ]
 read Fprompt
 do
  case "$Fprompt" in
   [yY]) copy_boot=y
	 select_boot=n
	break;;
   [0]) copy_boot=n
	select_boot=n
	break;;
   [aA]) echo "Aborting!"
	exit;;
   [nN]) break;;
     *)  echo "$Rprompt PLEASE TYPE y OR n:"
 	Fprompt=""
	;;
  esac
 done
done # End of boot subdirectory selection.

# Copy files from boot subdirectory to final resting places.
if [ $copy_boot = y ]
then
 echo ""
 if [ $auto_conf = y ]
 then
  $ECHO ./configure
 else 
 $ECHO cp $bootsd/custom.h $web
 $ECHO cp $bootsd/defaults.mk $web
 fi
else
 echo ""
 echo "Skipped configuration commands."
fi
echo ""

# Do the make.
echo "Now ready to run make.  Here's what will happen:"
echo ""
($ECHO cd web; $ECHO make -n bootstrap)
echo ""
echo "$Rprompt DO THE MAKE FOR REAL?  [y/n]"
Fprompt=""
while [ ! Fprompt ]
read Fprompt
do
 case "$Fprompt" in
  [yY]) ($ECHO cd web; $ECHO make bootstrap)
	break;;
  [nN]) break;;
  [aA]) echo "Aborting!"
	exit;;
     *) echo "$Rprompt PLEASE TYPE y OR n:"
	Fprompt=""
	;;
 esac
done

fi

echo ""
echo "Now ready to copy to system areas.  YOU MUST BE ROOT TO PROCEED!"
echo "The following will happen:"
echo ""
($ECHO cd web; $ECHO make -n install)
echo ""
echo "$Rprompt PLEASE TYPE ONE OF THE FOLLOWING:"
echo ""
echo "  y --- PROCEED with the copies."
echo "  n --- Skip the copies and proceed to final advice."
echo "  a --- ABORT!"
Fprompt=""
while [ ! Fprompt ]
read Fprompt
do
 case "$Fprompt" in
  [yY]) copy_system=y
	break;;
  [nN]) copy_system=n
	break;;
  [aA]) echo "Aborting!"
	exit;;
 esac
done

echo ""
if [ $copy_system = y ]
then
 echo ""
 ($ECHO cd web; $ECHO make install)
else
 echo ""
 echo "Skipped final copies to system areas."
fi

# Some final advice.
echo ""
echo ""
echo "SOME FINAL ADVICE:"
echo ""
echo "* The user manual now has its own make file, manual/Makefile."
echo ""
echo "* To obtain a short reference guide, type"
echo ""
echo "         cd manual"
echo "         make guide"
echo ""
echo "* To obtain the complete (LONG!) user manual, type"
echo ""
echo "         cd manual"
echo "         make manual"
echo ""
echo "* For brief information about some important entry points to the Makefiles,"
echo "  type \`\`make help''.  For more information, see the discussion in the"
echo "  beginning of Makefile."
echo ""
echo ""
echo "Please send questions, suggestions, and bug reports to krommes@princeton.edu."