#!/bin/sh 
#--------------------------- Shell MegaWave2 Macro --------------------------#
_sccsid="%Z%MegaWave %R%, %M% %I%, %G%";
_Func="Install a new MegaWave2 version";
_Prog="`basename $0`"
_Vers="1.11"
_Date="1999-2006"
_Auth="Jacques Froment";
_Usage=""
#-----------------------------------------------------------------------------
# This file is part of the MegaWave2 Distribution.
# MegaWave2 is a "soft-publication" for the scientific community. It has
# been developed for research purposes and it comes without any warranty.
# The last version is available at http://www.cmla.ens-cachan.fr/Cmla/Megawave
# CMLA, Ecole Normale Superieure de Cachan, 61 av. du President Wilson,
#       94235 Cachan cedex, France. Email: megawave@cmla.ens-cachan.fr 
#-----------------------------------------------------------------------------
# Run this shell-script to make a new version of MegaWave2.
# It simply calls mwinstall with the right parameters.
#-----------------------------------------------------------------------------

Echo()

{
 echo "$1"
 echo "$1" >> $MWSRC/Install.log
}

Answer()

{
ok=0
while [ $ok -ne 1 ]; do
 if  [ "$2" != "" ]; then
   Echo "$1 [Y/N] ? [default $2]"
 else
   Echo "$1 [Y/N] ?"
 fi
 read ans
 if [ "$ans" = "" ] && [ "$2" != "" ]; then
  ans=$2
 fi
 if [ "$ans" = "y" ] ||  [ "$ans" = "Y" ]; then
   ans="Y"
   ok=1
 fi
 if [ "$ans" = "n" ] ||  [ "$ans" = "N" ]; then
   ans="N"
   ok=1
 fi
 if [ $ok -ne 1 ]; then
  if  [ "$2" != "" ]; then
   Echo "Please, answer Y for Yes or N for No (default means $2) !"
  else
   Echo "Please, answer Y for Yes or N for No !"
  fi
 fi
done
echo "(Answer is $ans)" >> $MWSRC/Install.log
echo ""
}

MWSRC=`/bin/pwd`
#--------------------------
echo ====  >> $MWSRC/Install.log
echo ==== `date`: Run $_Prog Vers $_Vers to install MegaWave2 Vers `cat $MWSRC/VERS` >> $MWSRC/Install.log
echo ====  >> $MWSRC/Install.log
#--------------------------

a=`diff $0 $MWSRC/$_Prog`
if [ "$a" != "" ] || [ ! -r $MWSRC/COPYRIGHT ]; then
    Echo "+++++ Please, run Install from the MegaWave2 Distribution home directory" 
    exit 1
fi
MWSHELL=$MWSRC/kernel/shell
if [ ! -x $MWSHELL/mwinstall ]; then
  Echo "+++++ Cannot exec $MWSHELL/mwinstall : Are you sure you" 
  Echo "+++++ have called Install from the MegaWave2 Distribution home directory ?" 
  exit 1
fi
Guid1=$MWSRC/doc/guid1.dvi
if [ ! -r $Guid1 ]; then
  Echo "+++++ Cannot find documentation $Guid1 : Are you sure you" 
  Echo "+++++ have called Install from the MegaWave2 Distribution home directory ?" 
  exit 1
fi

insopt=""
debug=0

Echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
Echo "This shell is intended to help the MegaWave2 Administrator to install the MegaWave2 software."
Echo "We call MegaWave2 Administrator the user which is in charge of installing and maintaining the"
Echo "local MegaWave2 version. He must not to be root, but he has to be the proprietary of the"
Echo "PRIVATE MegaWave2 Distribution directory $MWSRC."
Echo "If you are not the MegaWave2 Administrator, please exit this shell."
Echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
Echo ""
Echo "In addition to the PRIVATE version, you may want to maintain a PUBLIC version of the software."
Echo "In this way, you will be able to perform changes and tests on the PRIVATE version without"
Echo "bothering the users. To make your changes in effect in the PUBLIC version, you can use this"
Echo "shell or you can directly use system macros you will find in the documentation."
Echo "If you will be the ONLY ONE MegaWave2 user, or if you don't plan to modify MegaWave2, you"
Echo "don't need of course to manage a PUBLIC version. In that case, answer NO to the following"
Echo "question. Later, you will still be able to generate a PUBLIC version by running this shell"
Echo "one more time. If you answer NO, I will install the PRIVATE version only. If you answer YES,"
Echo "I will install both PRIVATE and PUBLIC version".
Answer "Do you want to create or to update a PUBLIC version different to the PRIVATE one" "N"
if [ "$ans" = "Y" ]; then
  insopt="$insopt -public"
else
  Echo "If you answer NO to the following question, it means that you will be the only user"
  Echo "concerned by this current installation."
  Answer "Do you want to make the PRIVATE version the PUBLIC version for all users" "N"
  if [ "$ans" = "Y" ]; then  
    insopt="$insopt -public=private"
  fi
fi

if [ -d $MWSRC/bin ] && [  -d $MWSRC/kernel_obj ] && [  -d $MWSRC/lib ] && \
   [ -d $MWSRC/obj ]; then
  Echo "You have to run Install on each machine architecture you want MegaWave2. If you answer"
  Echo "YES to the following question, it means that you already have installed MegaWave2 for"
  Echo "a machine architecture, and now you want to get the same installation on a new machine."
  Answer "Are you installing a new machine architecture" "N"
  if [ "$ans" = "N" ]; then  
    insopt="$insopt -clear"
  fi
else 
  insopt="$insopt -clear"
fi

Echo "If you answer NO to the following question, optimization will be turned on."
Answer "Do you want to be able to debug the code" "N"
if [ "$ans" = "Y" ]; then  
  insopt="$insopt -debug"
  debug=1
fi
Echo "If you answer NO to the following question, kernel libraries will be shared."
Echo "WARNING : modules linked with static kernel libraries use lot of DISK and RAM memory."
if [ $debug -eq 1 ]; then
  Echo "However, some debuggers don't correctly work with shared libraries;"
  Echo "so you may want to answer YES to safely debug the code."
fi
Answer "Do you want to create STATIC kernel libraries" "N"
if [ "$ans" = "Y" ]; then  
  insopt="$insopt -static"
  Echo "OK, but I hope you know what your are doing !"
fi

Echo "**** This version includes the new 'light' preprocessor ****"
Echo "At the time being, the system will install both 'traditional' and 'light' preprocessors"
Echo "so that you can compile modules using the preprocessor of your choice."
Echo "Now, you have to decide which one you want to use for the first compilation phase."
Echo "If you answer NO to the following question I will use the 'light' preprocessor if possible"
Echo "that is, I will turn to the 'traditional' one only if your system fails with the 'light' one."
Answer "Do you want to use the 'traditional' preprocessor" "N"
if [ "$ans" = "Y" ]; then  
  insopt="$insopt -traditional"
fi

Echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
Echo "Well ladies and gentlemen, I am ready to start the BIG installation process"
Echo ""
Echo "  $MWSHELL/mwinstall $insopt $MWSRC"
Echo ""
Echo "This installation process is supposed to work on the very most common systems only."
Echo "In any case, remember that NOTHING is WARRANTY and please read the manuals, starting"
Echo "with Volume 1 located at $Guid1."
Echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
Echo "" 

xdvi=`which xdvi | cut -d " " -f 1`
if [ "$xdvi" != "" ]; then
 if [ -x $xdvi ]; then
  xdvi -s 9 -iconic $Guid1 1> /dev/null 2> /dev/null &
  Echo "+++++ An Icon is created to display the MegaWave2 User's Guide (Vol.1)."
 fi
fi

Echo "+++++ Press <return> to process..."
read key

Echo "+++++ Please watch the screen, you may have to answer to some questions while the installation progresses. "

machinetype=`$MWSHELL/mwarch -s`
MWPROFILE=$MWSRC/sys/lib/$machinetype/.profile_adm_megawave2
MWCSHRC=$MWSRC/sys/lib/$machinetype/.cshrc_adm_megawave2

$MWSHELL/mwinstall $insopt $MWSRC

if [ $? -ne 0 ]; then
  Echo "+++++ Installation NOT COMPLETE using"
  Echo "+++++      $MWSHELL/mwinstall $insopt $MWSRC"
  Echo "+++++ Try to fix the problem (look at '$MWSRC/Install.log') and rerun mwinstall."
  Echo "+++++ If mwinstall has failed at a level greater than 1, you may save time"
  Echo "+++++ by adding the parameter '-level l'. In that case, make sure "
  Echo "+++++ your environment variables are correctly set."
else
  Echo "+++++ Installation DONE using"
  Echo "+++++      $MWSHELL/mwinstall $insopt $MWSRC"
  Echo "+++++ Before using MegaWave2, you need to set the environement variables in your shell."
fi
if [ -x $MWPROFILE ] || [ -x $MWCSHRC ]; then
  Echo "+++++ The environment variables you need are initialized in the following files :"
  if [ -x $MWPROFILE ]; then 
    Echo "+++++ $MWPROFILE (Profile for Bourne-compatible shells)"
  fi
  if [ -x $MWCSHRC ]; then 
    Echo "+++++ $MWCSHRC (Csh for C-compatible shells)"
  fi
fi


