#!/bin/sh 
#--------------------------- Shell MegaWave2 Macro --------------------------#
_sccsid="%Z%MegaWave %R%, %M% %I%, %G%";
_Func="Install a new MegaWave2 full version (adm only)";
_Prog="`basename $0`"
_Vers="1.27"
_Date="1999-2006"
_Auth="Jacques Froment";
_Usage="[-static] [-public || -public=private] [-clear] [-debug] [-level l] [-traditional] mw2distribution"
#-----------------------------------------------------------------------------
# This file is part of the MegaWave2 kernel.
# 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
# <mw2distribution> must be a MegaWave2 distribution main directory.
# Options :
# -static : Make static kernel libraries (default : shared)
# -public : Install MegaWave2 both for adm and plain users (default: adm only),
#           using two different locations. 
#           If you select this option and if a previous PUBLIC MegaWave2 is 
#           already installed, select also -clear.
# -public=private : Install MegaWave2 both for adm and plain users (default: adm 
#           only), using only one location.
# -clear : Clear previous version. If a previous version is installed, this
#          option may be required to perform the action you expect.
# -debug : Produce debugging information (default : optimize the code).
# -level l : Install levels greater or equal than l only.
# -traditional : Compile modules using the 'traditional' preprocessor mwp (by default, 
#          it uses the new 'light' preprocessor if possible).
#-----------------------------------------------------------------------------

ChooseTMP()

{
if  [ "$TMP" = ""  ] || [ ! -d $TMP ] ||  [ ! -w $TMP ]; then
 TMP=/usr/tmp
 if  [ ! -d $TMP ] ||  [ ! -w $TMP ]; then
  TMP=/tmp
  if  [ ! -d $TMP ] ||  [ ! -w $TMP ]; then
   echo "$_Prog : Fatal Error : cannot choose TMP !"
   exit 1
  fi
 fi
fi
}

Echo()

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

NewTrap()
{
trap "Echo '***********************************'; \
      Echo '***** Installation canceled ! *****'; \
      Echo '***********************************';\
      Abort" 2 3
}

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 ""
}

Abort()
{
  cd $CWD
  Echo "***** Abort $_Prog at level $level." 
  if [ -d $MWNEWPUB ]; then
    Echo "***** If you don't plan to continue the installation later using '$_Prog -level $level'," 
    Echo "***** you should remove $MWNEWPUB."
    Answer "***** Remove it now" "Y"
    if [ "$ans" = "Y" ]; then
      rm -rf $MWNEWPUB
    fi
  fi
 exit 1
} 


# Usage
if [ $# -lt 1 ] || [ $# -gt 7 ]; then
  . .mw2_help_lg_com
fi


CWD=`/bin/pwd`
pubinstall=0
clear=0
kernelopt=""

ChooseTMP
cmw2trace=${TMP}/cmw2_all$$.trace
cmw2opt="-2p -dep -force -v $cmw2trace"
preferredmwp="mwplight"

setenvopt="-privateonly"
l=1
level=0
MWNEWPUB="/void$$"

while [ "$1" != "" ]
do
        case "$1" in
	  "-static") kernelopt="${kernelopt} -static"
		     shift
		     ;;
	  
	  "-public") kernelopt="${kernelopt} -public"
                     setenvopt=""
		     pubinstall=1
		     shift
		     ;;

	  "-public=private") setenvopt="-public=private"
		     pubinstall=2
		     shift
		     ;;

	  "-clear") kernelopt="${kernelopt} -clear"
		    cmw2opt="${cmw2opt} -clear"
		    clear=1
		    shift
		    ;;

	  "-debug") kernelopt="${libopt} -debug"
		    cmw2opt="${cmw2opt} -g"
		    shift
		    ;;

	  "-level") l=$2
		    shift; shift
		    ;;

	  "-traditional") preferredmwp="mwp"
		    shift
		    ;;

	  
           -*)      . .mw2_help_lg_com
                ;;
 
           *)       MWSRC=$1
		    shift
		    ;;
       
       esac
done


#--------------------------
echo ==== >> $MWSRC/Install.log
echo ==== `date`: Run $_Prog Vers $_Vers >> $MWSRC/Install.log
echo ====  >> $MWSRC/Install.log
#--------------------------

NewTrap

# Set optimization flag for cmw2 if -g not set
a=`echo $cmw2opt | grep "\-g"`
if [ "$a" = "" ]; then
   cmw2opt="${cmw2opt} -O"
fi 

if [ ! -r $MWSRC/VERS ]; then
 Echo "***** Cannot find version file in $MWSRC : Are you sure that" 
 Echo "***** $MWSRC is the MegaWave2 Distribution home directory ?" 
 Abort
fi

if [ ! -r $MWSRC/kernel/Install ]; then
 Echo "***** Cannot find kernel Install in $MWSRC : Are you sure that" 
 Echo "***** $MWSRC is the MegaWave2 Distribution home directory ?"
 Abort
fi

Echo "************************************************************************"
Echo "***** Begin the MegaWave2 Installation Process (cross the fingers) *****"
Echo "************************************************************************"
Echo "***** `date`"

level=`expr $level + 1`
NewTrap
if [ $l -le $level ]; then 
 Echo "*****************************************"
 Echo "***** Level $level : Set the environment *****"
 Echo "*****************************************"

 MWSHELL=$MWSRC/kernel/shell
 if [ ! -x $MWSHELL/mwsetenv ]; then
   Echo "***** Cannot exec $MWSHELL/mwsetenv : Are you sure that" 
   Echo "***** $MWSRC is the MegaWave2 Distribution home directory ?" 
   Abort
 fi
 $MWSHELL/mwsetenv $setenvopt $MWSRC
 if [ $? -ne 0 ]; then
   Echo "***** Error while setting environment !"
   Abort
 fi
 MWSHELL=$MWSRC/kernel/shell
 machinetype=`$MWSHELL/mwarch -s`
 MWPROFILE=$MWSRC/sys/lib/$machinetype/.profile_adm_megawave2
 if [ ! -x $MWPROFILE ]; then
   Echo "***** Cannot exec profile $MWPROFILE !" 
   Abort
 fi
 . $MWPROFILE
 if [ $? -ne 0 ]; then
    Echo "***** Profile $MWPROFILE malformed !" 
    Abort
 fi

# end of level
fi

MWSHELL=$MWSRC/kernel/shell
if [ $pubinstall -eq 1 ]; then
  if [ "$PUBLIC_MEGAWAVE2" = "$PRIVATE_MEGAWAVE2" ]; then
    Echo "***** Option -public is meaningless since PUBLIC MegaWave2 is the same than PRIVATE." 
    Echo "***** Please rerun $_Prog with right options or change PUBLIC_MEGAWAVE2 value." 
    Abort
  fi
  MWDIRPUB=`dirname $PUBLIC_MEGAWAVE2`
  if [ ! -w $MWDIRPUB ]; then
    Echo "***** You don't have permission to install PUBLIC MegaWave2 on $MWDIRPUB !"
    Echo "***** Are you sure you are the MegaWave2 Administrator ?" 
    Abort
  fi
  if [ $clear -eq 1 ] && [ -d $PUBLIC_MEGAWAVE2 ]; then
    MWORGPUB=$PUBLIC_MEGAWAVE2
    if [ -d $MWORGPUB ] && [ ! -r  $MWORGPUB/VERS ]; then
      Echo "***** Cannot find version file in $MWORGPUB !" 
      Echo "***** I suppose this PUBLIC MegaWave2 is an obsolete version." 
      Answer "***** Ok to rename it ${MWORGPUB}_old and continue the installation" "Y"
      if [ "$ans" = "Y" ]; then
        if [ -d ${MWORGPUB}_old ]; then
          Echo "***** This old directory already exists !"  
          Answer "***** Ok to remove it and continue the installation" "Y"
          if [ "$ans" = "Y" ]; then
            rm -rf ${MWORGPUB}_old
          else
            Abort
          fi
        fi                  
        mv $MWORGPUB ${MWORGPUB}_old
      else
        Abort
      fi                  
    fi
  fi
fi

# Set default value for newvers
newvers=`cat $MWSRC/VERS`

# If Install PUBLIC, check if $PUBLIC_MEGAWAVE2 comes from a former incomplete
# installation. If yes, do not create a temporary directory.

#if [ $pubinstall -ne 1 ] || [ ! -r $PUBLIC_MEGAWAVE2/INSTALL_NOT_COMPLETE ]; then
if [ $pubinstall -eq 1 ] && [ ! -r $PUBLIC_MEGAWAVE2/INSTALL_NOT_COMPLETE ]; then

# If Install PUBLIC with clear option selected, it means that users may
# use current version of PUBLIC_MEGAWAVE2 : make the installation in a
# temporary directory.

  if [ $pubinstall -eq 1 ] && [ $clear -eq 1 ] && [ -d $PUBLIC_MEGAWAVE2 ]; then

# Check if the version number major.minor is the same or not that the current
# installation. If the same, increment the variant number of the current
# installation. If not, of the distribution.

    oldvers=`cat $MWORGPUB/VERS`
    mmoldvers=`echo $oldvers | cut -f 1-2 -d "."`
    mmsrcvers=`cat $MWSRC/VERS | cut -f 1-2 -d "."`
    if [ "$mmoldvers" = "$mmsrcvers" ]; then
      newvers=`$MWSHELL/mwincvers $MWORGPUB`
    else
      newvers=`$MWSHELL/mwincvers $MWSRC`
    fi

    MWNEWPUB=$MWDIRPUB/MegaWave2_new_V${newvers}
    PUBLIC_MEGAWAVE2=$MWNEWPUB
    Echo "***** Make PUBLIC installation in the temporary directory $PUBLIC_MEGAWAVE2"
    if [ -d $PUBLIC_MEGAWAVE2 ] && [ $l -le 1 ]; then
      Answer "***** This directory already exists. May I remove it" "Y"
      if [ "$ans" = "Y" ]; then
        rm -rf $PUBLIC_MEGAWAVE2
      else
        Echo "***** OK, hope you know what you are doing..."       
      fi              
    fi
  else

# If Install PUBLIC with no former PUBLIC_MEGAWAVE2, set version to be the 
# version of the distribution in MWSRC.

    if [ $pubinstall -eq 1 ] && [ ! -d $PUBLIC_MEGAWAVE2 ]; then
      newvers=`$MWSHELL/mwincvers $MWSRC`
    fi
  fi

# Make the PUBLIC_MEGAWAVE2 dir if needed

 if [ ! -d $PUBLIC_MEGAWAVE2 ]; then
      mkdir $PUBLIC_MEGAWAVE2
      chmod 755 $PUBLIC_MEGAWAVE2
 fi
 echo $newvers > $PUBLIC_MEGAWAVE2/VERS
 chmod 644 $PUBLIC_MEGAWAVE2/VERS 
fi

if [ $pubinstall -eq 1 ]; then
  touch $PUBLIC_MEGAWAVE2/INSTALL_NOT_COMPLETE
fi

level=`expr $level + 1`
NewTrap
if [ $l -le $level ]; then 
 Echo "****************************************"
 Echo "***** Level $level : Compile the kernel *****"
 Echo "*****************************************"

 cd $CWD/kernel; 
 ./Install $kernelopt
 if [ $? -ne 0 ]; then
   Echo "***** Error while compiling kernel !" 
   Abort
 fi
# end of level
fi

level=`expr $level + 1`
NewTrap
if [ $l -le $level ]; then 
 Echo "*****************************************"
 Echo "***** Level $level : Compile the modules *****"
 Echo "*****************************************"

# Check if cmw2 works well and using which preprocessor. If not, output error message from cmw2
# so the user can guess what is happening.
 
 mwcmwcheck
 res=$?
 if [ $res -eq 1 ] ||  [ $res -eq 2 ]; then
   Echo "***** Modules cannot be compiled ! It means something went wrong during the kernel installation stage..." 
   Abort
 fi
 if [ $res -eq 3 ]; then
  if [ "$preferredmwp" != "mwplight" ]; then
   Echo "***** Modules cannot be compiled using the 'traditional' preprocessor ! Switching to the 'light' one..." 
   preferredmwp="mwplight"
  fi
 fi
 if [ $res -eq 4 ]; then
  if [ "$preferredmwp" != "mwp" ]; then
   Echo "***** Modules cannot be compiled using the 'light' preprocessor ! Switching to the 'traditional' one..." 
   preferredmwp="mwp"
  fi
 fi 
 if [ "$preferredmwp" = "mwp" ]; then
  cmw2opt="${cmw2opt} -traditional"
 fi


# Now, compile all modules.

 cd $MWSRC
 cmw2_all $cmw2opt $MWSRC/src

 if [ $? -ne 0 ]; then
   Echo "***** Error while compiling modules !" 
   if [ -f $cmw2trace ]; then
    echo "***** To see why errors occurred, here is the content of '$cmw2trace' trace file :" >> $MWSRC/Install.log
    cat $cmw2trace >> $MWSRC/Install.log
    rm -f $cmw2trace > /dev/null
    echo "***** End of content of trace file" >> $MWSRC/Install.log
   fi  
   Answer "***** Some module(s) could not be successfully compiled ! Abort the installation" "Y"
   if [ "$ans" = "Y" ]; then
    Abort       
   else
    Echo "***** I continue, but remember that some module(s) won't be available..."       
   fi 
 fi

# Remove trace file
 rm -f $cmw2trace > /dev/null

# end of level
fi

level=`expr $level + 1`
NewTrap
if [ $l -le $level ]; then 
 Echo "*******************************************************"
 Echo "***** Level $level : Compile the documentation (guid3) *****"
 Echo "*******************************************************"

 mwdep -adm
 if [ $? -ne 0 ]; then
   Echo "***** Error while making dependencies list ! I continue but" 
   Echo "***** you will not get modules dependencies in the documentation."
 fi
 mwmakedoc -c $MWSRC
 if [ $? -ne 0 ]; then
   Echo "***** Error while making documentation !" 
   Abort
 fi
# end of level
fi

# If public=private, set right uid
if  [ $pubinstall -eq 2 ]; then
  chmod -R a+rX $PRIVATE_MEGAWAVE2
else 
  chmod o-rx $PRIVATE_MEGAWAVE2
  chmod g-rx $PRIVATE_MEGAWAVE2
fi

level=`expr $level + 1`
NewTrap
if [ $l -le $level ] && [ $pubinstall -eq 1 ]; then
  Echo "*********************************************"
  Echo "***** Level $level : Install PUBLIC modules  *****"
  Echo "*********************************************"

  if [ ! -d $PUBLIC_MEGAWAVE2 ]; then
    Echo "***** Cannot find previous temporary PUBLIC installation" 
    Echo "***** in $PUBLIC_MEGAWAVE2 !" 
    Echo "***** You have to rerun $_Prog from level 1." 
    Abort
  fi

# Make the MODULES file
  mwmodlist -mfile $MWSRC > $MWSRC/MODULES.${MW_MACHINETYPE}
  if [ $? -ne 0 ]; then
    Echo "***** Cannot generate MODULES file on ${MW_MACHINETYPE} !" 
    Abort
  fi
  mwmodinstall $MWSRC/MODULES.${MW_MACHINETYPE}
  if [ $? -ne 0 ]; then
    Echo "***** Cannot install PUBLIC modules !" 
    Abort
  fi
# end of level
fi

level=`expr $level + 1`
NewTrap
if [ $l -le $level ] && [ $pubinstall -eq 1 ]; then
  Echo "**************************************************"
  Echo "***** Level $level : Install miscellaneous files  *****"
  Echo "**************************************************"

  if [ ! -d $PUBLIC_MEGAWAVE2 ]; then
    Echo "***** Cannot find previous temporary PUBLIC installation" 
    Echo "***** in $PUBLIC_MEGAWAVE2 !" 
    Echo "***** You have to rerun $_Prog from level 1." 
    Abort
  fi

# Compiled doc files
  cp $PRIVATE_MEGAWAVE2/doc/*.dvi $PUBLIC_MEGAWAVE2/doc
  chmod 644 $PUBLIC_MEGAWAVE2/doc/*.dvi

# Profile and Cshrc User files
  userprofile=0
  usercshrc=0
  if [ -r $PRIVATE_MEGAWAVE2/sys/lib/$MW_MACHINETYPE/.profile_megawave2 ]; then
    cp -f $PRIVATE_MEGAWAVE2/sys/lib/$MW_MACHINETYPE/.profile_megawave2  $PUBLIC_MEGAWAVE2/sys/lib/$MW_MACHINETYPE/.
    chmod 755 $PUBLIC_MEGAWAVE2/sys/lib/$MW_MACHINETYPE/.profile_megawave2
    userprofile=1
  else
    if [ -d $MWNEWPUB ] &&  [ -r $MWORGPUB/sys/lib/$MW_MACHINETYPE/.profile_megawave2 ]; then
      cp -f $MWORGPUB/sys/lib/$MW_MACHINETYPE/.profile_megawave2 $PUBLIC_MEGAWAVE2/sys/lib/$MW_MACHINETYPE/.
      chmod 755 $PUBLIC_MEGAWAVE2/sys/lib/$MW_MACHINETYPE/.profile_megawave2
      userprofile=1
    fi
  fi
  if [ -r $PRIVATE_MEGAWAVE2/sys/lib/$MW_MACHINETYPE/.cshrc_megawave2 ]; then
    cp -f $PRIVATE_MEGAWAVE2/sys/lib/$MW_MACHINETYPE/.cshrc_megawave2  $PUBLIC_MEGAWAVE2/sys/lib/$MW_MACHINETYPE/.
    chmod 755 $PUBLIC_MEGAWAVE2/sys/lib/$MW_MACHINETYPE/.cshrc_megawave2
    usercshrc=1
  else 
    if [ -d $MWNEWPUB ] && [ -r $MWORGPUB/sys/lib/$MW_MACHINETYPE/.cshrc_megawave2 ]; then
      cp -f $MWORGPUB/sys/lib/$MW_MACHINETYPE/.cshrc_megawave2 $PUBLIC_MEGAWAVE2/sys/lib/$MW_MACHINETYPE/.
      chmod 755 $PUBLIC_MEGAWAVE2/sys/lib/$MW_MACHINETYPE/.cshrc_megawave2
      usercshrc=1
    fi
  fi

# List of modules
  if [ -r $MWSRC/MODULES.${MW_MACHINETYPE} ]; then
    echo "%----------------------------------------------------------------" >  $PUBLIC_MEGAWAVE2/MODULES.${MW_MACHINETYPE}
    echo "% List of MegaWave2 modules available on $MW_MACHINETYPE architecture" >>  $PUBLIC_MEGAWAVE2/MODULES.${MW_MACHINETYPE}
    echo "%----------------------------------------------------------------" >>  $PUBLIC_MEGAWAVE2/MODULES.${MW_MACHINETYPE}
    cat $MWSRC/MODULES.${MW_MACHINETYPE} >> $PUBLIC_MEGAWAVE2/MODULES.${MW_MACHINETYPE}
    chmod 644 $PUBLIC_MEGAWAVE2/MODULES.${MW_MACHINETYPE}
  fi

# README file
  echo "This is the MegaWave2 PUBLIC directory, generated by your local MegaWave2 administrator $LOGNAME." > $PUBLIC_MEGAWAVE2/README
  echo "" >> $PUBLIC_MEGAWAVE2/README
  echo "This is NOT the original distribution : please do not copy it, it may not work on another machine !" >> $PUBLIC_MEGAWAVE2/README
  echo "To get the original distribution, ask your local MegaWave2 administrator or download the latest"  >> $PUBLIC_MEGAWAVE2/README
  echo "version available on the Web at"  >> $PUBLIC_MEGAWAVE2/README
  echo "     http://www.cmla.ens-cachan.fr/Cmla/Megawave"  >> $PUBLIC_MEGAWAVE2/README
  echo "" >> $PUBLIC_MEGAWAVE2/README

  if [ $userprofile -eq 1 ] || [ $usercshrc -eq 1 ]; then
    echo "To get the environement needed to use this PUBLIC MegaWave2, source the following files " >> $PUBLIC_MEGAWAVE2/README
    if [ $userprofile -eq 1 ]; then
      if  [ -d $MWNEWPUB ]; then
        echo "     $MWORGPUB/sys/lib/$MW_MACHINETYPE/.profile_megawave2"  >> $PUBLIC_MEGAWAVE2/README
      else
        echo "     $PUBLIC_MEGAWAVE2/sys/lib/$MW_MACHINETYPE/.profile_megawave2" >> $PUBLIC_MEGAWAVE2/README
      fi
      echo "if your shell is bsh-compatible."  >> $PUBLIC_MEGAWAVE2/README
    fi
    if [ $usercshrc -eq 1 ]; then
      if  [ -d $MWNEWPUB ]; then
        echo "     $MWORGPUB/sys/lib/$MW_MACHINETYPE/.cshrc_megawave2"  >> $PUBLIC_MEGAWAVE2/README
      else 
        echo "     $PUBLIC_MEGAWAVE2/sys/lib/$MW_MACHINETYPE/.cshrc_megawave2"  >> $PUBLIC_MEGAWAVE2/README
      fi
      echo "if your shell is csh-compatible."  >> $PUBLIC_MEGAWAVE2/README
    fi
  else
    echo "To get the environement needed to use this PUBLIC MegaWave2, ask your MegaWave2 administrator" >> $PUBLIC_MEGAWAVE2/README    
    echo "or see Volume 1 located at $PUBLIC_MEGAWAVE2/doc/guid1.dvi" >> $PUBLIC_MEGAWAVE2/README
  fi  
  chmod 644  $PUBLIC_MEGAWAVE2/README

# COPYRIGHT file
  if [ -r $MWSRC/COPYRIGHT ]; then
    cp $MWSRC/COPYRIGHT $PUBLIC_MEGAWAVE2/.
    chmod 644  $PUBLIC_MEGAWAVE2/COPYRIGHT
  fi

# Guides
  if [ -r $MWSRC/doc/guid1.dvi ]; then
    cp $MWSRC/doc/guid1.dvi $PUBLIC_MEGAWAVE2/doc/.
    chmod 644 $PUBLIC_MEGAWAVE2/doc/guid1.dvi
  fi
  if [ -r $MWSRC/doc/guid2.dvi ]; then
    cp $MWSRC/doc/guid2.dvi $PUBLIC_MEGAWAVE2/doc/.
    chmod 644 $PUBLIC_MEGAWAVE2/doc/guid2.dvi
  fi

# Bibliographic database for public MegaWave2 modules 
  if [ -r $MWSRC/doc/public.bib ]; then
    cp $MWSRC/doc/public.bib $PUBLIC_MEGAWAVE2/doc/.
    chmod 644 $PUBLIC_MEGAWAVE2/doc/public.bib
  fi
# end of level
fi


level=`expr $level + 1`
NewTrap
if [ -d $MWNEWPUB ]; then
  Echo "*****************************************************************"
  Echo "***** Level $level : Make changes in effect in PUBLIC MegaWave2  *****"
  Echo "*****************************************************************"
  mv -f $MWORGPUB $MWDIRPUB/MegaWave2_V${oldvers}
  if [ $? -ne 0 ]; then
    Echo "***** Cannot rename $MWORGPUB ! ($MWORGPUB ->  $MWDIRPUB/MegaWave2_V${oldvers})" 
    Abort
  fi
  mv -f $PUBLIC_MEGAWAVE2 $MWORGPUB
  if [ $? -ne 0 ]; then
    Echo "***** Cannot rename $PUBLIC_MEGAWAVE2 ! ($MWORGPUB -> $PUBLIC_MEGAWAVE2)" 
    Abort
  fi
  chmod 755 $MWORGPUB
  echo $newvers > $MWORGPUB/VERS
  chmod 644 $MWORGPUB/VERS
  Echo "***** Now, users should experiment in $MWORGPUB the new PUBLIC version $newvers"
  Echo "***** They still may get the old PUBLIC version $oldvers in $MWDIRPUB/MegaWave2_V${oldvers}"
  PUBLIC_MEGAWAVE2=$MWORGPUB
fi

if [ $pubinstall -eq 1 ]; then
  rm -f $PUBLIC_MEGAWAVE2/INSTALL_NOT_COMPLETE
fi
cd $CWD
Echo " "
Echo "***** `date`"
Echo "*******************************************************************"
Echo "***** Install done for MegaWave2 ! (Leave your fingers quiet) *****"
Echo "*******************************************************************"
Echo " "

# After installation done, optional checking of modules
trap "Echo '***** Checking of modules aborted'; exit 1" 2 3
chk=`mwwhere -bin Checkmodules`
if [ "$chk" != "" ]; then
  Answer "***** Do you want to check the module library" "Y"
  if [ "$ans" = "Y" ]; then
    MW_CHECK_HIDDEN=1
    export MW_CHECK_HIDDEN
    Checkmodules
  fi
fi

exit 0














