#!/bin/sh
# PRODUCT_NAME: IBM Visualization Data Explorer
#
# (C) COPYRIGHT International Business Machines Corp. 1992-1997
# All Rights Reserved
# Licensed Material - Property of IBM
# Version: 3.1.4
#
# FUNCTION: install script for Data Explorer 
#
# USAGE : installdx [ ibm6000 | hp700 | sgi | aviion | solaris | sun4 | alphax ]
#
# Determination of the current architecture is done automatically
# unless one of the above architectures is provided on the command line.
#
# This script will work for both tape and CD installations.  It asks
# the user for the installation directory, tape device (if tape installation),
# whether or not this is a personal install, and the subsystems that are
# desired for de/installation.
#
# When installing from CD, the following is assumed
#
# 	1) the CD is mounted (on for example /mnt)
# 	2) this script is found in /mnt/installdx (it may appear as uppercase
#		and may have a ';1' as a suffix)
#	3) the user does a 'cd /mnt; ./installdx' to run the script.
#
# When installing from a tar file the following are assumed
#
#	1) The tar file is a relative tar file with files tar from the
#	    	directory below the dx directory, so that all files appear
#		in the tar file as bin, bin_ibm6000....
#


dbg=${DXDBG-off} 
PATH=".:$PATH:/usr/ucb"; export PATH
ECHO=
superuser=root
# Order of files on tape with position of an architecture name
# indicating the position of the architecture specific file on the tape
# boot and common are the first two tar files on the tape
# NOTE: in the case of 1/4" tape the solaris and sun4 compressed images
# 	are on the 2nd tape.
headerfiles="boot common"
tape_map="$headerfiles alphax aviion hp700 ibm6000 sgi solaris sun4"
qic150files=7	# The # of files on the 1st 1/4" tape, the 2nd tape has the rest
		# Note that the 8mm should have all files on a single tape

if [ "$dbg" = "on" ]; then
    ECHO=echo
fi

cfg_args=		# Args to Configure script
arch=			# is optional, but allows override of
			# auto determination of architecture
echo ""
dxroot=/usr/lpp/dx	# Dir tree found in tar files.
noconfig=false		# Run Configure if curr arch == install arch
suffix=
lscase=lower
media=${DXMEDIA-unknown} # one of: CD, tape, disk
single=false		# Does the tape file contain the single architecture
whoami=`id | sed -e 's/[^(]*(\([^)]*\).*/\1/'`
cat=cat			# cat or zcat

#
# Parse the arguments
#
while [ ! "$*" = "" ]; do
    case $1 in
        -single)   single=true;;   # The tape has only one arch file on it
	-noconfig*)noconfig=true;; # Don't run Configure even if correct arch
	-archorder)tape_map="$headerfiles $2"; shift;;
        -*)        echo "Unrecognized argument $1, exiting"; exit 1;;
        *)	   arch=$1 ;;
    esac
    shift;
done
###############################################################################
################### Miscellaneous Helper routines #############################
###############################################################################
#
# Routine to ask user if we should proceed or quit.
#
ASK_ANSWER=
ask()
{
    ASK_ANSWER=
    while [ -z "$ASK_ANSWER"  ]; do
        echo ""
        question="$1 ? (y/n) : "
        /bin/csh -f -c "echo -n \"$question\""
        read ans
        case $ans in
            y|Y|yes|YES|Yes) ASK_ANSWER=yes;;
            n|N|no|NO|No)    ASK_ANSWER=no ;;
            *) echo "Please answer with 'y' or 'n'." 2>&1
                 ASK_ANSWER=
            ;;
        esac
    done
}
#
# Routine to ask user if we should proceed or quit.
#
ask_proceed()
{
    ask "Proceed"
    if [ $ASK_ANSWER = yes ]; then
	echo "Proceeding..."
    else
	echo "Installation terminated."
	exit 0
    fi
}

get()
{
   question="$1: "
   /bin/csh -f  -c "echo -n \"$question\""
   read ASK_ANSWER
}

get_with_default()
{
   question="$1 [$2] : "
   /bin/csh -f  -c "echo -n \"$question\""
   read ASK_ANSWER
   if [ -z "$ASK_ANSWER" ]; then
	ASK_ANSWER=$2
   fi
}

#
# A routine to create a directory path.  For example, given /a/b/c/d/e/f,
# each directory will be created so that there is a path to directory f.
#
mkpath()
{
        d=
        dirs=`echo $1 | tr '/' ' '`
        for k in $dirs; do
            d="$d/$k"
            if [ ! -d $d ]; then
                $ECHO mkdir $d
            fi
        done
}

#
# Skip the rewindable tape device ahead one file
# $1 is architecture, $2 is device
#
fsf_tape()
{
    a=$1
    drive=$2
    files=$3
    if [ $files != 0 ]; then
	case $a in
	    ibm6000)  			cmd="tctl -f";;
	    sgi|indigo|hp700)  		cmd="mt -t";;
	    solaris|alphax|sun4|aviion) cmd="mt -f";;
	esac
	echo "Skipping forward $files file(s) on $drive..."
	$ECHO $cmd $drive fsf $files
    fi
    # looping on ': 2>/dev/null < /dev/rmt0' may be better at some point
    $ECHO sleep 5	# Let the tape drive recover (even when we do nothing)
}

#
# Rewind the tape device
# $1 is architecture, $2 is device
#
rew_tape()
{
    a=$1
    drive=$2
    case $a in
        ibm6000)  			cmd="tctl -f";;
        sgi|indigo|hp700)  		cmd="mt -t";;
        solaris|sun4|alphax|aviion)  	cmd="mt -f";;
    esac
    echo Rewinding tape drive $drive...
    $ECHO $cmd $drive rewind
}

dx_untar() # Usage : dx_untar  tarfile file1 file2 ...
{
    TARFILE=$1;  shift
    FILES="$*"
    if [ "$dbg" = on ]; then
	# Use dd because IRIX sometimes coughs on the tape itself.
	$ECHO "(cd $dxroot; dd if=$TARFILE bs=4k |$cat| tar $tarargs - $FILES)"
	status=$?
    else
	(cd $dxroot; dd if="$TARFILE" bs=4k | $cat | tar $tarargs - $FILES)
	status=$?
    fi
    $ECHO sleep 15	# Wait until the tape is ready
}

find_drive()
{
   # FIXME: determine these dynamically
   case $1 in
	ibm6000) 	echo /dev/rmt0.1;;
	sun4) 		echo /dev/nrst0;;
	solaris) 	echo /dev/rmt/0n;;
	hp700) 		echo /dev/rmt/0mn;;
	sgi*) 		echo /dev/rmt/tps0d4nrns;;
	aviion) 	echo /dev/rmt/0n;;
	alphax) 	echo /dev/nrmt0h;;
   esac
}

###############################################################################
######################### Begin CD/Tape Installation ##########################
###############################################################################


#
# Determine the architecture if not given
#
    # determine the machine type automatically
    thissys=`uname -s`
    case $thissys in
        AIX*) thisarch=ibm6000  ;;

	IRIX*)  thisarch=sgi    ;;
	SunOS*)
	    thisver=`/bin/uname  -r`
	    case "$thisver" in
	       4*) thisarch=sun4    ;;
	       *)  thisarch=solaris ;;
	    esac
        ;;

	HP-UX*) thisarch=hp700  ;;
	dgux)  thisarch=aviion ;;
	OSF1*)  thisarch=alphax;;

        *)
	cat << +++
    Your machine type (uname -s) is not recognized.
    This installation program is for use only on RS/6000, Sun, HP, SGI,
    AViION or Dec/AXP workstations.  To override the machine type rerun
    this script and give one of the following arguments:
        ibm6000  hp700  sgi  aviion  solaris  sun4  alphax

+++
	exit 1
        ;;
    esac
if [ -z "$arch" ]; then
    arch=$thisarch
else
    # Make sure the given architecture is supported
    # and do any architecture name conversion
    #
    case $arch in
	aviion|hp700|sun4|sgi|ibm6000|alphax|solaris)
	;;
	crimson|indigo|onyx) arch=sgi
	;;
	*)
	    cat << +++
The given architecture, $arch, is not supported.  Supported architectures
include ibm6000, hp700, sun4, sgi, solaris, alphax and aviion.
+++
	    exit 1
	;;
    esac
fi
cfg_args="$cfg_args $arch"

operation=UNKNOWN
while [ $operation = UNKNOWN ]; do
    cat << +++

DX Installation Script, Version 3.1.4a

Do you wish to install or deinstall Data Explorer or one of its subsystems:

  1. Install
  2. Deinstall
  3. No action desired. Quit now.

+++
    get_with_default "Enter Selection" "1"
    action=$ASK_ANSWER
    case $action in
	1) operation=install;;	
	2) operation=deinstall;;	
	3) echo "Quitting..."
	   exit 0
	;;
	*)
	   echo "Incorrect Input."
	;;
    esac
done
cfg_args="$cfg_args $operation"

#
# require user to type 'accept' to indicate they read this license info
#
if [ $operation = install ]; then
    cat << +++

  The Visualization Data Explorer is licensed under one of the following
  license agreements, the IBM Customer Agreement (ICA) or the IBM
  License Agreement for Programs (ILAP).

  If you acquire this product directly from IBM and you accept the
  terms and conditions of the IBM Customer Agreement (or any equivalent
  agreement signed by you and IBM) then that agreement takes precedence.

  Otherwise the terms and conditions of the IBM License Agreement for
  Programs applies to this program. By using this program you agree
  to its terms and conditions. Please read the IBM License Agreement
  for Programs, shipped in the packaging with the media, before you
  proceed.

  If you accept these terms and conditions, type the word 'accept' followed
  by ENTER to continue, otherwise press ENTER to terminate the installation.

+++
    read ans
    if [ "$ans" != "accept" -a "$ans" != "ACCEPT" ]; then
        echo Installation terminated.
        exit 0
    fi

#
# Find out what tape drive or file to use if this is a tar installation
#
    while [ $media = unknown ]; do
	cat << +++

Are you installing from:

  1. CD-ROM
  2. Tape
  3. Disk file(s)

+++
	get_with_default "Enter Selection" "1"
	action=$ASK_ANSWER
	case $action in
	    1) media=CD;;
	    2) media=tape;;
	    3) media=disk;;
	    *) echo "Incorrect Input."
	    ;;
	esac
    done

#
# we know what input media is now
#

    pwd=`pwd`
    if [ $media = CD ]; then
	tarsrc1=
	while [ "$tarsrc1" = "" ]; do
	    cat << +++

Enter the name of the directory where the CD-ROM is mounted.

+++
	    get_with_default "Enter directory name" "/cdrom"
	    src=$ASK_ANSWER

            # find the tar directory and test it for uppercase.
            # then check a file to see if it has a trailing ';1'
            norm=tarfiles
            upcase=`echo $norm | tr '[a-z]' '[A-Z]'`
            if [ -d $src/$norm ]; then
                lscase=
            elif [ -d $src/$upcase ]; then
                lscase=upper
            else
                # error msg here - can't find tarfiles dir
	        cat << +++
               
Cannot find the directory $src/$norm
Check that CD-ROM is correctly mounted and that "$src" 
matches the directory where the CD is mounted.

+++
                continue
            fi
            norm=$norm/dx_common.tar
            if [ "$lscase" = upper ]; then
               norm=`echo $norm | tr '[a-z]' '[A-Z]'`
            fi
            suff="${norm};1"

	    if [ -f $src/$norm ]; then
                suffix=
            elif [ -f $src/$suff ]; then
                suffix=';1'
	    else
                # error msg here - can't find common file
	        cat << +++
               
Cannot find the file $src/$norm or $src/$suff
Check that CD-ROM is correctly mounted and that "$src" 
matches the directory where the CD is mounted.

+++
                continue
            fi            

	    #
	    # Get absolute path to tar file and massage it into the correct case
	    # and add a suffix if the CD format uses them
	    #
	    common_tarfile="tarfiles/dx_common.tar$suffix"
	    arch_tarfile="tarfiles/dx_$arch.tar$suffix"
	    if [ "$lscase" = upper ]; then
		common_tarfile=`echo "$common_tarfile" | tr '[a-z]' [A-Z]'`
		arch_tarfile=`echo "$arch_tarfile" | tr '[a-z]' [A-Z]'`
	    fi
	    tarsrc1="$src/$common_tarfile"
	    tarsrc2="$src/$arch_tarfile"
	    if [ ! -f "$tarsrc1" -o ! -f "$tarsrc2" ]; then
		cat << +++

Cannot find one or both of the following file(s):

$tarsrc1
$tarsrc2

This is probably due to improper mounting of the CD-ROM.
Please refer to the installation instructions provided with the
CD-ROM for instructions on how to properly access the CD-ROM.

+++
                exit 2;
	    fi
        done   # while tarsrc1 = ""

    elif [ $media = tape ]; then 
	while [ "$tarsrc1" = "" ]; do
	    cat << +++

Enter the name of the tape device.  The device must NOT be
auto-rewinding!  For example,

	On AIX............../dev/rmt0.1
	On SunOS............/dev/nrst0
	On Solaris........../dev/rmt/0n
	On HP-UX............/dev/rmt/0mn
	On IRIX............./dev/rmt/tps0d4nrns
	On DG/UX............/dev/rmt/0n
	On OSF1............./dev/nrmt0h

Note: on IRIX be sure to use the no-swap tape drives which have the 'ns'
      characters in the device name.

+++
	    drive=`find_drive $thisarch`
	    get_with_default "Enter device" "$drive"
	    src=$ASK_ANSWER
	    tarsrc1=`echo $src | awk '{print $1}'`
	    if [ ! -r "$tarsrc1" ]; then
		echo Cannot read $tarsrc1
		tarsrc1=
	    fi
            cat=zcat # As of 2.1 we compress #2-#n files to fit on 1/4" tape
	done
    elif [ $media = disk ]; then 
        retry=false
	while [ "$tarsrc1" = "" ]; do
            if [ "$retry" = false ]; then
	        cat << +++

Enter the name of the directory that contains the DX installation files.

+++
	        get_with_default "Enter directory name" "$pwd"
	        src=$ASK_ANSWER
            else # give them more help here
	        cat << +++

Enter the name of the directory that contains the DX installation files.
The files "dx_common.tar" and "dx_${arch}.tar" OR "dx_common.tar.Z" and "dx_${arch}.tar.Z"
must be in that directory.  Both files are required for a normal installation.
If this is a special installation, or if the files have different names,
you can explicitly enter one or both filenames below.  If entering two
filenames put them both on the same line separated by a space.

+++
	        get_with_default "Enter directory name or file name(s)" "$pwd"
	        src=$ASK_ANSWER
            fi

	    # ksh will do this correctly, but is not available on SunOS 4.1
            # echo $src | read srcdir remainder
	    srcdir=`echo $src | awk '{print $1}'`
	    if [ ! -r "$srcdir" ]; then
		echo Cannot read $srcdir
		tarsrc1=
	        continue
	    fi
	    # assume they have answered with a directory name.
            if [ -d "$srcdir" ]; then
	        tarsrc1="$srcdir/dx_common.tar"
	        tarsrc2="$srcdir/dx_$arch.tar"
                if [ ! -f "$tarsrc1" ]; then
                    tarsrc1z=${tarsrc1}.Z
                    if [ ! -f "$tarsrc1z" ]; then
                        echo Cannot find file $tarsrc1 or $tarsrc1z
                        tarsrc1=
                        retry=true
                        continue
                    fi
                    tarsrc1=$tarsrc1z
                fi
                if [ ! -f "$tarsrc2" ]; then
                    tarsrc2z=${tarsrc2}.Z
                    if [ ! -f "$tarsrc2z" ]; then
                        echo Cannot find file $tarsrc2 or $tarsrc2z
                        tarsrc1=
                        retry=true
                        continue
                    fi
                    tarsrc2=$tarsrc2z
                fi
                # we have the filename(s) set

	    else # answer was not a dir - also accept 1/2 tar files as input
	        # echo $src | read tarsrc1 tarsrc2 remainder
	        tarsrc1=`echo $src | awk '{print $1}'`
	        tarsrc2=`echo $src | awk '{print $2}'`

                if [ ! -f "$tarsrc1" ]; then
    	            echo Cannot find $tarsrc1
    	            tarsrc1=
                    continue
    	        fi
                if [ ! -z "$tarsrc2" -a ! -f "$tarsrc2" ]; then
    	            echo Cannot find $tarsrc2
    	            tarsrc1=
                    continue
    	        fi
             fi

             # either way we have the names now
    	     x=`echo $tarsrc1 | grep '\.Z$'`
    	     if [ ! -z "$x" ]; then
    	        # Tar file has .Z suffix and so is compressed
    	        cat=zcat
    	        x=`echo $tarsrc2 | grep '\.Z$'`
    	        if [ -z "$x" ]; then
    		    echo Both tar files must be either compressed or not compressed
    		    tarsrc1=
    	            tarsrc2=
                    continue
    	        fi
    	    fi
            # if the files are relative names, force them to be absolute
    	    x=`echo $tarsrc1 | grep '^/'`
    	    if [ -z "$x" ]; then
	        tarsrc1="$pwd/$tarsrc1"
    	    fi
    	    if [ ! -z "$tarsrc2" ]; then
    	        x=`echo $tarsrc2 | grep '^/'`
    	        if [ -z "$x" ]; then
    		    tarsrc2="$pwd/$tarsrc2"
    	        fi
     	    fi	
	done  # while tarsrc1 != ""
    else
        cat << +++

Unrecognized input media.  It must be one of: CD, tape or disk.  Check the
setting of the DXMEDIA environment variable.
+++
        exit 2
    fi     # media: one of CD, tape or disk
fi   # if operation == install

#
# Find out the directory to which we should install DX.
#
targetdir=
while [ "$targetdir" = "" ]; do

    cat << +++

Enter the full name of an existing directory where DX should be ${operation}ed.
The DX software directory tree will be placed there.  The default, and 
recommended directory is /usr/lpp/dx.   

NOTE FOR PREVIOUS DX USERS: Please enter the full directory name here
including the trailing 'dx' if that is where you desire to install dx.
A final directory name of 'dx' is no longer assumed.

Note: In a networked environment in which you plan on running the
      Data Explorer User Interface and Server on separate machines, it
      is best to make the installation directory the same (or at least
      accessible through the same path via symbolic links or NFS mounts)
      on those machines.

+++
    get_with_default "Enter directory" "/usr/lpp/dx"
    targetdir=$ASK_ANSWER
    if [ "$targetdir" = "" ]; then
	targetdir=/usr/lpp/dx;
    fi
    case $targetdir in
	/*) # Accept the input
	    if [ ! -w $targetdir ]; then
		cat << +++

The $targetdir directory is not writable or does not exist.

+++
		ask "Create now"
                if [ $ASK_ANSWER = yes ]; then
		    mkpath $targetdir
                    if [ ! -w $targetdir ]; then
		        cat << +++

Cannot create $targetdir directory.

+++
                        targetdir=
                    fi
                else
 		    targetdir=
		fi
	    fi
	;;
	*)
	   echo "Directory must have a leading slash."
	   targetdir=	
	;;
    esac

done
dxroot=$targetdir
cfg_args="$cfg_args -dxroot $dxroot"

#
# Now let's find out what operation we want to perform.
#
case $arch in
    # Only the sun, dec and aviion don't provide NetLS with the OS.
    solaris|sun4|aviion|alphax) os_provides_ncs=false;;
    *) 		 	        os_provides_ncs=true;;
esac

# set system sizes, first system independent ones, then by arch
pssize=12
docsize=16
sampsize=17
case $thisarch in
    ibm6000)	fullsize=78
		recsize=66
            	rtsize=17
                devsize=16 
		;;
    sun4)       fullsize=85
		recsize=73
            	rtsize=25  
                devsize=16 
		;;  		         
    solaris) 	fullsize=87
		recsize=75
            	rtsize=25  
                devsize=18 
		;;	         
    hp700) 	fullsize=74
		recsize=62
            	rtsize=16  
                devsize=14 
		;;	         
    sgi*) 	fullsize=86
		recsize=74
            	rtsize=18  
                devsize=23 
		;;	         
    aviion) 	fullsize=80
		recsize=68
            	rtsize=22  
                devsize=13 
		;;	         
    alphax) 	fullsize=120
		recsize=107
            	rtsize=34  
                devsize=41
		;;	         
esac
minsize=$rtsize


systems=UNKNOWN
while [ $systems = UNKNOWN ]; do
	cat << +++

Please select the type of ${operation}:

  1. Full (all subsystems, $fullsize Mbytes)
  2. Normal (all subsystems except postscript documentation, $recsize Mbytes)
  3. Minimum (no development tools, no documentation, no samples, $minsize Mbytes)
  4. Custom (choose which subsystems to ${operation})

+++
  get_with_default "Enter Selection" "1"
  action=$ASK_ANSWER
  case $action in
    [1-4]) systems=KNOWN ;;
    *)     echo "Incorrect Input." ;;
  esac
done

case $action in
    1)  subsystems="Run-time Development Online-help Samples Postscript"
	allsystems=true;
	;;
    2)  subsystems="Run-time Development Online-help Samples"
	;;
    3)  subsystems="Run-time"
        ;;
    4)  systems=UNKNOWN
        while [ $systems = UNKNOWN ]; do

            cat << +++

Please select the specific subsystems you would like ${operation}ed:

  1. Base Executable System ($rtsize Megabytes)
  2. Development Environment ($devsize Megabytes)
  3. Samples: visual programs, scripts and data ($sampsize Megabytes)
  4. On-line Help and HTML Documentation Files ($docsize Megabytes)
  5. Postscript and Flat Ascii Documentation Files ($pssize Megabytes)

+++
	    get "Enter Selection(s)" 
	    action=$ASK_ANSWER
	    case $action in
 	      [1-5]*) systems=KNOWN	
	 	      ;;
	      *) echo "Incorrect Input."
    		 ;;
            esac
	done

        subsytems=
        allsystems=false
        for i in 1 2 3 4 5; do
            x=`echo $action | grep $i`
            if [ ! -z "$x" ]; then
                case $i in
    		1)  subsystems="$subsystems Run-time"
    		;;
    		2)  subsystems="$subsystems Development"
    		;;
    		3)  subsystems="$subsystems Samples"
    		;;
    		4)  subsystems="$subsystems Online-help"
    		;;
    		5)  subsystems="$subsystems Postscript"
    		;;
                esac
            fi
	done
	;;
esac

#
# Find out what type of license the user expects to run DX under.
#
UPproduct="5765-586"
SMPproduct="5765-587"

license=UNSPECIFIED
if [ $operation = install -a $thisarch = $arch ]; then
    license=
    while [ -z "$license" ]; do
        cat << +++

Are you installing a:

   1. Temporary Trial Version
   2. Permanently Purchased Product

+++
	get "Enter Selection"
	action=$ASK_ANSWER
        case $action in
	    1)  license=trial 
		support_phone="1-800-435-6813"
	        ;;

	    2) 	support_phone="1-800-237-5511"
	        cat << +++

When you purchased Data Explorer, you specified that it was to run 
on either a single machine or a group of machines.

   1.  Single machine ("Node-Locked")
   2.  A Group of machines ("Concurrent or Floating")

+++

	    get "Enter Selection"
	    action=$ASK_ANSWER
            case $action in
	        1) license=node-locked  
		   product="$UPproduct" 
		   ;;

                2) license=concurrent
		   cat << +++

Which version of Data Explorer did you purchase?

   1.  Single processor (product number $UPproduct)
   2.  Multiprocessor (SMP) (product number $SMPproduct)

+++

	          get "Enter Selection"
	          action=$ASK_ANSWER
		  case $action in
		    1) product="$UPproduct"  ;;
		    2) product="$SMPproduct" 
                       nodeidflag="-smp"
	               ;;
		    *) echo "Incorrect Input."  
		       license=""
		       ;;             
   	          esac
                  ;;

		*) echo "Incorrect Input."  
                   license=""
                   ;;
	    esac
            ;;

	*) echo "Incorrect Input."
	   license=""
	   ;;
        esac
    done
fi

#
# If installing runtime or development subsystems, allow bindir/libdir settings
#
bindir_done=true
libdir_done=true
bindir=
libdir=
for i in $subsystems; do
    case $i in
        Run-time) 
            bindir_done=false
	    ;;
	Development) 
            bindir_done=false
	    libdir_done=false
            ;;
    esac
done
#
#
if [ $bindir_done = false ]; then
    cat << +++

The name of a directory which should be in the user's search path can
be specified here.  The directory must already exist and be writable by
the user running this installation script.  The Data Explorer startup
shell script will be copied here.  For a normal system install, a public
directory such as /usr/local/bin or /usr/bin should be specified (which
generally requires root privileges).  For a private install, a bin directory
under a user's home directory might be specified.  If no directory is given,
then ${dxroot}/bin must be added to a user's search path before running 
Data Explorer.

+++
    while [ $bindir_done != true ]; do
            /bin/csh -f -c 'echo -n "Enter executable directory: "'
            read bindir
            if [ -z "$bindir" ]; then
                ask "Are you sure you do not want to specify a directory"
                if [ $ASK_ANSWER = yes ]; then
                    bindir_done=true
                fi
	elif [ ! -w "$bindir" ]; then
	    echo $bindir is not writable.
	    echo ""
	elif [ "$bindir" = "${dxroot}/bin" ]; then
	    echo "This directory cannot be in the installation directory ("$dxroot")"
	    echo ""
	else
	    bindir_done=true
	fi
    done
    if [ ! -z "$bindir" ]; then
	cfg_args="$cfg_args -bindir $bindir"
    else
	cfg_args="$cfg_args -nobindir"
    fi
fi
#
# Get the name of the library directory
#
if [ $libdir_done = false ]; then
    cat << +++

The name of a directory which will hold symbolic links to the library
files associated with dx can be specified here.  The directory must
already exist and be writable by the user running this installation
script.  For a normal system install, a public directory such as
/usr/local/lib or /usr/lib should be specified (which generally requires
root privileges).  For a private install, no directory should be specified.
Before building Data Explorer modules, the BASE variable in the
Makefiles distributed with the samples should be set to ${dxroot}/lib.

+++
    while [ $libdir_done != true ]; do
	/bin/csh -f -c 'echo -n "Enter library directory: "'
	read libdir
	if [ -z "$libdir" ]; then
	    ask "Are you sure you do not want to specify a directory"
	    if [ $ASK_ANSWER = yes ]; then
		libdir_done=true
	    fi
	elif [ ! -w "$libdir" ]; then
	    echo $libdir is not writable.
	    echo ""
	elif [ "$libdir" = "${dxroot}/lib" ]; then
	    echo "This directory cannot be in the installation directory ("$dxroot")"
	    echo ""
	else
	    libdir_done=true
	fi
    done
    if [ ! -z "$libdir" ]; then
	cfg_args="$cfg_args -libdir $libdir"
    else
	cfg_args="$cfg_args -nolibdir"
    fi
fi



#
# Build a list of files based on the subsystems selected.
#

common_rtfiles="README README_SMP bin fonts lib man ui"
arch_rtfiles="README_${arch} bin_${arch}"
common_devfiles="include"
arch_devfiles="lib_${arch}"
helpfiles="help html"
sampfiles=samples
docfiles=doc

common_files=
arch_files=
runtime=false
develop=false
help=false
samples=false
postscript=false
for i in $subsystems; do
    case $i in
	Run-time)     	
	    common_files="$common_files $common_rtfiles"
	    arch_files="$arch_files $arch_rtfiles"
	    runtime=true
	;;
	Development)
	    common_files="$common_files $common_devfiles"
	    arch_files="$arch_files $arch_devfiles"
	    develop=true
	;;
	Online-help)
	    common_files="$common_files $helpfiles"
	    help=true
	;;
	Samples)  	
	    common_files="$common_files $sampfiles"
	    samples=true
	;;
	Postscript)  	
	    common_files="$common_files $docfiles"
	    postscript=true
	;;
    esac
done

if [ $runtime = true -a $help = false ]; then
    # Include the help not available message
    common_files="$common_files help/HelpNotAvailable"
fi

files=

case $operation in

###########################################################################
#                         Installation Routines                           #
###########################################################################
install)


if [ $media != CD ]; then
    cat << +++

Installation script configured for installation of the following
Data Explorer subsystems for the $arch architecture.

$subsystems

Installation will install DX in $dxroot
from
$tarsrc1
$tarsrc2

+++
else
    cat << +++

Installation script configured for installation of the following
Data Explorer subsystems for the $arch architecture.

$subsystems

Installation is from $media media and will install DX in $dxroot.

+++

fi

ask_proceed
	

if [ $whoami = $superuser ]; then
    tarargs=xvpf
else
    tarargs=xvf
fi

#
# FINALLY, extract the files from the media
#
mkpath $dxroot
if [ $media = disk -o $media = CD ]; then
    dx_untar $tarsrc1 $common_files $arch_files
    if [ $status = 0 -a ! -z "$tarsrc2" ]; then
	dx_untar $tarsrc2 $common_files $arch_files
    fi
else # media is tape
    rew_tape $thisarch $tarsrc1
    if [ $single != true ]; then
	#
	# Unload the common files 
	#
	fsf_tape $thisarch $tarsrc1 1
	dx_untar $tarsrc1 $common_files
	if [ $status = 0 ]; then
	    #
	    # Find out how many files to skip
	    #
	    filenum=1
	    for i in $tape_map; do
		if [ $i = $arch ]; then
		     break
		fi
		filenum=`expr $filenum + 1`
	    done
	    firsttape=true
	    if [ $filenum -gt $qic150files ]; then
		ask 'Is this a 1/4 inch (QIC-150) tape'
		if [ $ASK_ANSWER = "yes" ]; then
		    firsttape=false
		fi	
	    fi
	    if [ $firsttape = true ]; then
		# we skipped the first file and read the 2nd already
		filenum=`expr $filenum - 2`	
	    else
		rew_tape $thisarch $tarsrc1
		echo 'Please replace tape #1 with tape #2 in the drive.'
		ASK_ANSWER=no
		while [ "$ASK_ANSWER" != "yes" ]; do
		    ask 'Is tape #2 in the tape drive' 
		done
		rew_tape $thisarch $tarsrc1
		filenum=`expr $filenum - $qic150files`	
	    fi
	    #
	    # Unload the architecture specific files 
	    #
	    skips=`expr $filenum - 1`	
	    fsf_tape $thisarch $tarsrc1 $skips
	    dx_untar $tarsrc1 $arch_files
	fi
    else
	cat=cat
	dx_untar $tarsrc1 $common_files $arch_files
    fi
fi

if [ $whoami = $superuser ]; then
    $ECHO chown -R bin.bin $dxroot
fi

if [ $status = 0 ]; then
    cat << +++

Installation of the following Data Explorer subsystem(s) was successful:

    $subsystems

+++
else
    cat << +++

Installation of the following Data Explorer subsystem(s) was unsuccessful:

    $subsystems

+++
    exit $status
fi

if [ $noconfig = true ]; then
    cat << +++
Skipping configuration at your request (-noconfig option).

The installation process is now complete.

+++
    exit 0
elif [ $thisarch = $arch ]; then
    cat << +++
Beginning configuration of Data Explorer for this workstation.

+++
else
    cat << +++
Installation was performed FOR an architecture other than the architecture
FROM which the installation was performed (i.e. $thisarch != $arch).
Therefore, we are skipping the configuration of Data Explorer for this
workstation.  You will need to run $dxroot/bin/Configure
on the workstations which you expect to use this installation tree.
You will also need to run "dx -nodeid" to get the license key
information needed to enable Data Explorer if you are not using 
a concurrent NetLS license server.

The installation process is now complete.

+++
    exit 0
fi

#
# Now configure the installation
#
failed_systems=
dxstatus=0
if [ "$dbg" = on ]; then
    cfg_args="-check $cfg_args"
fi
for i in $subsystems; do
    #
    # Configure each subsystem separately so we can tell which ones failed
    #
    flag=
    case $i in
	Run-time) 	flag=-runtime ;;
	Development) 	flag=-develop;;
	Online-help) 	flag=-online-help;;
	Samples) 	flag=-samples;;
	Postscript)     flag=-postscript;;
	*)		echo Unexpected subsystem
			exit 1
	;;
    esac
    if [ ! -z "$flag" ]; then
	if [ -f $dxroot/bin/Configure ]; then
	    echo Executing: $dxroot/bin/Configure $flag $cfg_args
	    $dxroot/bin/Configure $flag $cfg_args
	    status=$?
	elif [ "$dbg" = on ]; then  # this is for debugging this script
	    echo Executing: ./Configure $flag $cfg_args
	    ./Configure $flag $cfg_args
	    status=$?
        else
            cat << +++

The Configuration file "$dxroot/bin/Configure" 
was NOT found.  Configuration must be run before
DX is ready for use.  Check the $dxroot/bin directory
for the status of the "Configure" file.

+++
            failed_systems="$failed_systems Configuration"
            dxstatus=1
            break
	fi
	if [ $status != 0 ]; then
	    if [ $status = 10 ]; then
		echo Installation terminated.
		exit 10;
	    fi
	    failed_systems="$failed_systems $i"
	    dxstatus=1
	fi
    fi
done


if [ $dxstatus != 0 ];  then
    cat << +++

Configuration of the following Data Explorer subsystem(s) has failed:

    $failed_systems

Contact your IBM software support center at $support_phone if you
need assistance.

+++
else

    cat << +++

Configuration of the following Data Explorer subsystem(s) was successful:

    $subsystems

+++

fi

#
# Give the installer a chance to see what happened.
#
ask_proceed


case $license in
    concurrent)
        cat << +++

You must ensure that a license server is installed on your network.
You must supply the output of "ls_targetid" from the machine where
the license server is running to get your permanent license key.

If this current machine is intended to be a license server, the Network
Computing System (NCS) software MAY already be supplied as part of your
vendor's Operating System distribution media (if it is not already installed).

We provide license server software on our installation media primarily
to support downlevel operating systems and to resolve compatibility
issues for certain platforms.  With this in mind, PLEASE adhere to the
following:

    Use the license server (NetLS(tm) or the newer iFOR/LS(tm)) that is
    already set up on your network OR that is distributed with your
    operating system, WITH A FEW EXCEPTIONS.  A notable exception are
    certain SGI Irix distributions containing an incompatible build of the
    server software.

    DO NOT use the Data Explorer distribution media and installation tools
    to install a license server UNLESS you have determined that an
    appropriate level of iFOR/LS(tm) or NetLS(tm) is NOT already installed
    on your server or distributed with its operating system.

If you determine you must install the NCS software from the DX distribution
media, you can do so by running the following commands after the end of the
install process:

+++
        if  [ $media != CD ]; then
	    cat << +++
    tar xvf <device> install_lsk
    install_lsk

+++
        else
	    if [ "$lscase" = upper ]; then
	        echo ./INSTALL_LSK$suffix
	    else
	        echo ./install_lsk$suffix
	    fi
        fi

	cat << +++
Is the NetLS license server machine a different machine than 
the one which this install is currently running on?
+++
	ask "Different machine"
	answer=$ASK_ANSWER
	if [ "$answer" = "no" ]; then
	    $dxroot/bin/NodeID -dxroot $dxroot $license $nodeflag
	else
	    cat << +++
You will have to run either "dx -nodeid" or ls_targetid
on the NetLS server machine.  ls_targetid may be found in one
of the following directories: /usr/lib/netls/bin, /usr/netls/bin
or /var/netls/bin.
+++
	fi
	ask_proceed
    ;;
    node-locked)
	case $arch in
	  aviion|sun4|solaris|alphax)
	    if [ -w /var ]; then
		# Make sure the nodelock file exists (not absolutely necessary).
		mkpath /var/netls
		touch  /var/netls/nodelock
	    fi
	    ;;
	  sgi|hp700)
	    if [ -w /usr ]; then
		# Make sure the nodelock file exists (not absolutely necessary).
		mkpath /usr/netls
		touch  /usr/netls/nodelock
	    fi
	    ;;
	  *)
	    if [ -w /usr/lib ]; then
		# Make sure the nodelock file exists (not absolutely necessary).
		mkpath /usr/lib/netls/conf
		touch  /usr/lib/netls/conf/nodelock
	    fi
	    ;;
	esac

        $dxroot/bin/NodeID -dxroot $dxroot $license $nodeflag

	cat << +++

The license information can be obtained at anytime by running:
  dx -nodeid

+++
    ;;
    trial)
	#Don't do this since it gets in the way of DXTRIALKEY
	#touch $dxroot/expiration

        $dxroot/bin/NodeID -dxroot $dxroot $license $nodeflag

        cat << +++

The license information can be obtained at anytime by running:
  dx -nodeid

+++
    ;;
    *)
        echo Unknown license type.
        exit 1
    ;;
esac


cat << +++

The installation and configuration process is now complete.
Contact your IBM software support center at $support_phone if you
have any questions regarding your installation.

+++

;;

###########################################################################
#                       UnInstallation Routines                           #
###########################################################################
deinstall)

if [ "$allsystems" = "true" ]; then
    cat << +++

De-installation will remove all files in, and support files external to,
the $dxroot directory tree.

+++
else
    cat << +++

De-installation will remove support files external to the
$dxroot directory tree.  You will then be allowed to remove the
the $dxroot directory or a subset of the files there.

+++

fi

echo "This is your last chance to quit the ${operation}ation process!"
ask_proceed

if [ $thisarch = $arch ]; then
    if [ "$dbg" = on ]; then
	cfg_args="-check $cfg_args"
    fi
    if [ -f $dxroot/bin/Configure ]; then
	echo Executing: $dxroot/bin/Configure $cfg_args
	$dxroot/bin/Configure $cfg_args
	dxstatus=$?
    elif [ "$dbg" = on ]; then # this is for debugging this script
	echo Executing: ./Configure $cfg_args
	./Configure $cfg_args
	dxstatus=$?
    else
        cat << +++

The Configuration file "$dxroot/bin/Configure" 
was NOT found.  ${operation}ation may not be complete.

+++
    fi
fi

echo ""
echo PLEASE NOTE: You can now execute the following command...
echo ""
if [ "$allsystems" = "true" ]; then
    echo "  " rm -r -f $dxroot
else
    echo "  " rm -r -f $arch_files $common_files
fi

;;
*)
;;
esac	# end of switch on operation
	

