# The SHELL is choosen by install.sh

# $Id: main_aster.sh,v 1.42 2004/05/21 11:00:03 mcourtoi Exp $
# $Name: v7_3-8 $

######################################################################
#
# Installation script for Code_Aster
#
# Unix version SUN/ultra sparc
#              TRU64/Alpha
#              IRIX/MIPS
#              Linux/x86
#
######################################################################

umask 022

######################################################################
#
# load functions from utils
. `dirname $0`/utils.sh

######################################################################
#
# Test if ASTK package is provided in this distrib
is_astk=0
if [ -f `dirname $0`/inst_astk.sh ]; then
   is_astk=1
fi

######################################################################
#
CLEAR
echo " CODE_ASTER $vaster INSTALLATION SETUP"
if [ $vaster != $pseudo_vers ]; then
   echo " ... as a development version called $pseudo_vers"
fi
echo " "
echo " Supported platform : Linux x86, SUN Solaris 32/64 bits,"
echo "                      Compaq Alpha TRU64 5.1, SGI IRIX64 6.5,"
echo " "
echo " Installation will check :"
echo "          - Python $python_v"
echo "            and modules :"
echo "              - Numerical Python $numeric_v      (optional)"
echo "              - Gnuplot.py $gnuplotpy_v             (optional)"
echo "              - Python MegaWidgets $pmw_v (for Eficas)"
echo "          - TclTk $tcl_v"
echo "              - Python Tkinter extension (for Eficas)"
echo "          - X11 library"
if [ $SRC -eq 1 ]; then
   echo "          - med $med_v and hdf $hdf_v"
   echo "          - blas or equivalent (depending on platform type)"
fi
echo "            Tools :"
echo "              - metis 4.0 ('$metis_v')"
echo "              - homard $homard_v                 (optional)"
echo "              - gnuplot $gnuplot_v              (optional)"
echo "              - gibi $gibi_v                  (optional)"
echo "          - gzip"
if [ $SRC -eq 1 ]; then
   echo "          - C, fortran compilers and tools (ar)"
fi
echo " If you have not exactly these versions, see README file"
echo " to known how change variables."
echo " "
if [ $is_astk -eq 1 ]; then
   echo " After Code_Aster installation you could install ASTK $vastk."
   echo " ASTK is a graphic interface to run Code_Aster using run_aster."
   echo " "
fi
compdir `dirname $0`/..
dirhome=$fulldir
if [ $dirhome = "." ]; then
   dirhome=`pwd`
fi
def_instdir=$HOME

######################################################################
#
#  system identification
#  modify system commands if necessary
#
OS_TYPE=`uname -s`
if [ $OS_TYPE = "SunOS" ]; then
   BLAS="sunperf"
 	OS_LEVEL=`uname -r`
   OS_NIV=`echo $OS_LEVEL | $awk -F'.' '{print $2}'`
   if [ $OS_NIV -lt 6 ]; then
      echo "unavailable OS for Aster SOLARIS"
      exit 8
   fi
   echo " System identification: SUN SunOS   $OS_LEVEL"
   echo " "
   confirm "Do you want to install a 64 bit version" "bidon" "n"
   iret=$?
   if [ $iret -eq 0 ]; then
      OS_TYPE=SunOS64
   fi
elif [ $OS_TYPE = "OSF1" ]; then
   BLAS="cxml"
 	OS_LEVEL=`uname -r`
   echo " System identification: COMPAQ Tru64 $OS_LEVEL"
elif [ $OS_TYPE = "IRIX64" ]; then
   BLAS="sgimath"
 	OS_LEVEL=`uname -r`
   echo " System identification: SGI Irix $OS_LEVEL"
elif [ $OS_TYPE = "Linux" ]; then
   BLAS="blas"
   OS_LEVEL=`uname -r`
   echo " System identification: Linux $OS_LEVEL"
   nmD="$nm -D"
else
	echo " Operating system $OS_TYPE unknown on this distribution"
	echo " Installation failed !"
   exit 8
fi

if [ $SRC -eq 0 ] && [ $OS_TYPE != $BIN ]; then
	echo " This package is designed for $BIN (not for $OS_TYPE)."
	echo " Installation failed !"
   exit 8
fi

echo " Your system identification : $OS_TYPE - Release $OS_LEVEL"
echo " "
confirm "Continue" "bidon" "y"
iret=$?
if [ $iret -ne 0 ]; then
	echo "Installation aborted !"
	exit 8
fi
echo " "

######################################################################
#
#  Installation directory
#
CLEAR
echo " INSTALLATION DIRECTORY"
echo " "
echo " Install from : $dirhome "
echo " "
iret=1
while [ $iret -ne 0 ];
do
   iret=0
   echo " "
   echo " Pathname of install directory (default $def_instdir) : "
   echo " (This default will produce '$def_instdir/$pseudo_vers')"
   read rtn
   if [ -z "$rtn" ]; then
      rtn="$def_instdir"
   fi
   inst_dir=$rtn
   jret=0
   if [ ! -d "$inst_dir" ]; then
      mkdir -p $inst_dir > /tmp/$$.instv70 2>&1
      iret=$?
      if [ $iret -ne 0 ]; then
   		echo " Fail to create directory $inst_dir "
         echo " System message :"
         cat /tmp/$$.instv70
         echo " "
	      confirm "Change installation directory" "bidon" "y"
         jret=$?
	      if [ $jret -ne 0 ]; then
	         echo " Installation aborted !"
	      	exit 8
	      fi
      fi
      if [ -f /tmp/$$.instv70 ]; then
         rm -f /tmp/$$.instv70
      fi
   fi
   compdir "$inst_dir"
   inst_dir="$fulldir"
   if [ $jret -eq 0 ]; then
      if [ -d "$inst_dir/$pseudo_vers" ]; then
      	echo " Directory $inst_dir/$pseudo_vers already exists, files will be overridden."
      	confirm "Keep this directory" "bidon" "y"
         iret=$?
      fi
	   if [ ! -w $inst_dir  ]; then
         iret=1
	   	echo " No write access to directory $inst_dir."
	   	confirm "Change installation directory" "bidon" "y"
         jret=$?
	   	if [ $jret -ne 0 ]; then
	   	   echo " Installation aborted !"
	   		exit 8
	   	fi
	   fi
   fi
done

######################################################################
#
# required Python installation
#
CLEAR
echo "Check for Python installation"
echo "(binary, include and libraries if sources distrib)"
echo " "
defdir="/usr/bin"
quoi="python$python_v"
short="python"

# bin
echo " Search for $quoi, if not found, choose another path or cancel to search for $short (without release number)."
iret=1
while [ $iret -ne 0 ];
do
   a_supp="/bin/$quoi"
   search_bin "$quoi" "$defdir" "$a_supp" "n"
   iret=$?
   python_dir=$result
   if [ $iret -ne 0 ]; then
      quoi="$short"
   fi
   defdir=""
done
python_bin="$quoi"

# installed version
python_vtest=`$python_dir/bin/$python_bin -c 'import sys ; v=sys.version_info; print str(v[0])+"."+str(v[1])'`
quoi=python$python_vtest
echo " Your python version is $python_vtest"

if [ $SRC -eq 1 ]; then
   # library
   libpy="$python_dir/lib/$quoi/config/lib$quoi.a"
   check_lib $libpy "Python" "PyArg_ParseTuple" "y"

   # include
   incpy="$python_dir/include/$quoi/Python.h"
   check_inc $incpy "Python" "y"
else
# python version is imposed by Code_Aster binary (linked with python library) !
   if [ $python_vtest != $python_v ]; then
      echo " ERROR : Code_Aster executable has been linked with"
      echo "         libpython$python_v so it can't run with another one !"
      echo " You need to install Python $python_v or recompile Code_Aster"
      echo " (download its sources)"
      exit 2
   fi
fi

# update python_v
python_v=$python_vtest

# python modules
check_modpy "$python_dir" "$python_dir/bin/$quoi" "Numerical Python" "Numeric" "$numeric_v"
is_numeric=$?

check_modpy "$python_dir" "$python_dir/bin/$quoi" "Gnuplot.py" "Gnuplot" "$gnuplotpy_v"
is_gnuplotpy=$?

check_modpy "$python_dir" "$python_dir/bin/$quoi" "Pmw" "Pmw" "$pmw_v"
is_pmw=$?

######################################################################
#
# required Tcl/Tk installation
#
CLEAR
echo "Check for Tcl/Tk installation"
echo "(binary and libraries if sources distrib)"
echo " "
defdir="/usr/bin"
if [ -n "$python_dir" ]; then
   defdir="$python_dir"
fi
quoi="tclsh$tcl_v"
short="tclsh"
# for ASTK
wish_bin="wish$tcl_v"

# bin
echo " Search for $quoi, if not found, choose another path or cancel to search for $short (without release number)."
iret=1
while [ $iret -ne 0 ];
do
   a_supp="/bin/$quoi"
   search_bin "$quoi" "$defdir" "$a_supp" "n"
   iret=$?
   tcl_dir=$result
   if [ $iret -ne 0 ]; then
      quoi="$short"
      wish_bin="wish"
   fi
   defdir=""
done
tcl_bin="$quoi"

# installed version
tcl_vtest=`echo 'puts $tcl_version' | $tcl_dir/bin/$tcl_bin`
echo " Your Tcl version is $tcl_vtest"

# update tcl_v
tcl_v=$tcl_vtest

opt_tcl=$tcl_dir/lib
if [ $SRC -eq 1 ]; then
   # library
   # tcl
   search_lib "tcl$tcl_v" "Tcl" "$opt_tcl" "y"
   opt_tcl="$opt_lib"
   tcl_libdir="$chem"
   pref_typ=$typ
   check_lib "$result" "Tcl" "Tcl_Init" "y"

   # tk
   search_lib "tk$tcl_v" "Tk" "$tcl_libdir" "y" "$pref_typ"
   opt_tk="$opt_lib"
   check_lib "$result" "Tk" "Tk_Init" "y"

   # Tkinter
#   check_modpy "$python_dir" "$python_dir/bin/$python_bin" "Tkinter" "Tkinter" ""
cat <<EOF> /tmp/$$.ttkinter
import sys
try:
  import Tkinter
except ImportError:
  sys.exit(4)
else:
  sys.exit(0)
EOF
#   check_lib $libpy "Tkinter in Python" "tkinter" "n"
#MC tkinter may be installed without any symbol in libpython
   echo " Check for Tkinter Python module"
   $python_dir/bin/$python_bin /tmp/$$.ttkinter
   iret=$?
   rm -f /tmp/$$.ttkinter
   is_tkinter=$iret
   if [ $iret -ne 0 ]; then
      echo " Eficas needs Python with Tkinter."
      confirm "Continue Code_Aster installation" "bidon" "y"
      iret=$?
      if [ $iret -ne 0 ]; then
         echo " Installation aborted"
         exit 8
      fi
   else
      echo "   Tkinter seems ok."
   fi
   echo " "
fi

######################################################################
#
# required X11 library
#
CLEAR
echo "Check for X11 installation (xterm and library if sources distrib)"
echo " "
if [ $OS_TYPE = "Linux" ]; then
   defdir="/usr/X11R6"
elif [ $OS_TYPE = "SunOS" -o $OS_TYPE = "SunOS64" ]; then
   defdir="/usr/openwin/bin"
else
   defdir="/usr/bin"
fi
quoi="xterm"
a_supp="/$quoi"
search_bin $quoi $defdir $a_supp "y"
home_xterm="$result"

if [ $SRC -eq 1 ]; then
   if [ $OS_TYPE = "Linux" ]; then
      defdir="/usr/X11R6"
   elif [ $OS_TYPE = "SunOS" -o $OS_TYPE = "SunOS64" ]; then
      defdir="/usr/openwin/lib"
   elif [ $OS_TYPE = "OSF1" ]; then
      defdir="/usr/shlib"
   elif [ $OS_TYPE = "IRIX64" ]; then
      defdir="/usr/lib64"
   else
      defdir="/usr/lib"
   fi
   iret=1
   while [ $iret -eq 1 ];
   do
      search_lib "X11" "X11" "$defdir" "y" "d"
      iret=$?
      opt_x11="$opt_lib"
#      check_lib "$result" "X11" "XFree" "n"
      if [ $iret -eq 0 ]; then
         confirm "Accept" "$result" "y"
         iret=$?
      fi
      defdir=""
   done
fi

######################################################################
#
# required med library installation directory
#
if [ $SRC -eq 1 ]; then
   CLEAR
   echo "Check for MED installation (library)"
   echo " "
   iret=1
   while [ $iret -eq 1 ];
   do
      search_lib "med" "MED" "" "y" "s"
      opt_med="$opt_lib"
      med_libdir="$chem"
   #  efproi exists in med2.1.5 but not in med2.1.4
      check_lib "$result" "MED" "efproi" "n"
      iret=$?
      if [ $iret -eq 0 ]; then
         confirm "Accept" "$result" "y"
         iret=$?
      fi
   done
fi

######################################################################
#
# required hdf library installation directory
#
if [ $SRC -eq 1 ]; then
   CLEAR
   echo "Check for HDF installation (library)"
   echo " "
   iret=1
   while [ $iret -eq 1 ];
   do
      search_lib "hdf5" "HDF" "$med_libdir" "y" "s"
      opt_hdf="$opt_lib"
      hdf_dir=`echo $chem | sed -e "s#/lib\\$##"`
   #  H5F_get_fileno exists in hdf5.1.4.4 but not in previous hdf5.1
      check_lib "$result" "HDF" "H5F_get_fileno" "n"
      iret=$?
      if [ $iret -eq 0 ]; then
         confirm "Accept" "$result" "y"
         iret=$?
      fi
   done
   # include
   inc_hdf="$hdf_dir/include/hdf5.h"
   check_inc $inc_hdf "HDF" "y"
fi

######################################################################
#
# check for blas library
#
if [ $OS_TYPE = "Linux" ]; then
   defdir="/usr/lib"
elif [ $OS_TYPE = "TRU64" ]; then
   defdir="/lib"
else
   defdir="/usr/lib"
fi
opt_blas=""
if [ $SRC -eq 1 ] && [ -n "$BLAS" ]; then
   CLEAR
   echo "Check for BLAS (or equivalent) installation (library)"
   echo " "
   iret=1
   while [ $iret -eq 1 ];
   do
      search_lib "$BLAS" "BLAS" "$defdir" "y"
      opt_blas="$opt_lib"
      check_lib "$result" "BLAS" "daxpy" "n"
      iret=$?
      if [ $iret -eq 0 ]; then
         confirm "Accept" "$result" "y"
         iret=$?
      fi
   done
fi

######################################################################
#
# tools directory
#
CLEAR
echo "Configure TOOLS directory (metis, homard, gnuplot, gibi...)"
echo " This directory should contain all tools or links to these tools."
echo " "
tools_dir="$inst_dir/outils"
iret=1
while [ $iret -ne 0 ];
do
   iret=0
   echo " "
   echo " TOOLS directory (default $tools_dir) : "
   read rtn
   if [ -z "$rtn" ]; then
      rtn="$tools_dir"
   fi
   tools_dir=$rtn

   mkdir -p $tools_dir 2>&1 /tmp/$$.instv72
   iret=$?
   if [ $iret -ne 0 ]; then
   	echo " Fail to create directory $tools_dir "
   	echo " System message :"
   	cat /tmp/$$.instv72
   	echo " "
	   confirm "Change TOOLS directory" "bidon" "y"
      jret=$?
	   if [ $jret -ne 0 ]; then
	      echo " Installation aborted !"
	   	exit 8
	   fi
   fi
   if [ -f /tmp/$$.instv72 ]; then
      rm -f /tmp/$$.instv72
   fi
done
compdir "$tools_dir"
tools_dir="$fulldir"
echo " "

######################################################################
#
# check TOOLS
#
echo " Do you want to check that TOOLS are correctly installed ?"
echo " If they are not in $tools_dir,"
echo " you can search them and add link to them."
echo " "
confirm "Ready to check TOOLS" "bidon" "y"
iret=$?
# default values
is_metis=-1
is_homard=-1
is_gnuplot=-1
is_gmsh=-1
is_grace=-1
is_gibi=-1

if [ $iret -eq 0 ]; then
#
   CLEAR
   echo "Check for metis installation (binary)"
   echo " "
   defdir="$tools_dir"
   quoi="onmetis"
   a_supp="/$quoi"
   search_bin $quoi $defdir $a_supp "n"
   iret=$?
   is_metis=$iret
   metis_dir=$result

   if [ $iret -ne 0 ] || [ `$metis_dir/onmetis --version | $awk '{print $1}'` != $metis_v ]; then
      is_metis=2
      echo " Incorrect version."
      echo " You need metis Version '$metis_v' to use metis solver option."
      echo " (you could install correct version later)"
      confirm "Continue Code_Aster installation" "bidon" "y"
      iret=$?
      if [ $iret -ne 0 ]; then
         echo " Installation aborted"
         exit 8
      fi
      echo " "
   else
      if [ ! -f "$tools_dir/$quoi" ]; then
         ln -s "$metis_dir/$quoi" "$tools_dir/"
         echo " Link to $quoi added in $tools_dir."
      fi
   fi
#
   CLEAR
   echo "Check for homard installation (binary)"
   echo " "
   defdir="$tools_dir"
   quoi="homard"
   a_supp="/$quoi"
   search_bin $quoi $defdir $a_supp "n"
   iret=$?
   is_homard=$iret
   homard_dir=$result
   if [ $iret -ne 0 ]; then
      echo " You need homard to use adaptative mesh capability."
      confirm "Continue Code_Aster installation without homard" "bidon" "y"
      iret=$?
      if [ $iret -ne 0 ]; then
         echo " Installation aborted"
         exit 8
      fi
      echo " "
   else
      if [ ! -f "$tools_dir/$quoi" ]; then
         ln -s "$homard_dir/$quoi" "$tools_dir/"
         echo " Link to $quoi added in $tools_dir."
      fi
   fi
#
   CLEAR
   echo "Check for xmgrace installation (binary)"
   echo " "
   defdir="$tools_dir"
   quoi="xmgrace"
   a_supp="/$quoi"
   search_bin $quoi $defdir $a_supp "n"
   iret=$?
   is_grace=$iret
   grace_dir=$result

   if [ $iret -ne 0 ]; then
      echo " Xmgrace not found, Stanley call xmgrace from Code_Aster."
      confirm "Continue Code_Aster installation without xmgrace" "bidon" "y"
      iret=$?
      if [ $iret -ne 0 ]; then
         echo " Installation aborted"
         exit 8
      fi
      echo " "
   else
      if [ ! -f "$tools_dir/$quoi" ]; then
         ln -s "$grace_dir/$quoi" "$tools_dir/"
         echo " Link to $quoi added in $tools_dir."
      fi
   fi
#
   CLEAR
   echo "Check for gnuplot installation (binary)"
   echo " "
   defdir="$tools_dir"
   quoi="gnuplot"
   a_supp="/$quoi"
   search_bin $quoi $defdir $a_supp "n"
   iret=$?
   is_gnuplot=$iret
   gnuplot_dir=$result

   if [ $iret -ne 0 ]; then
      echo " gnuplot not found, some tests/examples call gnuplot from Code_Aster."
      confirm "Continue Code_Aster installation without gnuplot" "bidon" "y"
      iret=$?
      if [ $iret -ne 0 ]; then
         echo " Installation aborted"
         exit 8
      fi
      echo " "
   else
      if [ ! -f "$tools_dir/$quoi" ]; then
         ln -s "$gnuplot_dir/$quoi" "$tools_dir/"
         echo " Link to $quoi added in $tools_dir."
      fi
   fi
#
   CLEAR
   echo "Check for gmsh installation (binary)"
   echo " "
   defdir="$tools_dir"
   quoi="gmsh"
   a_supp="/$quoi"
   search_bin $quoi $defdir $a_supp "n"
   iret=$?
   is_gmsh=$iret
   gmsh_dir=$result
   if [ $iret -ne 0 ]; then
      echo " gmsh not found, Stanley call gmsh from Code_Aster."
      confirm "Continue Code_Aster installation without gmsh" "bidon" "y"
      iret=$?
      if [ $iret -ne 0 ]; then
         echo " Installation aborted"
         exit 8
      fi
      echo " "
   else
      if [ ! -f "$tools_dir/$quoi" ]; then
         ln -s "$gmsh_dir/$quoi" "$tools_dir/"
         echo " Link to $quoi added in $tools_dir."
      fi
   fi
#
   CLEAR
   echo "Check for gibi installation (binary)"
   echo " "
   defdir="$tools_dir"
   quoi="gibi"
   a_supp="/$quoi"
   search_bin $quoi $defdir $a_supp "n"
   iret=$?
   is_gibi=$iret
   gibi_dir=$result
   if [ $iret -ne 0 ]; then
      echo " gibi not found, mesh macros (ASPIC/ASCOUF) couldn't run."
      confirm "Continue Code_Aster installation without gibi" "bidon" "y"
      iret=$?
      if [ $iret -ne 0 ]; then
         echo " Installation aborted"
         exit 8
      fi
      echo " "
   else
      if [ ! -f "$tools_dir/$quoi" ]; then
         ln -s "$gibi_dir/$quoi" "$tools_dir/"
         echo " Link to $quoi added in $tools_dir."
      fi
   fi
fi

######################################################################
#
# gzip directory
#
CLEAR
echo "Check for GZIP installation (binary)"
echo " "
defdir="/usr/bin"
quoi="gzip"
a_supp="/$quoi"
search_bin $quoi $defdir $a_supp "y"
gzip=$result

######################################################################
#
# cc, f77, ld, ar
#
if [ $SRC -eq 1 ]; then
   CLEAR
   echo "Check for C compiler installation (depends on OS type)"
   echo " "
   if [ $OS_TYPE = "Linux" ]; then
      quoi="gcc"
   else
      quoi="cc"
   fi
   defdir="/usr/bin"
   a_supp="/$quoi"
   search_bin $quoi $defdir $a_supp "y"
   home_cc=$result
   cmp_c=$quoi

   CLEAR
   echo "Check for Fortran compiler installation (depends on OS type)"
   echo " "
   if [ $OS_TYPE = "Linux" ]; then
      quoi="g77"
   elif [ $OS_TYPE = "OSF1" -o $OS_TYPE = "SunOS64" -o $OS_TYPE = "IRIX64" ]; then
      quoi="f90"
   else
      quoi="f77"
   fi
   defdir="/usr/bin"
   a_supp="/$quoi"
   search_bin $quoi $defdir $a_supp "y"
   home_f77=$result
   home_f90=$result
   cmp_f=$quoi

   CLEAR
   echo "Check for Archiver installation (ar)"
   echo " "
   defdir="/usr/bin"
   quoi="ar"
   a_supp="/$quoi"
   search_bin $quoi $defdir $a_supp "y"
   home_ar=$result
fi

######################################################################
#
# Ready
#
CLEAR
echo "CODE_ASTER $pseudo_vers installation - Summary :"
echo " "
echo "  Destination            : $inst_dir/$pseudo_vers"
echo "  Python                 : $python_dir"
if [ $is_numeric -lt 4 ]; then
   echo "    Numeric installed    : yes"
else
   echo "    Numeric installed    : no"
fi
if [ $is_gnuplotpy -lt 4 ]; then
   echo "    Gnuplot.py installed : yes"
else
   echo "    Gnuplot.py installed : no"
fi
if [ $SRC -eq 1 ]; then
   if [ $is_tkinter -eq 0 ]; then
      echo "    Tkinter installed    : yes"
   else
      echo "    Tkinter installed    : no"
   fi
fi
if [ $is_pmw -lt 4 ]; then
   echo "    Pmw installed        : yes"
else
   echo "    Pmw installed        : no"
fi
echo "  Tcl/Tk binaries        : $tcl_dir/bin"
if [ $SRC -eq 1 ]; then
   echo "    tcl library          : $opt_tcl"
   echo "    tk library           : $opt_tk"
fi
echo "  Xterm binary           : $home_xterm/xterm"
if [ $SRC -eq 1 ]; then
   echo "  X11 library            : $opt_x11"
   echo "  MED library            : $opt_med"
   echo "  HDF library            : $opt_hdf"
fi
echo "  Tools                  : $tools_dir"
if [ $is_metis -lt 0 ]; then
   echo "    metis installed      : not tested"
elif [ $is_metis -eq 0 ]; then
   echo "    metis installed      : yes"
elif [ $is_metis -eq 2 ]; then
   echo "    metis installed      : incorrect version"
else
   echo "    metis installed      : no"
fi
if [ $is_homard -lt 0 ]; then
   echo "    homard installed     : not tested"
elif [ $is_homard -eq 0 ]; then
   echo "    homard installed     : yes"
else
   echo "    homard installed     : no"
fi
if [ $is_gnuplot -lt 0 ]; then
   echo "    gnuplot installed    : not tested"
elif [ $is_gnuplot -eq 0 ]; then
   echo "    gnuplot installed    : yes"
else
   echo "    gnuplot installed    : no"
fi
if [ $is_grace -lt 0 ]; then
   echo "    xmgrace installed    : not tested"
elif [ $is_grace -eq 0 ]; then
   echo "    xmgrace installed    : yes"
else
   echo "    xmgrace installed    : no"
fi
if [ $is_gmsh -lt 0 ]; then
   echo "    gmsh installed       : not tested"
elif [ $is_gmsh -eq 0 ]; then
   echo "    gmsh installed       : yes"
else
   echo "    gmsh installed       : no"
fi
if [ $is_gibi -lt 0 ]; then
   echo "    gibi installed       : not tested"
elif [ $is_gibi -eq 0 ]; then
   echo "    gibi installed       : yes"
else
   echo "    gibi installed       : no"
fi
echo "  GZIP                   : $gzip/gzip"
echo " "
if [ $SRC -eq 1 ]; then
   echo "    C                    : $home_cc/$cmp_c"
   echo "    Fortran              : $home_f77/$cmp_f"
   echo "    Archiver             : $home_ar/ar"
   echo " "
   echo " "
fi
confirm "Ready to install Code_Aster" "bidon" "y"
iret=$?
if [ $iret -ne 0 ]; then
   echo " Re-run ./install.sh to modify parameters..."
   exit 8
fi

######################################################################
#
# extract tar file
#
cd $inst_dir
if [ ! -d $pseudo_vers ]; then
   mkdir $pseudo_vers
fi
mkdir tmp_extract
cd tmp_extract
echo " "
echo " Extracting tar file, please wait..."
echo " "
$gzip/gzip -d < $dirhome/aster.tar.gz | tar -xf -
mv -f $vaster/* $inst_dir/$pseudo_vers/
cd ..
rm -rf tmp_extract

######################################################################
#
# change user files with installation directory
#
if [ $OS_TYPE = "SunOS" ]; then
   nom_os=SOLARIS
   v_ifdef=SOLARIS
elif [ $OS_TYPE = "SunOS64" ]; then
   nom_os=SOLARIS64
   v_ifdef=SOLARIS64
elif [ $OS_TYPE = "OSF1" ]; then
   nom_os=TRU64
   v_ifdef=TRU64
elif [ $OS_TYPE = "IRIX64" ]; then
   nom_os=IRIX
   v_ifdef=IRIX
elif [ $OS_TYPE = "Linux" ]; then
   nom_os=LINUX
   v_ifdef=P_LINUX
fi
cd $inst_dir/$pseudo_vers/tcl
if [ $SRC -eq 0 ]; then
   \rm -f make_aster make_exec make_lib maj_*
fi
# solaris ne semble supporter -o !
#for fic in `find . -name 'make_*' -o -name 'maj_*'`
for fic in `find . -name 'make_*'`
do
  sed -e "s#HOME_CODE_ASTER#$inst_dir/$pseudo_vers#g"  \
      -e "s#IFDEF#$v_ifdef#" \
      -e "s#HOME_XTERM#$home_xterm#" \
      -e "s#REP_TOOLS#$tools_dir#" \
     $fic > $fic.out
  mv -f $fic.out $fic
done
for fic in `find . -name 'maj_*'`
do
  sed -e "s#HOME_CODE_ASTER#$inst_dir/$pseudo_vers#g"  \
      -e "s#IFDEF#$v_ifdef#" \
      -e "s#HOME_XTERM#$home_xterm#" \
      -e "s#REP_TOOLS#$tools_dir#" \
     $fic > $fic.out
  mv -f $fic.out $fic
done

sed -e "s#HOME_CODE_ASTER#$inst_dir/$pseudo_vers#" \
    -e "s#HOME_TCL_TK#$tcl_dir#g"  \
    -e "s#TCL_BIN#$tcl_bin#g"  \
    -e "s#TCL_TK_VERSION#$tcl_v#g"  \
    -e "s#HOME_PYTHON#$python_dir#g"\
    -e "s#/bin/sh#$SHELL_INSTALL_ASTER#g"  \
         run_aster > run_aster.out
mv -f run_aster.out run_aster
chmod 755 run_aster

if [ $SRC -eq 1 ]; then
   sed -e "s#OPT_HDF#$opt_hdf#" \
       -e "s#HDF_DIR#$hdf_dir#" \
       -e "s#OPT_MED#$opt_med#" \
       -e "s#OPT_TCL#$opt_tcl#g"  \
       -e "s#OPT_TK#$opt_tk#g"  \
       -e "s#OPT_X11#$opt_x11#" \
       -e "s#OPT_BLAS#$opt_blas#" \
       -e "s#HOME_AR#$home_ar#g"  \
       -e "s#HOME_F77#$home_f77#g"  \
       -e "s#HOME_F90#$home_f90#g"  \
       -e "s#HOME_CC#$home_cc#g"  \
       -e "s#HOME_GZIP#$gzip#g"  \
       -e "s#HOME_PYTHON#$python_dir#g"\
       -e "s#PYTHON_BIN#$python_bin#g"\
       -e "s#PYTHON_VERSION#$python_v#g" \
   	 conf/$v_ifdef/config.txt > config.txt.out
else
   sed -e "s#HOME_GZIP#$gzip#g"  \
       -e "s#HOME_PYTHON#$python_dir#g"\
       -e "s#PYTHON_BIN#$python_bin#g"\
       -e "s#PYTHON_VERSION#$python_v#g" \
   	 conf/$v_ifdef/config.txt > config.txt.out
fi
mv -f config.txt.out $inst_dir/$pseudo_vers/config.txt
rm -rf conf
cd $inst_dir
echo " "
if [ $SRC -eq 1 ]; then
   echo " Installation of Code_Aster sources completed !"
else
   echo " Installation of Code_Aster completed !"
fi
echo " "

######################################################################
#
# ASTK installation
#
astk_inst=-1
if [ $is_astk -eq 1 ]; then
   CLEAR
   echo " You can install ASTK $vastk"
   echo " (graphic interface to manage your calculations)"
   confirm "Install ASTK" "bidon" "y"
   astk_inst=$?

   if [ $astk_inst -eq 0 ]; then
      #
      # Editor
      #
      is_edit=-1
      if [ $is_astk -eq 1 ]; then
         CLEAR
         echo "Check for editor installation for ASTK (binary)"
         echo " "
         echo " This editor will called from ASTK"
         echo " It must accept '-display' argument (example : nedit, xedit...)"
         echo " "
         defdir="/usr/bin"
         quoi="nedit"
         search_prog $quoi "editor" $defdir "" "n"
         iret=$?
         is_edit=$iret
         edit_cmd=$result
         if [ $iret -ne 0 ]; then
            edit_cmd=$quoi
            echo " "
            confirm "Continue Code_Aster installation without editor" "bidon" "y"
            iret=$?
            if [ $iret -ne 0 ]; then
               echo " Installation aborted"
               exit 8
            fi
            echo " "
         fi
      fi

      #
      # hostname and domainname
      #
      mach=`uname -n`
      # astk for domain name if not present
      is_ip=1
      domain_name=""
      if [ `echo $mach | egrep -c '[_a-zA-Z]+'` -ne 0 ]; then
         is_ip=0
         domain_name=`echo $mach | sed -e 's/[-_0-9a-zA-Z]*//' -e 's/^\.//'`
      fi
      if [ -z "$domain_name" ]; then
         echo " "
         echo " Full-qualified hostname of your machine is necessary to use"
         echo " cross-network capabilities of ASTK."
         echo " Your machine hostname is : $mach"
         iret=1
         while [ $iret -ne 0 ];
         do
            iret=0
            echo " "
            echo " Please enter your domain name :"
            if [ $is_ip -eq 0 ]; then
               echo " (ex.: domain.org if the full name is $mach.domain.org)"
            fi
            read domain_name
            echo " "
            if [ $is_ip -eq 0 ]; then
               if [ -z "$domain_name" ]; then
                  nom_complet=$mach
               else
                  nom_complet=$mach.$domain_name
               fi
               echo " The full name will be : $nom_complet"
            else
               nom_complet=$mach
               echo " IP address is : $mach, domain name : $domain_name"
	         fi
            if [ -z "$domain_name" ]; then
               echo " "
               echo " WARNING : Domain name is empty, you may have problems"
               echo "           if all the machines are not on the same sub-network."
            fi
            confirm "Confirm domain name" "bidon" "y"
            iret=$?
         done
      else
         nom_complet=$mach.$domain_name
      fi
      echo " "
      echo " Hostname    : $mach"
      echo " Domain name : $domain_name"
      echo " Full name   : $nom_complet"
      echo " "
      if [ -z "$domain_name" ]; then
         domain_name="_VIDE"
      fi
      
      #
      # Main installation script
      #
      . $dirhome/UTILS/inst_astk.sh
      
      # Modify config file
      fconf=$astk_inst_dir/ASTK_SERV/conf/config
      modif_config $fconf $v_ifdef $mach $pseudo_vers $edit_cmd
      echo " $fconf has been modified."
      echo " "
      echo " - debugger command lines :"
      egrep '^cmd_' $fconf
      echo " To modify these parameters, edit $fconf file."
      echo " "

      # Add a new config.VVV file
      nconf=$fconf.$pseudo_vers
      if [ -f $nconf ]; then
         echo " File already exists : $nconf"
         echo " You must probably modify it to reflect this installation"
      else
         create_config_VVV $nconf $inst_dir/$pseudo_vers $tools_dir
         echo " $nconf file created."
      fi
      echo " "
      
      # tools
      fout=$astk_inst_dir/ASTK_CLIENT/lib/ASTK/astkrc/outils
      if [ $is_gmsh -eq 0 ]; then
         echo "nom : Gmsh" >> $fout
         echo "cmde : $gmsh_dir/gmsh (@F)" >> $fout
         echo "ext : geo pos" >> $fout
         echo "dist : on" >> $fout
         echo "#" >> $fout
      fi
      if [ $is_gibi -eq 0 ]; then
         echo "nom : Gibi" >> $fout
         echo "cmde : $gibi_dir/gibi (@F)" >> $fout
         echo "ext : datg" >> $fout
         echo "dist : off" >> $fout
         echo "#" >> $fout
      fi
      if [ $is_grace -eq 0 ]; then
         echo "nom : Grace" >> $fout
         echo "cmde : $grace_dir/xmgrace (@F)" >> $fout
         echo "ext : dat" >> $fout
         echo "dist : on" >> $fout
         echo "#" >> $fout
      fi
   fi
fi

######################################################################
#
# instructions
#
CLEAR
echo " "
if [ $SRC -eq 1 ]; then
   echo "To build Code_Aster, type :"
   echo " "
   echo " cd $inst_dir/$pseudo_vers/tcl"
   echo " ./run_aster make_aster  "
   echo " "
   echo "If you want to build a debug executable, set debug variable to debug (!)"
   echo "in 'make_aster' file (optional)."
   echo " "
   echo " "
   echo "It could be a good idea to test the executable by running"
   echo "some cases from 'etude' or 'astest' directories."
   echo " "
   echo "To run the tests from 'etude', type :"
   echo " cd $inst_dir/$pseudo_vers/tcl"
   echo " ./run_aster make_test  "
   echo " Depending on platform, it could take about 120 s to 1500 s..."
   echo " "
   echo "To run the tests from 'astest', type :"
   echo " cd $inst_dir/$pseudo_vers/tcl"
   echo " ./run_aster make_test_full  "
else
   echo "To run Code_Aster on an example, type :"
   echo " "
   echo " cd $inst_dir/$pseudo_vers/tcl"
   echo " ./run_aster make_etude  "
fi
echo " "
echo " For additional informations, visit http://www.code-aster.org"
echo " and ask your questions to the forum."
echo " "

exit 0
