#!/bin/csh
#==============================================================================
#
#  Name   :  install.RASS-OSX.361.command
#  
#  Version:  2.7.1  (15/02/23)
set myVersion = 2.7.1
#
#  Purpose:  Install RASS release, version 361,
#            on any host
#            
#  Usage:    Under Solaris
#  
#                 install.RASS-OSX.361 [deinstallOld]
#  
#            Under Mac OS X double-click 
#            
#            	   install.RASS-OSX.361.command
#            
#            or from a shell using optional arguments
#            
#            	   install.RASS-OSX.361.command [deinstallOld] [S]
#
# 			In general it is recommended to execute in a Terminal window
# 			commands similar to the following to also get a protocol from the
# 			installation
# 			
# 			  cd <directory where this script and the RASS-OSX.361.tar.Z reside>
# 			  install.RASS-OSX.361.command -S 2>&1 | tee S-install.protocol.txt
#
#  Remark:   This script is a RASS utility designed to be used by a 
#            software administrator on the host on which RASS is to be 
#            installed
#            
#            Note the companion script 'install_RMSP1.command' installs RMSP1,
#            while this script installs RASS either on a Sun, i.e. RASS-Sun, or 
#            on a Mac running OS X, i.e. RASS-OSX. The name of this script 
#            varies according to the platform (Sun vs. OSX).
#            
#            Note, there are also the scripts 'doRass-SunInstallation' or
#            'doARassOSXInstallation' (only internally used
#            'install_RASS_On_SimServ.command').  All are identical but named
#            differently to emphasize their purpose.  In addition to this
#            installer script, they also download a RASS release, then call this
#            script, and finally download also all library sources (.DEFs and
#            .MODs) and MREF files (P1 compiler only) for debugging purposes,
#            mostly only of interest to RASS developers.
#            
#            'RMSP1' differs little from RASS-OSX, since it is a superset
#            of RASS-OSX and installs RASS-OSX in a similar manner as this
#            routine does (see RASS utility 'mk' help and 'mk1' help,
#            option -L to make use of these features and consult the
#            'READ_ME.pdf' of 'RMSP1' also released as part of any
#            'RASS-OSX' release).
#
#==============================================================================
### Implementation and Revisions:
#------------------------------------------------------------------------------
# Author  Date      Description
# ------  ----      -----------
# dg      24/07/00  First implementation
# dg      18/08/00  Installation of additional files and templates
#                   - All script files and templates now installed in directory  
#                   /usr/local/bin/RASS
# af      21/08/00  Fixing permission bug of libRass* files in /usr/local/lib 
# af      26/08/00  V 1.1: Adding salvation mechanism and documenting result
# af      27/08/00  V 1.1.1 for RASS v3.0.3: documents option and salvaged files
# af      10/09/00  V 1.2.0 for RASS v3.0.3: Bug fix - Correcting list of RASS utils
# af      12/02/01  V 1.3.0 ext2ext and autoedit added to list of RASS utilities
# dg      17/08/01  V 1.4.0 SymDiff and symdiff added to list of RASS utilities
# af      05/03/03  V 1.4.1 for RASS v3.0.6 reprep added
# af      21/04/03  V 1.5 for preparing util finish added
# af      25/02/05  V 1.6 for RASS 3.1.8 (releasing of new script younger)    
# af      05/03/05  V 1.7 for RASS 3.2.0 (releasing of RASS-OSX)    
# af      18/04/05  V 1.7.1 fixing relase bug by workDir starting with RASS 
# af      27/04/05  V 1.7.2 fixing all release bugs for RASS-OSX 
# af      28/04/05  V 1.8 overhauling this script to make it working really 
# af      30/04/05  V 1.8.1 releasing also mk1 
# af      11/05/05  V 1.9 releasing doBatchExecute utility
# af      11/05/05  V 2.0 for RASS 3.2.2 supporting finish for RASS-OSX
# af      31/05/05  V 2.0.1 for RASS 3.2.3 Give at end hint on use of finish
# af      05/06/05  V 2.1 - RASS 3.2.3 renamed 'local.config.M2PATH.TEMPLATE' 
#                     to 'config.M2PATH.TEMPLATE' 
# af      07/06/05  V 2.1.1 for RASS 3.2.3 - RMSP1 1.01 - debug.dat.TEMPLATE
#                     installed
# af      12/06/05  V 2.1.2 for RASS 3.2.4 - RMSP1 1.11 - more robust 
#                     chmod for finish/finish.command utility
# af      02/01/06  V 2.2 for RASS 3.2.9 - RMSP1 1.42 
#                   - support for installation for simulation servers such
#                     as superior.ethz.ch (exported via NFS by
#                     se-server.ethz.ch to only the simulation servers)
#                   - disables installation on clustered OS X simulation 
#                     servers such as superior.ethz.ch
#                   - support for conditional installation of developer 
#                     utilities such as start on any machine, which can
#                     be used for development
#                   - skipping profile installation if isOSXSimServExporter
#                   - finish now listed in devUtilityFiles to ensure it is
#                     available on superior.ethz.ch
#                   - Removing all '!' in echo strings to avoid crash of 
#                     script on Suns in case that message is actually used
#                   - Releasing for RASS-OsX also setmailto, setRASSmailto,  
#                     and setprojdescr
# af      02/02/06  V 2.2.1 for RASS 3.3.0 - RMSP1 1.5
#                   - Documenting date and time at begin and end of script
# af      09/10/06  V 2.3 for RASS 3.4.1 - RMSP1 1.9
#                   - rassUtilsDir is no longer ~/bin/RASS for private
#                     simulationists machines, but depends on
#                     new environment var RASSOSXHOME (by default
#                     ~/Library/RASS)
#                   - ~/.profile overwriting is by default disabled
#                     and implemented more conservatively, i.e. nothing 
#                     done if not all preconditions are fully met.
#                   - Installed .profile is edited for giving RASS-OSX
#                     higher priority than RMSP1 (default priority, see
#                     installationFOR)
#                   - READ_ME.pdf no longer installed into 'bin' 
#                     directory, but installed into RASSOSXHOME (same 
#                     structure as in RMSP1 release)
#                   - Introducing new RMSP1/RASS-OSX utility 'switch2using'
#                   - RMSP1Help comes now under its original name. 
#                     Install still RASSHelp as hard link to RMSP1Help.
#                     RASSHelp is restricted to the Unix/Solaris variant of
#                     the two.
#                   - If there exists '.profile' on simulationists private 
#                     machines, utility switch2using RASS-OSX is used to
#                     ensure the profile points to the new installation
#                   - If there exists '~/local.profile' on simulationists
#                     private machine, simulationist is asked for installation
#                     permission (default no)
# af      12/01/08  V 2.3.1 for RASS 3.5.2 - RMSP1 2.2
#                   - Polished instructions at end
# af      03/07/09  V 2.3.2 for RASS 3.5.4 - RMSP1 2.4
#                   - Polished protocol information
#                   - Fixing bugs following from executing this script no 
#                     longer as root (sudo), i.e. cp -f instead of merely cp
# af      05/07/10  V 2.3.3 for RASS 3.5.5  - RMSP1 2.5
#                   - Replacing 'tcl' by 'Shell Scripts' mode sctructural marks
#                   - Avoid the hanging of this script when the host 
#                     machine is not online by no longer using utility
#                     'host'. Use 'system_profiler SPNetworkDataType' 
#                     instead.
# af      19/07/10  V 2.4 - RASS-OSX/Sun 3.5.5 - RAMSES 3.5.5 - RMSP1 2.5
#                   - Avoiding installation of any .profile. Instead using
#                     file 'rassProfileName' (=my.RASS.profile-new replacing 
#                     local.profile). If .profile is not yet sourcing 
#                     'rassProfileName' user is asked to add it to the 
#                     .profile
#                   - Added 'addRassProfileSourcing'
# af      26/11/10  - Bug fix: Bad syntax after "# Check whether user's # .profile 
#                     is sourcing my.RASS.profile" in several statements 
#                     fixed
# af      29/05/11  V 2.5 - RMSP1 1.6 - RASS 3.5.6
#                   - Installing sym links 'prj' and 'setprj' for 'setprojdescr'
#                   - Also using sym link 'RASSHelp' for 'RMSP1Help' (was 
#                     hard link, however this is not necessary if the 
#                     physical file is given without a path)
# af      11/06/11  V 2.6 - RASS-OSX 3.5.7 - RAMSES 3.5.7 - RMSP1 2.7
#                   - Installation of universal binary release (flag 
#                     'UBIRelease')
#                   - Installing 'switchp1'
#                   - This script can be called with new argument 'simpleVariantDFN'
#                     (= "S") to extract RASS from the actually downloaded file
#                   - added usage section above
#                   - adding giveHelp
#                   - Introducing DOITQUIETLY environment variable testing
#                     in case a callee such as 'doRassInstallation' wants 
#                     this script to quietly end (in contrast to 
#                     double-click technique that needs the wait at the 
#                     end for the user to inspect the result)
#                   - Giving better support for marking of protocols in 
#                     AlphaX mode shell scripts
# af      13/06/11  - Renaming 'giveFirstPriorityTo' -> 'RASSgiveFirstPriorityTo'
#                   - Bug fix: Listing "Old RASS utilities and templates 
#                     (before installation)" listed wrongly 'rassLibDir'
#                     instead of correct 'rassUtilsDir' to report in case
#                     it would be empty
#                   - Bug fixes: Avoiding "csh: Word too long." errors by
#                     using 'ls -1' instead of 'ls -l' for listings of 
#                     'bin', 'lib', and 'SYMs' dirs
#                   - Bug fix: Introducing mode flag 'simpleVariant' to 
#                     allow creation of all target dirs as needed and 
#                     before UBIRelease can be defined. ppc and i386 sub 
#                     directories were not created properly
# af      20/06/11  V 2.1 - RASS 3.5.8 - RMSP1 2.8
#                   - Introducing mode flag 'tigerVariant'
#                   - Renaming 'simpleVariantDFN' -> 'libVariantKind'
#                   - Accepting new option T and adjusting help accordingly
# af      20/06/11  V 2.2 (RASS 3.5.8 - RMSP1 2.8)
#                   - Documenting version and release variant (new var
#                     'rassFullVersion') and more comprehensive 
#                     documentation of installation at the very beginnig
#                   - Making effort to avoid 'csh: too long word' error in
#                     ls -l or ls -1 statements. 
#                   - Introducing new global var 'aRASSutil', 'aRASSLib', 
#                     and 'aMSYMFile' to avoid above problem
#                   - Better documentation of RASS lib installation
# af      28/07/11  V 2.3 (RASS 3.5.9 - RMSP1 2.9)
#                   - Bug fix in case of answering question "Do you wish to 
#                     have a sourcing statement be added to your" with
#                     yes
#                   - Using getopt for consistency with other Unix 
#                     conventions, i.e. option 'deinstallOld' becomes '-d'
#                     'S' -> '-S', 'T' -> '-T' anything else triggers help
# af      21/01/13  Comment for RASS 3.6.0 - RMSP1 3.0 releases:
#                   - It needs to be noted that 'symdiff' and 'SymDiff' were 
#                     RASS-Sun only and could not be released under Mac OS X
#                     due to a name conflict in the standard file system
#                   - Renaming RASS-Sun utility from 'symdiff' to 'runSymDiff'
#                   - Releasing now also 'runSymDiff', now a RASS utility, 
#                     together with Modula-2 program 'SymDiff'
# af      28/01/23  V 2.6.1 (RASS 3.6.1 - RMSP1 3.1)
#                   - All exit 1 statements preceeded by a halt so that
#                     the OS X user can read the error message that lead
#                     to the abort in case the script is run as a .command, 
#                     i.e. by double-clicking.
# af      01/02/23  V 2.7 (RASS 3.6.1 - RMSP1 3.1)
#                   - Adding option -p (preserveModifDate, preserveFAttrOption),
#                     which preserves file attributes such as modification dates
#                     of RASS utilities and MSYMs during installation.  In
#                     contrast to old behavior is by default on (this option 
#                     affects behavior only under OS X)
#                   - Fixing help messaging
#                   - Adding var myVersion for better self documentation in
#                     help messaging
# af      07.02.23  V 2.7.1 (RASS 3.6.1 - RMSP1 3.1)
#                   - New naming convention for the release directory (tmpWorkDir) 
#                     put into the tar archive to support the new utility
#                     'doUpdateFileRASSRelease.sh' and a better distinction
#                     between the release variants.  That utility distinguishes
#                     the release by appending a character (none for standard
#                     release, 'S' for simpleVariant, 'T' for tigerVariant).
#                     The unarchiving process no longer calls for a fixed target
#                     name (now stored in var 'tmpWorkDirDflt') and unarchives
#                     everything (tar options -vxp).  This script needs then to
#                     guess the name of the directory 'tmpWorkDir', which allows
#                     for backward compatibility as the release machinery until
#                     updated will still use for all release variants the very
#                     same name 'tmpWorkDirDflt' for 'tmpWorkDir'.
#                   - Fixing wrong explanation of option 'deinstallOldLibs'
#                   - Introducing var 'doRassInstFNAlias' to adjust the name
#                     of 'doRassInstallation' in a more logical manner (the
#                     master is always in all releases (Sun/OSX) 
#                     'install_RASS_On_SimServ.command', but the hard links
#                     or otherwise copied file as generated during installation
#                     (running either install.RASS-Sun.361 or install.RASS-OSX.361)
#                     are now called according to their actual variant, i.e.
#                     'doARassSunInstallation' or 'dRassOSXInstallation'.
# af      09.02.23  - Adding Xcode2.5.zip, Xcode2.5SE.zip, Xcode3.2.6.zip
#                     added to the release for RASS-OSX only
#                                        
#==============================================================================



#==============================================================================
### 0. Start
#------------------------------------------------------------------------------

set argv=`getopt ":diST" $*`
 
if ( $status != 0 ) then
    set giveHelp = TRUE
else
    set giveHelp = FALSE
endif

# Defaults
set deinstallOldLibs    = FALSE # if deinstallOldLibs = TRUE, old RASS libs are salvaged
set simpleVariant       = FALSE # install S-release
set preserveModifDate   = TRUE  # is by default on
set tigerVariant        = FALSE # install T-release
set libVariantKind      = ""
# According to https://www.shrubbery.net/solaris9ab/SUNWaman/hman5/fsattr.5.html
# Sun OS 5.9 (Solaris) should also offer this option. Newer Solaris systems 
# offer it for sure, cf. https://docs.oracle.com/cd/E88353_01/html/E37839/cp-1.html
set preserveFAttrOption = "-p"

while ( "$1" != "--" )
    switch($1)
        case "-d":
            set deinstallOldLibs = TRUE
            breaksw
        case "-i":
            set preserveModifDate = FALSE
            set preserveFAttrOption = ""
            breaksw
        case "-S":
            set simpleVariant = TRUE
            set libVariantKind = "S"
            breaksw
        case "-T":
            set tigerVariant = TRUE
            set libVariantKind = "T"
            breaksw
    endsw
    shift
end
shift
if ( "${1}" != "" ) then
    set giveHelp = TRUE
endif



# check for simple variant or tiger download file (note, once the file
# could be downloaded, its content will be checked and the actual
# installation mode determined from the content without bothering about
# this argument.  This supports the convenient calling of this script from
# RASS utility install_RASS_On_SimServ.command (= doRassInstallation) and
# the use of this installation script by double clicking under Mac OS X
# (thanks to extension .command) where passing of arguments is not possible
# (See also installation mode UBIRelease = NOT simpleVariant).
if ( ( $simpleVariant == TRUE ) && ( $tigerVariant == TRUE ) ) then
    set giveHelp = TRUE
endif


if ( $giveHelp == TRUE ) then
    echo ""
    echo " Usage:    Under Solaris\
\
               install.RASS-OSX.361 -d\
\
           Under Mac OS X double-click \
\
               install.RASS-OSX.361.command\
\
           or from a shell using optional arguments\
\
               install.RASS-OSX.361.command [-dhi[S|T]]\
\
           Following options are available:\
\
           -d deinstall old RASS libraries (by default off as salvaging\
              of previously installed utilities and MSYMs is always done)\
           -i do not preserve file attributes such as modification dates\
              and do set for all RASS utilities and MSYMs the\
              modification date to the installation date (by default off)\
           -S stands for simple, i.e. install instead of the standard\
              release the S-release, which is a not universal binary RASS\
              designed to use P1 8.2 and Xcode 2.5 on Power PC Macs\
              typically running Mac OS X 10.4.11 (Tiger)\
           -T stands for Tiger, i.e. install instead of the standard\
              the T-release, which is a universal binary but Xcode 2.5\
              compatible RASS using P1 9.0.2 or newer (Note, Xcode 2.5 is\
              the most recent Xcode available under Mac OS X 10.4.11)\
\
           -h this help\
\
           Options -S and -T can be used only exclusively\
\
 This is install.RASS-OSX.361.command version $myVersion\
"
    exit 0        
endif



# Determine OS on which release machinery is running
set releaseOS = `uname`
if ("${releaseOS}" == "SunOS") then
    set releaseOSName = "Solaris"
    set isSolaris = 1
    set isOSX = 0
    set isP1 = 0
    set targetName = "RASS-Sun"
else if ("${releaseOS}" == "Darwin") then
    set releaseOSName = "OS X"
    set isSolaris = 0
    set isOSX = 1
    set isP1 = 1
    set targetName = "RASS-OSX"
endif

# always salvage RASS utilities and templates
set salvageOldUtils = TRUE
# always salvage MSYM files
set salvageMSYMs = TRUE
set  myName       = `basename "${0}"`
if $isSolaris then
    set  myDir        = `dirname  "${0}"`
    set  curDir       = `pwd`
    set  isOSXCommand = 0
else if $isOSX then
    # support the use of this script as double-clickable command
    if ( "${myName}" == "install.RASS-OSX.361.command" ) then
        set  isOSXCommand = 1
        if ( $?DOITQUIETLY ) then 
            if ( "$DOITQUIETLY" == "TRUE" ) then
                set isOSXCommand = 0
            endif
        endif
    else
        set  isOSXCommand = 0
    endif
    set  curDir = `dirname "${0}"`
    cd   "$curDir"
    set  curDir = `pwd -L`
endif


# Determine user
set devUserNames = ( \
  rass               \
  afischli           \
  gyalistr           \
  sfukutom           \
  adminse            )
if ( ${isSolaris} ) then
    set  curUserName  = `/usr/ucb/whoami`
else if ( ${isOSX} ) then
    set  curUserName  = `/usr/bin/whoami`
else
    set  curUserName  = `whoami`
endif
set  curLoginUserName = "$LOGNAME"
set isDevUser = 0
# Developers may freely use developer utilities
foreach theU ( $devUserNames )
    if ( ( "${curLoginUserName}" == "${theU}" ) | ( "$HOME" == "/Users/${theU}" ) ) then
	set isDevUser = 1
    endif
end


# Determine category of OS X server on which script is run from 
# if isOSXSimServExporter then host is SESimSoftHost
# if runsOnOSXSimServer then host is OS X simulation server
# if NOT isOSXSimServExporter AND NOT runsOnOSXSimServer then host is any
# other machine such as a Sun or end user OS X Macintosh. 
set hostToInstallOn = `uname -n`
set SESimSoftHost = "se-server.ethz.ch"
set SESimSoftInstaller = "adminse"
if ( "${hostToInstallOn}" == "$SESimSoftHost" ) then
    set isOSXSimServExporter = 1
    set runsOnOSXSimServer = 0
else
    set isOSXSimServExporter = 0
    # This assumes that any "public" OS X simulation server is within the
    # indicated range of IP numbers.  Note, those OS X simulation servers
    # form a cluster and get RASS only from a central server, i.e.
    # 'SESimSoftHost' and thus MUST NOT install RASS themselves!
    # 129.132.165.30 (se-server), 129.132.165.31 (superior) .. 129.132.165.39 (biwa)
    set simServerIPRange = 129.132.165.3
    if ( $isOSX ) then	
	    # OS X recommends to no longer use 'nslookup', since it might be
	    # deprecated in the future. Instead one should use 'host'. 
	    # However, host hangs if machine is not online. Efficient 
	    # should be the use of 'system_profiler SPNetworkDataType'.
	    set hostInRange = `system_profiler SPNetworkDataType | grep "IPv4 Addresses:" | grep $simServerIPRange`
    else
	    set hostInRange = `nslookup $hostToInstallOn | grep $simServerIPRange`
    endif	
    if ( $isOSX && ( "$hostInRange" != "" ) ) then
	    set runsOnOSXSimServer = 1
    else
	    set runsOnOSXSimServer = 0
    endif
endif


# Determine whether development utilities are to be installed as well
if ( $isOSXSimServExporter | $isDevUser ) then
    set installDevUtils = 1
else
    set installDevUtils = 0
endif


# Determine basic global vars
set rassLibVersion       = 361
set rassFullVersion      = `echo $rassLibVersion | cut -c 1`.`echo $rassLibVersion | cut -c 2`.`echo $rassLibVersion | cut -c 3`
set tarFName             = "${targetName}.${rassLibVersion}${libVariantKind}.tar"
set tmpWorkDirDflt       = RASS.${rassLibVersion}
set curStep              = 0

if ( $simpleVariant == TRUE ) then
    set tmpWorkDir = "${tmpWorkDirDflt}S"
else if ( $tigerVariant == TRUE ) then
    set tmpWorkDir = "${tmpWorkDirDflt}T"
else
    set tmpWorkDir = "${tmpWorkDirDflt}T"
endif


if ( ${isSolaris} ) then
    # Global installation
    set rassLibDir           = /usr/local/lib
    set rassUtilsDir         = /usr/local/bin/RASS
else  if ( ${isOSX} ) then
    if ( ! $isOSXSimServExporter ) then
	# Assume single user installation
	if ( $?RASSOSXHOME ) then
	    set rassInstallHome = "${RASSOSXHOME}"
	else
	    set rassInstallHome = ~/Library/RASS
	endif
	set rassLibDir           = "${rassInstallHome}/lib"
	set rassMSYMDir          = "${rassInstallHome}/SYMs"
	set rassUtilsDir         = "${rassInstallHome}/bin"
    else
	# Assume multi user simulation server installation
	# provided by se-server on behalf of simulation server cluster
	set rassInstallHome      = /Volumes/ramses/SESimSoft/RASS
	set rassLibDir           = $rassInstallHome/lib
	set rassMSYMDir          = $rassInstallHome/SYMs
	set rassUtilsDir         = $rassInstallHome/bin
    endif
endif

# Determine data and time of installation
set curYear = `date '+%y'`;  
if ( ${curYear} < 10 ) then
  set curYear = 20${curYear}
else
  if ( ${curYear} < 100 ) then
    if ( ${curYear} >= 99 ) then
      set curYear = 19${curYear}
    else
      set curYear = 20${curYear}
    endif
  endif
endif
set curMonth = `date '+%m'`;  set curDay = `date '+%d'`
set curHour = `date '+%H'`;  set curMinute = `date '+%M'`;  set curSecond = `date '+%S'`
set curDateTime = ${curYear}-${curMonth}-${curDay}_${curHour}h${curMinute}.${curSecond}

# Determine salvage dir
set salvageDir           = salvaged.${curDateTime}
if ( ${isSolaris} ) then
    set salvagedUsrLocalBin  = $salvageDir/from.usr_local_bin_RASS
    set salvagedRASSLibs     = $salvageDir/from.usr_local_lib
else if ( ${isOSX} ) then
    set salvagedUsrLocalBin  = $salvageDir/from.YOUR-HOME_bin_RASS
    set salvagedRASSLibs     = $salvageDir/from.YOUR-HOME-Library-RASS-lib
    set salvagedMSYMS        = $salvageDir/from.YOUR-HOME-Library-RASS-SYMs
endif

# RASS utility common to all releases
set aRASSutil = "ext2ext"      # If present it is assumed remaining utilities are also present 
set aRASSLib  = "libRass???.a" # If present it is assumed more RASS libraries are also present 
set aMSYMFile = "DMMaster"     # If present it is assumed remaining MSYMs are also present


# Document begin of script
echo ""
echo "#######################################################################"
echo ""
echo "#### ## Begin of script '$myName'"
echo ""
echo "" `date +"Installation of ${targetName} started at %D, %T"`
echo 
echo " Installing ${targetName}"
echo " ==================="
echo " Installing on host '${hostToInstallOn}'"
if ( $isOSXSimServExporter ) then
    echo " This host offers RASS to all OS X simulation servers"
    echo " Installing RASS in '${rassInstallHome}'"
    echo " On an OS X simulation server above directory becomes '/usr/local'"
else if ( ${isSolaris} ) then
    echo " This host is a Sun simulation server offering RASS to its users"
endif
if ( $isOSX ) then
    if ( "$libVariantKind" != "" ) then
        set libVariantDescr = "${libVariantKind}-"
    else
        set libVariantDescr = "standard "
    endif
    echo " Installing ${libVariantDescr}release of ${targetName} ${rassFullVersion}"
else
    echo " Installing ${targetName} ${rassFullVersion}"
endif
echo " Installing libraries in '$rassLibDir'"
echo " Installing utilities in '$rassUtilsDir'"
echo " Installing user: '$curUserName'"
echo " Logged in user : '$curLoginUserName'"
if ( $installDevUtils ) then
    echo " Installing also developer utilities, since system may be used to run "
    echo " RASS release machinery"
endif

echo ""
if ( $simpleVariant == TRUE ) then
    set releaseVariant = "S-Release (Simple, Xcode 2.5, no universal binary support, P1 8.2)"
else if ( $tigerVariant == TRUE ) then
    set releaseVariant = "T-Release (Tiger, Xcode 2.5, supports mk/mk1 -t and -u, P1 >= 9.0.2)"
else
    set releaseVariant = "Standard Release (Tiger .. Mojave, Xcode 2.5 .. 11.3.1, P1 9.0.3"
endif

echo " Release variant: $releaseVariant"
echo ""


#------------------------------------------------------------------------------
### 1. Check preconditions
#------------------------------------------------------------------------------
@ curStep++
echo ""
echo "### Step $curStep / Checking preconditions... ('${myName}')"

# User running this script
if ( ${runsOnOSXSimServer} ) then
    echo ""
    echo "  --- STOP: This script MUST NOT be run on a clustered OS X simulation server"
    echo "            Nothing installed"
    echo ""
    if $isOSXCommand then
        printf "%sTo terminate script '$myName' press <return> ..."
        set answer = $<
    endif
    exit 1
endif

# User running this script
if ( ${isSolaris} ) then
    if ( "${curUserName}" != "root" ) then
      echo ""
      echo "  --- STOP: Please log in as super user first"
      echo ""
      if $isOSXCommand then
          printf "%sTo terminate script '$myName' press <return> ..."
          set answer = $<
      endif
      exit 1
    endif
endif

if ( ${isOSXSimServExporter} ) then
    if ( ( "${curLoginUserName}" != "root") && ( "${curLoginUserName}" != "$SESimSoftInstaller" ) ) then
        echo ""
        echo "  --- STOP: Please log in as $SESimSoftInstaller onto $SESimSoftHost to run this script"
        echo "            You are currently logged in as '${curLoginUserName}'"
        echo ""
        if $isOSXCommand then
            printf "%sTo terminate script '$myName' press <return> ..."
            set answer = $<
        endif
        exit 1
    endif
endif


# Release file presence
set theFile = "${curDir}/${tarFName}.Z"
if ( ! -f "${theFile}" ) then
    echo ""
    echo "  --- STOP: release file '${theFile}' not found"
    echo ""
    if $isOSXCommand then
        printf "%sTo terminate script '$myName' press <return> ..."
        set answer = $<
    endif
    exit 1
endif


# Check for presence of Modula-2 compiler and warn if absent
if ( ${isSolaris} ) then
    if ( ! -f /opt/epc/bin/em2 ) then
      echo ""
      echo "  --- WARNING: epc Modula-2 seems not to be installed"
      echo ""
    endif
else if ( ${isOSX} ) then
    set expectedCompilerName=Modula2
    set compiler=`which ${expectedCompilerName}`
    set compilerName=`basename ${compiler}`
    if ( "${compilerName}" != "${expectedCompilerName}" ) then
	    echo ""
	    echo " --- WARNING: P1 compiler '${expectedCompilerName}' appears to be missing."
	    echo "              Error message: '${compiler}'"
	    echo "              You have to install it before you can use RASS."
	    echo ""
    endif
endif


#------------------------------------------------------------------------------
### 2. Create all target directories if not yet present
#------------------------------------------------------------------------------
@ curStep++
echo ""
echo "### Step $curStep / Creating needed directories... ('${myName}')"


# Check for directory holding RASS libraries 
# Assume here there are at most two levels of directory creation necessary
# This assumption ought to be valid for Solaris and OS X
set theDir = "${rassLibDir}"
if ( ! -d "${theDir}" ) then
  set rassLibDirCreated = TRUE
  set theParentDir = `dirname "${theDir}"`
  # In Solaris the parent of theParentDir should always exist (/usr/local)
  # In OS X the parent of theParentDir should always exist (~/Library)
  if ( ! -d "${theParentDir}" ) then
      echo -n " Creating directory '${theParentDir}' ... "
      mkdir "${theParentDir}"
      chmod 755 "${theParentDir}"
      echo "done"
      echo -n " Creating directory '${theDir}' ... "
      mkdir "${theDir}"
      chmod 755 "${theDir}"
      echo "done"
  else
      echo -n " Creating directory '${theDir}' ... "
      mkdir "${theDir}"
      chmod 755 "${theDir}"
      echo "done"
  endif
else
    set rassLibDirCreated = FALSE
endif
if ( ! -d "${theDir}" ) then
    echo ""
    echo "  --- STOP: directory '${theDir}' could not be created - unknown reasons"
    echo ""
    if $isOSXCommand then
        printf "%sTo terminate script '$myName' press <return> ..."
        set answer = $<
    endif
    exit 1
endif


# Check for directory holding MSYM files (only OS X) 
# Assume here there are at most two levels of directory creation necessary
# This assumption ought to be valid for OS X
if ( ${isOSX} ) then
    set theDir = "${rassMSYMDir}"
    if ( ! -d "${theDir}" ) then
      set theParentDir = `dirname "${theDir}"`
      # In OS X the parent of theParentDir should always exist (~/Library)
      if ( ! -d "${theParentDir}" ) then
	  echo -n " - Creating directory '${theParentDir}' ... "
	  mkdir "${theParentDir}"
	  chmod 755 "${theParentDir}"
	  echo "done"
	  echo -n " - Creating directory '${theDir}' ... "
	  mkdir "${theDir}"
	  chmod 755 "${theDir}"
          echo "done"
      else
	  echo -n " - Creating directory '${theDir}' ... "
	  mkdir "${theDir}"
	  chmod 755 "${theDir}"
          echo "done"
      endif
      set rassMSYMDirCreated = TRUE
    else
	set rassMSYMDirCreated = FALSE
    endif
    if ( ! -d "${theDir}" ) then
      echo ""
      echo "  --- STOP: directory '${theDir}' could not be created - unknown reasons"
      echo ""
      if $isOSXCommand then
          printf "%sTo terminate script '$myName' press <return> ..."
          set answer = $<
      endif
      exit 1
    endif
    if ( ( -d "${theDir}" ) && ( "$simpleVariant" != "TRUE" ) ) then
        set theSubDir = "${theDir}/ppc"
        if ( ! -d "${theSubDir}" ) then
            echo -n " - Creating directory '${theSubDir}' ... "
            mkdir "${theSubDir}" ; chmod 755 "${theSubDir}"
            echo "done"
        endif
        if ( ! -d "${theSubDir}" ) then
            echo ""
            echo "  --- STOP: dir '${theSubDir}' could not be created - unknown reasons"
            echo ""
            if $isOSXCommand then
                printf "%sTo terminate script '$myName' press <return> ..."
                set answer = $<
            endif
            exit 1
        endif
        set theSubDir = "${theDir}/i386"
        if ( ! -d "${theSubDir}" ) then
            echo -n " - Creating directory '${theSubDir}' ... "
            mkdir "${theSubDir}" ; chmod 755 "${theSubDir}"
            echo "done"
        endif
        if ( ! -d "${theSubDir}" ) then
            echo ""
            echo "  --- STOP: dir '${theSubDir}' could not be created - unknown reasons"
            echo ""
            if $isOSXCommand then
                printf "%sTo terminate script '$myName' press <return> ..."
                set answer = $<
            endif
            exit 1
        endif
    endif
endif

# Check for directory holding RASS utilities 
# Assume here there are at most two levels of directory creation necessary
# This assumption ought to be valid for Solaris and OS X
set theDir = "${rassUtilsDir}"
if ( ! -d "${theDir}" ) then
  echo ""
  set rassUtilsDirCreated = TRUE
  set theParentDir = `dirname "${theDir}"`
  # In Solaris the parent of theParentDir should always exist (/usr/local)
  # In OS X the parent of theParentDir should always exist (~)
  if ( ! -d "${theParentDir}" ) then
      echo -n " Creating directory '${theParentDir}' ... "
      mkdir "${theParentDir}"
      chmod 755 "${theParentDir}"
      echo "done"
      echo -n " Creating directory '${theDir}' ... "
      mkdir "${theDir}"
      chmod 755 "${theDir}"
      echo "done"
  else
      echo -n " Creating directory '${theDir}' ... "
      mkdir "${theDir}"
      chmod 755 "${theDir}"
      echo "done"
  endif
else
    set rassUtilsDirCreated = FALSE
endif
if (! -d "${theDir}") then
    echo ""
    echo "  --- STOP: directory '${theDir}' could not be created - unknown reasons"
    echo ""
    if $isOSXCommand then
        printf "%sTo terminate script '$myName' press <return> ..."
        set answer = $<
    endif
    exit 1
endif


#------------------------------------------------------------------------------
### 3. Document possibly present previous installation
#------------------------------------------------------------------------------
@ curStep++
echo ""
echo "### Step $curStep / Document previous installation... ('${myName}')"

# Document current possibly present installation
if ( ${rassUtilsDirCreated} != "TRUE" ) then
    if ( -d "${rassUtilsDir}" ) then
      echo ""
      echo "Old RASS utilities and templates (before installation):"
      echo "------------------------------------------------------"
      echo "ls -l '${rassUtilsDir}' yields:"
      ls -l "${rassUtilsDir}"
      if ( ${isOSX} ) then
          # Avoid too long word (ls -1 vs. ls -l)
	  set someFilesPresent = `ls -1 "${rassUtilsDir}/${aRASSutil}"`
	  if ( "${someFilesPresent}" == "" ) then
	      echo "total 0"
	  endif
      endif
    endif
endif

if ( ${rassLibDirCreated} != "TRUE" ) then
    if ( -d "${rassLibDir}" ) then
      echo ""
      echo "Content of directory holding RASS libraries (before installation):"
      echo "-----------------------------------------------------------------"
      echo "ls -l '${rassLibDir}' yields:"
      ls -l "${rassLibDir}"
      if ( ${isOSX} ) then
          # Avoid too long word (ls -1 vs. ls -l)
	  set someFilesPresent = `ls -1 "${rassLibDir}/${aRASSLib}"`
	  if ( "${someFilesPresent}" == "" ) then
	      echo "total 0"
	  endif
      endif
    endif
endif

if ( ${isOSX} ) then
    if ( ${rassMSYMDirCreated} != "TRUE" ) then
        set theRassMSYMDirs = ( "${rassMSYMDir}" "${rassMSYMDir}/ppc" "${rassMSYMDir}/i386" )
        foreach symDir ($theRassMSYMDirs)
            if ( -d "${symDir}" ) then
              echo ""
              echo "Content of directory holding RASS `basename ${symDir}` symbol files (*.MSYM before installation):"
              echo "-------------------------------------------------------------------------------"
              echo "ls -l '${symDir}' yields:"
              ls -l "${symDir}"
              # Avoid too long word
              set someFilesPresent = `ls -l "${symDir}"/${aMSYMFile}*`
              if ( "${someFilesPresent}" == "" ) then
                  echo "total 0"
              endif
            endif
	end
    endif
endif


#------------------------------------------------------------------------------
### 4. Extract release files
#------------------------------------------------------------------------------
@ curStep++
echo ""
echo "### Step $curStep / Extracting files from archive... ('${myName}')"
echo "    Please be patient, the extraction may require quite some time..."
echo ""

# Previously used: uncompress -c "${tarFName}.Z" | tar -vxpf  -  "${tmpWorkDir}"
# Current solution is more flexible and extracts whatever is in the tar archive
uncompress -c "${tarFName}.Z" | tar -vxp

# Check presence of unarchived temporary work dir and guess its name if new 
# naming convention was not followed
if ( ! -d "${tmpWorkDir}" ) then
    # Try the default name
    set tmpWorkDir = "${tmpWorkDirDflt}"
endif
if ( ! -d "${tmpWorkDir}" ) then
  echo ""
  echo "  --- STOP: dir '${tmpWorkDir}' with unarchived release not found - unknown reasons"
  echo ""
  if $isOSXCommand then
      printf "%sTo terminate script '$myName' press <return> ..."
      set answer = $<
  endif
  exit 1
endif

if ( -f "${tmpWorkDir}/libRass361PPC_x.a" ) then
    # Assume it is a universal binary release
    set UBIRelease = TRUE
else
    # Assume if this lib file is missing it is NOT a universal binary release
    set UBIRelease = FALSE
endif

if ( ${isOSX} ) then
    # Unpack MSYMs
    set symFileDir = "SYMs"
    set theToken = "S"
    set theLibFile = "libRass361${theToken}_x.a"
    if ( -f "${tmpWorkDir}/$theLibFile" ) then
        set theDestSymDir = "${tmpWorkDir}/${symFileDir}"
        # Extract tar archive only if destination dir contains no MSYMs (avoid too long word)
        (ls -1 "${theDestSymDir}"/${aMSYMFile}* > tmp.ls) >& /dev/null;
        set someMSYMsPresent = `cat tmp.ls` ; rm -f tmp.ls
        if ( "${someMSYMsPresent}" == "" ) then
            (cd "${theDestSymDir}" ; tar xf "../${theLibFile}")
        endif
    endif
    set theTokenList = ( ppc i386 )
    foreach theToken ($theTokenList)
        set theCapToken = `echo ${theToken} | tr "[:lower:]" "[:upper:]" `
        set theLibFile = "libRass361${theToken}_x.a"
        if ( -f "${tmpWorkDir}/$theLibFile" ) then
            set theDestSymDir = "${tmpWorkDir}/${symFileDir}/${theToken}"
            # Extract tar archive only if destination dir contains no MSYMs (avoid too long word)
            (ls -1 "${theDestSymDir}"/${aMSYMFile}* > tmp.ls) >& /dev/null;
            set someMSYMsPresent = `cat tmp.ls` ; rm -f tmp.ls
            if ( "${someMSYMsPresent}" == "" ) then
                (cd "${theDestSymDir}" ; tar xf "../../${theLibFile}")
            endif
        endif
    end
endif


#------------------------------------------------------------------------------
### 5. Installing RASS utilities and template files
#------------------------------------------------------------------------------
@ curStep++
echo ""
echo "### Step $curStep / Installing utilities and templates... ('${myName}')"

set targetDir = "${rassUtilsDir}"
if ( ! -d "${targetDir}" ) then
  echo ""
  echo "  --- STOP: directory '${targetDir}' not found - unknown reasons"
  echo ""
  if $isOSXCommand then
      printf "%sTo terminate script '$myName' press <return> ..."
      set answer = $<
  endif
  exit 1
endif

# Document installation option
if ( "$salvageOldUtils" == "TRUE" ) then
  echo ""
  echo " Option 'salvageOldUtils' = TRUE - Old RASS utilities will be salvaged"
else
  echo ""
  echo " Option 'salvageOldUtils' = FALSE - Old RASS utilities won't be salvaged"
endif

# salvaging utils
if ( "$salvageOldUtils" == "TRUE" ) then
    if (! -d "${salvageDir}" ) then
      mkdir "${salvageDir}"
      chmod 777 "${salvageDir}"
    else
      echo ""
      echo " --- ERROR: Creation of dir '${salvageDir}' failed - unknown reasons"
      echo ""
    endif
    if ( -d "${salvageDir}" ) then
      mkdir "${salvagedUsrLocalBin}"
      chmod 777 "${salvagedUsrLocalBin}"
      if ( -d "${salvagedUsrLocalBin}" ) then
	echo ""
	echo "  Salvaging old RASS Utilities and templates..."
        # Avoid too long word
	(ls -1 "${targetDir}"/${aRASSutil} > tmp.ls) >& /dev/null; 
	set someFilesPresent = `cat tmp.ls` ; rm -f tmp.ls
	if ( "${someFilesPresent}" != "" ) then
	    mv "${targetDir}"/* "${salvagedUsrLocalBin}"
	    chmod 777 "${salvagedUsrLocalBin}"/*
	    echo ""
	    echo "  Old RASS utils of dir '${targetDir}'"
	    echo "  salvaged to dir '${salvagedUsrLocalBin}':"
            # Here we must not avoid too long word
	    set rassUtils = `ls -1 "${salvagedUsrLocalBin}"`
	    foreach f ($rassUtils)
		echo "   $f"
	    end
	else
	    echo "  No old RASS utils found in dir '${targetDir}'"
	endif
	echo ""
      else
	echo ""
	echo " --- ERROR: Creation of dir '${salvagedUsrLocalBin}' failed - unknown reasons"
	echo ""
      endif
    endif
endif

# Make sure the following lists are consistent among following scripts
# - Job.08.ProduceSlowLibsRelease
# - RASS.xxx.install.TEMPLATE
# - install_RMSP1.command
# - doUpdateFileRASSRelease.sh
# Exceptions:
# - watch out of difference between lists 'utilityFiles' and 'devUtilityFiles'
# - Job.08.ProduceSlowLibsRelease: Watch out for files that may get renamed later, e.g. in step 5.  of
# Job.08.ProduceSlowLibsRelease
# - install_RMSP1.command: READ_ME.pdf (only RASS-OSX) and first two items in list (only RMSP1)
set doRassInstFN = install_RASS_On_SimServ.command
if ( ${isSolaris} ) then
    set utilityFiles = (         \
        $doRassInstFN    \
        DEF2def          \
        MOD2mod          \
        PrepRASSProject  \
        reprep           \
        RASSHelp         \
        RASSjob.TEMPLATE \
        autoedit         \
        younger          \
        cleanup          \
        def2DEF          \
        ext2ext          \
        fis              \
        getjob           \
        getm2config      \
        config.M2PATH.TEMPLATE \
        config.M2PATH.sh.TEMPLATE \
        mac2unix         \
        mod2MOD          \
        run              \
        setmailto        \
        setRASSmailto    \
        setprojdescr     \
        SymDiff          \
        runSymDiff       \
        unix2mac         )
    set doRassInstFNAlias = doARassSunInstallation
else if (${isOSX}) then
    set utilityFiles = (         \
        $doRassInstFN    \
        setenv_for_M2_RMSP1_RASS-OSX \
        READ_ME.pdf      \
        RMSP1Help        \
        RASSjob.TEMPLATE \
        autoedit         \
        cleanup          \
        debug.dat.TEMPLATE \
        def2DEF          \
        doBatchExecute   \
        ext2ext          \
        fis              \
        getjob           \
        getm2config      \
        config.M2PATH.TEMPLATE \
        config.M2PATH.sh.TEMPLATE \
        my.RASS.profile-new  \
        mac2unix         \
        mk               \
        mk1              \
        mknewlib         \
        mod2MOD          \
        setmailto        \
        setRASSmailto    \
        setprojdescr     \
        switch2using     \
        switchp1         \
        SymDiff          \
        runSymDiff       \
        unix2mac         \
        Xcode2.5.zip     \
        Xcode2.5SE.zip   \
        Xcode3.2.6.zip   )
    set doRassInstFNAlias = doARassOSXInstallation
endif
# Utilities supporting development of RASS
if ( ${isSolaris} ) then
    set devUtilityFiles =  (         \
		    start            )
else if (${isOSX}) then
    set devUtilityFiles =  (         \
		    start            \
		    finish           )
endif




echo -n " Installing RASS utilities and templates ..."
foreach f ( ${utilityFiles} )
  if ( -f "${tmpWorkDir}/${f}" ) then
      if ( "${f}" != "READ_ME.pdf" ) then
	  cp -f $preserveFAttrOption "${tmpWorkDir}/${f}"  "${targetDir}"
      else
	  # In parent dir, i.e. RASSOSXHOME
	  cp -f $preserveFAttrOption "${tmpWorkDir}/${f}"  "${targetDir}/.."
      endif
  else
      echo ""
      echo " --- ERROR: RASS utility '${f}' seems to be absent from this release."
      echo "            Please get a new release, since this one appears to be incomplete."
  endif
end
if ( ${isSolaris} ) then
    # 'RASSMakeMake' is not in above list, since that list should be kept
    # identical as in Job.08.ProduceSlowLibsRelease, where 'RASSMakeMake'
    # is constructed from a TEMPLATE. This differs from companion utility
    # 'mk', which serves itself as a script as well as as a TEMPLATE.
    set f = RASSMakeMake
    if ( -f "${tmpWorkDir}/${f}" ) then
	cp -f $preserveFAttrOption "${tmpWorkDir}/${f}" "${targetDir}"
	link  "${targetDir}/PrepRASSProject" "${targetDir}/prepare"
    else
	echo ""
	echo " --- ERROR: RASS utility '${f}' seems to be absent from this release."
	echo "            Please get a new release, since this one appears to be incomplete."
    endif
else if ( ${isOSX} ) then
    # Support RASSHelp (for upward compatibility with earlier Unix releases)
    set f = RMSP1Help ; set aliasF = RASSHelp
    if ( -f "${targetDir}/${f}" ) then
	ln -s "${f}" "${targetDir}/${aliasF}" 
    else
	echo ""
	echo " --- ERROR: RASS utility '${f}' seems to be absent from this release."
	echo "            Please get a new release, since this one appears to be incomplete."
    endif
    # Support installation of my.RASS.profile 
    # (not on simulation servers, which require no user specific .profile)
    if ( ! $isOSXSimServExporter ) then
	# This script gets here only either if run on se-server or on a 
	# simulationists private machine, i.e. a RASS-OSX installation.
	set f = my.RASS.profile-new
	if ( -f "${targetDir}/${f}" ) then
	    set theSourceFile="${targetDir}/${f}"
	    set rassProfileName=my.RASS.profile
	    set editableProfileName=${f}
	    set theTargetFile=~/${rassProfileName}
	    set theBUTargetFile=~/"${editableProfileName}~"
	    set RMSP1PrioFlag="RASSgiveFirstPriorityTo=RMSP1"
	    set RASSOSXPrioFlag="RASSgiveFirstPriorityTo=RASS-OSX"
	    if ( -f "${theTargetFile}" ) then
		# Existing my.RASS.profile
		echo
		echo " You already have a RASS profile '~/${rassProfileName}'!"
		echo " Depending on your choice, this script will now either save your current"
		echo " profile (if you choose overwrite option) or by default leave your existing"
		echo " profile untouched (if you choose not to overwrite). WARNING: To ensure"
		echo " a functioning RASS-OSX, you may need to manually edit your profile"
		echo " To this end use the nearby stored file as provided by this installation."
		echo
		echo -n " Do you wish to overwrite the '${rassProfileName}' in your home dir (y/n=cr)? "
		set answer = $<
		if ( "${answer}" == "y" ) then
		    if ( -f "${theSourceFile}" ) then
			# Make first backup
			mv -f "${theTargetFile}" "${theBUTargetFile}"
			# Now create new my.RASS.profile (rename, edit)
			cat "${theSourceFile}" | sed -e "s/$RMSP1PrioFlag/$RASSOSXPrioFlag/" > "${theTargetFile}"
			rm -f "${theSourceFile}"
			echo
			echo " new '${rassProfileName}' installed in your home directory"
			echo " old '${rassProfileName}' preserved under name '${rassProfileName}~'"
			echo
		    else
			echo
			echo " STOP: Your release looks not as expected. Could not find expected "
			echo "       file '${theSourceFile}'. Existing '${rassProfileName}' "
                        echo "       left untouched."
			echo
		    endif
		else
		    # Create an additional my.RASS.profile-new (copy, edit)
		    set theTargetFile=~/${editableProfileName}
		    if ( -f "$theTargetFile" ) then
			echo -n " Do you wish to overwrite the '${editableProfileName}' in your home dir (y/n=cr)? "
		    else
			echo -n " Do you wish to add a '${editableProfileName}' to your home dir (y/n=cr)? "
		    endif
		    set answer = $<
		    if ( "${answer}" == "y" ) then
			cat "${theSourceFile}" | sed -e "s/$RMSP1PrioFlag/$RASSOSXPrioFlag/" > "${theTargetFile}"
			echo " Added new '${editableProfileName}' in your home directory"
                        echo " Delete it or use it for manual merging with existing '${rassProfileName}'"
		    endif
		    # Now ensure the my.RASS.profile is properly set for RASS-OSX
		    set switchUtil = "${targetDir}/switch2using"
		    if ( -f "${switchUtil}" ) then
			chmod 555 "${switchUtil}"
			"${switchUtil}" RASS-OSX
		    endif
		endif
	    else
		# User has no my.RASS.profile (rename, edit)
		cat "${theSourceFile}" | sed -e "s/$RMSP1PrioFlag/$RASSOSXPrioFlag/" > "${theTargetFile}"
		rm -f "${theSourceFile}"
	    endif
            # Check whether user's .profile is sourcing my.RASS.profile
            set activeProfileName = .profile
            set activeProfile = ~/${activeProfileName}
            if ( ! -f "${activeProfile}" ) then
                echo ""
                echo " WARNING: It seems you have no '${activeProfileName}' in your home directory!"
                echo "          To use RASS you need one that sources '${rassProfileName}'."
                echo ""
                echo -n " Do you wish to have the needed '${activeProfileName}' installed (y=cr/n)? "
                set answer = $<
                if ( "${answer}" != "n" ) then
                    # create a new .profile that sources my.RASS.profile
                    # addRassProfileSourcing "${activeProfile}" "${rassProfileName}"
                    set theDotProfile = "${activeProfile}"
                    set theRassProfileName = "${rassProfileName}"
                    echo "# .profile to customize shells and define global environment" >  "${theDotProfile}"
                    echo "" >> "${theDotProfile}"
                    echo "# Sourcing RASS profile '${theRassProfileName}' to enable use of RASS" >> "${theDotProfile}"
                    echo "# RASS is the RAMSES Simulation Server, http://www.sysecol.ethz.ch/ramses" >> "${theDotProfile}"
                    echo "if [ -f ${theRassProfileName} ]; then" >> "${theDotProfile}"
                    echo "    source ${theRassProfileName}" >> "${theDotProfile}"
                    echo "fi" >> "${theDotProfile}"
                    echo "" >> "${theDotProfile}"
                    echo "" >> "${theDotProfile}"
                endif
            endif
            if ( -f "${activeProfile}" ) then
                set rassProfileSourced = `grep ${rassProfileName} ${activeProfile}`
                if ( "$rassProfileSourced" == "" ) then
                    echo ""
                    echo " WARNING: It seems your '${activeProfileName}' does not source '${rassProfileName}'!"
                    echo "          This needs to be fixed to use RASS."
                    echo ""
                    echo    " Do you wish to have a sourcing statement be added to your '${activeProfileName}'"
                    echo -n " in your home directory (invisible file) (y/n=cr)? "
                    set answer = $<
                    if ( "${answer}" == "y" ) then
                        # add a few sourcing statements to existing .profile
                        # addRassProfileSourcing "${activeProfile}" "${rassProfileName}"
                        set theDotProfile = "${activeProfile}"
                        set theRassProfileName = "${rassProfileName}"
                        echo "" >> "${theDotProfile}"
                        echo "" >> "${theDotProfile}"
                        echo "# Sourcing RASS profile '${theRassProfileName}' to enable use of RASS" >> "${theDotProfile}"
                        echo "# RASS is the RAMSES Simulation Server, http://www.sysecol.ethz.ch/ramses" >> "${theDotProfile}"
                        echo "if [ -f ${theRassProfileName} ]; then" >> "${theDotProfile}"
                        echo "    source ${theRassProfileName}" >> "${theDotProfile}"
                        echo "fi" >> "${theDotProfile}"
                        echo "" >> "${theDotProfile}"
                        echo "" >> "${theDotProfile}"
                    endif
                endif
            endif
	else
	    echo ""
	    echo " --- ERROR: RASS file '${f}' seems to be absent from this release."
	    echo "            Please get a new release, since this one appears to be incomplete."
	endif
    endif
endif


# Make aliases for greater convenience
set f = setprojdescr ; set aliasF = prj
if ( -f "${targetDir}/${f}" ) then
    ln -s "${f}" "${targetDir}/${aliasF}"
else
    echo ""
    echo " --- ERROR: RASS utility '${f}' seems to be absent from this release."
    echo "            Please get a new release, since this one appears to be incomplete."
endif
set f = setprojdescr ; set aliasF = setprj
if ( -f "${targetDir}/${f}" ) then
    ln -s "${f}" "${targetDir}/${aliasF}"
else
    echo ""
    echo " --- ERROR: RASS utility '${f}' seems to be absent from this release."
    echo "            Please get a new release, since this one appears to be incomplete."
endif


# Support installation of developer utilities
if ( $installDevUtils ) then
    set devTargetDir = "${targetDir}"
    foreach f ( ${devUtilityFiles} )
	set sourcePFN = "${tmpWorkDir}/${f}"
	set destinPFN = "${devTargetDir}/${f}"
	if ( -f "${sourcePFN}" ) then
	    cp -f $preserveFAttrOption "${sourcePFN}"  "${destinPFN}"
	else
	    echo ""
	    echo " --- ERROR: RASS developer utility '${f}' seems not properly installed."
	    echo "            Please check installation in '${targetDir}'."
	endif
    end
    set f = "$doRassInstFN" ; set aliasF = $doRassInstFNAlias
    if ( -f "${devTargetDir}/${f}" ) then
        # Use no longer a hard link as original name 
        # 'install_RASS_On_SimServ.command' is mostly just of 
        # interest for the se-server
        # ln "${devTargetDir}/${f}" "${devTargetDir}/${aliasF}"
        mv -f "${devTargetDir}/${f}" "${devTargetDir}/${aliasF}"
    else
	echo ""
	echo " --- ERROR: RASS utility '${f}' seems to be absent from this release."
	echo "            Please get a new release, since this one appears to be incomplete."
    endif
endif

# Set permissions of installed files
chmod 555 "${targetDir}"/* 
chmod 444 "${targetDir}"/*.TEMPLATE
# test installation
# Avoid too long word
(ls -1 "${targetDir}"/${aRASSutil} > tmp.ls) >& /dev/null; 
set someRASSUtils = `cat tmp.ls` ; rm -f tmp.ls
if ( "${someRASSUtils}" != "") then
    echo " done"
else
    echo " not done"
    echo ""
    echo " --- ERROR: Installation failed for unknown reasons"
    echo ""
endif


#------------------------------------------------------------------------------
### 6. Install library files
#------------------------------------------------------------------------------
@ curStep++
echo ""
echo "### Step $curStep / Installing library files... ('${myName}')"

# Document installation option
if ( "$deinstallOldLibs" == "TRUE" ) then
  echo ""
  echo " Option 'deinstallOldLibs' = TRUE - Old RASS will first be salvaged and then completely"
  echo "                                    deleted before the new RASS is installed."
else
  echo ""
  echo " Option 'deinstallOldLibs' = FALSE - Old RASS libraries will not be deleted."
  echo "                                     Only the files in bin and SYMs are overwritten"
  echo "                                     after having been salvaged."
endif

set targetDir = "${rassLibDir}"
if ( ! -d "${targetDir}" ) then
  echo ""
  echo "  --- STOP: directory '${targetDir}' not found - unknown reasons"
  echo ""
  if $isOSXCommand then
      printf "%sTo terminate script '$myName' press <return> ..."
      set answer = $<
  endif
  exit 1
endif
# Avoid too long word
(ls -1 "${targetDir}"/${aRASSLib} > tmp.ls) >& /dev/null; 
set someRASSLibs = `cat tmp.ls` ; rm -f tmp.ls
if ( "${someRASSLibs}" != "") then
  echo ""
  echo -n " Old RASS libraries found on this machine - "
  if ( "$deinstallOldLibs" == "TRUE") then
    echo "will attempt to salvage them"
    if ( ! -d "${salvageDir}" ) then
      mkdir "${salvageDir}"
      chmod 777 "${salvageDir}"
      if ( ! -d "${salvageDir}" ) then
	echo ""
        echo " --- ERROR: Creation of dir '${salvageDir}' failed - unknown reasons"
	echo ""
      endif
    endif
    if ( -d "${salvageDir}" ) then
      mkdir "${salvagedRASSLibs}"
      chmod 777 "${salvagedRASSLibs}"
      if ( -d "${salvagedRASSLibs}" ) then
        echo ""
	echo "  Salvaging old RASS libraries..."
        mv "${targetDir}"/libRass* "${salvagedRASSLibs}"
        echo ""
        echo "  Old RASS libs from dir '${targetDir}' removed"
        echo "  salvaged to dir '${salvagedRASSLibs}'"
        # Here we must not try to avoid too long word
        set someRASSLibs = `ls -1 "${salvagedRASSLibs}"`
        foreach f ($someRASSLibs)
          echo "   $f"
        end
        chmod 666 "${salvagedRASSLibs}"/*
        echo ""
      else
	echo ""
        echo " --- ERROR: Creation of dir '${salvagedRASSLibs}' failed - unknown reasons"
	echo ""
      endif
    endif
  else
    echo "will be overwritten"
  endif
else
  echo ""
  echo " No old RASS libraries found on this machine"
endif
# mv quietly overwrites if reinstalling library files
echo -n " Installation of new RASS libraries ..."
mv -f "${tmpWorkDir}"/libRass*  "${targetDir}"
chmod 444 "${targetDir}"/libRass*
# test installation
(ls -1 "${targetDir}"/libRass361* > tmp.ls) >& /dev/null; 
set someRASSLibs = `cat tmp.ls` ; rm -f tmp.ls
if ( "${someRASSLibs}" != "") then
    echo " done"
else
    echo " not done"
    echo ""
    echo " --- ERROR: Installation failed for unknown reasons"
    echo ""
endif

# Install now also MSYM files
if ( ${isOSX} ) then
    
    # Document installation option
    if ( "$salvageMSYMs" == "TRUE" ) then
      echo ""
      echo " Option 'salvageMSYMs' = TRUE - Old MSYM files will be salvaged"
    else
      echo ""
      echo " Option 'salvageMSYMs' = FALSE - Old MSYM files won't be salvaged"
    endif
    set symFileDir = "SYMs"
    set targetDir = `dirname "${rassLibDir}"`
    set targetDir = "${targetDir}/${symFileDir}"
    if ( ! -d "${targetDir}" ) then
      echo ""
      echo "  --- STOP: directory '${targetDir}' not found - unknown reasons"
      echo ""
      if $isOSXCommand then
          printf "%sTo terminate script '$myName' press <return> ..."
          set answer = $<
      endif
      exit 1
    endif
    if ( ( "$salvageMSYMs" == "TRUE" ) && ( -d "${targetDir}" ) ) then
	if ( -d "${salvageDir}" ) then
	    if ( ! -d "${salvagedMSYMS}" ) then
		mkdir "${salvagedMSYMS}"
		chmod 777 "${salvagedMSYMS}"
	    endif
	    if ( -d "${salvagedMSYMS}" ) then
		echo ""
		echo " Salvaging old RASS MSYMs..."
                # Avoid too long word
		(ls -1 "${targetDir}"/${aMSYMFile}* > tmp.ls) >& /dev/null; 
		set someFilesPresent = `cat tmp.ls` ; rm -f tmp.ls
		if ( "${someFilesPresent}" != "" ) then
                    (cd "${rassLibDir}" ; cd .. ; tar cf "${curDir}/oldMSYMs.tar" "${symFileDir}" )
                    mv oldMSYMs.tar "${salvagedMSYMS}"
		    echo "  Old RASS MSYMs from dir '${targetDir}' removed"
		    echo "  salvaged as 'oldMSYMs.tar' to dir '${salvagedMSYMS}'"
                    echo ""
                    (cd "${salvagedMSYMS}" ; tar xf  oldMSYMs.tar ; rm -f oldMSYMs.tar)
		else
		    echo "  No MSYMs found in dir '${targetDir}'"
		endif
	    else
		echo ""
		echo " --- ERROR: Directory '${salvagedMSYMS}' missing - unknown reasons"
		echo ""
	    endif
	else
	    echo ""
	    echo " --- ERROR: Directory '${salvageDir}' missing - unknown reasons"
	    echo ""
	endif
    endif
    echo " Installing new symbol files ... "
    set theSourceDir = "${tmpWorkDir}/${symFileDir}"
    # Avoid too long word
    (ls -1 "${theSourceDir}"/${aMSYMFile}* > tmp.ls) >& /dev/null; 
    set someFilesPresent = `cat tmp.ls` ; rm -f tmp.ls
    if ( "${someFilesPresent}" != "" ) then
        echo " - Copying MSYMs from '${theSourceDir}'"
        echo "   to '${targetDir}'"
        cp -f $preserveFAttrOption "${theSourceDir}"/*.MSYM  "${targetDir}"
    endif
    set theTokenList = ( ppc i386 )
    foreach theToken ($theTokenList)
        # set theCapToken = `echo ${theToken} | tr "[:lower:]" "[:upper:]" `
        set theSourceDir = "${tmpWorkDir}/${symFileDir}/${theToken}"
        # Avoid too long word
        (ls -1 "${theSourceDir}"/${aMSYMFile}* > tmp.ls) >& /dev/null; 
        set someFilesPresent = `cat tmp.ls` ; rm -f tmp.ls
        if ( "${someFilesPresent}" != "" ) then
            echo " - Copying ${theToken} MSYMs from '${theSourceDir}'"
            echo "   to '${targetDir}/${theToken}'"
            cp -f $preserveFAttrOption "${theSourceDir}"/*.MSYM  "${targetDir}/${theToken}"
        endif
    end
    echo "   done"
endif


#------------------------------------------------------------------------------
### 7. Prepare utility finish for subsequent manual execution 
#------------------------------------------------------------------------------
# assume this is executed from within dir Release_RASS361
# by a developer while installing RASS after running the release machinery. 
# Otherwise quietly skip this step
set theFinishUtil = "finish"
set srceDir = "../RASSDev361/_ReleaseFiles/"
set destDir = "../"
# Needed for hint given at end of this script
set finishInstalled = 0
if ( -f "${srceDir}${theFinishUtil}" ) then
    @ curStep++
    cp -f $preserveFAttrOption "${srceDir}${theFinishUtil}" "${destDir}"
    echo ""
    if ( ${isOSX} ) then
	echo "### Step $curStep / Preparing make&release utility 'finish.command' ('${myName}')"
    else
	echo "### Step $curStep / Preparing make&release utility 'finish' ('${myName}')"
    endif
    echo ""
    echo "Copied utility '${theFinishUtil}' to RASS work dir"
    if ( -f "${destDir}${theFinishUtil}" ) then
	# Needed for hint given at end of this script
	set finishInstalled = 1
        chown rass "${destDir}${theFinishUtil}"
	chmod 775 "${destDir}${theFinishUtil}"
	if ( ${isOSX} ) then
	    mv -f "${destDir}${theFinishUtil}" "${destDir}${theFinishUtil}.command"
	    # Needed for hint given at end of this script
	    set theFinishUtil = "${theFinishUtil}.command"
	endif
    endif
endif
    

#------------------------------------------------------------------------------
### 8. Finish 
#------------------------------------------------------------------------------
@ curStep++
echo ""
echo "### Step $curStep / Finishing RASS 361 installation... ('${myName}')"
rm -rf "${tmpWorkDir}"

echo ""
echo "Salvaged files:"
echo "--------------"
echo "ls -l '${salvageDir}' yields:"
ls -lR "${salvageDir}"

echo ""
echo ""
echo "Content of directory holding RASS libraries (after installation):"
echo "----------------------------------------------------------------"
echo "ls -l '${rassLibDir}' yields:"
ls -l "${rassLibDir}"

if ( ${isOSX} ) then
    set theRassMSYMDirs = ( "${rassMSYMDir}" "${rassMSYMDir}/ppc" "${rassMSYMDir}/i386" )
    foreach symDir ($theRassMSYMDirs)
        if ( -d "${symDir}" ) then
          echo ""
          echo "Content of directory holding RASS `basename ${symDir}` symbol files (*.MSYM after installation):"
          echo "-------------------------------------------------------------------------------"
          echo "ls -l '${symDir}' yields:"
          ls -l "${symDir}"
          # Avoid too long word
          set someFilesPresent = `ls -1 "${symDir}"/${aMSYMFile}*`
          if ( "${someFilesPresent}" == "" ) then
              echo "total 0"
          endif
        endif
    end
endif

echo ""
echo ""
echo "Installed RASS utilities and templates (after installation):"
echo "-----------------------------------------------------------"
echo "ls -l '${rassUtilsDir}' yields:"
ls -l "${rassUtilsDir}"

echo ""
echo ""
echo "Installed RASS libraries (after installation):"
echo "---------------------------------------------"
echo "ls -l '${rassLibDir}' yields:"
ls -l "${rassLibDir}"

echo ""
echo ""
echo "Newly installed RASS libraries:"
echo "------------------------------"
if ( ${isSolaris} ) then
    ls -1 "${rassLibDir}"/libRass361*
else if ( ${isOSX} ) then
    if ( "$libVariantKind" != "" ) then
        ls -1 "${rassLibDir}"/libRass361[${libVariantKind}]*
    else
        ls -1 "${rassLibDir}"/libRass361[^ST]*
    endif
endif

echo ""
echo ""
if ( $isOSX ) then
    echo " Installed ${libVariantDescr}release of ${targetName} ${rassFullVersion}"
else
    echo " Installed ${targetName} ${rassFullVersion}"
endif
echo ""
echo ""
echo "#### ## End of script '$myName'"
echo ""
echo "#######################################################################"
echo "     " `date +"Installation of ${targetName} completed at %D, %T"`
echo "#######################################################################"
echo ""
echo ""
echo ""

if ( $finishInstalled ) then
    echo "If this installation is not only a test installation, please run now utility "
    echo "'${theFinishUtil}' as user '${curLoginUserName}' in parent directory of current directory"
    echo
endif

if ( $isOSXCommand ) then
    printf "%sTo terminate script '$myName' press <return> ..."
    set answer = $<
endif


exit 0

#==============================================================================