#!/bin/csh -f
#
#--------------------------------------------------------------------
#
#       opus_install
#
#       C shell script to install OPUS and sample pipeline
#       from CD-ROM.
#
#       Copyright: (c) 1997 The Association of Universities for
#                  Research in Astronomy, Inc. All rights reserved.
#                  see: http://www.stsci.edu/policy/Copyright.html
#
#--------------------------------------------------------------------
#                          REVISION HISTORY
#--------------------------------------------------------------------
#  MOD             PR
# LEVEL   DATE   NUMBER  User     Description
# ----- -------- ------  -------  ------------------------------------
#  001  08/07/97 34945   WMiller  Initial code
#  002  11/18/97 34811   WMiller  Add opus_login.csh sourcing
#  003  02/19/98 36350   WMiller  Correct .cshrc update when done before
#  004  02/25/98 36397   WMiller  Linux port
#  005  03/18/98 36554   WMiller  Add upgrade capability
#  005  05/14/98 36554.1 MSwam    Replace HOSTTYPE with uname test
#  006  06/26/98 36969   MSwam    Create lock directories under home,obs
#  007  07/24/98 37263   WMiller  Use full file spec for ls command
#  008  08/19/98 37263   WMiller  Update for 1.4 release
#  009  12/29/98 38080   WMiller  Configure XUSERFILESEARCHPATH dynamically
#  010  04/20/00 41456   WMiller  Setup for SHARE 2.1A release
#  011  06/23/00 41693_06 Heller  change 2.1a to 2.2
#  012  03/21/01 43520   WMiller  Update for 3.2 release
#  013  09/19/02 46438   Sontag   Updates to 'quick' for example intrnl pollers
#  014  09/25/02 46596   Sontag   Updates for 4.2 release
#  015  12/10/02 46765   Sontag   Changes for latest Linux settings
#  016  04/24/03 47450   Sontag   Port to AIX
#  017  09/26/03 48405   Sontag   Edited opath and added chmod's
#  018  10/07/03 49485   Sontag   Update tar file sizes, and add message
#  019  10/30/03 49783   Sontag   Finish port to AIX
#  020  09/14/04 49860   Sontag   Updates for 5.4x release
#--------------------------------------------------------------------
#
set opus_install_version = 020  # Set this to MOD LEVEL above
#
set BASE_INSTALL_SIZE = 48   # megabytes of common disk install
set SOLARIS_DISK =     307   # megabytes of Solaris-specific disk install
set LINUX_DISK =       135   # megabytes of Linux-specific disk install
set AIX_DISK =         354   # megabytes of AIX-specific disk install
#
set opsys = `uname -s`
switch ( $opsys )
   case SunOS:
      set arch = sparc_solaris
      breaksw
   case Linux:
      set arch = linux
      breaksw
   case AIX:
      set arch = ibm_aix
      breaksw
   default:
      echo ""
      echo "ERROR: Operating system type $opsys unknown/unsupported."
      echo ""
      exit 1
endsw
#
onintr INTRPT
#-----------------------------------------------------
# Disable this section of code for now, since we have
# decided to no longer provide upgrade scripts.
#
#     # Determine if upgrade exists
#     set upgrade = $0
#     set upath = $upgrade:h
#     if ( $upath == $upgrade ) then
#        set upgrade = `/bin/ls upgrade.*`
#        set upath = .
#     else
#        set upgrade = `/bin/ls $upath/upgrade.*`
#     endif
#     # At this point, $upgrade could be something like
#     # "./upgrade.2_2 ./upgrade.3_2", get the numeric extension of last item
#     set upgrade = `echo $upgrade | sed 's/.*\(._.\)$/\1/'`
#     if ( "$upgrade" == "" ) unset upgrade
#     set udot = `echo $upgrade | sed 's/_/\./g'`
#
#-----------------------------------------------------
# current version number
set udot = "5.4"
#
# Main Menu
#
MAIN_MENU:
clear
echo    ""
echo    "   --------------------------------------------"
echo    "   - Welcome to the OPUS Installation Script\! -"
echo    "   --------------------------------------------"
echo    ""
echo    "   Please choose from the following items:"
echo    ""
echo    "      [1] Install OPUS to run from a local disk"
echo    ""
echo    "      [2] Configure a user account to use OPUS for the first time"
echo    ""
echo    "      [3] Install the OPUS Managers"
echo    ""
echo    "      [4] NOTE\! about upgrading from previous versions"
set ecount = 5 
if ( $?upgrade ) then
   echo ""
   echo "      [5] Upgrade existing version of OPUS to v$udot"
   @ ecount ++
   if ( $udot == 3.2 ) then
      echo ""
      echo "      [6] Upgrade an existing v1.4 or v2.2 user account to v$udot"
      @ ecount ++
   endif
endif
echo    ""
echo    "      [$ecount] Exit"
echo    ""
echo    ""
echo -n "      Selection: "
set response = $<
switch ( $response )
   case 1:
      set min_disk = $BASE_INSTALL_SIZE
      goto INSTALL
   case 2:
      goto UPDATECSHRC
   case 3:
      goto MANAGERS
   case 4:
      goto UPGD_NOTE
   case $ecount:              # this label must precede next two
      clear
      exit 0
   case 5:
      if ( ! $?upgrade ) goto MAIN_MENU
      $upath/upgrade.$upgrade
      if ( $status != 0 ) then
         echo "WARNING: An error occurred during the upgrade process."
         set query = "Press return to continue : "
         set yes = MAIN_MENU
         set no = $yes
         set default = $yes
         goto YESORNO
      endif
      goto MAIN_MENU
   case 6:
      if ( ! $?upgrade || $udot != 3.2 ) then
         goto MAIN_MENU
      endif
      $upath/new_car_smell
      goto MAIN_MENU
   default:
      goto MAIN_MENU
endsw
#
# Note about upgrade scripts
#
UPGD_NOTE:
clear
echo    ""
echo    "OPUS is no longer distributed with upgrade scripts.  Users with"
echo    "previous versions of OPUS should take the following steps before"
echo    "installation of this version of OPUS :"
echo    ""
echo    "   1 - Terminate any running processes or servers in any pipelines."
echo    "   2 - Perform a backup of the OPUS dist and any user created files."
echo    "   3 - Uninstall the previous version as described in the OPUS FAQ."
echo    ""
set query = "Press return to continue : "
set yes = MAIN_MENU
set no = MAIN_MENU
set default = $yes
goto YESORNO
#
# Installation
#
INSTALL:
clear
set installing
echo    ""
echo    "You have chosen to install the OPUS sample pipeline to run"
echo    "from disk. A directory named opus will be created under"
echo    "which the OPUS distribution will exist. During the installation"
echo    "procedure, you will be prompted for the location at which to"
echo    "place this directory. The installation requires approximately"
echo    "$min_disk MB of disk space plus:"
echo    "     $SOLARIS_DISK MB for Solaris,"
echo    "     $LINUX_DISK MB for Linux, or"
echo    "     $AIX_DISK MB for AIX"
echo    "(you will be able to choose which version or versions to install)."
echo    ""
set query = "Do you wish to continue (y or n)? [n] "
set yes = INST_GO
set no = MAIN_MENU
set default = $no
goto YESORNO
#
# Go with OPUS installation
#
INST_GO:
clear
set cd_done_goto = ""
#
# Set path to CD-ROM drive.  This section of code has a quirk in that you
# can go here and have set a place to go to afterwards, via cd_done_goto.
# During the base installation, that is empty so we just fall through to
# the next step.
#
CD_ROM_PATH:
echo    ""
echo -n "Please enter the path to the OPUS CD-ROM : [/cdrom] "
set cd_path = $<
if ( $cd_path == "") set cd_path = /cdrom
if ( ! -e $cd_path/install ) then
   set query = "WARNING: I can't find $cd_path/install. Specify another (y or n)? [n] "
   set yes = CD_ROM_PATH
   set no = MAIN_MENU
   set default = $no
   goto YESORNO
endif
# If we get here then they have successfully selected a path to the cdrom,
# so now we either move on, or go to the place specified in cd_done_goto.
if ( $?cd_done_goto ) then
   if ( $cd_done_goto != "" ) then
      goto $cd_done_goto
   endif
endif
#
# Set install directory
#
PARENT_PATH:
echo    ""
echo    "Please indicate the directory under which the OPUS sample"
echo    "pipeline directory tree will be installed. Note that this"
echo    "directory must be accessible to all systems that will"
echo -n "participate in the OPUS pipeline: [/usr/local/] "
set parent_dir = $<
if ( $parent_dir == "" ) set parent_dir = /usr/local
if ( ! -d $parent_dir ) then
   set query = "WARNING: I can't find $parent_dir. Specify another (y or n)? [n] "
   set yes = PARENT_PATH
   set no = MAIN_MENU
   set default = $no
   goto YESORNO
endif
if ( ! -w $parent_dir ) then
   set query = "WARNING: I can't write in $parent_dir. Specify another (y or n)? [n] "
   set yes = PARENT_PATH
   set no = MAIN_MENU
   set default = $no
   goto YESORNO
endif
if ( -e $parent_dir/opus ) then
   set query = "WARNING: $parent_dir/opus already exists. Specify another location (y or n)? [n] "
   set yes = PARENT_PATH
   set no = MAIN_MENU
   set default = $no
   goto YESORNO
endif
#
# Determing which OS versions to install
#
OS_LIST:
echo    ""
echo    "Please list which operating system(s) binaries and libraries"
echo    "should be installed:"
echo    ""
echo    "     [1] Solaris"
echo    "     [2] Linux"
echo    "     [3] AIX"
echo    ""
echo -n "Enter choice(s) separated by spaces: [1 2 3] "
set os_list = "$<"
if ( "$os_list" == "" ) then
   set os_list = "1 2 3"
endif
foreach os ( $os_list)
   if ( $os == "1" ) then
      @ min_disk += $SOLARIS_DISK
   else if ( $os == 2 ) then
      @ min_disk += $LINUX_DISK
   else if ( $os == 3 ) then
      @ min_disk += $AIX_DISK
   else
      echo ""
      set query = "WARNING: Invalid selection. Try again (y or n)? [n] "
      set yes = OS_LIST
      set no = MAIN_MENU
      goto YESORNO
   endif
end
@ min_disk_kb = $min_disk
@ min_disk_kb *= 1000
#
# Check available disk space
#
if ( $arch == sparc_solaris ) then
   set disk_space = `df -b $parent_dir | awk '{if ( NR == 2) print $2}'`
else
   set disk_space = `df -kP $parent_dir | awk '{if ( NR == 2) print $4}'`
endif
if ( $disk_space < $min_disk_kb ) then
   echo ""
   echo "WARNING: There is not enough disk space on $parent_dir in"
   echo "order to complete installation."
   echo "(free: $disk_space kilobytes; required: $min_disk_kb kilobytes)"
   set query = "Specify another (y or n)? [n] "
   set yes = PARENT_PATH
   set no = MAIN_MENU
   set default = $no
   goto YESORNO
endif
#
# Begin installation
#
cd $parent_dir
umask 22
mkdir opus
if ( $status != "0" ) then
   echo ""
   echo "WARNING: Cannot create $parent_dir/opus directory\! Bailing out"
   echo ""
   exit 1
endif
cd opus
set log = install.log
touch $log
if ( $status != "0" ) then
   set log = '/dev/null'
else
   set logfile
endif
date | tee -a $log
echo "OPUS Install Version : $opus_install_version" | tee -a $log
echo "Installing OPUS on: $arch" | tee -a $log
foreach os ( $os_list )
   if ( $os == "1" ) then
      echo "...for Solaris." | tee -a $log
   else if ( $os == 2 ) then
      echo "...for Linux." | tee -a $log
   else if ( $os == 3 ) then
      echo "...for AIX." | tee -a $log
   endif
end
echo "" | tee -a $log
echo "Installing OPUS sample pipeline" | tee -a $log
echo "...CD-ROM path: $cd_path" | tee -a $log
echo "...OPUS directory created in $parent_dir" | tee -a $log
echo "...extracting base tar file" | tee -a $log
if ( $arch == sparc_solaris ) then
   set tar_command = "tar xvef"
else
   set tar_command = "tar xvf"
endif
$tar_command $cd_path/install/opus_disk.tar
if ( $status != "0" ) goto BAILOUT
foreach os ( $os_list )
   if ( $os == "1" ) then
      echo "...copying OS-specific tar file" | tee -a $log
      /bin/cp $cd_path/install/solaris_disk.tar.gz install/
      echo "...unzipping OS-specific tar file" | tee -a $log
      gunzip -v install/solaris_disk.tar.gz
      echo "...extracting OS-specific tar file" | tee -a $log
      $tar_command install/solaris_disk.tar
      if ( $status != "0" ) goto BAILOUT
      /bin/rm -f install/solaris_disk.tar
   else if ( $os == 2 ) then
      echo "...copying OS-specific tar file" | tee -a $log
      /bin/cp $cd_path/install/linux_disk.tar.gz install/
      echo "...unzipping OS-specific tar file" | tee -a $log
      gunzip -v install/linux_disk.tar.gz
      echo "...extracting OS-specific tar file" | tee -a $log
      $tar_command install/linux_disk.tar
      if ( $status != "0" ) goto BAILOUT
      /bin/rm -f install/linux_disk.tar
   else if ( $os == 3 ) then
      echo "...copying OS-specific tar file" | tee -a $log
      /bin/cp $cd_path/install/aix_disk.tar.gz install/
      echo "...unzipping OS-specific tar file" | tee -a $log
      gunzip -v install/aix_disk.tar.gz
      echo "...extracting OS-specific tar file" | tee -a $log
      $tar_command install/aix_disk.tar
      if ( $status != "0" ) goto BAILOUT
      /bin/rm -f install/aix_disk.tar
   endif
end
#
echo "" | tee -a $log
echo "...building .cshrc stub" | tee -a $log
set opath = "$parent_dir/opus/bin/$arch/"
set sogs_disk = $parent_dir/opus/
set sample_db = $sogs_disk/db/
set libpath = $parent_dir/opus/lib/$arch
cat $cd_path/install/cshrc.install | sed s=OPATH="$opath"=g | sed s=OHOME=$parent_dir/opus=g >! install/cshrc_stub
cat install/cshrc_stub >>! $log
#
echo "...building pmg.dat" | tee -a $log
set short_host = `uname -n | awk -F. '{print $1}'`
#
if ( $arch == linux ) then
   cat $cd_path/install/pmg.install | /bin/grep -v fontList | sed s=DEFHOST=$short_host=g >! install/pmg.dat
else
   cat $cd_path/install/pmg.install | sed s=DEFHOST=$short_host=g >! install/pmg.dat
endif
#
echo "...building omg.dat" | tee -a $log
if ( $arch == linux ) then
   cat $cd_path/install/omg.install | /bin/grep -v fontList >! install/omg.dat
else
   /bin/cp $cd_path/install/omg.install install/omg.dat
endif
#
echo "...building opus_login_template.csh" | tee -a $log
cat $cd_path/install/opus_login_template.install | sed s=SGDSK="$sogs_disk"=g | sed s=OPUSSHRLIB=$libpath=g >! install/opus_login_template.csh
cat install/opus_login_template.csh >>! $log
#
echo "...building g2f.path" | tee -a $log
cat $cd_path/install/g2f.install | sed s=SPDB="$sample_db"=g >! install/g2f.path
cat install/g2f.path >>! $log
#
echo "...building repro.path" | tee -a $log
cat $cd_path/install/repro.install | sed s=SPDB="$sample_db"=g >! install/repro.path
cat install/repro.path >>! $log
#
echo "...building quick.path" | tee -a $log
cat $cd_path/install/quick.install | sed s=SPDB="$sample_db"=g >! install/quick.path
cat install/quick.path >>! $log
#
echo "...building null.path" | tee -a $log
cat $cd_path/install/null.install | sed s=SPDB="$sample_db"=g >! definitions/null.path
cat definitions/null.path >>! $log
#
echo "...building null_pipeline.stage" | tee -a $log
/bin/cp -f $cd_path/definitions/g2f_pipeline.stage definitions/null_pipeline.stage >>! $log
#
echo "" | tee -a $log
echo "Installation Complete\!" | tee -a $log
echo ""
unset installing
if ( $?logfile ) unset logfile
set query = "Press return to continue : "
set yes = MAIN_MENU
set no = $yes
set default = $yes
goto YESORNO
#
# Tack cshrc_stub onto user's .cshrc file
#
UPDATECSHRC:
clear
echo    ""
echo    "This procedure will update your .cshrc file to include the"
echo    "OPUS executables in your path (or create .cshrc if you do not"
echo    "have one). It will also copy resource files needed to run the"
echo    "managers to your home directory, generate a minimal"
echo    "opus_login.csh, path, and server configuration files for you."
echo    ""
echo    "The OPUS system must have already been installed on your system"
echo    "(you will be prompted for the OPUS directory path)."
echo    ""
set query = "Do you wish to continue (y or n)? [n] "
set yes = UPDATE_GO
set no = MAIN_MENU
set default = $no
goto YESORNO
clear
UPDATE_GO:
echo ""
echo    "Enter the complete path to the OPUS directory already installed"
echo -n "(eg. /usr/local/opus): "
set opus_tree = $<
if ( ! -d $opus_tree ) then
   set query = "No such directory $opus_tree. Specify another (y or n)? [n] "
   set yes = UPDATE_GO
   set no = EXIT
   set default = $no
   goto YESORNO
endif
cd ~
if ( ! -e $opus_tree/install/cshrc_stub || ! -e $opus_tree/install/opus_login_template.csh || ! -e $opus_tree/install/g2f.path || ! -e $opus_tree/install/repro.path || ! -e $opus_tree/install/quick.path ) then
   set query = "WARNING: I could not find the OPUS installation. Do you want to install OPUS now (y or n)? [y] "
   set yes = MAIN_MENU
   set no = EXIT
   set default = $yes
   goto YESORNO
endif
HOMEDIR:
echo    ""
echo    "Please specify where you would like to save the output generated"
echo    "by the sample pipeline as well as the process log files. A "
echo    "directory called opus_test will be created at this location:"
echo    ""
echo -n "Location to create opus_test [$HOME]: "
set home_dir = $<
if ( ${home_dir} == "" ) set home_dir = $HOME
if ( ! -d ${home_dir} ) then
   set query = "WARNING: I can't find ${home_dir}. Specify another (y or n)? [n] "
   set yes = HOMEDIR
   set no = MAIN_MENU
   set default = $yes
   goto YESORNO
endif
if ( ! -w ${home_dir} ) then
   set query = "WARNING: I can't write in ${home_dir}. Specify another (y or n)? [n] "
   set yes = HOMEDIR
   set no = MAIN_MENU
   set default = $yes
   goto YESORNO
endif
if ( -e ${home_dir}/opus_test ) then
   echo ""
   echo "CANNOT PROCEED: ${home_dir}/opus_test/ already exists."
   echo "      Existing pipeline data must be moved out of the way first."
   echo "      See instructions in the FAQ about upgrading from previous"
   echo "      versions of OPUS."
   echo ""
   set query = "Press return to return to the Main Menu."
   set yes = HOMEDIR
   set no = MAIN_MENU
   set default = $no
   goto YESORNO
endif
mkdir ${home_dir}/opus_test
mkdir ${home_dir}/opus_test/home
mkdir ${home_dir}/opus_test/home/lock
mkdir ${home_dir}/opus_test/definitions
mkdir ${home_dir}/opus_test/g2f
mkdir ${home_dir}/opus_test/g2f/obs
mkdir ${home_dir}/opus_test/g2f/obs/lock
mkdir ${home_dir}/opus_test/g2f/fits
mkdir ${home_dir}/opus_test/g2f/input
mkdir ${home_dir}/opus_test/repro
mkdir ${home_dir}/opus_test/repro/obs
mkdir ${home_dir}/opus_test/repro/obs/lock
mkdir ${home_dir}/opus_test/repro/fits
mkdir ${home_dir}/opus_test/repro/input
mkdir ${home_dir}/opus_test/quick
mkdir ${home_dir}/opus_test/quick/obs
mkdir ${home_dir}/opus_test/quick/obs/lock
mkdir ${home_dir}/opus_test/quick/fits
mkdir ${home_dir}/opus_test/quick/input
mkdir ${home_dir}/opus_test/quick/error
# 
# build opus_login.csh
#
cat $opus_tree/install/opus_login_template.csh | sed s=OHDIR=${home_dir}/opus_test/home/=g | sed s=ODDIR=${home_dir}/opus_test/=g >! ${home_dir}/opus_test/definitions/opus_login.csh
cat $opus_tree/install/cshrc_stub | sed s=ODEF=${home_dir}/opus_test/definitions/=g >! ${home_dir}/opus_test/definitions/cshrc_stub
#
# build g2f.path
#
cat $opus_tree/install/g2f.path | sed s=GIFDAT=${home_dir}/opus_test/g2f/input/=g | sed s=OSFS=${home_dir}/opus_test/g2f/obs/=g | sed s=FITSDAT=${home_dir}/opus_test/g2f/fits/=g >! ${home_dir}/opus_test/definitions/g2f.path
#
# build repro.path
#
cat $opus_tree/install/repro.path | sed s=GIFDAT=${home_dir}/opus_test/repro/input/=g | sed s=OSFS=${home_dir}/opus_test/repro/obs/=g | sed s=FITSDAT=${home_dir}/opus_test/repro/fits/=g >! ${home_dir}/opus_test/definitions/repro.path
#
# build quick.path
# 
cat $opus_tree/install/quick.path | sed s=GIFDAT=${home_dir}/opus_test/quick/input/=g | sed s=OSFS=${home_dir}/opus_test/quick/obs/=g | sed s=ERRDIR=${home_dir}/opus_test/quick/error/=g | sed s=FITSDAT=${home_dir}/opus_test/quick/fits/=g >! ${home_dir}/opus_test/definitions/quick.path
#
echo ""
if ( -e .cshrc ) then
   echo "Saving original .cshrc as cshrc_041367OPUS..."
   /bin/cp .cshrc cshrc_041367OPUS
   /bin/grep 041367OPUS .cshrc >& /dev/null
   if ( $status != "1" ) then
      echo ""
      echo "WARNING: OPUS modifications already exist in ~/.cshrc"
      echo ""
      set query = "Replace previous modifications (y or n)? [n] "
      set yes = OVERWRITE
      set no = EXIT
      set default = $no
      goto YESORNO
OVERWRITE:
      set lin = `cat .cshrc | /bin/grep -n "041367OPUS:1" | awk -F: '{print $1}'`
      @ strt = $lin - 1
      set lin = `cat .cshrc | /bin/grep -n "041367OPUS:8" | awk -F: '{print $1}'`
      if ( $lin == "" ) set lin = `cat .cshrc | /bin/grep -n "041367OPUS:7" | awk -F: '{print $1}'`
      @ end = $lin + 1
      if ( $strt > 0 ) then
         head -$strt .cshrc >! cshrc_tmp_041367OPUS
      else
         touch cshrc_tmp_041367OPUS
      endif
      tail +$end .cshrc >>! cshrc_tmp_041367OPUS
      mv -f cshrc_tmp_041367OPUS .cshrc
   endif
   echo "Modifying .cshrc..."
   cat ${home_dir}/opus_test/definitions/cshrc_stub >>! .cshrc
   set save_status = $status
   /bin/rm -f ${home_dir}/opus_test/definitions/cshrc_stub
else
   echo "Creating .cshrc..."
   mv ${home_dir}/opus_test/definitions/cshrc_stub ./.cshrc
   set save_status = $status
endif
if ( $save_status != "0" ) then
   echo ""
   echo "WARNING: Problem creating new .cshrc file"
   echo ""
   exit 1
endif
echo "Copying opus_corba_objs to ${home_dir}/opus_test/definitions/..."
/bin/cp $opus_tree/definitions/unix/opus_corba_objs_template ${home_dir}/opus_test/definitions/opus_corba_objs
/bin/chmod 644 ${home_dir}/opus_test/definitions/opus_corba_objs
echo "Creating CORBA object map file..."
touch ${home_dir}/opus_test/home/opus_iors
/bin/chmod go-rwx ${home_dir}/opus_test/home/opus_iors
echo ""
echo "Modifications complete.  Please log into a new shell before running OPUS."
echo ""
set query = "Press return to continue : "
set yes = MAIN_MENU
set no = $yes
set default = $yes
goto YESORNO
#
# Install the OPUS managers
#
MANAGERS:
clear
echo    ""
echo    "You have chosen to install the OPUS Managers.  The Institute has"
echo    "selected the InstallAnywhere package from ZeroG to bundle the"
echo    "OPUS Managers and help with the installation.  The top level"
echo    "/bin/ directory on the CDROM contains the binaries you need for"
echo    "installation. The OpusMgrs.bin file is for Unix platforms, and"
echo    "the OpusMgrs.exe file is for Windows platforms.  This script will"
echo    "now run the OpusMgrs.bin file, which will display a window."
echo    ""
echo    "You can also run these installation tasks directly from the CDROM,"
echo    "if you choose not to continue now, except on the AIX platform where"
echo    "installation from here is required for proper functionality."
set query = "Do you wish to continue (y or n)? [n] "
set yes = MGRS_CHECK_CD
set no = MAIN_MENU
set default = $no
goto YESORNO
#
# Before installing the OPUS Managers, check the CD path.
#
MGRS_CHECK_CD:
if ( $?cd_path ) then
   if (-e $cd_path/install ) then
      goto MANAGERS_GO
   endif
endif
# If we get here then they haven't yet specified the correct CD path.
set cd_done_goto = MANAGERS_GO
goto CD_ROM_PATH
#
# Now really install the OPUS Managers - they said OK and we have the CD path.
#
MANAGERS_GO:
set binfile = ${cd_path}/bin/JavaMgrs/unix/OpusMgrs.bin
if ( -e $binfile ) then
   clear
   echo    ""
   echo    "Installing the OPUS Managers."
   echo    "Executing $binfile ..."
   echo    ""
   $binfile
   if ( $status == 0 ) then
      echo ""
      echo "OpusMgrs.bin appears to have completed safely."

      # on AIX we override the InstallAnywhere OMG/PMG scripts to edit LIBPATH
MGRS_SHORTCUT_GO:
      if ( $arch == ibm_aix ) then
         /bin/rm -f ~/OMG ~/PMG >& /dev/null
         set quest = WE_SEEK_THE_GRAIL
         if ($?opus_tree) then
            if (-d $opus_tree/lib) then
               set quest = i_told_them_we_already_got_one
            endif
         endif
         if ( $quest == WE_SEEK_THE_GRAIL ) then
            echo ""
            echo "Please enter the full path to the installed OPUS directory"
            echo "so that startup scripts can be created for the OPUS Managers"
            echo "(This is a required step on AIX)"
            echo ""
            echo -n "(eg. /usr/local/opus): "
            set opus_tree = $<
            if ($opus_tree == "") then
               set opus_tree = "/usr/local/opus"
            endif
            if (! -d $opus_tree) then
               set query="$opus_tree not found. Specify another (y or n)? [y] "
               set yes = MGRS_SHORTCUT_GO
               set no = MAIN_MENU
               set default = $yes
               goto YESORNO
            endif
         endif

         echo ""
         echo "Creating OMG and PMG shortcuts in $HOME."
         # The problem with this script is it assumes the mgrs are
         # installed in the default path (~/OPUSMgrs/[OP]MG).
         echo '#\!/bin/sh' > ~/OMG
         echo "LIBPATH=$opus_tree/lib/ibm_aix/non_rtl"':$LIBPATH' >> ~/OMG
         echo "export LIBPATH" >> ~/OMG
         echo "$HOME/OPUSMgrs/OMG" >> ~/OMG
         sed s=OMG=PMG=g ~/OMG >& ~/PMG
         chmod ugo+x ~/OMG ~/PMG
      endif
   else
      echo ""
      echo "WARNING: An error has occurred during the installation process."
   endif
   set query = "Press return to continue : "
   set yes = MAIN_MENU
   set no = $yes
   set default = $yes
   goto YESORNO
else
   echo ""
   echo "WARNING: Could not locate OpusMgrs.bin in the CD-ROM bin directory."
   echo "There does not appear to be a normal OPUS distribution under:"
   echo "          $cd_path"
   set cd_path = ""
   set query = "Specify another CD-ROM path (y or n)? [n] "
   set yes = MGRS_CHECK_CD
   set no = MAIN_MENU
   set default = $no
   goto YESORNO
endif
#
set yes = MAIN_MENU
set no = MAIN_MENU
set default = $no
goto YESORNO
#
# In case error occurs during installation
#
BAILOUT:
echo "" | tee -a $log
echo "WARNING" | tee -a $log
echo "An error has prevented installation from completing" | tee -a $log
echo "successfully." | tee -a $log
echo "" | tee -a $log
if ( $?logfile ) then
   echo "A log of the installation attempt was created in $parent_dir/opus/$log" | tee -a $log
endif
echo "" | tee -a $log
exit 1
#
# Interrupt signal
#
INTRPT:
echo ""
if ( $?installing ) then
   echo ""
   echo "WARNING: You have interrupted the installation procedure."
   echo "OPUS may not be fully installed."
endif
exit 1
#
# Generic exit
#
EXIT:
exit 0
#
# Yes or no query to user
#
YESORNO:
echo    ""
echo -n "$query"
set response = $<
if ( $response == "y" || $response == "Y" ) goto $yes
if ( $response == "n" || $response == "N" ) goto $no
if ( $response == "" ) goto $default
goto YESORNO
