#!/bin/sh 
#
#  cross_install
#  Release 4.5
#
#
# This script is used to install cross C and/or FORTRAN compilers
# This install assumes that the related compiler tar files are on
# a remote system. It prompts the user to get the correct information.
#
DIST_NODENAME="unknown"
DIST_PATH="/u/tmp"
PARA_NODENAME="unknown"
PARA_DIST_PATH="/tmp"
FTP_USER="anonymous"
PARA_FTP_USER="anonymous"
SUNC_TAR=sun_c.tar
SGIC_TAR=sgi_c.tar
SOLC_TAR=sol_c.tar
SUNF_TAR=sun_ftn.tar
SGIF_TAR=sgi_ftn.tar
SOLF_TAR=sol_ftn.tar
SYS_TAR=sysfiles.tar
C_DOC=icc.doc.tar
FTN_DOC=if77.doc.tar
INVALID="Invalid input"
INSTALL_SGI="y"
INSTALL_SUN4="y"
INSTALL_SOL="y"
CMP_DIR="/tmp"
INSTALL_SYS="n"
LINK_SYS="n"
LINK_DIR=
WORK_FILE="./cross_install_work_4.5"

###########################################################################
# FUNCTION:     GetParam
#
#       This function checks for arguments and sets the appropriate flags.
###########################################################################
GetParam()
{
if [ $# = 0 ]; then
   INSTALL=3
   INSTALL_F77="y"
   INSTALL_C="y"
elif [ $# = 1 -a \( $1 = "C" -o $1 = "c" \) ]; then
   INSTALL=1
   INSTALL_C="y"
   INSTALL_F77="n"
elif [ $# = 1 -a \( $1 = "F77" -o $1 = "f77" \) ]; then
   INSTALL=2
   INSTALL_C="n"
   INSTALL_F77="y"
else
   $ECHO "usage:  cross_install C   - install cross C compiler(s)"
   $ECHO "        cross_install F77 - install cross FORTRAN compiler(s)"
   $ECHO "        cross_install     - install cross C and FORTRAN compilers(s)"
   exit
fi
}
###########################################################################
# FUNCTION:     GetTarFiles
#
#       This function will go to the distribution system and retrieve the
#       tar files. If a failure happens, the user will be given the chance
#       to change the information.
###########################################################################
GetTarFiles()
{
        GET_COMPRESSED=1
        Done=0
        while [ $Done -eq 0 ]; do
                if [ -f "$WORK_FILE" ]; then
                   /bin/rm -f $WORK_FILE
                fi
                if [ "$INSTALL_C" = "Y" -o "$INSTALL_C" = "y" -o "$INSTALL_F77" = "Y" -o "$INSTALL_F77" = "y" ]; then
                   $ECHO "user $FTP_USER" > $WORK_FILE 
                   $ECHO "binary" >> $WORK_FILE
                   $ECHO "lcd $CMP_DIR" >> $WORK_FILE
                   $ECHO "cd $DIST_PATH" >> $WORK_FILE
                   if [ "$INSTALL_C" = "Y" -o "$INSTALL_C" = "y" ]; then
                      $ECHO "get $C_DOC.Z" >> $WORK_FILE
                      if [ "$INSTALL_SGI" = "Y" -o "$INSTALL_SGI" = "y" ]; then
                         $ECHO "get $SGIC_TAR.Z" >> $WORK_FILE
                      fi
                      if [ "$INSTALL_SUN4" = "Y" -o "$INSTALL_SUN4" = "y" ]; then
                         $ECHO "get $SUNC_TAR.Z" >> $WORK_FILE
                      fi
                      if [ "$INSTALL_SOL" = "Y" -o "$INSTALL_SOL" = "y" ]; then
                         $ECHO "get $SOLC_TAR.Z" >> $WORK_FILE
                      fi
                   fi
                   if [ "$INSTALL_F77" = "Y" -o "$INSTALL_F77" = "y" ]; then
                      $ECHO "get $FTN_DOC.Z" >> $WORK_FILE
                      if [ "$INSTALL_SGI" = "Y" -o "$INSTALL_SGI" = "y" ]; then
                         $ECHO "get $SGIF_TAR.Z" >> $WORK_FILE
                      fi
                      if [ "$INSTALL_SUN4" = "Y" -o "$INSTALL_SUN4" = "y" ]; then
                         $ECHO "get $SUNF_TAR.Z" >> $WORK_FILE
                      fi
                      if [ "$INSTALL_SOL" = "Y" -o "$INSTALL_SOL" = "y" ]; then
                         $ECHO "get $SOLF_TAR.Z" >> $WORK_FILE
                      fi
                   fi
                   if [ "$INSTALL_SYS" = "Y" -o "$INSTALL_SYS" = "y" ]; then
                      $ECHO "close" >> $WORK_FILE
                      $ECHO "open $PARA_NODENAME" >> $WORK_FILE
                      $ECHO "user $PARA_FTP_USER" >> $WORK_FILE 
                      $ECHO "binary" >> $WORK_FILE
                      $ECHO "cd $PARA_DIST_PATH" >> $WORK_FILE
                      $ECHO "get $SYS_TAR.Z" >> $WORK_FILE
                   fi
                   $ECHO "quit" >> $WORK_FILE
                
                   ftp -n -v $DIST_NODENAME < $WORK_FILE
#
#  only copying sysfiles.tar.Z
#
                else
                   $ECHO "user $PARA_FTP_USER" > $WORK_FILE 
                   $ECHO "binary" >> $WORK_FILE
                   $ECHO "lcd $CMP_DIR" >> $WORK_FILE
                   $ECHO "cd $PARA_DIST_PATH" >> $WORK_FILE
                   $ECHO "get $SYS_TAR.Z" >> $WORK_FILE
                   $ECHO "quit" >> $WORK_FILE
                   ftp -n -v $PARA_NODENAME < $WORK_FILE
                fi


# Check to make sure each of the files has been copied down to the target
# machine. If these files are not here, give the user a change to repeat.
                Fail=0
                if [ "$INSTALL_C" = "Y" -o "$INSTALL_C" = "y"  ]; then
                   if [ ! -f $CMP_DIR/$C_DOC.Z  ]; then
                           $ECHO "ERROR: $C_DOC.Z was not retrieved."
                           Fail=1
                   fi
                   if [ "$INSTALL_SUN4" = "Y" -o "$INSTALL_SUN4" = "y"  ]; then
                      if [ ! -f $CMP_DIR/$SUNC_TAR.Z  ]; then
                           $ECHO "ERROR: $SUNC_TAR.Z was not retrieved."
                           Fail=1
                      fi
                   fi
                   if [ "$INSTALL_SGI" = "Y" -o "$INSTALL_SGI" = "y"  ]; then
                      if [ ! -f $CMP_DIR/$SGIC_TAR.Z  ]; then
                           $ECHO "ERROR: $SGIC_TAR.Z was not retrieved."
                           Fail=1
                      fi
                   fi
                   if [ "$INSTALL_SOL" = "Y" -o "$INSTALL_SOL" = "y"  ]; then
                      if [ ! -f $CMP_DIR/$SOLC_TAR.Z  ]; then
                           $ECHO "ERROR: $SOLC_TAR.Z was not retrieved."
                           Fail=1
                      fi
                   fi
                fi
                if [ "$INSTALL_F77" = "Y" -o "$INSTALL_F77" = "y"  ]; then
                   if [ ! -f $CMP_DIR/$FTN_DOC.Z  ]; then
                           $ECHO "ERROR: $FTN_DOC.Z was not retrieved."
                           Fail=1
                   fi
                   if [ "$INSTALL_SUN4" = "Y" -o "$INSTALL_SUN4" = "y"  ]; then
                      if [ ! -f $CMP_DIR/$SUNF_TAR.Z  ]; then
                           $ECHO "ERROR: $SUNF_TAR.Z was not retrieved."
                           Fail=1
                      fi
                   fi
                   if [ "$INSTALL_SGI" = "Y" -o "$INSTALL_SGI" = "y"  ]; then
                      if [ ! -f $CMP_DIR/$SGIF_TAR.Z  ]; then
                           $ECHO "ERROR: $SGIF_TAR.Z was not retrieved."
                           Fail=1
                      fi
                   fi
                   if [ "$INSTALL_SOL" = "Y" -o "$INSTALL_SOL" = "y"  ]; then
                      if [ ! -f $CMP_DIR/$SOLF_TAR.Z  ]; then
                           $ECHO "ERROR: $SOLF_TAR.Z was not retrieved."
                           Fail=1
                      fi
                   fi
                fi
        
                if [ "$INSTALL_SYS" = "Y" -o "$INSTALL_SYS" = "y" ]; then
                   if [ ! -f $CMP_DIR/$SYS_TAR.Z  ]; then
                        $ECHO "ERROR: $SYS_TAR.Z was not retrieved."
                        Fail=1
                   fi
                fi
 
 
                if [ $Fail -eq 1 ]; then
                        $ECHO "\n"
                        $ECHO "There were errors retrieving the files."
                        $ECHO "Continue  (y/n) ?\c"
                        read answer
                        $ECHO " "
                        if [ "$answer" = "Y" -o "$answer" = "y" ];  then
                           AskQuestions
                        else
                           exit 1
                        fi
 
                else
                        Done=1
                        /bin/rm -f $WORK_FILE
                fi
        done
        if [ -f "$WORK_FILE" ]; then
           /bin/rm -f $WORK_FILE
        fi
}

###########################################################################
# FUNCTION:     AskQuestions
#
#       This function retrieves the installation info
###########################################################################

AskQuestions()
{
accept=0
while [ $accept = 0 ] 
do
   clear
   $ECHO " "
   $ECHO "======================================================================="
   $ECHO " "
   $ECHO "                  Cross Compiler Installation"
   $ECHO " "
   $ECHO "======================================================================="
   $ECHO " "
   if [ $INSTALL = 2 -o $INSTALL = 3 ]; then
      $ECHO "Install FORTRAN? [y/n]:                           $INSTALL_F77"
   fi
   if [ $INSTALL = 1 -o $INSTALL = 3 ]; then
      $ECHO "Install C? [y/n]:                                 $INSTALL_C"
   fi
   $ECHO "Install Sun4? [y/n]:                              $INSTALL_SUN4"
   $ECHO "Install Solaris? [y/n]:                           $INSTALL_SOL"
   $ECHO "Install SGI? [y/n]:                               $INSTALL_SGI"
   $ECHO "Root directory for compiler installation [path]:  $ROOT_DIR"
   $ECHO "Location for compressed tar files [path]:         $CMP_DIR"
   $ECHO "Distribution host name:                           $DIST_NODENAME"   
   $ECHO "Distribution host user name for ftp:              $FTP_USER"
   $ECHO "Distribution path:                                $DIST_PATH"
   $ECHO "Install system files? [y/n]:                      $INSTALL_SYS"
   if [ $INSTALL_SYS = "Y" -o $INSTALL_SYS = "y" ]; then
      $ECHO "   Paragon system name:                           $PARA_NODENAME"
      $ECHO "   Paragon user name for ftp:                     $PARA_FTP_USER"
      $ECHO "   Path for compressed system tar file:           $PARA_DIST_PATH"
   fi
   $ECHO "Create links for system files? [y/n]:             $LINK_SYS"
   if [ $LINK_SYS = "Y" -o $LINK_SYS = "y" ]; then
      $ECHO "   Create links to:                               $LINK_DIR"
   fi
   $ECHO  "Is this correct? (y/n): \c"
   read answer
   $ECHO " "
   if [ "$answer" != "Y" -a "$answer" != "y" ];  then

      if [ $INSTALL = 2 -o $INSTALL = 3 ]; then
      f77_ok=0
      while [ $f77_ok = 0 ]
      do
         $ECHO  "Install FORTRAN? [$INSTALL_F77]: \c"
         read answer
         test $answer
         if [ $? = 1 ]; then
            f77_ok=1
         elif [ "$answer" != "N" -a "$answer" != "n" -a "$answer" != "Y" -a "$answer" != "y" ]; then
            $ECHO $INVALID
         else
            f77_ok=1
            INSTALL_F77=$answer
         fi
      done
      fi
 
      if [ $INSTALL = 1 -o $INSTALL = 3 ]; then
      cc_ok=0
      while [ $cc_ok = 0 ]
      do 
         $ECHO  "Install C? [$INSTALL_C]: \c"
         read answer
         test $answer
         if [ $? = 1 ]; then
            cc_ok=1
         elif [ "$answer" != "N" -a "$answer" != "n" -a "$answer" != "Y" -a "$answer" != "y" ]; then
            $ECHO $INVALID
         else
            cc_ok=1
            INSTALL_C=$answer
         fi
      done
      fi

      sun4_ok=0
      while [ $sun4_ok = 0 ]
      do
         $ECHO  "Install Sun4? [$INSTALL_SUN4]: \c"
         read answer
         test $answer
         if [ $? = 1 ]; then
            sun4_ok=1
         elif [ "$answer" != "N" -a "$answer" != "n" -a "$answer" != "Y" -a "$answer" != "y" ]; then
            $ECHO $INVALID
         else
            sun4_ok=1
            INSTALL_SUN4=$answer
         fi
      done

      solaris_ok=0
      while [ $solaris_ok = 0 ]
      do
         $ECHO  "Install Solaris? [$INSTALL_SOL]: \c"
         read answer
         test $answer
         if [ $? = 1 ]; then
            solaris_ok=1
         elif [ "$answer" != "N" -a "$answer" != "n" -a "$answer" != "Y" -a "$answer" != "y" ]; then
            $ECHO $INVALID
         else
            solaris_ok=1
            INSTALL_SOL=$answer
         fi
      done

      sgi_ok=0
      while [ $sgi_ok = 0 ]
      do
         $ECHO  "Install SGI? [$INSTALL_SGI]: \c"
         read answer
         test $answer
         if [ $? = 1 ]; then
            sgi_ok=1
         elif [ "$answer" != "N" -a "$answer" != "n" -a "$answer" != "Y" -a "$answer" != "y" ]; then
            $ECHO $INVALID
         else
            sgi_ok=1
            INSTALL_SGI=$answer
         fi
      done

      root_ok=0
      while [ $root_ok = 0 ]
      do  
         $ECHO  "Enter root directory for compiler installation [$ROOT_DIR]: \c"
         read answer
         test $answer
         if [ $? = 1 ]; then
            root_ok=1 
         elif  [ ! -d "$answer" ]; then
            $ECHO "$answer does not exist or is not a directory"
         elif  [ ! -w "$answer" ]; then
            $ECHO "You do not have write permission for Directory $answer "
         else 
            ROOT_DIR=$answer
            root_ok=1
         fi
      done

      cmp_ok=0
      while [ $cmp_ok = 0 ]
      do  
         $ECHO  "Enter directory for compressed tar files [$CMP_DIR]: \c"
         read answer
         test $answer
         if [ $? = 1 ]; then
            cmp_ok=1
         elif  [ ! -d "$answer" ]; then
            $ECHO "$answer does not exist or is not a directory"
         else 
            CMP_DIR=$answer
            cmp_ok=1
         fi
      done

      dist_ok=0
      while [ $dist_ok = 0 ]
      do
         $ECHO "Enter the host name of the distribution system [$DIST_NODENAME]: \c"
         read answer
         test $answer
         if [ $? = 1 ]; then
            dist_ok=1
         else 
            DIST_NODENAME=$answer
            dist_ok=1
         fi
      done

      ftp_ok=0
      while [ $ftp_ok = 0 ]
      do
         $ECHO "Enter the user name for ftp from $DIST_NODENAME [$FTP_USER]: \c"
         read answer
         test $answer
         if [ $? = 1 ]; then
            ftp_ok=1
         else 
            FTP_USER=$answer
            ftp_ok=1
         fi
      done

      distp_ok=0
      while [ $distp_ok = 0 ]
      do
         $ECHO "Enter the distribution path on $DIST_NODENAME [$DIST_PATH]:\c"
         read answer
         test $answer
         if [ $? = 1 ]; then
            distp_ok=1
         else 
            DIST_PATH=$answer
            distp_ok=1
         fi
      done

      ins_ok=0
      while [ $ins_ok = 0 ]
      do
         $ECHO "Install system files? [$INSTALL_SYS]: \c"
         read answer
         test $answer
         if [ $? = 1 ]; then
            ins_ok=1
         elif [ "$answer" != "N" -a "$answer" != "n" -a "$answer" != "Y" -a "$answer" != "y" ]; then
            $ECHO $INVALID
         else
            if [ "$answer" = "Y" -o "$answer" = "y" ]; then
               $ECHO "Enter name of paragon system where $SYS_TAR.Z was created: \c"
               read answer2
               test $answer2
               if [ $? = 1 ]; then
                  $ECHO $INVALID
               else
                  PARA_NODENAME=$answer2
               fi
               $ECHO "Enter user name for ftp from $PARA_NODENAME: [$PARA_FTP_USER] \c"
               read answer2
               test $answer2
               if [ $? != 1 ]; then
                  PARA_FTP_USER=$answer2
               fi
               $ECHO "Enter path of $SYS_TAR on $PARA_NODENAME: [$PARA_DIST_PATH] \c"
               read answer2
               test $answer2
               if [ $? != 1 ]; then
                  PARA_DIST_PATH=$answer2
               fi
            fi
            ins_ok=1
            INSTALL_SYS=$answer
         fi
      done

      lnks_ok=0
      while [ $lnks_ok = 0 ]
      do
         $ECHO "Create links for system files? [$LINK_SYS]: \c"
         read answer
         test $answer
         if [ $? = 1 ]; then
            lnks_ok=1
         elif [ "$answer" != "N" -a "$answer" != "n" -a "$answer" != "Y" -a "$answer" != "y" ]; then
            $ECHO $INVALID
         else
            if [ "$answer" = "Y" -o "$answer" = "y" ]; then
               $ECHO "Enter root directory of actual files: \c"
               read answer2
               test $answer2
               if [ $? = 1 ]; then
                  $ECHO $INVALID
               elif  [ ! -d "$answer2" ]; then
                  $ECHO "$answer2 does not exist or is not a directory"
               elif  [ ! -d "$answer2/paragon/lib-coff" -o ! -d "$answer2/paragon/include" ]; then
                  $ECHO "$answer2 is an invalid path"
                  $ECHO "subdirectories paragon/lib-coff and paragon/include must exist"
               elif  [ $answer2 = $ROOT_DIR ]; then
                  $ECHO "Root installation directory cannot be the same as the"
                  $ECHO "link directory" 
               else
                  LINK_DIR=$answer2
                  lnks_ok=1
                  LINK_SYS=$answer
               fi
            else
               lnks_ok=1
               LINK_SYS=$answer
               LINK_DIR=
            fi
         fi
      done

   else
      accept=1
      if [ $INSTALL_SYS = "Y" -o $INSTALL_SYS = "y" ];
      then
         if [ $LINK_SYS = "Y" -o $LINK_SYS = "y" ];
         then 
            $ECHO "You cannot install system files AND create links"
            $ECHO "Change one of these to N"
            $ECHO " "
            $ECHO "Press RETURN to continue \c"
            read answer
            accept=0
         fi
      fi
   fi
done
}
#
#  Install compilers
#
DoInstall()
{
not_installed=0
#
# install the system libraries and header files
#
if [ $INSTALL_SYS = "Y" -o $INSTALL_SYS = "y" ]; then
   if [ -f $CMP_DIR/$SYS_TAR.Z ]; then
      $ECHO "Uncompressing $SYS_TAR.Z..."
      uncompress $CMP_DIR/$SYS_TAR.Z
      if [ $? != 0 ]; then
         UncmpFailed 
      fi
      $ECHO "Installing system libraries and header files..."
      cd $ROOT_DIR
      mkdir paragon
      cd paragon
      tar xf $CMP_DIR/$SYS_TAR
      if [ $? = 0 ]; then
         /bin/rm -f $CMP_DIR/$SYS_TAR
      else
         TarFailed
      fi
   else
      $ECHO "$CMP_DIR/$SYS_TAR does not exist"
      $ECHO "Follow the installation instructions for creating this file"
      $ECHO " "
      $ECHO "Installation aborted"
      exit 1
   fi
fi
#
#  Install C compiler and documentation
#
cd $ROOT_DIR
if [ $INSTALL_C = "Y" -o $INSTALL_C = "y" ]; then
   if [ ! -d "$ROOT_DIR/paragon" ]; then
      mkdir paragon
   fi
   if [ -f $CMP_DIR/$C_DOC.Z ]; then
      $ECHO "Uncompressing $C_DOC..."
      uncompress $CMP_DIR/$C_DOC.Z
      if [ $? != 0 ]; then
         UncmpFailed 
      fi
      $ECHO "Installing C manual pages..."
      cd paragon
      tar xpf $CMP_DIR/$C_DOC
      if [ $? = 0 ]; then
         /bin/rm -f $CMP_DIR/$C_DOC
      else
         TarFailed
      fi
      cd ..
   else
      not_installed=1
      $ECHO "$CMP_DIR/$C_DOC does not exist"
      $ECHO "C manual pages were not installed"
      $ECHO " "
   fi
   if [ $INSTALL_SUN4 = "y" -o $INSTALL_SUN4 = "y" ]; then
      if [ -f $CMP_DIR/$SUNC_TAR.Z ]; then
         $ECHO "Uncompressing $SUNC_TAR.Z..."
         uncompress $CMP_DIR/$SUNC_TAR.Z
         if [ $? != 0 ]; then
            UncmpFailed 
         fi
         $ECHO "Installing Sun C compiler..."
         tar xpf $CMP_DIR/$SUNC_TAR
         if [ $? = 0 ]; then
            /bin/rm -f $CMP_DIR/$SUNC_TAR
         else
            TarFailed
         fi
      else
         not_installed=1
         $ECHO "$CMP_DIR/$SUNC_TAR does not exist"
         $ECHO "Sun C compiler was not installed"
         $ECHO " "
      fi
   fi
   if [ $INSTALL_SOL = "y" -o $INSTALL_SOL = "y" ]; then
      if [ -f $CMP_DIR/$SOLC_TAR.Z ]; then
         $ECHO "Uncompressing $SOLC_TAR.Z..."
         uncompress $CMP_DIR/$SOLC_TAR.Z
         if [ $? != 0 ]; then
            UncmpFailed 
         fi
         $ECHO "Installing Sun4/Solaris C compiler..."
         tar xpf $CMP_DIR/$SOLC_TAR
         if [ $? = 0 ]; then
            /bin/rm -f $CMP_DIR/$SOLC_TAR
         else
            TarFailed
         fi
      else
         not_installed=1
         $ECHO "$CMP_DIR/$SOLC_TAR does not exist"
         $ECHO "Sun4/Solaris C compiler was not installed"
         $ECHO " "
      fi
   fi

   if [ $INSTALL_SGI = "y" -o $INSTALL_SGI = "y" ]; then
      if [ -f $CMP_DIR/$SGIC_TAR.Z ]; then
         $ECHO "Uncompressing $SGIC_TAR.Z..."
         uncompress $CMP_DIR/$SGIC_TAR.Z
         if [ $? != 0 ]; then
            UncmpFailed 
         fi
         $ECHO "Installing SGI C compiler..."
         tar xpf $CMP_DIR/$SGIC_TAR
         if [ $? = 0 ]; then
            /bin/rm -f $CMP_DIR/$SGIC_TAR
         else
            TarFailed
         fi
      else
         not_installed=1
         $ECHO "$CMP_DIR/$SGIC_TAR does not exist"
         $ECHO "SGI C compiler was not installed"
         $ECHO " "
      fi
   fi
   if [ $not_installed = 0 ]; then
      if [ ! -f $ROOT_DIR/paragon/lib-coff/iclib.a ]; then
         cd $ROOT_DIR/paragon/lib-coff
         ln -s libic.a iclib.a
         cd $ROOT_DIR
      fi
      if [ $LINK_SYS = "Y" -o $LINK_SYS = "y" ]; then
         $ECHO "Creating links for header files and libraries..."
         $ROOT_DIR/xmklinks_c $LINK_DIR
      fi
      rm -f $ROOT_DIR/xmklinks_c
   fi
fi
#
#  Install FORTRAN compiler and documentation
#
if [ $INSTALL_F77 = "Y" -o $INSTALL_F77 = "y" ]; then
   if [ ! -d "$ROOT_DIR/paragon" ]; then
      mkdir paragon
   fi
   if [ -f $CMP_DIR/$FTN_DOC.Z ]; then
      $ECHO "Uncompressing $FTN_DOC.Z..."
      uncompress $CMP_DIR/$FTN_DOC.Z
      if [ $? != 0 ]; then
         UncmpFailed 
      fi
      $ECHO "Installing FORTRAN manual pages..."
      cd paragon
      tar xpf $CMP_DIR/$FTN_DOC
      if [ $? = 0 ]; then
         /bin/rm -f $CMP_DIR/$FTN_DOC
      else 
         TarFailed
      fi
      cd ..
   else
      not_installed=1
      $ECHO "$CMP_DIR/$FTN_DOC does not exist"
      $ECHO "FORTRAN manual pages were not installed"
      $ECHO " "
   fi
   if [ $INSTALL_SUN4 = "y" -o $INSTALL_SUN4 = "y" ]; then
      if [ -f $CMP_DIR/$SUNF_TAR.Z ]; then
         $ECHO "Uncompressing $SUNF_TAR.Z..."
         uncompress $CMP_DIR/$SUNF_TAR.Z
         if [ $? != 0 ]; then
            UncmpFailed 
         fi
         $ECHO "Installing Sun FORTRAN compiler..."
         tar xpf $CMP_DIR/$SUNF_TAR
         if [ $? = 0 ]; then
            /bin/rm -f $CMP_DIR/$SUNF_TAR
         else 
            TarFailed
         fi
      else
         not_installed=1
         $ECHO "$CMP_DIR/$SUNF_TAR does not exist"
         $ECHO "Sun FORTRAN compiler was not installed"
         $ECHO " "
      fi
   fi
   if [ $INSTALL_SOL = "y" -o $INSTALL_SOL = "y" ]; then
      if [ -f $CMP_DIR/$SOLF_TAR.Z ]; then
         $ECHO "Uncompressing $SOLF_TAR.Z..."
         uncompress $CMP_DIR/$SOLF_TAR.Z
         if [ $? != 0 ]; then
            UncmpFailed 
         fi
         $ECHO "Installing Sun4/Solaris FORTRAN compiler..."
         tar xpf $CMP_DIR/$SOLF_TAR
         if [ $? = 0 ]; then
            /bin/rm -f $CMP_DIR/$SOLF_TAR
         else 
            TarFailed
         fi
      else
         not_installed=1
         $ECHO "$CMP_DIR/$SOLF_TAR does not exist"
         $ECHO "Sun4/Solaris FORTRAN compiler was not installed"
         $ECHO " "
      fi
   fi

   if [ $INSTALL_SGI = "y" -o $INSTALL_SGI = "y" ]; then
      if [ -f $CMP_DIR/$SGIF_TAR.Z ]; then
         $ECHO "Uncompressing $SGIF_TAR.Z..."
         uncompress $CMP_DIR/$SGIF_TAR.Z
         if [ $? != 0 ]; then
            UncmpFailed 
         fi
         $ECHO "Installing SGI FORTRAN compiler..."
         tar xpf $CMP_DIR/$SGIF_TAR
         if [ $? = 0 ]; then
            /bin/rm -f $CMP_DIR/$SGIF_TAR
         else 
            TarFailed
         fi
      else
         not_installed=1
         $ECHO "$CMP_DIR/$SGIF_TAR does not exist"
         $ECHO "SGI FORTRAN compiler was not installed"
         $ECHO " "
      fi

   fi
   if [ $not_installed = 0 ]; then
      if [ ! -f $ROOT_DIR/paragon/lib-coff/iclib.a ]; then
         cd $ROOT_DIR/paragon/lib-coff
         ln -s libic.a iclib.a
         cd $ROOT_DIR
      fi
      if [ $LINK_SYS = "Y" -o $LINK_SYS = "y" ]; then
         $ECHO "Creating links for header files and libraries..."
         $ROOT_DIR/xmklinks_f $LINK_DIR
      fi
      rm -f $ROOT_DIR/xmklinks_f
   fi
fi
$ECHO " "
if [ $not_installed = 0 ]; then
   $ECHO "Installation complete"
else
   $ECHO "Installation was unsuccessful due to missing files in $CMP_DIR"
fi
}
###########################################################################
# FUNCTION:    TarFailed 
#
#       This function echo prints an abort message and exits
###########################################################################
TarFailed()
{
cd $ROOT_DIR
$ECHO "tar failed"
$ECHO "Installation aborted"
exit 1
}
###########################################################################
# FUNCTION:    UncmpFailed 
#
#       This function echo prints an abort message and exits
###########################################################################
UncmpFailed()
{
cd $ROOT_DIR
$ECHO "uncompress failed"
$ECHO "Installation aborted"
exit 1
}
############################################################################
#              S T A R T  O F  I N S T A L L A T I O N
############################################################################
if [ -f /usr/5bin/echo ]; then
   ECHO="/usr/5bin/echo"
else
   ECHO="echo"
fi
export ECHO 
test $PARAGON_XDEV
if [ $? = 1 ]; then
   ROOT_DIR="/usr/paragon/XDEV"
else
   ROOT_DIR=$PARAGON_XDEV
fi
accept=0
GetParam $@
AskQuestions
if [ "$INSTALL_C" = "Y" -o "$INSTALL_C" = "y" -o "$INSTALL_F77" = "Y" -o "$INSTALL_F77" = "y" -o $INSTALL_SYS = "Y" -o $INSTALL_SYS = "y" ]; then
   GetTarFiles
   DoInstall
else
   $ECHO "No installation required"
fi
