#!/bin/sh 
#
#	$Id: post_unpack,v 1.51 2001/05/10 22:05:45 beth Exp $
#
# unpack_idl
#
# This script expects to be run from the top level RSI directory
# after IDL has been unpacked from the distribution media. It performs
# tasks that need to be run on the target machine to complete localization.
#
#	$1 - If $1 is non-empty, this script assumes that it's being
#	     run directly from the tty and offers the user the option
#	     of trimming excess binaries from the IDL tree. Otherwise, it
#	     limits itself to non-interactive setup tasks.

if [ "$1" != "STUDENT" ]; then
VERSION=5.5
else
VERSION=5.5sv
fi
IDL_DIR=`pwd`/idl_$VERSION
IDL_BIN=$IDL_DIR/bin
SCRIPT=`basename $0`
UDIR=`pwd`
RSI_DIR=`pwd`


if [ "$1" != "STUDENT" ]; then
# Generate idldemo command.
echo "#! /bin/sh
# Defines the environment variables required to get an unlicensed IDL
# residing in a non-standard location up and running the IDL demo. This
# lets people give IDL a quick demo without having to get installation
# and license management done first.
#

if [ \"\$IDL_DIR\" = \"\" ]; then
    IDL_DIR=$IDL_DIR
    export IDL_DIR
fi

IDL_PATH=\"<IDL_DEFAULT>\"
IDL_DEVICE=X
export IDL_PATH IDL_DEVICE

if [ ! -f \$IDL_DIR/lib/hook/demo.sav ]; then
   echo \"	The IDL Demos have not been installed.  Please consult the
	installation guide for instructions on installing the demos.\"
   exit 0
fi


\$IDL_DIR/bin/idl -em=\$IDL_DIR/lib/hook/demo.sav" > $IDL_BIN/idldemo
chmod 755 $IDL_BIN/idldemo
fi	# !STUDENT



# Generate idlman script
echo "#!/bin/sh
# This script is automatically generated at install time by
# the installation process.  It starts the Adobe Acrobat Reader
# to view the IDL Online Manuals

APPLICATION=\`basename \$0\`

if [ \"\$IDL_DIR\" = \"\" ]; then
    IDL_DIR=$IDL_DIR
    export IDL_DIR 
fi
IDL_BIN=\"\$IDL_DIR/bin\"

if [ ! -f \$IDL_DIR/docs/onlguide.pdf ]; then
   echo \"      The IDL Online Manuals have not been installed.  Please consult the installation guide for instructions on installing the IDL Online manuals.\"
   exit 0
fi


acroread  \$IDL_DIR/docs/onlguide.pdf 
 
if [ \"\$?\" != \"0\" ]; then
 
echo \"
      There was an error starting the Adobe Acrobat Reader.  Please check to see if the Acrobat Reader is installed and included in your path.  Adobe Acrobat Reader 4.0 with Search has been included on your IDL CD-ROM in the /rdr_srch directory along with the installation instructions in the instguid.txt file.

Visit Adobe Systems Web site at www.adobe.com for the latest information and downloads concerning Acrobat Reader.
 
\"
 exit 1
fi " > $IDL_BIN/idlman
chmod 755 $IDL_BIN/idlman
# Create the shell scripts idl_setup and idl_setup.ksh which can be used
# to set up the environment variables and aliases required by IDL
# related commands (idl, idlde, idlhelp, idldemo) if the links to
# the default directory (/usr/local/rsi/idl) are not being used.
#
# C shell users should source idl_setup or envi_setup from their .cshrc files,
# using the full path to the IDL directory as follows:
#    source full_path_to_IDL_Directory/idl_setup
# Korn shell users should run idl_setup.ksh or envi_setup.ksh from their
# .profile file (using the ". idl_setup.ksh" notation), as follows:
#    . full_path_to_IDL_Directory/idl_setup.ksh
#

if [ "$1" != "STUDENT" ]; then
echo "# C shell commands to define IDL environment variables and aliases.
#
# This script can be used by IDL users who use csh as their interactive shell
# to define the environment variables and aliases required by IDL
# related commands (idl, idlde, idlhelp, idldemo) if the symbolic links to
# the default directory (/usr/local/rsi/idl) are not being used.
#
# csh users should source idl_setup from their .cshrc files,
# using the following command:
#
#    source $IDL_DIR/bin/idl_setup
#

setenv RSI_DIR $RSI_DIR
setenv IDL_DIR $IDL_DIR
setenv IDL_PATH \"<IDL_DEFAULT>\"
alias rsilicense \$IDL_DIR/bin/rsilicense
alias idl \$IDL_DIR/bin/idl
alias idlde \$IDL_DIR/bin/idlde
alias idldeclient \$IDL_DIR/bin/idldeclient
alias idlhelp \$IDL_DIR/bin/idlhelp
alias idlman \$IDL_DIR/bin/idlman
alias idlrpc \$IDL_DIR/bin/idlrpc
alias idldemo \$IDL_DIR/bin/idldemo" > $IDL_BIN/idl_setup
chmod 755 $IDL_BIN/idl_setup

else
echo "# C shell commands to define IDL environment variables and aliases.
#
# This script can be used by IDL users who use csh as their interactive shell
# to define the environment variables and aliases required by IDL
# related commands (idl, idlde, idlhelp, idldemo) if the symbolic links to
# the default directory (/usr/local/rsi/idl) are not being used.
#
# csh users should source idl_setup from their .cshrc files,
# using the following command:
#
#    source $IDL_DIR/bin/idl_setup
#
setenv RSI_DIR $RSI_DIR
setenv IDL_DIR $IDL_DIR
setenv IDL_PATH \"<IDL_DEFAULT>\"
alias sidl \$IDL_DIR/bin/sidl
alias sidlde \$IDL_DIR/bin/sidlde
alias idlhelp \$IDL_DIR/bin/idlhelp" > $IDL_BIN/idl_setup
chmod 755 $IDL_BIN/idl_setup
fi			# STUDENT

if [ "$1" != "STUDENT" ]; then
echo "# Korn shell commands to define IDL environment variables and aliases.
#
# This script can be used by IDL users who use ksh as their interactive shell
# to define the environment variables and aliases required by IDL
# related commands (idl, idlde, idlhelp, idldemo) if the symbolic links to
# the default directory (/usr/local/rsi/idl) are not being used.
#
# ksh users should run idl_setup from their .profile file 
# using the following command:
#
#    . $IDL_DIR/bin/idl_setup.ksh
#
RSI_DIR=$RSI_DIR
IDL_DIR=$IDL_DIR
export IDL_DIR RSI_DIR
IDL_PATH=\"<IDL_DEFAULT>\"
export IDL_PATH 
alias -x rsilicense=\$IDL_DIR/bin/rsilicense
alias -x idl=\$IDL_DIR/bin/idl
alias -x idlde=\$IDL_DIR/bin/idlde
alias -x idldeclient=\$IDL_DIR/bin/idldeclient
alias -x idlhelp=\$IDL_DIR/bin/idlhelp
alias -x idlman=\$IDL_DIR/bin/idlman
alias -x idlrpc=\$IDL_DIR/bin/idlrpc
alias -x idldemo=\$IDL_DIR/bin/idldemo" > $IDL_BIN/idl_setup.ksh
chmod 755 $IDL_BIN/idl_setup.ksh
else
echo "# Korn shell commands to define IDL environment variables and aliases.
#
# This script can be used by IDL users who use ksh as their interactive shell
# to define the environment variables and aliases required by IDL
# related commands (idl, idlde, idlhelp, idldemo) if the symbolic links to
# the default directory (/usr/local/rsi/idl) are not being used.
#
# ksh users should run idl_setup from their .profile file 
# using the following command:
#
#    . $IDL_DIR/bin/idl_setup.ksh
#
RSI_DIR=$RSI_DIR
IDL_DIR=$IDL_DIR
export IDL_DIR RSI_DIR
IDL_PATH=\"<IDL_DEFAULT>\"
export IDL_PATH 
alias -x sidl=\$IDL_DIR/bin/sidl
alias -x sidlde=\$IDL_DIR/bin/sidlde
alias -x idlhelp=\$IDL_DIR/bin/idlhelp" > $IDL_BIN/idl_setup.ksh
chmod 755 $IDL_BIN/idl_setup.ksh
fi			# STUDENT


if [ "$1" != "STUDENT" ]; then
# Call script to generate the odbc.ini file for the platforms
# which support it.
$IDL_BIN/gen_odbc_ini $IDL_DIR HP
$IDL_BIN/gen_odbc_ini $IDL_DIR SOLARIS2
$IDL_BIN/gen_odbc_ini $IDL_DIR AIX
$IDL_BIN/gen_odbc_ini $IDL_DIR IRIX
$IDL_BIN/gen_odbc_ini $IDL_DIR LINUX
fi  			# !STUDENT

# Create the action file for CDE
if [ -w /etc/dt/appconfig/types/C ]; then
   # if the file already exists, be sure it's writable.
   if [ -f /etc/dt/appconfig/types/C/Idl.dt ]; then
      if [ -w /etc/dt/appconfig/types/C/Idl.dt ]; then
         sed "s|WHERE_IS_IDL|$IDL_BIN|" $IDL_BIN/Idl.dtorig > /etc/dt/appconfig/types/C/Idl.dt
      fi
   else
      sed "s|WHERE_IS_IDL|$IDL_BIN|" $IDL_BIN/Idl.dtorig > /etc/dt/appconfig/types/C/Idl.dt
   fi
fi
sed "s|WHERE_IS_IDL|$IDL_BIN|" $IDL_BIN/Idl.dtorig > $IDL_BIN/Idl.dt

# Update INSTALL_DIR in startapp/lmremove
if [ -w $IDL_BIN/idl ]; then
sed "s|INSTALL_DIR=.*|INSTALL_DIR=$RSI_DIR|" $IDL_BIN/idl.orig > $IDL_BIN/idl
fi
if [ -w $IDL_BIN/lmremove ]; then
sed "s|INSTALL_DIR=.*|INSTALL_DIR=$RSI_DIR|" $IDL_BIN/idl.orig > $IDL_BIN/lmremove
fi
if [ -w $IDL_BIN/idlhelp ]; then
sed "s|INSTALL_DIR=.*|INSTALL_DIR=$RSI_DIR|" $IDL_BIN/idl.orig > $IDL_BIN/idlhelp
fi


if [ "$1" = "INTERACTIVE" ]; then

  # How many sets of binaries are there?
  NUM=0
  for FILE in $IDL_BIN/bin.*; do
    if [ $FILE != "*.tar.Z" ]; then
      NUM=`expr $NUM + 1`
    fi
  done

  echo "        This IDL distribution supports $NUM operating
         system/hardware combination(s).
"

  # If this distribution supports multiple OS/hardware combinations, offer
  # to remove some of them to save room.
  if [ $NUM != 1 ]; then
    echo "
        This distribution is able to support multiple hardware/operating
        systems. This is done by providing multiple copies of the IDL
        binaries. If you do not need all the combinations present,
        you can remove the unwanted ones and save disk space. You will
        now be given a description of each one and then asked if it
        should be deleted.
"
    if [ `sh $IDL_BIN/yesno "Do you wish to remove excess binaries"` = 1 ]; then
      for FILE in $IDL_BIN/bin.*; do
        if [ -f $FILE/DESCRIP ]; then
          echo " "
          cat $FILE/DESCRIP
          if [ `sh $IDL_BIN/yesno "Delete"` = 1 ]; then
            echo "    Removing " $FILE
            rm -r $FILE
          fi
        fi
      done
    fi
  fi

fi
