#!/bin/csh -f
#Tag 1024

#    The preceding tag label has to be on line 2 or the workspace/desktop views
#    do not recognize it properly.


# InstallAlias: loads the contents of the ALIAS Software and customizes the user
#               environment so that the package can be run. The ALIAS Software
#               tape contains 3 separate tar images:
#
#               - Installation tools
#
#               - Optional system support files
#
#               - ALIAS software
#
#           while the ALIAS 3D Software area on the Alias CD-ROM contains a
#           hierarchy of files which includes:
#
#               - Optional system support files
#
#               - ALIAS software
#
#           and 3 install tools:
#
#               - Install       (master install script)
#
#               - InstallAlias  (installs Alias software)
#
#               - InstallTablet (customizes Alias tablet setup)
#
#           and selected other packages that the installer may find
#           interesting.
#
#           The CD-ROM also contains the 3DCD Digital Content Library.
#
#    The following steps are performed to install the ALIAS software:
#
#    1) Set a default search path:
#
#       The components of the search path are directories that contain tools
#       which are used to load the ALIAS software.
#
#    2) Verify that the installer is root:
#
#       If the installer is not root, inform them that the Install procedure
#       must be run as root. Prompt them for the root password (via su) and
#       execute InstallAlias in a root subshell. If the installer fails to
#       specify the root password in 3 attempts, ask them to try again later
#       and exit.
#
#    3) The InstallAlias procedure is capable of installing one of six ALIAS
#       software packages on machines running IRIX 5:
#
#           Alias Studio
#           Alias Designer
#           Alias PowerAnimator
#           Alias Animator
#           Alias AutoStudio
#           Alias Render Software
#
#       Before the installation can begin, InstallAlias must be informed which
#       software package is being installed. This can be done in one of two
#       ways:
#
#       If any of the following environment variables are set (by the master
#       Install script), it indicates which software package is to be installed:
#
#           Environment variable | Software Package
#           ---------------------+--------------------
#                STUD3D          | Alias Studio
#                DES3D           | Alias Designer
#                PANIM3D         | Alias PowerAnimator
#                ANIM3D          | Alias Animator
#                ASTUD3D         | Alias AutoStudio
#                REND3D          | Alias Render
#
#       If none of the environment variables are set, InstallAlias asks the
#       installer to indicate which software package they wish to install.
#
#       In all cases (studio, designer, power animator, animator and render),
#       the software will be installed in a directory named aliasYYMM (where
#       YYMM are the year and month of the release).
#
#       In all cases, the username of the default demo account is aldemo.
#
#       If a machine is running a variant of IRIX 4, the Alias software cannot
#       be installed as it will not run due to incompatible executable file
#       formats.
#
#    4) Determine if the installer is a guru. If InstallAlias runs in guru (or
#       advanced) mode, it may ask some detailed questions about how the
#       installation of the ALIAS software should proceed. It will try not to
#       assume anything.
#
#       If InstallAlias does not run in guru mode, it will tend to assume some
#       of the more detailed unix things and not ask the installer for their
#       opinion.
#
#       The choice of whether to run in guru mode is indicated by the `-g'
#       flag on the command line. If the flag is present, InstallAlias runs
#       in guru mode.
#
#    5) Determine where InstallAlias will place its working files. Search for
#       a writable temporary directory among the following directories:
#
#           /var/tmp
#           /usr/tmp
#           /tmp
#
#       InstallAlias will place its temporary files in one of these directories.
#
#    6) Set the file creation mask (umask) to 022 so that when files are created
#       (i.e.: read off the distribution media), they will be readable by
#       everyone but only writable by the owner.
#
#    7) Determine the type of media from which the Alias software will be
#       installed:
#
#       The Alias software may be installed from CD-ROM or tape (local or
#       remote).
#
#       If the environment variable ALIAS_CDLOCN is set, it represents the full
#       pathname of the mount point of the Alias CD-ROM. This environment
#       variable is set by the master install script (Install). The Alias
#       software will be installed from the Alias CD-ROM mounted at the location
#       specified by ALIAS_CDLOCN.
#
#       If ALIAS_CDLOCN is not set, InstallAlias asks the installer if they wish
#       to install the software from a CD-ROM. If they say `yes', InstallAlias
#       asks the installer to specify the mount point of the CD-ROM.
#
#       Once, the mount point of the CD-ROM is known ($ALIAS_CDLOCN or installer
#       specified), InstallAlias verifies the contents of the CD-ROM. If the
#       contents of the CD-ROM are valid, the installation continues, else
#       InstallAlias exits with an explanatory error message. After the
#       CD-ROM has been validated, InstallAlias runs `getid -i' to display
#       machine dependent information and asks the installer to compare it
#       against the requirements for Alias software listed in the documentation.
#       The installer should make sure their machine meets the suggested
#       requirements. InstallAlias then asks the installer if they wish to
#       continue with the installation. If they say `yes', the installation
#       continues, else InstallAlias exits.
#
#       If the Alias software is not being installed from CD-ROM, InstallAlias
#       asks the installer if they are installing from tape. If they say `no',
#       it informs them that the software may only be installed from CD-ROM or
#       tape and exits. If they say `yes' to installing from a tape,
#       InstallAlias asks them if the tape drive is connected to the machine.
#       If they say `yes', InstallAlias (with installer interaction) determines
#       the (rewinding and non-rewinding) device names of a local tape drive
#       that can be used for the installation. If the installer says `no' to
#       installing from a local tape drive, InstallAlias asks them if they wish
#       to install the software using a remote tape drive. If they say `no',
#       InstallAlias tells them that once they know which tape device they wish
#       to use, they should attempt the installation again, then exits. If they
#       say `yes' to installing using a remote tape drive, InstallAlias queries
#       them for three pieces of information:
#
#       - the hostname of the machine with the tape drive
#       - the username of a user account on the remote host which will be
#         used to perform remote commands on the remote host
#       - the full pathname of a rewinding tape device on that machine (only if
#         the default tape devices do not exist OR are not used for the
#         installation).
#
#       Given this information, InstallAlias verifies the remote hostname
#       (queries DNS and/or hosts file) and verifies that remote commands
#       between your machine and the remote host succeed. If this fails,
#       InstallAlias lists a number of possible reasons for the failure and
#       asks the installer to check them out. Once the execution of remote
#       commands has been verified, InstallAlias (with installer interaction)
#       determines the (rewinding and non-rewinding) device names of a tape
#       drive on the remote host. It verifies that the tape drive is accessible
#       and available for the installation.
#
#       At the end of this step (assuming no errors have occurred), InstallAlias
#       will know the type of media to use for the installation of the Alias
#       software (CD-ROM or tape) and its location (CD-ROM mount point or
#       tape device names for rewinding and non-rewinding tape devices).
#
#    8) Determine the space requirements of the software:
#
#           - Render software requires 50 megabytes
#
#           - Full ALIAS software requires 150 megabytes
#
#    9) Get a copy of the old Alias encryption file:
#
#       If the encryption file is not empty, make a copy of it. Since some old
#       Alias encryption strings work with the new Alias software, InstallAlias
#       will append the contents of the copied encryption file to the new
#       encryption file after the new Alias software is installed (see step
#       #20).
#
#   10) Save any system files that may be modified during an attempt to install
#       the ALIAS software:
#
#       Foreach filename, if filename.pre_alias does not exist, copy filename
#       to filename.pre_alias.
#
#       When the installation succeeds, the saved files reflect the state of the
#       system before the ALIAS software was installed.
#
#       The files affected by this step are:
#
#           /etc/magic
#           /etc/passwd
#           /usr/lib/workspace/sgidefault.wsrc
#
#   11) Find all filesystems that have sufficient free disk space for the
#       ALIAS software.
#
#       Find the amount of free disk space available on each local filesystem:
#
#       All disk space information is specified in units of kilobytes (rounded
#       up).
#
#       The disk space required for the ALIAS software is approximately 150Mb
#       and 50Mb for the render software. If there are no filesystems with
#       sufficient disk space, echo an error message and exit.
#
#   12) Choose the host filesystem and directory for the ALIAS software:
#
#       If only one writable filesystem has sufficient free disk space, it is
#       chosen by default; else inform the installer of the "the writable
#       filesystems with sufficient disk space" and let them choose where the
#       ALIAS software is to be installed ($sftwfs).
#
#       Once it has been determined on what filesystem the ALIAS software is to
#       be installed, ask the installer where the software should be installed
#       on the filesystem.
#
#       Ask the installer if they wish to install the ALIAS software in
#       /<dir>/aliasYYMM, where /<dir> is the name of a directory on a local
#       writable filesystem where the software will be installed:
#
#       If a machine has one or more writable filesystems with sufficient disk
#       space for the Alias software, the value of /<dir> will be the name of a
#       filesystem where the installer wishes to install the software (i.e.:
#       /usr). In this case, the root filesystem (/) is removed from the list
#       of filesystems considered as target filesystems for the installation of
#       the Alias software.
#
#       If a machine has one or more writable filesystems, but the root
#       filesystem is the only writable filesystem with sufficient disk space
#       and /usr is a writable filesystem, the value of /<dir> will be /. The
#       installer will have the option of specifying an alternate location for
#       the software or approving its installation at the suggested location.
#
#       If a machine has one writable filesystem (the root filesystem) and it
#       has sufficient disk space for the software, the value of /<dir> will be
#       /usr which is where InstallAlias would like to install the software.
#
#       and aliasYYMM is a directory indicating the Alias software and its
#       release date.
#
#       If the installer doesn't want to install the software in
#       /<dir>/aliasYYMM, ask them where they do want it.
#
#       When the installer specifies a location for the ALIAS software, verify
#       that:
#
#       - the directory is located in the filesystem that the installer approved
#       - the name of the directory is aliasYYMM (for identification purposes)
#
#       If any of these points are not met, InstallAlias warns the installer and
#       asks them to specify a location which matches the criteria.
#
#       Assuming everything goes okay, the shell variable `sftwdir' will contain
#       the pathname of the directory where the ALIAS software will be
#       installed, pending installer approval.
#
#   13) Verify that the home directory for the ALIAS software does not exist:
#
#       The ALIAS software will be loaded in a directory specified by the
#       installer, that ends with aliasYYMM. If this directory already exists
#       (i.e.: if ALIAS software has been installed), InstallAlias will ask the
#       installer for approval to remove the directory and replace it with the
#       ALIAS software on the distribution media. If they say `no', explain the
#       situation and exit; else remove the file/directory and continue with the
#       installation.
#
#   14) Create a symbolic link between the home of the ALIAS software and
#       /usr/alias (i.e: /usr/alias ->  /usr/aliasYYMM):
#
#       If /usr/alias is a symbolic link and it's target is the home of the
#       ALIAS software, the link is correct.
#
#       If /usr/alias exists (and it is not a symbolic link to the home of the
#       ALIAS software), inform the user of it's existence and give them
#       the option to remove it. If they say `no', print an error message which
#       explains the problem and exit; else remove /usr/alias and form a
#       symbolic link from /usr/alias to the home of the ALIAS software.
#
#   15) Create/Verify an account for the owner of the ALIAS software:
#
#       This section of InstallAlias operates in one of two modes; guru and
#       non-guru modes.
#
#       If InstallAlias is running in guru mode, the installer has the ability
#       to specify who should own the ALIAS software when it is installed.
#
#       If InstallAlias is not running in guru mode, it will install/verify the
#       dist account and install the software such that it is owned by dist.
#
#       First, a description of how the code operates in guru mode:
#
#       - Ask the installer who should own the ALIAS software.
#       - If there is a password entry for the specified user, an owner for the
#         software has been found.
#       - If there is no password entry for the specified user, construct one.
#         Inform the installer that they will be given the option of picking the
#         value of each password field and that InstallAlias will pick the value
#         if they do not.
#       - If the installer does not specify the numeric userid for the user,
#         InstallAlias will choose an unused value and report it to the
#         installer.
#       - If the installer does not specify the group for the user, the user
#         is placed in group 20 (user group on default SGI systems).
#       - Ask the installer where they want the user's home directory to be
#         located. It is preferred if the installer specifies /usr/alias for
#         the home directory so that the account acts as a administrator for
#         the ALIAS software. Verify that the specified home directory is a
#         full pathname (starts with /) and not a file.
#       - Inform the installer that the default shell for the account is csh.
#       - Once the password entry for the user is complete, ask the installer
#         if they wish to add it to the local password file. If they say `yes',
#         the password entry is added to the password file. This user will own
#         the ALIAS software.
#       - Inform the installer that they may wish to set a password on the
#         owner account. If a password is not set, it will remain "starred"
#         and no one will be able to login to the account.
#       - If an owner for the ALIAS software has not been found (if the
#         installer answered `no' to the above question), ask the installer if
#         they wish to specify another potential owner for the software. If
#         they say `no', InstallAlias exits; else ask them who should own the
#         ALIAS software. This process is repeated until an owner for the
#         software is found or InstallAlias exits.
#
#       Now a description of how the code operates in non-guru mode:
#
#       - If there is no password entry for the dist account, search for a
#         possible value for dist's userid.
#       - When an unused userid has been found, add a password entry for the
#         dist account with the userid just chosen, default user group and a
#         home directory of /usr/alias, where /usr/alias is a symbolic link
#         to the directory containing the ALIAS software (see previous step).
#       - Inform the user that the chosen userid and default group id have
#         been assigned to the dist account.
#       - Ask the installer to specify a password for the dist account.
#       - Report the location of dist's home directory
#
#       The remainder of this step is common to guru and non-guru mode. If the
#       home directory of the owner user is not /usr/alias (symbolic link to
#       the ALIAS software), the following steps are performed:
#
#       If the home directory exists, but is not owned by the owner user (dist
#       or installer specified), ask the installer if the ownership should be
#       changed, explaining that if the ownership is not changed, the owner
#       account may not be able to create files in the directory.
#
#       If the installer says `yes', change the ownership of the home directory
#       to be owned by the owner user.
#
#       If the specified home directory is not a directory, inform the
#       installer.
#
#       If the home directory of the owner account is a symbolic link whose
#       target does not exist (i.e.: the test for existence above has failed),
#       determine the target of the symbolic link and inform the installer that
#       it should be created or no one will be able to login to the owner
#       account (no home directory). If they say `yes', create the target of the
#       symbolic link and fix permissions.
#
#       If they say `no', inform the installer that no one will be able to login
#       to the owner account.
#
#       If the home directory of the owner account does not exist and it is not
#       a symbolic link, create it and set permissions (ownership, group and
#       access mode).
#
#   16) If InstallAlias is using a remote tape drive to install the ALIAS
#       software, verify that the owner of the software (installer specified or
#       `dist') can access the tape drive. The type of verification depends on
#       the name of the remote user. If the owner of the software is root, no
#       verification is necessary: it has been verified (at the beginning of
#       InstallAlias) that root can execute remote commands on the remote host.
#
#       Otherwise, the following entry must appear in the .rhosts file in
#       the remote users' home directory on the remote machine:
#
#       <hostname of current machine> <username of owner of the software>
#
#       The hostname portion of the entry should include your domain name (if
#       you have a domain name) or remote commands may fail. If the username
#       of the remote user is the same as the owner of the software, the
#       username portion of the entry is not required. If the entry is not
#       present, the owner of the software will not be able to run commands
#       using the remote user's account on the remote machine. In this case,
#       InstallAlias informs you of the problem and exits.
#
#   17) Conditionally create a demo account for the ALIAS software:
#
#       This section of InstallAlias operates in one of two modes; guru and
#       non-guru modes.
#
#       If InstallAlias is running in guru mode, ask the installer if they wish
#       to create a demo account for the ALIAS software. If they say `yes', a
#       demo account will be verified/created. If they say `no', InstallAlias
#       continues without a demo account.
#
#       if InstallAlias is not running in guru mode, a default demo account will
#       be verified/created.
#
#       First, a description of how the code operates in guru mode:
#
#       - Ask the installer the username of the demo account.
#       - If the installer specified a demo account whose password entry exists,
#         set have_demo to indicate that a demo account has been found.
#       - If there is no password entry for the specified user, construct one.
#         Inform the installer that they will be given the option of picking the
#         value of each password field and that InstallAlias will pick the value
#         if they do not.
#       - If the installer does not specify the numeric userid for the user,
#         InstallAlias will choose an unused value and report it to the
#         installer.
#       - If the installer does not specify the group for the user, the account
#         is placed in group 20 (user group on default SGI systems).
#       - Ask the installer where they want the user's home directory to be
#         located. Verify that the specified home directory is a full pathname
#         (starts with /) and not a file.
#       - Inform the installer that the default shell for the account is csh.
#       - Once the password entry for the user is complete, ask the installer
#         if they wish to add it to the local password file. If they say `yes',
#         the password entry is added to the password file and the have_demo
#         flag is set. This user will act as the demo account for the ALIAS
#         software.
#       - Inform the installer that they may wish to set a password on the
#         demo account. If a password is not set, it will remain "starred"
#         and no one will be able to login to the account.
#       - If the demo account has not been setup (if the installer answered `no'
#         to the above question), ask the installer if they wish to specify
#         another potential demo account. If they say `no', InstallAlias
#         continues without a demo account; else ask them the name of the demo
#         account. This process is repeated until a demo account is setup or the
#         installer indicates they do not want one.
#
#       Now a description of how the code operates in non-guru mode:
#
#       As described in step #3, the username of the default demo account is
#       aldemo.
#
#       - If there is a password entry for the demo account, set the have_demo
#         flag to indicate that a demo account has been found.
#       - If there is no password entry for the specified user, construct one.
#       - Search for a possible value for the userid. When an unused userid has
#         been found, inform the installer that the demo account has been
#         assigned the chosen userid and will be in the default user group.
#       - Find a host filesystem for the home directory of the demo account.
#         If the root filesystem (/) is the only writable local filesystem,
#         the home directory will be on the root filesystem, else the home
#         directory will be on one of the other local writable filesystems
#         (<fsys>/aldemo). If the root filesystem is the only writable
#         filesystem and /usr is a writable directory (NOT a filesystem),
#         the home directory will be /usr/aldemo, else the home directory
#         will be /aldemo.
#       - Add the complete password entry to the password file and set the
#         have_demo flag.
#       - Ask the installer to specify a password for the aldemo account.
#       - Inform the installer of the location of the demo account's home
#         directory.
#
#       The remainder of this step is common to both guru and non-guru mode:
#
#       If the home directory of the demo account exists, but is not owned by
#       the demo user, ask the installer if the ownership should be changed,
#       explaining that if the ownership is not changed, the demo account will
#       not be customized to use the Alias software:
#
#       If the installer says `yes', change the ownership of the home directory
#       to be owned by the demo user. The group membership may not match that
#       of the demo user, but it isn't key to the operation of the software.
#
#       If the installer says `no', unset the have_demo flag to indicate that
#       there is no demo account to be customized.
#
#       If the specified home directory is not a directory, inform the installer
#       and unset the have_demo flag to indicate that there is no demo account
#       to be customized.
#
#       If the home directory of the demo account is a symbolic link whose
#       target does not exist (i.e.: the test for existence has failed),
#       determine the target of the symbolic link and inform the installer that
#       it must be created in order for the demo account to be customized to
#       use the Alias software (if it isn't created, the demo account will not
#       have a home directory). If they say `yes', create the target of the
#       symbolic link and fix permissions.
#
#       If they say `no', inform the installer that the demo account will not be
#       customized to use the Alias software.
#
#       If the home directory of the demo account does not exist (test for
#       existence failed and it is not a symbolic link), create it and set
#       permissions (ownership, group and access mode).
#
#   18) If the home directory for the ALIAS software does not exist, create it
#       and fix the permissions.
#
#   19) Install the ALIAS software:
#
#       Change directories to the home of the ALIAS software and extract the
#       software from the distribution tape or "copy" it from the CD-ROM (via
#       tar) to disk. Installation of the software is performed using the set
#       owner on extract option ('o') of tar while su'ed to the owner of the
#       software (see step #15). This sets the ownership of all ALIAS files to
#       the owner of the software as they are written to disk. After the
#       extraction or "copy" is complete, check the status of the operation to
#       verify that it completed successfully. If an error occurred, inform the
#       installer of the problem and ask them if they wish to try the
#       installation again. If they answer `yes', InstallAlias reattempts the
#       installation; else abort the installation and exit.
#
#       The Alias software may be distributed on a tape or compact disk. When
#       the software is distributed on tape, it must be compressed in order for
#       all of it to fit on one tape. Since a compact disk has greater storage
#       capacity than a tape, there is no need to compress the software.
#       Consequently, if you are installing the software from a distribution
#       tape, the individual files must be uncompressed after they are extracted
#       from the tape:
#
#       If the main executable $sftwdir/bin/Alias is compressed, InstallAlias
#       uncompresses it first. Since all other files remain compressed while
#       this is done, it should not exceed the disk space InstallAlias has said
#       is necessary to install the software.
#
#       In order to uncompress the remainder of any compressed files,
#       InstallAlias runs a find command which uncompresses them.
#
#   20) If InstallAlias made a copy of the old Alias encryption file before the
#       new Alias software was installed (see step #9), append its contents to
#       the new encryption file (/usr/alias/sys/install/en). This should allow
#       the new Alias software to run on completion of this script.
# 
#       Remove the saved encryption file after its contents have been added to
#       the new encryption file.
#
#   21) Fix permissions of the ALIAS software so that only the owner of the
#       software may modify the files (remove write permissions for others),
#       but everyone may read them. When tar extracts files from tape, it
#       attempts to restore their original permission modes. The value of the
#       umask has no control on the modes of these files.
#
#   22) Setup/Clean the demo account's home directory:
#
#       If a demo account exists (have_demo flag is set) and InstallAlias is
#       running in guru mode, ask the installer if they wish to customize it
#       to use the ALIAS software. If they say `no', InstallAlias informs the
#       installer how to customize the account at a later time. If they say
#       `yes' or InstallAlias is not running in guru mode, customize the demo
#       account to use the Alias software.
#
#       If the demo account's dotfiles (.cshrc, .login, .Xresources, .4Dwmrc
#       and .mwmrc) and/or its login icon file exist and an original copy of
#       each file has not been renamed to file.pre_alias, rename the dotfiles to
#       <file>.pre_alias (i.e.: .cshrc becomes .cshrc.pre_alias). Add the
#       original filename to the list of "saved system files". If InstallAlias
#       did not complete, the original dotfiles (.cshrc.pre_alias, etc) may
#       still exist and have to be "cleaned up" (renamed to filename= or
#       removed) when InstallAlias successfully completes.
#
#       Copy the new .cshrc, .login, .Xresources, .4Dwmrc and .mwmrc files to
#       the demo account's home directory and fix ownerships. (These files set
#       variables that are key to the operation of the ALIAS software). Note
#       that the .mwmrc file is actually a link to the .4Dwmrc as their contents
#       are identical. Also copy the login icon from /usr/alias/.icons to the
#       demo account's home directory (creating the .icons directory in the
#       home directory if necessary).
#
#       If there is a .AliasPrefs file in the demo account's home directory,
#       ask the installer to ensure that it is not out of date with respect to
#       the ALIAS software (compare it with /usr/alias/.AliasPrefs).
#
#   23) Enable the file command to recognize Alias format files:
#
#       Search /etc/magic for entries which describe Alias format files. The
#       magic file contains a number of definitions which allow the file command
#       to identify a number of different file formats. If the entries
#       describing Alias format files do not appear to be in the magic file and
#       InstallAlias is running in guru mode, ask the installer if they wish to
#       add the entries to the file. If they say `yes' or InstallAlias is not
#       running in guru mode, the entries are added to the magic file.
#
#   24) Conditionally enable virtual swap:
#
#       If the machine is running a variant of IRIX 5 and the vswap chkconfig
#       option (enable or disable virtual swap) is off, conditionally enable
#       it.
#
#       If InstallAlias is running in guru mode, inform the installer that
#       virtual swap must be enabled in order for the Alias software to
#       function correctly. Ask the installer if they wish to enable virtual
#       swap. If they say `yes' or InstallAlias is not running in guru mode,
#       enable virtual swap.
#
#   25) Conditionally optimize the size of virtual swap:
#
#       If the vswap chkconfig option (virtual swap) is on, inspect the size of
#       virtual swap which is set in /etc/config/vswap.options. If the size of
#       virtual swap is not equal to the total sum of main memory and all swap
#       partitions, InstallAlias would like to change the size. If InstallAlias
#       is running in guru mode, it informs the installer of the situation and
#       asks them if they wish to change the size of the virtual swap space. If
#       they say `yes' or InstallAlias is not running in guru mode, InstallAlias
#       updates the size in the options file and informs the installer that the
#       change will not take affect until the machine is rebooted.
#
#   26) Setup render control area:
#
#       In order to support distributed rendering with the Alias software, a
#       render control directory must be created. This directory must be world
#       writable in order to allow any Alias user to write to the directory.
#
#       By default, the render control area will be /usr/alias/render_control,
#       but customers do have the option of creating a shared area at a later
#       time:
#
#       If the machine has NFS enabled, inform the installer that they may wish
#       to setup a common render control area which is equally accessible from
#       all machines which have NFS enabled. The details for this are in the
#       Alias documentatioAlias documentationn.
#
#       InstallAlias makes the directory equally accessible for all users.
#
#   27) If InstallAlias is installing Alias software from a CD-ROM and a demo
#       account exists, conditionally install a set of tutorials in the home
#       directory of the demo account:
#
#       If InstallAlias is installing from a CD-ROM, there should be a set of
#       tutorial files in:
#
#           <mount point of CD-ROM>/Products/Common/3DCD/CourseWare
#
#       If the tutorial directory exists and there is a demo account whose
#       home filesystem has sufficient disk space for the tutorials, ask the
#       installer if they wish to install the tutorials in the demo accounts
#       home directory. If they say `yes', install the tutorials in
#       user_data/CourseWare in the demo accounts home directory.
#
#       If the tutorials are not installed (insufficient disk space or installer
#       disapproval about the installation), give instructions on how to install
#       the tutorials at a later time.
#
#       If the tutorials were installed successfully, remove any write
#       permissions so that the tutorial files can't be modified.
#
#   28) Conditionally copy the 3DCD examples to disk:
#
#       If InstallAlias is installing Alias software from a CD-ROM and the 3DCD
#       Digital Content Library (a set of example files) exists, conditionally
#       copy the library examples to disk:
#
#       If /usr/alias/3DCD already exists, ask the installer if they wish to
#       remove it. If they `yes', remove the file/directory and continue with
#       the installation. If the installer says `no', don't touch
#       /usr/alias/3DCD and skip any further processing of the example files.
#       This case should never happen as the Alias software is not shipped with
#       an existing 3DCD directory in /usr/alias.
#
#       If /usr/alias/3DCD does not exist, do the following:
#
#       - If there is sufficient disk space for the example files (215Mb), ask
#         the installer if they wish to copy them from the CD-ROM to disk. If
#         they say `yes', ask them where they want the files installed and copy
#         them to disk. If the examples are not installed in /usr/alias/3DCD,
#         create a symbolic link, /usr/alias/3DCD which points to the directory
#         where the examples are installed.
#
#       - If there is insufficient disk space or the installer does not want to
#         copy the example files to disk or the desired location for the example
#         files (any location other than /usr/alias/3DCD) exists and the
#         installer doesn't want to remove it, form a symbolic link,
#         /usr/alias/3DCD that "points" to the library example files on the
#         CD-ROM. The examples are accessible (via this link) as long as the
#         CD-ROM is mounted at its current mount point:
#
#             /usr/alias/3DCD -> <mount point of CD-ROM>/Products/Common/3DCD
#
#   29) If render software is being installed and a demo account exists, create
#       three directories in ~<demo account>/user_data/demo (default
#       ALIAS_RENDER_LOCATION):
#
#           mask
#           pix
#           sdl
#
#       then skip to the file renaming process (goto step #37). These
#       directories are required for remote rendering.
#
#   30) Conditionally setup the IRIX Workspace/Desktop:
#
#       There are two IRIX software packages which offer a user a graphical
#       view of the system. These are the IRIX Workspace and Indigo Magic (Also
#       referred to as the desktop software throughout this script). If the
#       machine is an Indy or the desktop chkconfig option is on, the machine
#       has the Indigo Magic software, else it has the Workspace software.
#
#       The following file is necessary for the customization of both the IRIX
#       Workspace and Indigo Magic software so that it recognizes Alias 3D based
#       files (i.e.: Alias executables and data files):
#
#           /usr/lib/filetype/install/Alias3D.ftr
#
#       It appears in the support system files area of the ALIAS software
#       tape or CD-ROM and contains a number of file type rules used by the
#       workspace/Indigo Magic software to identify Alias 3D based files.
#
#       If the installation is being performed on a machine with Indigo Magic,
#       some customization of the Indigo Magic software is required:
#
#       If InstallAlias adds new user accounts to a machine which has the
#       Indigo Magic software, some information servers must be informed of
#       the new user accounts. If the directoryserver or objectserver are
#       running (chkconfig values are on) and the file which starts them
#       (/etc/init.d/cadmin) exists, rebuild the user database. If this is
#       not done, the server(s) will complain when the new user(s) login and
#       execute the Indigo Magic software.
#
#       If the installation is being performed on a machine with the workspace
#       software, its customization involves the modification of some files in
#       /usr/lib/workspace to customize the look of the workspace view.
#
#       If InstallAlias is running in guru mode, ask the installer if they wish
#       to customize the workspace/desktop software on the machine. If they say
#       `no', the software will not be customized.
#
#       If InstallAlias is running in guru mode and the installer approved the
#       customization of the IRIX workspace/desktop software, or InstallAlias is
#       not running in guru mode, customize the IRIX workspace/desktop software.
#       The file named above is extracted from the distribution tape or "copied"
#       from the CD-ROM (via tar) and installed in /usr/lib/filetype/install.
#
#       If a demo account is being customized on a machine with the WorkSpace
#       software and the directories ~<demo account>/{.workspace,WorkSpace} do
#       not exist, copy the standard workspace directory from /usr/alias. If
#       one (or both) of the workspace directories exist, inform the installer
#       how they may install the new workspace files at a later time.
#
#       If a demo account is being customized on a machine with the Indigo Magic
#       software and both of the following directories do not exist:
#
#           ~<demo account>/.desktop
#           ~<demo account>/.desktop-<hostname>
#
#       copy the standard desktop directory from /usr/alias. If any of those
#       directories exists, inform the installer how they may customize the
#       desktop view at a later time.
#
#       If the Workspace or Desktop (Indigo Magic) software was not customized,
#       give some hints to the installer how to do so.
#
#   31) Install icon files:
#
#       The following files are icon files used by the 4Dwm window manager and
#       Motif window manager (mwm) to indicate stowed Alias executables:
#
#           /usr/lib/images/Alias.icon
#           /usr/include/X11/bitmaps/alias_icon
#
#       Both files appear in the system files area of the Alias software tape
#       and CD-ROM.
#
#       If InstallAlias is running in guru mode, ask the installer if they wish
#       to install the Alias icon files on the machine. If they say `no', the
#       icon files will not be installed.
#
#       If the installer says `yes' or InstallAlias is not running in guru
#       mode, extract the Alias icon files from the distribution tape or "copy"
#       them from the CD-ROM (via tar) and install them in the correct
#       directories.
#
#       If the Alias icon files are not installed, list some instructions on
#       how to install them at a later time.
#
#   32) If InstallAlias is installing Alias software from a CD-ROM,
#       conditionally install a set of support files for HyperHelp (a viewing
#       tool for online Alias documentation):
#
#       If InstallAlias is running in guru mode, ask the installer if they wish
#       to install the Hyperhelp support files in /usr/lib. If they say `yes'
#       or InstallAlias is not running in guru mode, install the support files
#       in /usr/lib.
#
#       If the support files are not installed, give instructions how to install
#       them at a later time.
#
#   33) Customize peripherals software:
#
#       In order for grab and recon to access video devices, they must
#       be setuid root. If InstallAlias is running in guru mode, ask the
#       installer if they wish to make grab and recon setuid root.
#
#       If the guru said `yes' or InstallAlias is not running in guru mode,
#       make recon and grab setuid and owned by root (actually make IRIX 5
#       versions of grab and recon setuid root).
#
#   34) If the machine is running a variant of IRIX 4, conditionally setup the
#       IEEE (gpib) daemon and install the IEEE driver (the driver is valid for
#       all variants of IRIX 4):
#
#       Setup IEEE (gpib) server daemon:
#
#       Make a backup copy of the inetd configuration file and services file
#       before possibly modifying them.
#
#       Search the inetd configuration file for an entry for the gpib daemon. If
#       no entry is found and InstallAlias is running in guru_mode, ask the
#       installer if they wish to setup the gpib daemon. If they say `yes' or
#       InstallAlias is not running in guru mode, InstallAlias checks for an
#       entry for `alias_gpibd' in the services file as the first step in
#       setting up the gpib daemon. If there is no entry for `alias-gpibd' in
#       the services file, one must be added.
#
#       If InstallAlias is running in guru mode and the installer wishes to pick
#       the port number, ask the installer for their choice and verify that it
#       is not already in use.
#
#       If InstallAlias is not running in guru mode or a guru did not pick a
#       port number, InstallAlias finds the first unused port <= 5999.
#
#       When a port number has been determined, a complete entry is added to
#       the services file.
#
#       If there is no entry for the gpib daemon in the inetd config file
#       (/usr/etc/inetd.conf), determine the pathname of the daemon
#       (/usr/alias/etc/gpibd), add a complete entry to the inetd configuration
#       file and send the inetd process a hangup signal which causes it to
#       reread its configuration file and start servicing requests for the
#       Alias gpib daemon.
#
#       If there is an entry for the gpib daemon in the inetd configuration
#       file, but the pathname of the daemon specified by the entry is not
#       correct, replace the entry with a new entry which specifies the correct
#       pathname (/usr/alias/etc/gpibd) and send the inetd process a hangup
#       signal which causes it to reread its configuration file.
#
#       In order for ALIAS software to use IEEE devices, the IRIX kernel must
#       have the IEEE driver installed. The driver consists of two files:
#
#           /usr/sysgen/master.d/gpib
#           /usr/sysgen/boot/gpib.o
#
#       These files will be installed under the following conditions:
#
#       - if InstallAlias is running in guru mode, InstallAlias asks the
#         installer if they wish to install the IEEE driver files. If the
#         installer says `yes' or InstallAlias is running in non-guru mode, the
#         installation proceeds.
#       - if existing versions of the driver files are found, the driver files
#         from the ALIAS distribution media will be compared with the existing
#         files. If the files are the same (i.e. gpib.o from the distribution
#         media is the same as gpib.o on disk), the file from the distribution
#         media is removed. If the files are different, the file from the
#         distribution media replaces the existing file, which is saved.
#       - if any of the IEEE driver files from the distribution media are
#         installed, a new IRIX kernel is built and the installer is instructed
#         to reboot the machine to start using the new kernel.
#       - if the kernel rebuild fails or InstallAlias was running in guru mode
#         and the installer chose not to install the IEEE driver files,
#         InstallAlias gives the installer instructions how to install the IEEE
#         driver files and rebuild a new kernel by hand.
#
#   35) Conditionally install Alias tablet support:
#
#       Inform the installer that they should install the Alias tablet drivers
#       if they are planning to use tablets with the Alias software. If the
#       Alias software is being installed from CD-ROM, inform the installer
#       that they may install tablet support via the master install script
#       (Install) at the top level of the CD-ROM.
#
#       If the Alias software is being installed from tape, InstallTablet
#       will have been extracted from the tape at the same time as InstallAlias.
#       It may be invoked after the successful installation of the Alias
#       software.
#
#   36) Conditionally install ibic, an IEEE debugging tool:
#
#       Now that the ALIAS software has been installed, InstallAlias is running
#       in guru mode and the machine is running a variant of IRIX 4, ask the
#       installer if they wish to install ibic, a program for debugging the
#       IEEE interface. If they say `yes', ibic is installed in /usr/sbin.
#
#       If InstallAlias is running in non-guru mode and the machine is running
#       a variant of IRIX 4, install ibic in /usr/sbin.
#
#   37) Rename changed system files:
#
#       Go though the "list of saved system files" (All files with a prefix of
#       ".pre_alias"). Compare each saved file with its namesake (minus the
#       ".pre_alias" suffix). If the two files are the same, remove the
#       ".pre_alias" file; else rename the ".pre_alias" file to its namesake
#       with a suffix of "=" (i.e.: mv /etc/passwd.pre_alias /etc/passwd=). The
#       files with a suffix of "=" represent the state of each file before the
#       ALIAS software was installed. As each file is renamed, it is reported to
#       the installer.
#
#   38) Conditionally make install_en setuid and owned by the owner of the
#       Alias software:
#
#       In order for users other than the owner of the Alias software to add
#       encryption strings to the encryption file (/usr/alias/sys/insall/en),
#       install_en should be setuid and owned by the owner of the software.
#
#       If InstallAlias is running in guru mode, ask the installer if they
#       wish to make install_en setuid and owned by the owner of the Alias
#       software. If the installer says `yes' or InstallAlias is not running
#       in guru mode, install_en permissions are made setuid. The change of
#       ownership is unecessary since install_en is already owned by the owner
#       of the Alias software (ownership is set on extraction from the
#       distribution tape or CD-ROM).
#
#       If install_en is not made setuid and owned by the owner of the Alias
#       software and InstallAlias is running in guru mode, inform the installer
#       that users other than the owner of the software will not be able to add
#       encryption strings to the encryption file unless the directory
#       containing the encryption file (/usr/alias/sys/install) is made writable
#       and examinable for everyone and the encryption file readable and
#       writable for everyone.
#
#       Ask the installer if they wish to make the directory and encryption file
#       writable for everyone. If the installer says `yes', make the directory
#       and encryption file writable; else inform the installer that only the
#       owner of the Alias software or root can add encryption strings to the
#       encryption file.
#
#   39) If the en file for ALIAS (/usr/alias/sys/install/en) is empty, run getid
#       and ask the user to record the numeric string. The user must complete
#       a SPAR form in order to receive an encrypted string.
#
#   40) Finish up:
#
#       Remove any working files used during the installation of the ALIAS
#       software. Inform the installer that the ALIAS software has been
#       installed, then exit.
#

#    The variable tfd (Temporary Files Defined) is used to indicate if the
#    temporary files used by InstallAlias (HOSTS_TMP, etc) have been defined.
#    It is unset here to indicate that the temporary files have not been
#    defined yet.

unset tfd
onintr userexit

#    Set the search path

set path = (/usr/bsd /usr/bin /usr/sbin /usr/lbin /bin /etc /sbin)

#    Verify that the installer is root:
#
#    If the installer is not root, inform them that InstallAlias must be run
#    as root. Prompt them for the root password (via su) and execute
#    InstallAlias in a root subshell. If the installer fails to specify the
#    root password in 3 attempts, ask them to try again later and exit.

set whoami = `id | cut -c6-11`
if ("$whoami" != "(root)") then
    echo ""
    echo "In order to install the Alias software, the InstallAlias procedure must be"
    echo "run as root. At this time, you may specify the root password to continue"
    echo "with the installation. If your machine does not have a root password, you"
    echo "will not be prompted and the installation will continue. If you don't know"
    echo "the root password, you will have to find someone who does before the software"
    echo "can be installed."
    echo ""

# Determine where InstallAlias is located.

    set pdir = `dirname $0`
    set pfc = `echo $pdir | cut -c1`
    if ("$pfc" == "/") then
        set cdir = $pdir
        set cmd = $0
    else
        set cdir = $cwd
        set cmd = $cdir/$0
    endif
    @ i = 1
    while ($i <= 3)
        su - root -c "$cmd $argv"
        if ($status == 0) exit 0
        @ i++
    end
    echo ""
    echo "Three attempts to specify the root password have failed. Please try again"
    echo "later."
    echo ""
    echo -n "Press <ENTER> to continue: "
    set a = $<
    exit 1
endif

#    The InstallAlias procedure is capable of installing one of six ALIAS
#    software packages:
#
#        Alias Studio          (from ALIAS Software Tape or Cdrom)
#        Alias Designer        (from ALIAS Software Tape or Cdrom)
#        Alias PowerAnimator   (from ALIAS Software Tape or Cdrom)
#        Alias Animator        (from ALIAS Software Tape or Cdrom)
#        Alias AutoStudio      (from ALIAS Software Tape or Cdrom)
#        ALIAS Render          (from ALIAS Software Tape or Cdrom)
#
#    Before the installation can begin, InstallAlias must be informed which
#    software package is being installed. This can be done in one of two
#    ways:
#
#    If any of the following environment variables are set (by the master
#    Install script), it indicates which software package is to be installed:
#
#        Environment variable | Software Package
#        ---------------------+--------------------
#             STUD3D          | Alias Studio
#             DES3D           | Alias Designer
#             PANIM3D         | Alias PowerAnimator
#             ANIM3D          | Alias Animator
#             ASTUD3D         | Alias AutoStudio
#             REND3D          | Alias Render
#
#    If none of the environment variables are set, InstallAlias asks the
#    installer to indicate which software package they wish to install.

set STUD = 1
set DES = 2
set PANIM = 3
set ANIM = 4
set ASTUD = 5
set REND = 6

if ($?STUD3D) then
    set choice = $STUD
else if ($?DES3D) then
    set choice = $DES
else if ($?PANIM3D) then
    set choice = $PANIM
else if ($?ANIM3D) then
    set choice = $ANIM
else if ($?ASTUD3D) then
    set choice = $ASTUD
else if ($?REND3D) then
    set choice = $REND
else
    echo ""
    echo "The InstallAlias procedure may be used to install one of six ALIAS software"
    echo "packages:"
    echo ""
    echo "    $STUD) Alias Studio V5.1"
    echo "    $DES) Alias Designer V5.1"
    echo "    $PANIM) Alias PowerAnimator V5.1"
    echo "    $ANIM) Alias Animator V5.1"
    echo "    $ASTUD) Alias AutoStudio V5.1"
    echo "    $REND) Alias Render Software"
    echo ""
    echo -n "Which software package do you wish to install? (1-$REND): "
    while (1)
        set choice = $<
        if ("$choice" !~ [123456]) then
            echo -n "Please specify a number between 1 and ${REND}: "
        else
            break
        endif
    end
endif

#    In all cases (studio, designer, power animator, animator, autostudio and
#    render), the software will be installed in a directory named aliasYYMM
#    (where YYMM are the year and month of the release).

set dir = alias9407
if ($choice == $STUD) then
    set vers = "ALIAS Studio"
else if ($choice == $DES) then
    set vers = "ALIAS Designer"
else if ($choice == $PANIM) then
    set vers = "PowerAnimator"
else if ($choice == $ANIM) then
    set vers = "ALIAS Animator"
else if ($choice == $ASTUD) then
    set vers = "AutoStudio"
else if ($choice == $REND) then
    set vers = "ALIAS Render"
    set render_sftw
endif

#    Determine if the machine is running a variant of IRIX 4 or IRIX 5. If
#    the machine is running a variant of IRIX 4, the software on the
#    distribution tape or CD-ROM cannot be installed as it will not
#    run on a machine running any version of IRIX 4.   

set fdig = `uname -r | cut -c1`
if ($fdig == "4") then
    set irix4
    echo ""
    echo ""
    echo "The $vers software cannot be installed on this machine because the"
    echo "machine is running a version of IRIX 4. The Alias software on the distribution"
    echo "media (tape or CD-ROM) is totally incompatible with any version of IRIX 4."
    echo "The $vers software MUST be installed on an IRIX 5 machine."
    echo ""
    echo ""
    echo -n "Press <ENTER> to continue: "
    set a = $<
    exit
else if ($fdig == "5") then
    set irix5
endif

#    Determine if the installer is a guru:
#
#    If InstallAlias runs in guru mode, it may ask some detailed questions
#    about how the installation of the ALIAS software should proceed. It will
#    try not to assume anything.
#
#    If InstallAlias does not run in guru mode, it will tend to assume some of
#    the more detailed unix things and not ask the installer for their opinion.
#
#    If InstallAlias is called with a `-g' flag, it runs in guru mode.

echo ""
if ($#argv == 1) then
    if ("$1" == "-g") then
        set guru_mode
        echo "InstallAlias will install the $vers software in advanced mode."
    endif
endif

if (! $?guru_mode) then
    echo "InstallAlias will install the $vers software in automatic mode."
endif

#    Set variables required by InstallAlias

set distname = dist # default owner of the ALIAS software
set demoname = aldemo # username of default demo account
set symlink_to_alias = /usr/alias # symbolic link to latest Alias software
set owner_uid = 60  # minimum value of dist's uid when chosen by InstallAlias
set demo_uid = 400 # minimum value of demo account's uid chosen by InstallAlias

set default_gid = 20
set DLR = '$'

#    Determine where InstallAlias will place its working files. The files will
#    be placed in one of /var/tmp, /usr/tmp or /tmp.

if (-d /var/tmp && -w /var/tmp) then
    set TMPDIR = /var/tmp
else if (-d /usr/tmp && -w /usr/tmp) then
    set TMPDIR = /usr/tmp
else
    set TMPDIR = /tmp
endif

#    Various variables used by InstallAlias

set HOSTS_TMP = $TMPDIR/alhosts.$$
set OERR = $TMPDIR/aloerr.$$
set OUT = $TMPDIR/alout.$$
set GPIB_OBJ = /usr/sysgen/boot/gpib.o
set GPIB_MASTER = /usr/sysgen/master.d/gpib
set SVEN = $TMPDIR/svd_en.pre_alias
set RCDIR = render_control

#    Name of Tablet installation script
set TABINST = InstallTablet

#    Locations of software and data files on Alias CD-ROM (pathnames relative
#    to CD-ROM mount point)

set ALDIR = Products/Alias3D
set SYSFILES = $ALDIR/sys
set ALIAS = $ALDIR/alias
set CDIR = Products/Common
set DCLIB = 3DCD
set TUT = CourseWare
set HELP = HyperHelp

#    After the temporary files have been defined, set the tfd
#    (Temporary Files Defined) variable.

set tfd

set errmsg1=""
set errmsg2=""
set mod_files = "/etc/passwd /usr/lib/workspace/sgidefault.wsrc /etc/magic"
set tut_reqd_Mbspace = 35 # Megabytes
set dcl_reqd_Mbspace = 215 # Megabytes

set DF = "df -k"
set DU = "du -s -k"

umask 022

#    Determine by which type of media the Alias software will be installed:
#
#    The Alias software may be installed from CD-ROM or tape (local or remote).
#
#    If the environment variable ALIAS_CDLOCN is set, it represents the full
#    pathname of the mount point of the Alias CD-ROM. This environment variable
#    is set by the master install script (Install). The Alias software will be
#    installed from the Alias CD-ROM mounted at the location specified by
#    ALIAS_CDLOCN.
#
#    If ALIAS_CDLOCN is not set, InstallAlias asks the installer if they wish
#    to install the software from a CD-ROM. If they say `yes', InstallAlias
#    asks the installer to specify the mount point of the CD-ROM.
#
#    Once, the mount point of the CD-ROM is known ($ALIAS_CDLOCN or installer
#    specified, InstallAlias verifies the contents of the CD-ROM. If the
#    contents of the CD-ROM are valid, the installation continues, else
#    InstallAlias exits with an explanatory error message.
#
#    If the Alias software is not being installed from CD-ROM, InstallAlias
#    asks the installer if they are installing from tape. If they say `no',
#    InstallAlias informs them that the software may only be installed from
#    CD-ROM or tape and exits. If they say `yes' to installing from a tape,
#    InstallAlias asks them if the tape drive is connected to the machine. If
#    they say `yes', InstallAlias (with installer interaction) determines the
#    (rewinding and non-rewinding) device names of a local tape drive that can
#    be used for the installation. If the installer says `no' to installing
#    from a local tape drive, InstallAlias asks them if they wish to install
#    the software using a remote tape drive. If they say `no', InstallAlias
#    tells them that once they know which tape device they wish to use, they
#    should attempt the installation again, then exits. If they say `yes' to
#    installing using a remote tape drive, InstallAlias queries them for three
#    pieces of information:
#
#    - the hostname of the machine with the tape drive
#    - the username of a user account on the remote host which will be
#      used to perform remote commands on the remote host
#    - the full pathname of a rewinding tape device on that machine (only if
#      the default tape devices do not exist OR are not used for the
#      installation).
#
#    Given this information, InstallAlias verifies the remote hostname (queries
#    DNS and/or hosts file) and verifies that remote commands between your
#    machine and the remote host succeed. If this fails, InstallAlias lists a
#    number of possible reasons for the failure and asks the installer to
#    check them out. Once the execution of remote commands has been verified,
#    InstallAlias (with installer interaction) determines the (rewinding and
#    non-rewinding) device names of a tape drive on the remote host. It
#    verifies that the tape drive is accessible and available for the
#    installation.
#
#    At the end of this step (assuming no errors have occurred), InstallAlias
#    will know the type of media to use for the installation of the Alias
#    software (CD-ROM or tape) and its location (CD-ROM mount point or
#    tape device names for rewinding and non-rewinding tape devices).

unset mtype

#    If the environment variable ALIAS_CDLOCN is set, it represents the full
#    pathname of the mount point of the Alias CD-ROM. This environment variable
#    is set by the master install script (Install). The Alias software will be
#    installed from the Alias CD-ROM mounted at the location specified by
#    ALIAS_CDLOCN.

if ($?ALIAS_CDLOCN) then
    set ALIAS_CDPATH = $ALIAS_CDLOCN
else
    echo ""
    echo "Before InstallAlias can install the $vers software, it must determine"
    echo "the type of media that the software is being installed from."

#    If ALIAS_CDLOCN is not set, determine from what type of media (tape or
#    CD-ROM) the Alias software will be installed from:
#
#    Ask the installer if they wish to install the Alias software from a
#    CD-ROM. If they say `yes', InstallAlias has to know where the CD-ROM is
#    mounted. InstallAlias determines its mount point and asks the installer
#    if it is the correct location. If they say `no', InstallAlias asks them
#    where the CD-ROM is mounted.

    echo ""
    echo -n "Are you installing the $vers software from a CD-ROM? (yes/no): "
    while (1)
        set ans = $<
        if ("$ans" !~ [yY][eE][sS] && "$ans" !~ [nN][oO]) then
            echo -n "Please specify yes or no: "
        else
            break
        endif
    end
    echo ""
    if ($ans =~ [yY][eE][sS]) then
        set pdir = `dirname $0`
        set pfc = `echo $pdir | cut -c1`
        if ("$pfc" == "/") then
            set cdir = $pdir
        else
            set cdir = $cwd
        endif
        echo -n "Is the CD-ROM mounted at $cdir? (yes/no): "
        while (1)
            set ans = $<
            if ("$ans" !~ [yY][eE][sS] && "$ans" !~ [nN][oO]) then
                echo -n "Please specify yes or no: "
            else
                break
            endif
        end
        if ($ans =~ [Yy][Ee][Ss]) then
            set ALIAS_CDPATH = $cdir
        else
            echo ""
            while (1)
                echo -n "Where is the CD-ROM mounted? (please specify a full pathname): "
                set pname = $<
                set ALIAS_CDPATH = ($pname)

#    Verify that the specified mount point is a full pathname (starts with /).

                set pfc = `echo $ALIAS_CDPATH | cut -c1`
                if ("$pfc" != "/") then
                    echo ""
                    echo "$ALIAS_CDPATH is not a full pathname. Please choose again."
                    echo ""
                    continue
                endif
                if ($#ALIAS_CDPATH == 1) break
            end
        endif
    endif
endif

if ($?ALIAS_CDPATH) then

#    If the ALIAS software is being installed from a CD-ROM, the CD-ROM must
#    have been mounted by the installer at a mount point specified by
#    the installer ($ALIAS_CDPATH).

    set almedia = "CD-ROM"
    echo ""
    echo "Validating the $almedia mounted at $ALIAS_CDPATH ..."

#    Once the mount point of the CD-ROM has been determined, InstallAlias
#    validates it:
#
#    Verify that the CD-ROM mount point specified by the installer exists, it
#    is a directory and the CD-ROM is mounted (actually, the pathname specified
#    by ALIAS_CDPATH contains the proper files to install the Alias software).

    if (-e $ALIAS_CDPATH) then
        if (-d $ALIAS_CDPATH) then
            set valid_cd
            foreach adir ($SYSFILES $ALIAS)
                if (! -d $ALIAS_CDPATH/$adir) then
                    echo ""
                    echo "The directory $adir is missing from the CD-ROM."
                    unset valid_cd
                endif
            end
            if (! $?valid_cd) then
                echo ""
                echo "Either the CD-ROM is not mounted, the correct CD-ROM is not being used, the"
                echo "CD-ROM is corrupted or the CD-ROM mount point you specified ($ALIAS_CDPATH)"
                echo "is not correct."
                echo ""
                echo "Once you have resolved the problem, attempt the installation again."
                echo ""
                echo -n "Press <ENTER> to continue: "
                set a = $<
                exit
            endif
        else
            echo ""
            echo "The CD-ROM mount point that you specified ($ALIAS_CDPATH) is not a directory."
            echo ""
            echo "Please make sure that the CD-ROM is mounted and the pathname that you specified"
            echo "($ALIAS_CDPATH) is the mount point of the CD-ROM, then attempt the"
            echo "installation again."
            echo ""
            echo -n "Press <ENTER> to continue: "
            set a = $<
            exit
        endif
    else
        echo ""
        echo "The CD-ROM mount point specified by the installer ($ALIAS_CDPATH) does not exist."
        echo ""
        echo "Please make sure that the CD-ROM is mounted and/or the pathname specified by"
        echo "the installer is correct, then attempt the installation again."
        echo ""
        echo -n "Press <ENTER> to continue: "
        set a = $<
        exit
    endif
    set mtype = $almedia

#    Now that we know that the Alias software is being installed from a
#    verified CD-ROM, run getid to give the installer some needed information.

    echo ""
    echo ""
    echo "Please compare your machine configuration described below with the minimum"
    echo "requirements described in the booklet accompanying your Alias CD-ROM. Ensure"
    echo "your machine meets the required configuration and suggested operating system"
    echo "before continuing with the installation."
    echo ""
    $ALIAS_CDPATH/InstallScripts/getid -i | sed "s/^/	/"
    echo ""
    echo -n "Do you wish to continue with the installation? (yes/no): "
    while (1)
        set ans = $<
        if ("$ans" !~ [yY][eE][sS] && "$ans" !~ [nN][oO]) then
            echo -n "Please specify yes or no: "
        else
            break
        endif
    end
    if ($ans =~ [nN][oO]) then
        echo ""
        echo -n "Press <ENTER> to continue: "
        set a = $<
        exit
    endif
endif

#    If the Alias software is not being installed from a CD-ROM, ask the
#    installer if they are using a tape drive for the installation.

if (! $?mtype) then
    echo -n "Are you installing the $vers software from a tape drive? (yes/no): "
    while (1)
        set ans = $<
        if ("$ans" !~ [yY][eE][sS] && "$ans" !~ [nN][oO]) then
            echo -n "Please specify yes or no: "
        else
            break
        endif
    end
    echo ""
    if ($ans =~ [Yy][Ee][Ss]) then
        unset notape
        set almedia = "tape"

#    Once it has been ascertained that the install is being done via a tape
#    drive, determine if the tape drive is local (connected to the machine)
#    or remote (connected to another machine on the network).

        echo -n "Is the tape drive connected to your machine? (yes/no): "
        while (1)
            set ans = $<
            if ("$ans" !~ [yY][eE][sS] && "$ans" !~ [nN][oO]) then
                echo -n "Please specify yes or no: "
            else
                break
            endif
        end
        if ($ans =~ [Yy][Ee][Ss]) then

#    If the installer indicates that they wish to install the Alias software
#    using a local tape drive, probe for the existence of /dev/tape and
#    /dev/nrtape. If these devices don't exist or an error occurs when
#    accessing them, warn the installer; else ask them if they wish to
#    continue the installation using the default tape devices.

            set mtype = "local tape"
            set usedflt
            echo ""
            echo "Checking for default tape devices ..."
            foreach tapedev (/dev/{tape,nrtape})
                if ($tapedev:t == "nrtape") then
                    set fill = "non-"
                else
                    set fill = ""
                endif

#    Verify that the default tape devices are character devices. If they are
#    character devices, run `mt stat' on each to make sure they are accessible.

                if (-c $tapedev) then
                    mt -t $tapedev stat >& $OUT
                    if ($status != 0) then
                        echo ""
                        echo "The default ${fill}rewinding tape device ($tapedev) exists,"
                        echo "but an error occurs when InstallAlias attempts to access it:"
                        echo ""
                        cat $OUT | sed "s/^/    /"
                        unset usedflt
                    endif
                    rm -f $OUT
                else

#    If the default tape device is not a character device, verify that it
#    exists.

                    echo ""
                    if (-e $tapedev) then
                        echo "The default ${fill}rewinding tape device ($tapedev) exists,"
                        echo "but it is not a character device as it should be."
                    else
                        echo "The default ${fill}rewinding tape device ($tapedev) does not exist."
                    endif
                    unset usedflt
                endif
            end
            if ($?usedflt) then
                echo ""
                echo "Both default tape devices (/dev/tape, /dev/nrtape) exist and are accessible."
                echo ""
                echo -n "Do you wish to use them to install the $vers software? (yes/no): "
                while (1)
                    set ans = $<
                    if ("$ans" !~ [yY][eE][sS] && "$ans" !~ [nN][oO]) then
                        echo -n "Please specify yes or no: "
                    else
                        break
                    endif
                end

#    If the default tape drives exist and are accessible, ask the installer
#    if they wish to install the Alias software using them. If they say `yes',
#    set TAPE and NRTAPE to the default tape device names.

                if ($ans =~ [Yy][Ee][Ss]) then
                    set TAPE = /dev/tape
                    set NRTAPE = /dev/nrtape
                endif
            endif

            if (! $?TAPE) then

#    If the default tape drives do not exist or are not usable (not accessible),
#    ask the installer if they wish to install the software from an alternate
#    pair of devices (one rewinding, the other non-rewinding).
#
#    If the installer wishes to specify an alternate tape device for the
#    installation, ask them their choice.

                echo ""
                echo "In order to install the $vers software, you must specify the device"
                echo "name of a rewinding tape device (i.e.: /dev/rmt/tps0d2). InstallAlias will"
                echo "verify that it (and its non-rewinding version) exist and are accessible"
                echo "before allowing them to be used for the installation."
                echo ""
                while (1)
                    echo "Which tape device do you wish to use? (please specify a full"
                    echo -n "pathname): "
                    set pname = $<
                    set altape = ($pname)
                    if ($#altape == 1) break
                end

#    Given the installers choice of an alternate rewindable tape device, verify:
#
#    - the device exists 
#    - it is a character device (i.e.: tape device)
#    - its minor device number is even; this indicates a rewindable device
#    - the corresponding non-rewind device exists (same major device number,
#      incremented minor number)
#    - Both devices pass the `mt stat' test with no errors
#
#    If any of these tests fail, InstallAlias informs the installer of the
#    problem and exits; else it continues with the installation.

                echo ""
                echo "Validating your choice of tape device ..."
                if (! -e $altape) then
                    echo ""
                    echo "The tape device that you specified ($altape) does not exist."
                    echo ""
                    echo "You must specify an existing tape device."
                    set notape
                else
                    if (-c $altape) then
                        set maj = `ls -l $altape | awk -F"," '{print $1}' | awk '{print $5}'`
                        set min = `ls -l $altape | awk -F"," '{print $2}' | awk '{print $1}'`
                        @ rem = $min % 2
                        if ($rem) then
                            echo ""
                            echo "The tape device that you specified ($altape) is not a rewinding"
                            echo "tape device."
                            echo ""
                            echo "You must specify a rewinding tape device, not a non-rewinding tape device."
                            echo ""
                            echo "For example, you should choose /dev/rmt/tps0d2 over /dev/rmt/tps0d2nr, as the"
                            echo 'second device is a non-rewinding device (note the "nr").'
                            set notape
                        else
                            set dpref = $altape:h
                            @ min++

#    Correctly format majmin for the search for the non-rewindable tape device.

                            if ($min < 10) then
                                set majmin = "$maj,  $min"
                            else if ($min < 100) then
                                set majmin = "$maj, $min"
                            else
                                set majmin = "$maj,$min"
                            endif

#    In awk:
#
#    crw-rw-rw-   2 root     sys       23, 64 Feb 11 09:19 /dev/rmt/tps0d2
#
#    has 10 elements while
#
#    crw-rw-rw-   2 root     sys       23,224 Feb 11 09:19 /dev/rmt/tps0d7
#
#    has 9 elements.
#
#    The difference is that the minor device number in the first example is
#    2 chars, thus creating a space in the `ls -l' output. This accounts for
#    the extra element.
#
#    In order to get the filename portion of the line, the next command uses
#    awk to break the line at the comma separating the major and minor numbers,
#    then prints the fifth element (the filename).
#
#    Also note the `ls -l $dpref/.'. The `/.' is required to get an accurate
#    long listing if $dpref is a symlink to another directory
#    (i.e. /dev/mt -> /dev/rmt).

                            set nrdev = `ls -l $dpref/. | grep " $majmin " | awk -F"," '{print $2}' | awk '{print $5}'`

#    A new tangle. Under IRIX 5, a tape device may have two (or more?) different
#    names that share the same <major,minor> number:
#
#    crw-rw-rw-    1 root     sys      144,224 Jul 10 11:37 /dev/rmt/tps0d7
#    crw-rw-rw-    1 root     sys      144,224 Jul 10 11:37 /dev/rmt/tps0d7s
#    crw-rw-rw-    1 root     sys      144,225 Jul 10 11:37 /dev/rmt/tps0d7nr
#    crw-rw-rw-    1 root     sys      144,225 Jul 10 11:37 /dev/rmt/tps0d7nrs
#
#    and exhibit the same behavior (i.e.: /dev/rmt/tps0d7 and /dev/tps0d7s
#    both access tape device 7 on scsi controller 0 which swaps bytes during
#    reads and writes) and are equivalent, despite the different name. All
#    InstallAlias has to do is use one of the device names (the first one).

                            if ($#nrdev > 1) then
                                set nrdev = $nrdev[1]
                            endif
                            set alnrtape = "$dpref/$nrdev"
                            foreach tapedev ($altape $alnrtape)
                                set tdev = $tapedev:t
                                if ("$tdev" == "$nrdev") then
                                    set fill = "non-"
                                else
                                    set fill = ""
                                endif
                                if ("$tdev" != "") then
                                    mt -t $tapedev stat >& $OUT
                                    if ($status != 0) then
                                        set notape
                                        echo ""
                                        echo "The ${fill}rewinding tape device ($tapedev) exists, but an error occurs"
                                        echo "when InstallAlias attempts to access it:"
                                        echo ""
                                        cat $OUT | sed "s/^/    /"
                                    endif
                                    rm -f $OUT
                                else
                                    set notape
                                    echo ""
                                    echo "The ${fill}rewinding version of the tape device that you specified does not exist."
                                endif
                            end
                            if (! $?notape) then
                                set TAPE = $altape
                                set NRTAPE = $alnrtape
                            endif
                        endif
                    else
                        echo ""
                        echo "All tape devices are character devices. The tape device that you specified"
                        echo "($altape) is not a character device and cannot be used for the installation."
                        echo ""
                        echo "You must specify a valid tape device."
                        set notape
                    endif
                endif
            endif
        else

#    If the Alias software is not being installed using a local tape drive, ask
#    the installer if they wish to install the software using a remote tape
#    drive. If they say `no', explain that since they have indicated that
#    they wish to install from tape, they must choose to install from a local
#    or remote tape drive. If they say `yes', continue with the installation.

            echo ""
            echo "Do you wish to install the $vers software using a remote tape drive?"
            echo -n "(yes/no): "
            while (1)
                set ans = $<
                if ("$ans" !~ [yY][eE][sS] && "$ans" !~ [nN][oO]) then
                    echo -n "Please specify yes or no: "
                else
                    break
                endif
            end
            if ($ans =~ [Yy][Ee][Ss]) then

#    Given that the Alias software is being installed using a remote tape
#    drive, InstallAlias requires three pieces of information:
#
#    - the hostname of the machine with the tape drive
#    - the username of a remote account; all commands performed on the
#      remote machine will be executed by that user.
#    - the full pathname of a rewinding tape device on that machine (only
#      if the default tape devices do not exist OR the installer chooses
#      not to use them for the installation).
#
#    Given this information, InstallAlias constructs two variables used by tar.
#    The format of these variables is:
#
#        <username>@<machine>:/dev/<rewinding tape drive>
#        <username>@<machine>:/dev/<non-rewinding tape drive>

                set mtype = "remote tape"
                echo ""
                echo "In order to install the $vers software, InstallAlias requires three"
                echo "pieces of information:"
                echo ""
                echo "    - the hostname of the machine whose tape drive you are using."
                echo "    - the full pathname of a (rewinding) tape device on the remote machine."
                echo "    - the username of a user account on the remote machine. All commands"
                echo "      executed on the remote machine are carried out as that user (i.e.: when"
                echo "      extracting the $vers software from the distribution $almedia)."
                echo ""

                while (1)
                    echo -n "Please enter the hostname of the machine whose tape drive you are using: "
                    set hname = $<
                    set REMOTE_TAPE_HOST = ($hname)
                    if ($#REMOTE_TAPE_HOST != 1) continue

#    Verify that this machine "knows" about the remote host:
#
#    If a valid resolv.conf file exists (the file exists and has a nameserver
#    entry), try to validate the remote host via the DNS. Since nslookup does
#    not return a status to indicate errors, InstallAlias assumes an error has
#    occurred (i.e.: the host is unknown) if something is written to standard
#    error.
#
#    If the DNS lookup fails (unlikely if the hostname is valid), search
#    the local hosts file (/etc/hosts) for the hostname. If this lookup
#    fails, indicate to the installer that the remote host is unknown.

                    set shf
                    unset unknown_rem_host
                    if (-f /usr/etc/resolv.conf) then
                        set ns = `grep "^nameserver[ 	]" /usr/etc/resolv.conf`
                        if ($#ns != 0) then
                            (nslookup $REMOTE_TAPE_HOST > /dev/null) >& $HOSTS_TMP
                            if (-z $HOSTS_TMP) then
                                unset shf
                            endif
                        endif
                    endif

                    if ($?shf) then
                        sed "/^#/d" /etc/hosts | awk '{for (i=2; i<=NF; i++) print $i}' >& $HOSTS_TMP
                        grep -s "^${REMOTE_TAPE_HOST}${DLR}" $HOSTS_TMP >& /dev/null
                        if ($status != 0) then
                            grep -s "^${REMOTE_TAPE_HOST}\." $HOSTS_TMP >& /dev/null
                            if ($status != 0) set unknown_rem_host
                        endif
                    endif
                    rm -f $HOSTS_TMP

#    If the specified host is unknown, ask the installer if they wish to
#    specify another hostname. If they say `no', exit; else accept and
#    validate the new hostname.

                    if ($?unknown_rem_host) then
                        echo ""
                        echo "InstallAlias is unable to verify the existence of $REMOTE_TAPE_HOST."
                        echo ""
                        echo -n "Do you wish to specify another hostname? (yes/no): "
                        while (1)
                            set ans = $<
                            if ("$ans" !~ [yY][eE][sS] && "$ans" !~ [nN][oO]) then
                                echo -n "Please specify yes or no: "
                            else
                                break
                            endif
                        end
                        echo ""
                        if ($ans =~ [Nn][Oo]) break
                    else
                        break
                    endif
                end
                if ($?unknown_rem_host) then
                    set errmsg1 = "$REMOTE_TAPE_HOST is an unknown host."
                    goto baderr
                endif

#    Now that InstallAlias has the hostname of a valid remote host, it asks for
#    the username of the user account on the machine. This account is necessary
#    to carry out remote commands on the remote host.

                echo ""
                while (1)
                    echo "Please enter the username of the user account on $REMOTE_TAPE_HOST"
                    echo -n "that will be used to execute remote commands from InstallAlias: "
                    set puser = $<
                    set ruser = ($puser)
                    if ($#ruser == 1) break
                end

#    Before InstallAlias can continue , it has to test if can get root access
#    to the remote machine. If "rsh <hostname> -l <ruser> date" fails (where
#    ruser is the username specified by the installer), remote commands between
#    this machine and the remote machine will not work.

                echo ""
                echo "Verifying remote command access to $REMOTE_TAPE_HOST ..."
                set hostname = `hostname`
                rsh $REMOTE_TAPE_HOST -l $ruser date >& /dev/null
                if ($status != 0) then
                    echo ""
                    echo "InstallAlias cannot run commands as root on $REMOTE_TAPE_HOST. There are"
                    echo "three possible reasons for this:"
                    echo ""
                    echo "    - there is no user account on $REMOTE_TAPE_HOST with a username of $ruser."
                    echo "    - the .rhosts file in ${ruser}'s home directory on $REMOTE_TAPE_HOST is"
                    echo "      not complete."
                    echo "    - the permissions of the .rhosts file are incorrect."
                    echo ""
                    echo "These problems must be addressed in order for the installation to continue."
                    echo ""
                    echo "Assuming that the $ruser account exists, the .rhosts file must be edited"
                    echo "in order to allow root and the owner of the $vers software to"
                    echo "execute commands as $ruser on $REMOTE_TAPE_HOST. The following entries"
                    echo "must appear in ${ruser}'s .rhosts file on ${REMOTE_TAPE_HOST}:"
                    echo ""
                    if ("$ruser" == "root") then
                        echo "$hostname"
                    else
                        echo "$hostname root"
                    endif
                    if ($?guru_mode) then
                        echo "$hostname <username of the owner of the $vers software>"
                    else
                        echo "$hostname $distname"
                    endif
                    echo ""   
                    echo "If the hostname portion of the entries ($hostname) does not include your"
                    echo "domain name (assuming you have a domain name), be sure to include it as"
                    echo "part of the hostname. Verify that both entries appear in the .rhosts file"
                    echo "and the permissions are correct (chmod go-w .rhosts)."
                    echo ""
                    echo "Any entries that you add to the .rhosts file should be removed when the"
                    echo "$vers software has been successfully installed."
                    echo ""
                    echo "If you are unsure of what to do next, contact Alias Assist for help."
                    echo ""
                    echo -n "Press <ENTER> to continue: "
                    set a = $<
                    exit
                endif

#    Now that we have a verified remote hostname and user account, it's time
#    to find a tape drive on the remote host. First, InstallAlias checks for
#    the existence of /dev/tape and /dev/nrtape by `mt stat'ing them. If no
#    errors occur when `mt stat'ing them, InstallAlias asks the installer if
#    they wish to use them for the installation. If they say `no', it asks them
#    for their choice of rewinding tape device. Given the installers choice,
#    InstallAlias verifies that the tape exists and is rewindable (minor number
#    is even). Given the major and minor numbers of the rewindable device,
#    InstallAlias increments the minor number and tries to find the
#    non-rewinding device with that <major, minor> device number.

                echo ""
                echo "Checking for default tape devices on $REMOTE_TAPE_HOST ..."
                set usedflt
                foreach tapedev (/dev/{tape,nrtape})
                    mt -t $ruser@${REMOTE_TAPE_HOST}:$tapedev stat >& $OUT

#    Probe for the existence of the rewinding tape drive (/dev/tape) and
#    non-rewinding tape drive (/dev/nrtape). If a probe fails, explain to the
#    installer the problem (stripping the `<ruser>@' off the error messages to
#    prevent confusion for those not familiar with the <user>@<mach>:/dev/tape
#    syntax).

                    if ($status != 0) then
                        unset usedflt
                        echo ""
                        echo -n "An error has occurred when trying to access the "
                        if ($tapedev == "/dev/nrtape") echo -n "non-"
                        echo "rewinding tape drive"
                        echo "($tapedev) on ${REMOTE_TAPE_HOST}:"
                        echo ""
                        cat $OUT | sed -e "s/$ruser@//" -e "s/^/    /"
                    endif
                    rm -f $OUT
                end
                if ($?usedflt) then
                    echo ""
                    echo "Both default tape devices on $REMOTE_TAPE_HOST (/dev/tape, /dev/nrtape) exist"
                    echo "and are accessible."
                    echo ""
                    echo -n "Do you wish to use them to install the $vers software? (yes/no): "
                    while (1)
                        set ans = $<
                        if ("$ans" !~ [yY][eE][sS] && "$ans" !~ [nN][oO]) then
                            echo -n "Please specify yes or no: "
                        else
                            break
                        endif
                    end

#    If the default tape drives on the remote machine exist and are accessible,
#    ask the installer if they wish to install the Alias software using them.
#    If they say `yes', set TAPE and NRTAPE to the appropriate names.

                    if ($ans =~ [Yy][Ee][Ss]) then
                        set TAPE = $ruser@${REMOTE_TAPE_HOST}:/dev/tape
                        set NRTAPE = $ruser@${REMOTE_TAPE_HOST}:/dev/nrtape
                    endif
                endif

                if (! $?TAPE) then

#    If the default tape drives do not exist or are not usable (not accessible),
#    ask the installer if they wish to install the software from an alternate
#    pair of devices (one rewinding, the other non-rewinding).

                    echo ""
                    echo "In order to install the $vers software, you must specify the name"
                    echo "of a rewinding tape device on $REMOTE_TAPE_HOST (i.e.: /dev/rmt/tps0d2)."
                    echo "InstallAlias will verify that it (and its non-rewinding version) exist and"
                    echo "are accessible before allowing them to be used for the installation."
                    echo ""
                    while (1)
                        echo "Which tape device do you wish to use? (please specify a full"
                        echo -n "pathname): "
                        set pname = $<
                        set altape = ($pname)
                        if ($#altape == 1) break
                    end

#    Given the installers choice of rewindable tape device, verify:
#
#    - the device exists 
#    - it is a character device (i.e.: tape drive)
#    - its minor device number is even; this indicates a rewindable device
#    - the corresponding non-rewind device exists (same major device number,
#      incremented minor number)
#    - Both devices pass the `mt stat' test with no errors
#
#    If any of these tests fail, InstallAlias informs the installer of the
#    problem and exits; else it continues with the installation.

                    echo ""
                    echo "Validating your choice of tape device ..."
                    (rsh $REMOTE_TAPE_HOST -l $ruser ls -l $altape > $OUT) >& $OERR
                    if ($status != 0) then
                        rm -f $OUT
                        echo ""
                        echo "An error occurred while probing for $altape on ${REMOTE_TAPE_HOST}:"
                        echo ""
                        cat $OERR | sed "s/^/    /"
                        rm -f $OERR
                        echo ""
                        set errmsg1 = "Cannot probe for $altape on $REMOTE_TAPE_HOST"
                        goto baderr
                    endif
                    rm -f $OERR
                    if (-z $OUT) then
                        echo ""
                        echo "The tape device that you specified ($altape) does not exist."
                        echo ""
                        echo "You must specify an existing tape device."
                        set notape
                    else
                        set ftype = `cut -c1 $OUT`
                        if ($ftype == "c") then
                            set maj = `awk -F"," '{print $1}' $OUT | awk '{print $5}'`
                            set min = `awk -F"," '{print $2}' $OUT | awk '{print $1}'`
                            @ rem = $min % 2
                            if ($rem) then
                                echo ""
                                echo "The tape device that you specified ($altape) is not a rewinding"
                                echo "tape device."
                                echo ""
                                echo "You must specify a rewinding tape device, not a non-rewinding tape device."
                                echo ""
                                echo "For example, you should choose /dev/rmt/tps0d2 over /dev/rmt/tps0d2nr, as the"
                                echo 'second device is a non-rewinding device (note the "nr").'
                                set notape
                            else
                                set dpref = $altape:h
                                @ min++

#    Correctly format majmin for the search for the non-rewindable tape device.

                                if ($min < 10) then
                                    set majmin = "$maj,  $min"
                                else if ($min < 100) then
                                    set majmin = "$maj, $min"
                                else
                                    set majmin = "$maj,$min"
                                endif

                                (rsh $REMOTE_TAPE_HOST -l $ruser ls -l $dpref/. | grep " $majmin " > $OUT) >& $OERR
                                if (! -z $OERR) then
                                    rm -f $OUT
                                    echo ""
                                    echo "An error occurred while probing for the non-rewinding version of $altape on"
                                    echo "${REMOTE_TAPE_HOST}:"
                                    echo ""
                                    cat $OERR | sed "s/^/    /"
                                    rm -f $OERR
                                    echo ""
                                    set errmsg1 = "Cannot probe for non-rewind tape device on $REMOTE_TAPE_HOST."
                                    goto baderr
                                endif
                                rm -f $OERR
                                set nrdev = `awk -F"," '{print $2}' $OUT | awk '{print $5}'`

#    A new tangle. Under IRIX 5, a tape device may have two (or more?) different
#    names that share the same <major,minor> number:
#
#    crw-rw-rw-    1 root     sys      144,224 Jul 10 11:37 /dev/rmt/tps0d7
#    crw-rw-rw-    1 root     sys      144,224 Jul 10 11:37 /dev/rmt/tps0d7s
#    crw-rw-rw-    1 root     sys      144,225 Jul 10 11:37 /dev/rmt/tps0d7nr
#    crw-rw-rw-    1 root     sys      144,225 Jul 10 11:37 /dev/rmt/tps0d7nrs
#
#    and exhibit the same behavior (i.e.: /dev/rmt/tps0d7 and /dev/tps0d7s
#    both access tape device 7 on scsi controller 0 which swaps bytes during
#    reads and writes) and are equivalent, despite the different name. All
#    InstallAlias has to do is use one of the device names (the first one).

                                if ($#nrdev > 1) then
                                    set nrdev = $nrdev[1]
                                endif
                                set alnrtape = "$dpref/$nrdev"
                                foreach tapedev ($altape $alnrtape)
                                    set tdev = $tapedev:t
                                    if ("$tdev" == "$nrdev") then
                                        set fill = "non-"
                                    else
                                        set fill = ""
                                    endif
                                    if ("$tdev" != "") then
                                        mt -t $ruser@${REMOTE_TAPE_HOST}:$tapedev stat >& $OUT
                                        if ($status != 0) then
                                            set notape
                                            echo ""
                                            echo "The ${fill}rewinding tape device ($tapedev) exists, but an error occurs"
                                            echo "when InstallAlias attempts to access it:"
                                            echo ""
                                            cat $OUT | sed -e "s/$ruser@//" -e "s/^/    /"
                                        endif
                                        rm -f $OUT
                                    else
                                        set notape
                                        echo ""
                                        echo "The ${fill}rewinding version of the tape device that you specified does not exist."
                                    endif
                                end
                                if (! $?notape) then
                                    set TAPE = $ruser@${REMOTE_TAPE_HOST}:$altape
                                    set NRTAPE = $ruser@${REMOTE_TAPE_HOST}:$alnrtape
                                endif
                            endif
                        else
                            echo ""
                            echo "All tape devices are character devices. The tape device that you specified"
                            echo "($altape) is not a character device and cannot be used for the installation."
                            echo ""
                            echo "You must specify a valid tape device."
                            set notape
                        endif
                    endif
                endif
            endif
        endif
        rm -f $OUT $OERR

#    If acceptable tape device(s) were not found, inform the installer and
#    exit.

        if ($?notape) then
            echo ""
            echo "Once you know which tape device you wish to use, attempt the installation"
            echo "again."
            echo ""
            echo -n "Press <ENTER> to continue: "
            set a = $<
            exit
        endif
    endif
endif

#    If the installer indicates that they do wish to install from CD-ROM or
#    tape, inform them that those are the only methods to install the software.

if (! $?mtype) then
    echo ""
    echo "You have indicated that you do not wish to install the $vers software"
    echo "from CD-ROM or tape. In order to install the software, you must choose one of"
    echo "the two methods."
    echo ""
    echo "Once you have determined the appropriate method, attempt the installation"
    echo "again."
    echo ""
    echo -n "Press <ENTER> to continue: "
    set a = $<
    exit
endif

echo ""
echo "Installing $vers software from a $mtype drive."

#    Get a copy of the old Alias encryption file:
#
#    If the encryption file is not empty, make a copy of it. Since some old
#    Alias encryption strings work with the new Alias software, InstallAlias
#    will append the contents of the copied encryption file to the new
#    encryption file after the new Alias software is installed.

if (! -f $SVEN) then
    if (-f $symlink_to_alias/sys/install/en && ! -z $symlink_to_alias/sys/install/en) then
        echo ""
        echo ""
        echo "Saving copy of $vers encryption file for later restoration."
        cp $symlink_to_alias/sys/install/en $SVEN
    endif
endif

#    The variable INSFTW represents a list of files to install from the
#    Alias software on the distribution media. If this variable has a
#    null value (as is the case when full Alias software is installed),
#    all files are installed, else only those files listed by the variable
#    are installed.
#
#    The space requirements for the software depends on which type of software
#    is being installed:
#
#        - Render software requires 50 megabytes
#
#        - ALIAS software requires 150 megabytes

if ($?render_sftw) then

#    If render software is being installed INSFTW needs to be set to those
#    files which comprise a render-only install. In the case of a tape install,
#    all files in the Alias image of the tape are compressed and must be
#    listed as such when assigned to INSFTW.
#
#    In the case of a CD-ROM install, none of the files are compressed
#    and must be listed as such when assigned to INSFTW.

    if ($?TAPE) then
        set INSFTW = ".cut .cshrc.Z .login.Z .AliasPrefs.Z .Xresources.Z .4Dwmrc .mwmrc bin/{beep.Z,convert.Z,findit.Z,fstats.Z,gamma.Z,get_alias_variable.Z,getid.Z,install_en.Z,pixdiff.Z,powercaster.Z,powercaster.i4.3k.Z,powercaster.i5.4k.Z,powertracer.Z,powertracer.i4.3k.Z,powertracer.i5.4k.Z,preview.Z,raytracer.Z,renderer.Z,raytracer.3k.Z,raytracer.4k.Z,renderer.3k.Z,renderer.4k.Z,renderit.Z,skd,wireframer.Z} etc/skd sys/install/en"
    else
        set INSFTW = ".cut .cshrc .icons .login .AliasPrefs .Xresources .4Dwmrc .mwmrc bin/{alias_render_demon,beep,convert,findit,fstats,gamma,get_alias_variable,getid,install_en,pixdiff,powercaster,powercaster.i5.3k,powercaster.i5.4k,powertracer,powertracer.i5.3k,powertracer.i5.4k,preview,raytracer,renderer,raytracer.i5.3k,raytracer.i5.4k,renderer.i5.3k,renderer.i5.4k,renderit,skd,wireframer} etc/skd sys/install/en"
    endif

    set alias_reqd_Mbspace = 50 # Megabytes required by render software
else
    set INSFTW = ""
    set alias_reqd_Mbspace = 150 # Megabytes required by ALIAS software
endif

foreach fname ($mod_files)

#    Save original copies of system files that may be modified by InstallAlias.
#    Copy $fname to $fname.pre_alias.

    if (-e $fname && ! -e $fname.pre_alias) cp $fname $fname.pre_alias
end

#    Find all filesystems that have enough disk space for the ALIAS software.
#    If none of the local filesystems have sufficient free disk space, inform
#    the user of the situation and exit.

@ alias_reqd_kbspace = $alias_reqd_Mbspace * 1024

#    Find all local filesystems (sorted to ensure / is first)

set local_fsys = `$DF | awk '$2 == "efs" {print $7}' | sort`

unset fsystems

#    Inspect all local filesystems on the machine for sufficient space for
#    the Alias software:
#
#    Work through the list of available filesystems backwards (last to first)
#    as we don't want to include the root filesystem (/) as a candidate
#    filesystem for the installation if other filesystems have sufficient
#    disk space. If a filesystem is writable (not a CD-ROM) and has sufficient
#    disk space, it is a candidate filesystem for the installation of the
#    Alias software.
#
#    Also compile a list of all writable filesystems (i.e.: not /CDROM) which
#    is used later. The list is in reverse order (i.e.: /usr before /)

set wlocal_fsys = ()
@ in = $#local_fsys
while ($in > 0)
    set lfs = $local_fsys[$in]
    if (-w $lfs) then
        set wlocal_fsys = ($wlocal_fsys $lfs)
        set fsys_ds = `$DF $lfs | awk '$2 == "efs"  {print $5}'`
        if ($fsys_ds > $alias_reqd_kbspace) then
            if ($?fsystems) then
                if ("$lfs" != "/") then
                    set fsystems = ($lfs $fsystems)
                endif
            else
                set fsystems = $lfs
            endif
        endif
    endif
    @ in--
end

if (! $?fsystems) then
    echo ""
    echo "There are no filesystems with sufficient disk space for the $vers"
    echo "software (requires approx $alias_reqd_Mbspace megabytes). Please free sufficient disk space"
    echo "and attempt the installation again. Consider removing any old software to"
    echo "free sufficient disk space. If you are unable to find enough space, ask"
    echo "Alias Assist for assistance."
    echo ""
    echo -n "Press <ENTER> to continue: "
    set a = $<
    exit
endif

#    Determine the filesystem on which to install ALIAS:
#
#    If only one filesystem has sufficient free disk space, it is chosen by
#    default; else inform the installer of the "the filesystems with sufficient
#    disk space" and let them choose.

if ($#fsystems != 1) then
    echo ""
    echo "The filesystems with sufficient disk space are:"

    while (1)
        echo ""
        @ index = 1
        while ($index <= $#fsystems)
            echo $fsystems[$index] | sed "s/^/    /"
            @ index++
        end
        echo ""
        while (1)
            echo -n "Please enter your choice: "
            set pname = $<
            set sftwfs = ($pname)
            if ($#sftwfs == 1) break
        end
        @ index = 1
        @ found = 0
        while ($index <= $#fsystems && $found == 0)
            if ("$fsystems[$index]" == "$sftwfs") then
                @ found++
            else
                @ index++
            endif
        end
        if ($found != 0) break
        echo ""
        echo "$sftwfs is not a valid choice. Please choose one of:"
    end
else
    set sftwfs = $fsystems
    echo ""
    echo "The only filesystem with sufficient disk space for the $vers software"
    echo "is $sftwfs."
endif

#    The Alias software will be installed on the root filesystem (/) only
#    if no other writable filesystems have sufficient disk space.
#
#    If the Alias software will be installed on the root filesystem, determine
#    where on the filesystem it can be installed. If the root filesystem is the
#    only writable filesystem on the machine, InstallAlias would like to install
#    the software in /usr. If the machine has other writable filesystems, it
#    has already been determined that they have insufficient disk space for the
#    software. In this case, the software will be installed in a directory on
#    the root filesystem (/).

if ("$sftwfs" == "/") then
    if ($#wlocal_fsys > 1) then
        set swstr = ""
    else
        set swstr = "/usr"
        echo ""
        echo "Your machine only has one filesystem ($sftwfs). This filesystem includes the $swstr"
        echo "directory which is where InstallAlias would like to install the $vers"
        echo "software. You may choose to install the software at any location on the"
        echo "filesystem."
    endif
else
    set swstr = $sftwfs
endif

#    Once it has been determined on what filesystem the ALIAS software is to be
#    installed ($sftwfs), ask the installer where the software should be
#    installed on the filesystem.

echo ""
echo "The $vers software will be installed in the $sftwfs filesystem in a"
echo "directory whose pathname ends with $dir; for example $swstr/$dir or"
echo -n "$swstr/u/$dir"
if ("$swstr" == "") then
    echo " (if /u is not a filesystem)."
else
    echo "."
endif

#    Ask the installer if they wish to install the ALIAS software in
#    /<dir>/aliasYYMM, where /<dir> is the name of a directory on a local
#    filesystem where the software will be installed:
#
#    If a machine has one or more filesystems with sufficient disk space for
#    the Alias software, the value of /<dir> will be the name of a filesystem
#    where the installer wishes to install the software (i.e.: /usr). In this
#    case, the root filesystem (/) will have been removed from the list of
#    filesystems considered as target filesystems for the installation of the
#    Alias software, even if it had enought disk space for the Alias software.
#
#    If a machine has one or more filesystems, but the root filesystem is the
#    only filesystem with sufficient disk space and /usr is a filesystem, the
#    value of /<dir> will be /. The installer will have the option of specifying
#    an alternate location for the software or approving its installation at the
#    given location.
#
#    If a machine has one filesystem (the root filesystem) and it has sufficient
#    disk space for the software, the value of /<dir> will be /usr which is
#    where InstallAlias would like to install the software.
#
#    and aliasYYMM is a directory indicating the Alias software and its release
#    date.
#
#    If they doesn't want to install the software in /<dir>/aliasYYMM, ask them
#    where they do want it.

set sftwdir = $swstr/$dir
echo ""
echo "Do you wish to install the $vers software in"
echo -n "$sftwdir? (yes/no): "

while (1)
    set ans = $<
    if ("$ans" !~ [yY][eE][sS] && "$ans" !~ [nN][oO]) then
        echo -n "Please specify yes or no: "
    else
        break
    endif
end

if ($ans =~ [nN][oO]) then

    while (1)
        unset bad_root bad_suffix
        echo ""
        echo "Where do you wish to install the $vers software? (please specify a"
        echo -n "full pathname): "
        set pname = $<
        set sftwdir = ($pname)

#    Verify that the installer typed something meaningful.

        if ($#sftwdir != 1) continue

#    When the installer specifies a location for the ALIAS software, verify
#    that:
#
#    - the directory is located in the filesystem that the installer approved
#    - the name of the directory is aliasYYMM (for identification purposes)
#
#    If any of these points are not met, InstallAlias warns the installer and
#    asks them to specify a location which matches the criteria.
#
#    Assuming everything goes okay, the shell variable sftwdir will contain
#    the pathname of the directory where the ALIAS software will be installed,
#    pending installer approval.

#    Verify that the specified location is a full pathname (starts with /).
#    If this is not done here, root_fs will be incorrectly set to / below.

        set pfc = `echo $sftwdir | cut -c1`
        if ("$pfc" != "/") then
            echo ""
            echo "$sftwdir is not a full pathname. Please choose again."
            continue
        endif

        @ i = 1
        while ($i <= $#wlocal_fsys)
            set wfs = $wlocal_fsys[$i]
            set mtch = `echo $sftwdir/ | grep "^$wfs/"`
            if ($#mtch) then
                set root_fs = $wfs
                break
            endif
            @ i++
        end
        if (! $?root_fs) set root_fs = "/"

        if ("$sftwfs" == "/") then
            @ i = 1

#    If the root filesystem (/) is the filesystem on which the Alias software
#    is being installed, verify that the install directory specified by the
#    installer does not reside on one of the other local filesystems.

            while ($i <= $#wlocal_fsys)
                set fsname = $wlocal_fsys[$i]
                if ("$fsname" != "/" && "$root_fs" == "$fsname") then
                    set bad_root
                    break
                endif
                @ i++
            end
        else
            if ("$root_fs" != "$sftwfs") set bad_root
        endif

        set suffix = $sftwdir:t
        if ("$suffix" != $dir) set bad_suffix
        if ($?bad_root || $?bad_suffix) then
            echo ""
            echo ""
            echo "$sftwdir is an invalid choice for the location of the"
            echo "$vers software."
            if ($?bad_root) then
                echo ""
                if ($#fsystems != 1) then
                    echo "Since you have chosen to install the software on $sftwfs, you must specify a"
                    echo "location on that filesystem."
                else
                    echo "Since $sftwfs is the only filesystem with sufficient disk space, you must"
                    echo "specify a location on that filesystem."
                endif
            endif
            if ($?bad_suffix) then
                echo ""
                echo "For the purpose of identification, please specify a location whose pathname"
                echo "ends with $dir."
            endif
        else
            break
        endif
    end

#    Once the pathname of the eventual location of the ALIAS software has been
#    agreed upon($sftwdir), ask the installer if it is okay to continue with
#    the installation. If they say `yes' , continue; else abort the
#    installation.

    echo ""
    echo "Proceeding to install the $vers software in $sftwdir."
    echo -n "Continue with the installation? (yes/no): "

    while (1)
        set ans = $<
        if ("$ans" !~ [yY][eE][sS] && "$ans" !~ [nN][oO]) then
            echo -n "Please specify yes or no: "
        else
            break
        endif
    end
    if ($ans =~ [nN][oO]) goto userexit

endif

#    Verify that the home directory for the ALIAS software does not exist. If
#    it exists, inform the user of its existence and how much disk space it
#    occupies, then give them the option to remove it. If they say `no',
#    explain the situation and exit; else remove the file/directory. Note that
#    running `du' on a file does not provide any disk space information and
#    `ls -l' must be used instead.

if (-e $sftwdir) then
    if (-d $sftwdir) then
        set al_sp = `$DU $sftwdir | awk '{print $1}'`
        set ftype = directory
    else
        set al_sp = `ls -l $sftwdir | awk '{printf "%.2f", $5 / 1024}'`
        set ftype = file
    endif
    echo ""
    echo ""
    echo "The $ftype $sftwdir exists and contains $al_sp kilobytes. It is"
    echo "strongly recommended that this be removed and then replaced with the"
    echo "$vers software on the distribution $almedia."
    echo ""
    echo "If this $ftype is not removed (or renamed), the $vers software"
    echo "cannot be installed in the location that you specified."
    echo ""
    echo -n "Do you wish to remove the old $sftwdir $ftype? (yes/no): "
    while (1)
        set ans = $<
        if ("$ans" !~ [yY][eE][sS] && "$ans" !~ [nN][oO]) then
            echo -n "Please specify yes or no: "
        else
            break
        endif
    end
    if ($ans =~ [nN][oO]) then
        set errmsg1 = "$sftwdir must be removed (or renamed) for the installation to succeed."
        goto baderr
    endif
    echo ""
    echo "Removing $sftwdir."
    rm -fr $sftwdir
endif

#    Attempt to form a symbolic link between the home of the ALIAS software
#    and /usr/alias (i.e: /usr/alias -> /usr/aliasYYMM):
#
#    If /usr/alias is a symbolic link and its target is the home of the
#    ALIAS software, the link is correct. 
#
#    Note that /usr/alias may be a symbolic link to a relative pathname. If
#    so (no leading slash), prepend the root directory of symlink_to_alias
#    (/usr) to the pathname to determine the full pathname of the link.

set link_usr_alias
if (-l $symlink_to_alias) then
    set target = `ls -l $symlink_to_alias | awk '{print $11}'`
    set pfc = `echo $target | cut -c1`
    if ("$pfc" != "/") then
        set target = $symlink_to_alias:h/$target
    endif
    if ("$target" == "$sftwdir") unset link_usr_alias
endif

#    This code is executed if a symbolic link from /usr/alias to the home of the
#    ALIAS software does not exist:
#
#    If /usr/alias exists, inform the user of its existence and the disk space
#    that it occupies, then give them the option to remove it. If they respond
#    negatively, print an error message which explains the problem and exit;
#    else remove /usr/alias and form a symbolic link from /usr/alias to the home
#    of the ALIAS software.
#
#    The (-e <fname> || -l <fname>) is needed here due to a csh bug:
#
#        Let <fname> be a symbolic link to a non-existent file. If you test
#        <fname> with "-e", it seems to do a stat() which fails because the
#        target of the symlink (non-existent) does not exist. If you test
#        <fname> with "-l", it does an lstat() which succeeds because lstat()
#        examines the symlink and not the target of the symlink.

if ($?link_usr_alias) then
    if (-e $symlink_to_alias || -l $symlink_to_alias) then
        echo ""
        echo ""
        if (-l $symlink_to_alias) then

#    At this point, we know that /usr/alias is a symbolic link whose target is
#    not the home directory of the ALIAS software (as it should be). The code
#    reveals the target of the symbolic link and instructs the user to dispose
#    of it somehow or the installation will not continue.

            echo "It has been determined that $symlink_to_alias is a symbolic link to $target."

#    Have to enclose string in double quotes so that `$symlink_to_alias' expands

            echo -n "The purpose of $symlink_to_alias"
            echo ' is to "point" to the latest version of ALIAS'
            echo "software that has been installed on this machine, thus it must be removed"
            echo "(or renamed) for the installation to continue."

#    If the target of /usr/alias is not null ($target == "/usr/" if /usr/alias
#    "points" to null) and is a directory, ask the installer if they wish to
#    install the old software.
#
#    If they `yes', remove the software and continue with the installation.
#    If they say `no', inform them that they may continue to use the old
#    software by changing the value of ALIAS_LOCATION.

            if ("$target" != "$symlink_to_alias:h/" && -d "$target") then
                echo ""
                echo "Since the $vers software on the ALIAS distribution $almedia is meant"
                echo "to replace the Alias software installed in $target, the old"
                echo "software should be removed. This will provide valuable disk space for"
                echo "further development."
                echo ""
                echo -n "Do you wish to remove $target? (yes/no): "
                while (1)
                    set ans = $<
                    if ("$ans" !~ [yY][eE][sS] && "$ans" !~ [nN][oO]) then
                        echo -n "Please specify yes or no: "
                    else
                        break
                    endif
                end
                if ($ans =~ [Yy][Ee][Ss]) then
                    echo ""
                    echo "Removing $target ..."
                    rm -fr $target
                else
                    echo ""
                    echo "If you wish to continue using the software in $target, you may do so"
                    echo "by setting your ALIAS_LOCATION to $target. If you have any questions"
                    echo "about this, contact Alias Assist for details."
                endif
            endif
        else

#    In this case, /usr/alias is anything except a symbolic link (directory,
#    file, <etc>), but this procedure requires that it be a symbolic link to the
#    home directory of the ALIAS software. Unlike the previous section of code,
#    the amount of disk space occupied by /usr/alias is computed and reported to
#    the user. Note that running `du' on a file does not provide any disk space
#    information and `ls -l' must be used instead.

            if (-d $symlink_to_alias) then
                set al_sp = `$DU $symlink_to_alias | awk '{print $1}'`
                set ftype = directory
            else
                set al_sp = `ls -l $symlink_to_alias | awk '{printf "%.2f",$5 / 1024}'`
                set ftype = file
            endif
            echo "The $ftype $symlink_to_alias exists and contains $al_sp kilobytes. The purpose"

#    Have to enclose string in double quotes so that `$symlink_to_alias' expands

            echo -n "of $symlink_to_alias"
            echo ' is to "point" to the latest version of ALIAS software that'
            echo "has been installed on this machine, thus it must be removed (or renamed)"
            echo "for the installation to continue."
        endif

        echo ""
        echo -n "Do you wish to remove $symlink_to_alias? (yes/no): "
        while (1)
            set ans = $<
            if ("$ans" !~ [yY][eE][sS] && "$ans" !~ [nN][oO]) then
                echo -n "Please specify yes or no: "
            else
                break
            endif
        end
        if ($ans =~ [nN][oO]) then
            set errmsg1 = "$symlink_to_alias must be removed (or renamed) for the installation to succeed."
            goto baderr
        endif
        rm -fr $symlink_to_alias
    endif
    ln -s $sftwdir $symlink_to_alias
    if ($status != 0) then
        echo ""
        set errmsg1 = "Cannot form symbolic link from $symlink_to_alias to $sftwdir"
        goto baderr
    endif
endif

#    Find an owner for the Alias software:
#
#    If InstallAlias is running in guru mode, the installer has the ability
#    to specify who should own the ALIAS software when it is installed.
#
#    If InstallAlias is not running in guru mode, it will install/verify the
#    dist account and install the software such that it is owned by dist.

unset newuser
if ($?guru_mode) then

    unset have_owner
    while (! $?have_owner)

#    Ask the guru who should own the ALIAS software

        echo ""
        echo -n "When the $vers software is installed, who should own it?: "
        set oname = $<
        set distname = ($oname)
        if ($#distname != 1) continue

#    Check if there is a password entry for the specified user. If a password
#    entry is found for the specified user, set the `have_owner' flag to
#    indicate that an owner for the ALIAS software has been found.

        set pwe = "`grep ^${distname}: /etc/passwd`"
        if ($#pwe != 0) then
            set have_owner
            set ugh = `echo "$pwe" | awk -F: '{print $3, $4, $6}'`
            @ owner_uid = $ugh[1]
            @ owner_gid = $ugh[2]
            set owner_home = $ugh[3]
        else

#    If there is no password entry for the specified user, construct one.
#    Inform the installer that they will be given the option of picking the
#    value of each password field and that InstallAlias will pick the value if
#    they do not.

            echo ""
            echo "There is no password entry for $distname."
            echo -n "Do you wish to create one? (yes/no): "
            while (1)
                set ans = $<
                if ("$ans" !~ [yY][eE][sS] && "$ans" !~ [nN][oO]) then
                    echo -n "Please specify yes or no: "
                else
                    break
                endif
            end
            if ($ans =~ [yY][eE][sS]) then
                echo ""
                echo "A password entry for $distname must be created. InstallAlias will ask you if you"
                echo "wish to specify a value for each field of the entry. If you say no, InstallAlias"
                echo "will choose a suitable value for that field."
                echo ""

#    Ask the user if they wish to specify the numeric uid for the specified
#    user. If they respond affirmatively, InstallAlias asks for the userid and
#    verifies that it is not in use by another user.
#
#    If the user indicates that they do not want to choose the userid,
#    InstallAlias will choose an unused value.

                echo -n "Do you wish to specify the numeric userid for $distname? (yes/no): "
                while (1)
                    set ans = $<
                    if ("$ans" !~ [yY][eE][sS] && "$ans" !~ [nN][oO]) then
                        echo -n "Please specify yes or no: "
                    else
                        break
                    endif
                end
                if ($ans =~ [yY][eE][sS]) then
                    while (1)
                        echo ""
                        echo -n "Please specify an unused numeric userid: "
                        set num = $<
                        set uid = ($num)
                        if ($#uid != 1) continue
                        set pwname = `grep "^[^:]*:[^:]*:${uid}:" /etc/passwd | awk -F: '{print $1}'`
                        if ($#pwname != 0) then
                            echo ""
                            echo "The numeric userid of $uid is in use by $pwname."
                        else
                            break
                        endif
                    end
                else
                    @ uid = $owner_uid
                    set pwname = "dummy entry"
                    while ($#pwname != 0)
                        set pwname = `grep "^[^:]*:[^:]*:${uid}:" /etc/passwd`
                        @ uid++
                    end
                    @ uid--
                    echo ""
                    echo "The $distname account has been assigned a userid of $uid."
                endif
                @ owner_uid = $uid

#    Ask the user if they wish to specify the group that the specified user
#    belongs to. If they respond affirmatively, InstallAlias asks for the group
#    identifer and verifies that it is valid.
#
#    If the user indicates that they do not want to choose the group,
#    InstallAlias uses a default group of 20 (user group on default SGI
#    systems).

                echo ""
                echo -n "Do you wish to specify the group that $distname belongs to? (yes/no): "
                while (1)
                    set ans = $<
                    if ("$ans" !~ [yY][eE][sS] && "$ans" !~ [nN][oO]) then
                        echo -n "Please specify yes or no: "
                    else
                        break
                    endif
                end

                if ($ans =~ [yY][eE][sS]) then
                    while (1)
                        echo ""
                        echo -n "Please specify an existing group: "
                        set numn = $<
                        set group = ($numn)
                        if ($#group != 1) continue

#    If the installer specifies the group that they wish the specified user
#    to belong to, InstallAlias verifies that the group is valid by checking to
#    see if it is a known group name or numeric group identifier.
#
#    The final group id must be numeric for inclusion in the password entry.

                        unset valid_group
                        set gid = `grep "^${group}:" /etc/group | awk -F: '{print $3}'`
                        if ($#gid != 0) then
                            set valid_group
                        else
                            set gid = `grep "^[^:]*:[^:]*:${group}:" /etc/group | awk -F: '{print $3}'`
                            if ($#gid != 0) set valid_group
                        endif
                        if (! $?valid_group) then
                            echo ""
                            echo "The group specified by $group does not exist."
                        else
                            break
                        endif
                    end
                else
                    @ gid = $default_gid
                    echo ""
                    echo "The $distname account will be placed in group $gid."
                endif
                @ owner_gid = $gid

#    Ask the installer where they want the specified user's home directory
#    to be located. It is preferred if the installer specifies /usr/alias
#    for the home directory so that the account acts as a administrator
#    for the ALIAS software.

                echo ""
                echo "If the only purpose of the $distname account is to act as the owner of"
                echo "the $vers software, you may want to set ${distname}'s home directory"
                echo "to $symlink_to_alias."
                while (1)
                    echo ""
                    echo -n "Please specify the full pathname of ${distname}'s home directory: "
                    set pname = $<
                    set owner_home = ($pname)
                    if ($#owner_home != 1) continue

#    Verify that the specified home directory is a full pathname (starts
#    with /).

                    set ohfc = `echo $owner_home | cut -c1`
                    if ("$ohfc" != "/") then
                        echo ""
                        echo "$owner_home is not a full pathname. Please choose again."
                        continue
                    endif

#    Verify that the specified home directory is not a file.

                    if (-f $owner_home) then
                        echo ""
                        echo "$owner_home is a file, not a directory. Please choose again."
                        continue
                    endif
                    if ("$owner_home" != "") break
                end

#    Inform the installer that the default shell for the account is csh.
#    All ALIAS users must use csh unless they wish to convert the supplied
#    .cshrc file into bourne shell (sh) or korn shell (ksh).

                echo ""
                echo "The default login shell is /bin/csh."

#    Ask the installer if they wish to add the completed password entry to
#    the password file. If they respond affirmatively, the password entry
#    is added to the password file.

                echo ""
                echo "Do you wish to add the following password entry:"
                echo ""
                echo "    ${distname}:*:${uid}:${gid}:ALIAS Administrator:${owner_home}:/bin/csh"
                echo ""
                echo -n "to the local password file? (yes/no): "
                while (1)
                    set ans = $<
                    if ("$ans" !~ [yY][eE][sS] && "$ans" !~ [nN][oO]) then
                        echo -n "Please specify yes or no: "
                    else
                        break
                    endif
                end
                if ($ans =~ [yY][eE][sS]) then

#    Add the password entry to the local password file and set the
#    `have_owner' flag (have an owner for the ALIAS software).

                    ex - /etc/passwd << EOF
                    ${DLR}a
${distname}:*:${uid}:${gid}:ALIAS Administrator:${owner_home}:/bin/csh
.
                    w! /etc/passwd
                    q
EOF
                    set have_owner newuser

#    Ask the installer if they wish to set a password on the owner account.
#    If a password is not set, it will remain "starred" and no one will be
#    able to login to the account.

                    echo ""
                    echo "If you wish to login to the $distname account, you must set a password"
                    echo "for the account. If ${distname}'s password is not set, you will not be able"
                    echo "to login to the account."
                    echo ""
                    echo -n "Do you wish to set ${distname}'s password? (yes/no): "
                    while (1)
                        set ans = $<
                        if ("$ans" !~ [yY][eE][sS] && "$ans" !~ [nN][oO]) then
                            echo -n "Please specify yes or no: "
                        else
                            break
                        endif
                    end
                    if ($ans =~ [yY][eE][sS]) then
                        passwd $distname
                    endif
                endif
            endif

#    If an owner for the ALIAS software has not been found (`have_owner' flag
#    is not set), ask the installer if they wish to specify another potential
#    owner for the software. If they say no, exit InstallAlias; else ask them
#    who should own the software.

            if (! $?have_owner) then
                echo ""
                echo "Do you wish to specify another user to own the $vers software? If you"
                echo -n "say no, InstallAlias will exit. Please specify your choice? (yes/no): "
                while (1)
                    set ans = $<
                    if ("$ans" !~ [yY][eE][sS] && "$ans" !~ [nN][oO]) then
                        echo -n "Please specify yes or no: "
                    else
                        break
                    endif
                end
                if ($ans =~ [nN][oO]) goto userexit
            endif
        endif
    end
else

#    If the installer does not run InstallAlias in guru mode, verify/install the
#    dist account. When the ALIAS software is installed, it will be owned by
#    dist.

    echo ""
    echo "Installing/verifying $distname account in the password file."

#    Check for a password entry for the dist account.

    set pwe = "`grep ^${distname}: /etc/passwd`"
    if ($#pwe != 0) then
        set ugh = `echo "$pwe" | awk -F: '{print $3, $4, $6}'`
        @ owner_uid = $ugh[1]
        @ owner_gid = $ugh[2]
        set owner_home = $ugh[3]
    else

#    If a password entry for the dist account was not found, search for a
#    possible value for dist's userid:
#
#    Set pwname to a dummy value, then loop until we find an unused userid. At
#    the end of the while loop, decrement the userid to arrive at the correct
#    value.
#
#    When an unused userid has been found, add a password entry for the dist
#    account with the userid just chosen and home directory of /usr/alias, where
#    /usr/alias is a symbolic link to the directory containing the ALIAS
#    software. At this point of the installation, the symbolic link /usr/alias
#    is guaranteed to exist.
#
#    Inform the user that the chosen userid has been assigned to the dist
#    account.

        set pwname = "dummy entry"
        while ($#pwname != 0)
            set pwname = `grep "^[^:]*:[^:]*:${owner_uid}:" /etc/passwd`
            @ owner_uid++
        end
        @ owner_uid--

        @ owner_gid = $default_gid

        ex - /etc/passwd << EOF
        ${DLR}a
${distname}:*:${owner_uid}:${owner_gid}:ALIAS Administrator:${symlink_to_alias}:/bin/csh
.
        w! /etc/passwd
        q
EOF

        echo ""
        echo "The ${distname} account has been assigned a userid of $owner_uid and will be placed"
        echo "in group $owner_gid."
        set newuser
        set owner_home = $symlink_to_alias

#    Ask the installer to set a password for the dist account.

        echo ""
        echo "Please specify a password for the $distname account."
        passwd $distname
    endif

#    Report the location of the dist account's home directory

    echo ""
    echo "The home directory of the $distname account is $owner_home."
endif

#    If the owner's home directory is not /usr/alias (symbolic link to the
#    ALIAS software), verify that it exists and the permissions are correct.

if ("$owner_home" != "$symlink_to_alias") then
    if (-e $owner_home) then
        if (-d $owner_home) then
            set duid = `ls -dln $owner_home | awk '{print $3}'`

#    If the home directory of the owner account exists, but is not owned by the
#    owner user, ask the installer if the ownership should be changed,
#    explaining that if the ownership is not changed, the owner account may
#    not be able to create files in the directory.
#
#    If the installer says `yes', change the ownership of the home directory to
#    be owned by the owner user.

            if ($duid != $owner_uid) then
                echo ""
                echo "${distname}'s home directory ($owner_home) exists, but is not owned"
                echo "by $distname."
                echo ""
                echo "$distname may not be able to create files in $owner_home if $owner_home is not"
                echo "owned by $distname. This will not affect the installation of the $vers"
                echo "software."
                echo ""
                echo -n "Do you wish to change the ownership of $owner_home to $distname? (yes/no): "
                while (1)
                    set ans = $<
                    if ("$ans" !~ [yY][eE][sS] && "$ans" !~ [nN][oO]) then
                        echo -n "Please specify yes or no: "
                    else
                        break
                    endif
                end
                if ($ans =~ [yY][eE][sS]) chown $distname $owner_home
            endif
        else

#    If the specified home directory is not a directory, inform the installer.

            echo ""
            if (-f $owner_home) then
                echo "${distname}'s home directory ($owner_home) is a file, not a directory."
            else
                echo "${distname}'s home directory ($owner_home) is not a directory:"
                echo ""
                ls -dl $owner_home | sed "s/^/    /"
            endif
        endif
    else
        if (-l $owner_home) then

#    If the home directory of the owner account is a symbolic link whose target
#    does not exist (i.e.: the test for existence above has failed), determine
#    the target of the symbolic link and inform the installer that it should be
#    created or no one will be able to login to the owner account (no home
#    directory). If they say `yes', create the target of the symbolic link and
#    fix permissions.
#
#    If they say `no', inform the installer that no one will be able to login
#    to the owner account.

            set ownertarg = `ls -l $owner_home | awk '{print $11}'`
            echo ""
            echo "${distname}'s home directory ($owner_home) is a symbolic"
            echo "link whose target ($ownertarg) does not exist."
            echo ""
            echo "This directory should be created or $distname will not have a home directory."
            echo "As a result, no one will be able to login to the $distname account."
            echo ""
            echo -n "Do you wish to create $ownertarg? (yes/no): "
            while (1)
                set ans = $<
                if ("$ans" !~ [yY][eE][sS] && "$ans" !~ [nN][oO]) then
                    echo -n "Please specify yes or no: "
                else
                    break
                endif
            end
            if ($ans =~ [yY][eE][sS]) then
                echo ""
                echo "Creating $ownertarg."
                mkdir -m 755 -p $ownertarg
                if ($status != 0) then
                    set errmsg1 = "Error creating $ownertarg directory."
                    goto baderr
                endif
                chown $distname.$owner_gid $ownertarg
            else
                echo ""
                echo "No one will be able to login to the $distname account."
            endif
        else

#    If the home directory of the owner account does not exist and it is not a
#    symbolic link, create it and set permissions (ownership, group and access
#    mode).

            echo ""
            echo "Creating ${distname}'s home directory ($owner_home)."
            mkdir -m 755 -p $owner_home
            if ($status != 0) then
                set errmsg1 = "Error creating ${distname}'s home directory ($owner_home)"
                goto baderr
            endif
            chown $distname.$owner_gid $owner_home
        endif
    endif
endif

#    If the installer is using a remote tape drive to install the ALIAS
#    software, verify that the owner of the software ($distname) can access
#    the tape drive.

if ($?REMOTE_TAPE_HOST) then
    unset valid_hostsequiv
    echo ""
    echo "Verifying that $distname can access the tape drive on $REMOTE_TAPE_HOST ..."
    set owner_uid = `grep "^${distname}:" /etc/passwd | awk -F: '{print $3}'`

#    If the owner of the Alias software is root, no verification is necessary
#    as it was done at the start of InstallAlias.

    if ($owner_uid != 0) then

#    In order for the non-root owner of the Alias software to perform commands
#    on a remote machine, the following entry must appear in the .rhosts file
#    in the remote users' home directory on the remote machine:
#
#    <hostname of current machine> <username of owner of the software>
#
#    The hostname portion of the entry should include your domain name (if
#    you have a domain name) or remote commands may fail. If the username
#    of the remote user is the same as the owner of the software, the
#    username portion of the entry is not required. If the entry is not
#    present, the owner of the software will not be able to run commands
#    using the remote user's account on the remote machine. In this case,
#    InstallAlias informs you of the problem and exits.

        su $distname -c "rsh $REMOTE_TAPE_HOST -l $ruser date >& /dev/null"
        if ($status != 0) then
            echo ""
            echo "In order for the $vers software to be properly installed on"
            echo "$hostname, the owner of the software ($distname) must be able to run"
            echo "commands on $REMOTE_TAPE_HOST. In order to enable this for the duration of"
            echo "InstallAlias, an entry must appear in the .rhosts file in ${ruser}'s home"
            echo "directory on $REMOTE_TAPE_HOST. The format of this entry should be:"
            echo ""
            if ("$ruser" == "$distname") then
                echo "$hostname"
                echo ""   
                echo "If the entry does not include your domain name (assuming you have a"
                echo "domain name), be sure to include it as part of the hostname. Add the"
                echo "complete entry to the .rhosts file, verify that the permissions are"
                echo "correct (chmod go-w .rhosts) and attempt the installation again."
            else
                echo "$hostname $distname"
                echo ""   
                echo "If the hostname portion of the entry ($hostname) does not include"
                echo "your domain name (assuming you have a domain name), be sure to include"
                echo "it as part of the hostname. Add the complete entry to the .rhosts file,"
                echo "verify that the permissions are correct (chmod go-w .rhosts) and attempt"
                echo "the installation again."
            endif
            echo ""
            echo "This entry should be removed when the installation is complete."
            goto clnout
        endif
    endif
endif

unset have_demo
if ($?guru_mode) then

#    If InstallAlias is running in guru mode, ask the installer if they wish to
#    create a demo account for the ALIAS software.

    echo ""
    echo "Do you wish to create a demo account to use the $vers"
    echo -n "software? (yes/no): "
    while (1)
        set ans = $<
        if ("$ans" !~ [yY][eE][sS] && "$ans" !~ [nN][oO]) then
            echo -n "Please specify yes or no: "
        else
            break
        endif
    end
    if ($ans =~ [yY][eE][sS]) then

        while (! $?have_demo)

#    If the installer wants a demo account, ask them the username of the
#    account.

            echo ""
            echo -n "What is the username of the account?: "
            set dname = $<
            set demoname = ($dname)
            if ($#demoname != 1) continue

#    Check if there is a password entry for the specified user. If a password
#    entry is found, set the `have_demo' flag to indicate that a demo account
#    has been found.

            set pwe = "`grep ^${demoname}: /etc/passwd`"
            if ($#pwe != 0) then
                set have_demo
                set ugh = `echo "$pwe" | awk -F: '{print $3, $4, $6}'`
                @ demo_uid = $ugh[1]
                @ demo_gid = $ugh[2]
                set demo_home = $ugh[3]
            else

#    If there is no password entry for the demo account, construct one.
#    Inform the installer that they will be given the option of picking the
#    value of each password field and that InstallAlias will pick the value if
#    they do not.

                echo ""
                echo "There is no password entry for $demoname."
                echo -n "Do you wish to create one? (yes/no): "
                while (1)
                    set ans = $<
                    if ("$ans" !~ [yY][eE][sS] && "$ans" !~ [nN][oO]) then
                        echo -n "Please specify yes or no: "
                    else
                        break
                    endif
                end
                if ($ans =~ [yY][eE][sS]) then
                    echo ""
                    echo "A password entry for $demoname must be created. InstallAlias will ask you if"
                    echo "you wish to specify a value for each field of the entry. If you say no,"
                    echo "InstallAlias will choose a suitable value for that field."
                    echo ""

#    Ask the user if they wish to specify the numeric uid for the demo account.
#    If they respond affirmatively, InstallAlias asks for the userid and
#    verifies that it is not in use by another user.
#
#    If the user indicates that they do not want to choose the userid,
#    InstallAlias will choose an unused value.

                    echo -n "Do you wish to specify the numeric userid for $demoname? (yes/no): "
                    while (1)
                        set ans = $<
                        if ("$ans" !~ [yY][eE][sS] && "$ans" !~ [nN][oO]) then
                            echo -n "Please specify yes or no: "
                        else
                            break
                        endif
                    end
                    if ($ans =~ [yY][eE][sS]) then
                        while (1)
                            echo ""
                            echo -n "Please specify an unused numeric userid: "
                            set num = $<
                            set uid = ($num)
                            if ($#uid != 1) continue
                            set pwname = `grep "^[^:]*:[^:]*:${uid}:" /etc/passwd | awk -F: '{print $1}'`
                            if ($#pwname != 0) then
                                echo ""
                                echo "The numeric userid of $uid is in use by $pwname."
                            else
                                break
                            endif
                        end
                    else
                        @ uid = $demo_uid
                        set pwname = "dummy entry"
                        while ($#pwname != 0)
                            set pwname = `grep "^[^:]*:[^:]*:${uid}:" /etc/passwd`
                            @ uid++
                        end
                        @ uid--
                        echo ""
                        echo "The $demoname account has been assigned a userid of $uid."
                    endif
                    @ demo_uid = $uid

#    Ask the user if they wish to specify the group that the demo account
#    belongs to. If they respond affirmatively, InstallAlias asks for the group
#    identifer and verifies that it is valid.
#
#    If the user indicates that they do not want to choose the group,
#    InstallAlias uses a default group of 20 (user group on default SGI
#    systems).

                    echo ""
                    echo -n "Do you wish to specify the group that $demoname belongs to? (yes/no): "
                    while (1)
                        set ans = $<
                        if ("$ans" !~ [yY][eE][sS] && "$ans" !~ [nN][oO]) then
                            echo -n "Please specify yes or no: "
                        else
                            break
                        endif
                    end

                    if ($ans =~ [yY][eE][sS]) then
                        while (1)
                            echo ""
                            echo -n "Please specify an existing group: "
                            set numn = $<
                            set group = ($numn)
                            if ($#group != 1) continue

#    If the installer specifies the group that they wish the demo account to
#    belong to, InstallAlias verifies that the group is valid by checking to see
#    if it is a known group name or numeric group identifier.
#
#    The final group id must be numeric for inclusion in the password entry.

                            unset valid_group
                            set gid = `grep "^${group}:" /etc/group | awk -F: '{print $3}'`
                            if ($#gid != 0) then
                                set valid_group
                            else
                                set gid = `grep "^[^:]*:[^:]*:${group}:" /etc/group | awk -F: '{print $3}'`
                                if ($#gid != 0) set valid_group
                            endif
                            if (! $?valid_group) then
                                echo ""
                                echo "The group specified by $group does not exist."
                            else
                                break
                            endif
                        end
                    else
                        @ gid = $default_gid
                        echo ""
                        echo "The $demoname account will be placed in group $gid."
                    endif
                    @ demo_gid = $gid

#    Ask the installer where they want the demo account's home directory to
#    be located.

                    while (1)
                        echo ""
                        echo -n "Please specify the full pathname of ${demoname}'s home directory: "
                        set pname = $<
                        set demo_home = ($pname)
                        if ($#demo_home != 1) continue

#    Verify that the specified home directory is a full pathname (starts
#    with /).

                        set dhfc = `echo $demo_home | cut -c1`
                        if ("$dhfc" != "/") then
                            echo ""
                            echo "$demo_home is not a full pathname. Please choose again."
                            continue
                        endif

#    Verify that the specified home directory is not a file.

                        if (-f $demo_home) then
                            echo ""
                            echo "$demo_home is a file, not a directory. Please choose again."
                        else
                            break
                        endif
                    end

#    Inform the installer that the default shell for the account is csh.
#    All ALIAS users must use csh unless they wish to convert the supplied
#    .cshrc file into bourne shell (sh) or korn shell (ksh).

                    echo ""
                    echo "The default login shell is /bin/csh."

#    Ask the installer if they wish to add the completed password entry to
#    the password file. If they respond affirmatively, the password entry
#    is added to the password file.

                    echo ""
                    echo "Do you wish to add the following password entry:"
                    echo ""
                    echo "    ${demoname}:*:${demo_uid}:${demo_gid}:ALIAS Demo Account:${demo_home}:/bin/csh"
                    echo ""
                    echo -n "to the local password file? (yes/no): "
                    while (1)
                        set ans = $<
                        if ("$ans" !~ [yY][eE][sS] && "$ans" !~ [nN][oO]) then
                            echo -n "Please specify yes or no: "
                        else
                            break
                        endif
                    end
                    if ($ans =~ [yY][eE][sS]) then

#    Add the password entry to the local password file and set the
#    `have_demo' flag (have a demo account).

                        ex - /etc/passwd << EOF
                        ${DLR}a
${demoname}:*:${demo_uid}:${demo_gid}:ALIAS Demo Account:${demo_home}:/bin/csh
.
                        w! /etc/passwd
                        q
EOF
                        set have_demo newuser

#    Ask the installer if they wish to set a password on the demo account.
#    If a password is not set, it will remain "starred" and no one will be
#    able to login to the account.

                        echo ""
                        echo "If you wish to login to the $demoname account, you must set a password"
                        echo "for the account. If ${demoname}'s password is not set, you will not be able"
                        echo "to login to the account."
                        echo ""
                        echo -n "Do you wish to set ${demoname}'s password? (yes/no): "
                        while (1)
                            set ans = $<
                            if ("$ans" !~ [yY][eE][sS] && "$ans" !~ [nN][oO]) then
                                echo -n "Please specify yes or no: "
                            else
                                break
                            endif
                        end
                        if ($ans =~ [yY][eE][sS]) then
                            passwd $demoname
                        endif
                    endif
                endif

#    If a demo account has not been setup (`have_demo' flag is not set), ask
#    the installer if they wish to specify another demo account.

                if (! $?have_demo) then
                    echo ""
                    echo "Do you wish to specify another demo account? If you say no, InstallAlias will"
                    echo -n "continue without a demo account. Please specify your choice? (yes/no): "
                    while (1)
                        set ans = $<
                        if ("$ans" !~ [yY][eE][sS] && "$ans" !~ [nN][oO]) then
                            echo -n "Please specify yes or no: "
                        else
                            break
                        endif
                    end
                    if ($ans =~ [Nn][Oo]) break
                endif
            endif
        end
    endif
else

#    If InstallAlias is not running in guru mode, verify that the demo account
#    is installed.

    echo ""
    echo "Installing/verifying $demoname account in the password file."

#    Check if there is a password entry for the demo account. If a password
#    entry is found, set the `have_demo' flag to indicate that a demo account
#    has been found.

    set pwe = "`grep ^${demoname}: /etc/passwd`"
    if ($#pwe != 0) then
        set have_demo
        set ugh = `echo "$pwe" | awk -F: '{print $3, $4, $6}'`
        @ demo_uid = $ugh[1]
        @ demo_gid = $ugh[2]
        set demo_home = $ugh[3]
    else

#    If there is no password entry for the demo account, search for a possible
#    value for its userid:
#
#    Set pwname to a dummy value, then loop until we find an unused userid. At
#    the end of the while loop, decrement the userid to arrive at the correct
#    value.
#
#    Inform the user that the chosen userid has been assigned to the demo
#    account and the group id.

        set pwname = "dummy entry"
        while ($#pwname != 0) 
            set pwname = `grep "^[^:]*:[^:]*:${demo_uid}:" /etc/passwd`
            @ demo_uid++
        end
        @ demo_uid--

#    Set the group id of the demo account to the default value.

        @ demo_gid = $default_gid

        echo ""
        echo "The ${demoname} account has been assigned a userid of $demo_uid and will be placed"
        echo "in group $demo_gid."

#    Find a host filesystem for the home directory of the demo account:
#
#    If there are no writable filesystems besides the root filesystem (/), the
#    demo account's home directory will be in the root filesystem.
#
#    If there are one (or more) writable filesystems besides the root filesystem
#    (i.e.: /usr), the root filesystem is not considered as a possible home
#    filesystem for the home directory.
#
#    Remember that wlocal_fsys is an array of writable local filesystems in
#    reverse order (i.e.: /usr before /).

        set ufs = ()
        set ufs_ds = ()
        @ ds = 1
        while ($ds <= $#wlocal_fsys)
            set wfs = $wlocal_fsys[$ds]
            if ("$wfs" == "/" && $#ufs > 0) then

#    The body of this `if' is deliberately empty

            else
                set ufs = ($wfs $ufs)

#    Compute number of Mb from df information

                set fds = `$DF $wfs | awk '$2 == "efs" { print $5}'`
                @ fds /= 1024

#    If we are considering the home filesystem of the ALIAS software ($sftwfs)
#    as a candidate for the home filesystem for the demo account, subtract the
#    size of the ALIAS software (not installed yet) from the filesystem's free
#    disk space to arrive at a more accurate figure for free space.

                if ("$wfs" == "$sftwfs") then
                    @ fds -= $alias_reqd_Mbspace
                endif
                set ufs_ds = ($fds $ufs_ds)
            endif
            @ ds++
        end

#    If there is one writable filesystem on the machine, the demo account's
#    home directory will be on that filesystem. If the filesystem is the root
#    filesystem (/), InstallAlias will place the home directory in a
#    subdirectory of the root filesystem:
#
#    If /usr is a writable directory, the home directory will be in /usr
#    (/usr/aldemo).
#
#    If /usr is not a writable directory or not a directory, the home directory
#    will be in / (/aldemo). This is very unlikely.

        if ($#ufs == 1) then
            if ("$ufs" == "/") then
                set demo_fs = "/usr"

                unset bad_fs
                if (-d $demo_fs) then
                    if (! -w $demo_fs) set bad_fs
                else
                    set bad_fs
                endif
                if ($?bad_fs) set demo_fs = "/"
            else
                set demo_fs = $ufs
            endif
        else
            echo ""
            echo -n "The ${demoname} account can be installed on one of the "
            echo "following filesystems:"
            while (1)
                echo ""
                @ ds = 1
                while ($ds <= $#ufs)
                    echo "    $ufs[$ds] ($ufs_ds[$ds] Megabytes free)"
                    @ ds++
                end
                echo ""
                echo -n "Please enter your choice: "
                set demo_fs = $<
                @ index = 1
                @ found = 0
                while ($index <= $#ufs && $found == 0)
                    if ("$ufs[$index]" == "$demo_fs") then
                        @ found++
                    else
                        @ index++
                    endif
                end
                if ($found != 0) break
                echo ""
                echo "$demo_fs is not a valid choice, please choose one of:"
            end
        endif

#    Prevent double slash (//aldemo) in the home directory pathname of the
#    demo account.

        if ("$demo_fs" == "/") then
            set demo_home = /$demoname
        else
            set demo_home = $demo_fs/$demoname
        endif

        ex - /etc/passwd << EOF
        ${DLR}a
${demoname}:*:${demo_uid}:${demo_gid}:ALIAS Demo Account:${demo_home}:/bin/csh
.
        w! /etc/passwd
        q
EOF
        set have_demo newuser


#    Ask the installer to set a password for the aldemo account.

        echo ""
        echo "Please specify a password for the $demoname account."
        passwd $demoname
    endif

#    Report the location of the demo account's home directory

    echo ""
    echo "The home directory of the $demoname account is $demo_home."
endif

#    If a demo account exists, verify that its home directory exists and the
#    ownership is correct.

if ($?have_demo) then
    if (-e $demo_home) then
        if (-d $demo_home) then
            set duid = `ls -dln $demo_home | awk '{print $3}'`

#    If the home directory of the demo account exists, but is not owned by the
#    demo user, ask the installer if the ownership should be changed, explaining
#    that if the ownership is not changed, the demo account will not be
#    customized to use the Alias software.
#
#    If the installer says `yes', change the ownership of the home directory to
#    be owned by the demo user.
#
#    If the installer says `no', unset the have_demo flag to indicate that
#    there is no demo account to be customized.

            if ($duid != $demo_uid) then
                echo ""
                echo "${demoname}'s home directory ($demo_home) exists, but is not owned"
                echo "by $demoname."
                echo ""
                echo "The $demoname account will not be customized to use the $vers software"
                echo "if $demo_home is not owned by $demoname."
                echo ""
                echo -n "Do you wish to change the ownership of $demo_home to $demoname? (yes/no): "
                while (1)
                    set ans = $<
                    if ("$ans" !~ [yY][eE][sS] && "$ans" !~ [nN][oO]) then
                        echo -n "Please specify yes or no: "
                    else
                        break
                    endif
                end
                if ($ans =~ [yY][eE][sS]) then
                    chown $demoname $demo_home
                else
                    unset have_demo
                endif
            endif
        else

#    If the specified home directory is not a directory, inform the installer
#    and unset the have_demo flag to indicate that there is no demo account
#    to be customized.

            echo ""
            if (-f $demo_home) then
                echo "${demoname}'s home directory ($demo_home) is a file, not a directory."
            else
                echo "${demoname}'s home directory ($demo_home) is not a directory:"
                echo ""
                ls -dl $demo_home | sed "s/^/    /"
            endif
            echo ""
            echo "The $demoname account will not be customized to use the $vers software."
            unset have_demo
        endif
    else
        if (-l $demo_home) then

#    If the home directory of the demo account is a symbolic link whose target
#    does not exist (i.e.: the test for existence above has failed), determine
#    the target of the symbolic link and inform the installer that it must be
#    created in order for the demo account to be customized to use the Alias
#    software (if it isn't created, the demo account will not have a home
#    directory). If they say `yes', create the target of the symbolic link and
#    fix permissions.
#
#    If they say `no', inform the installer that the demo account will not be
#    customized to use the Alias software.

            set demotarg = `ls -l $demo_home | awk '{print $11}'`
            echo ""
            echo "${demoname}'s home directory ($demo_home) is a symbolic"
            echo "link whose target ($demotarg) does not exist."
            echo ""
            echo "This directory must be created in order for the $demoname account to be"
            echo "customized to use the $vers software."
            echo ""
            echo -n "Do you wish to create $demotarg? (yes/no): "
            while (1)
                set ans = $<
                if ("$ans" !~ [yY][eE][sS] && "$ans" !~ [nN][oO]) then
                    echo -n "Please specify yes or no: "
                else
                    break
                endif
            end
            if ($ans =~ [yY][eE][sS]) then
                echo ""
                echo "Creating $demotarg."
                mkdir -m 755 -p $demotarg
                if ($status != 0) then
                    set errmsg1 = "Error creating $demotarg directory."
                    goto baderr
                endif
                chown $demoname.$demo_gid $demotarg
            else
                echo ""
                echo "The $demoname account will not be customized to use the $vers software."
                unset have_demo
            endif
        else

#    If the home directory of the demo account is not a symbolic link, create
#    it and set permissions (ownership, group and access mode).

            echo ""
            echo "Creating ${demoname}'s home directory ($demo_home)."
            mkdir -m 755 -p $demo_home
            if ($status != 0) then
                set errmsg1 = "Error creating ${demoname}'s home directory ($demo_home)"
                goto baderr
            endif
            chown $demoname.$demo_gid $demo_home
        endif
    endif

    if ($#wlocal_fsys > 1) then

#    If there is more than one writable local filesystem on the machine and
#    the home directory for the demo account is located on the root filesystem,
#    inform the installer that they may wish to move the home directory to
#    another filesystem due to the sometimes small size of the root filesystem.

        if ("$demo_home" == "/") then
            set root_fs = "/"
        else
            set root_fs = `expr $demo_home : '\(/[^/]*\).*'  \| $demo_home`
            unset is_fs
            @ i = 1
            while ($i <= $#wlocal_fsys)
                if ("$root_fs" == "$wlocal_fsys[$i]") then
                    set is_fs
                    break
                endif
                @ i++
            end
            if (! $?is_fs) set root_fs = "/"
        endif

        if ("$root_fs" == "/") then
            echo ""
            echo "${demoname}'s home directory is located on the root filesystem (/)."
            echo ""
            echo "Since this machine has multiple filesystems, you may wish to move the"
            echo "home directory to one of the other filesystem(s). This will avoid using"
            echo "up all the disk space in the root filesystem, which is sometimes small"
            echo "in size."
            echo ""
            echo "If the home directory is moved, don't forget to edit the password file"
            echo "and change the value of ${demoname}'s home directory."
        endif
    endif
endif

#    If the home directory for the ALIAS software does not exist, create it
#    and set the ownerships

if (! -d $sftwdir) then
    echo ""
    echo "Creating directory for the $vers software."
    mkdir -m 755 -p $sftwdir
    if ($status != 0) then
        set errmsg1 = "Error creating $vers directory ($sftwdir)"
        goto baderr
    endif
    chown $distname.$owner_gid $sftwdir
endif

#    Verify that the home of the ALIAS software exists

chdir $sftwdir
if ($status != 0) then
    set errmsg1 = "Cannot change directories to home of the $vers software ($sftwdir)"
    goto baderr
endif

while (1)

    if (! $?ALIAS_CDPATH) then
        echo ""
        echo "Positioning the tape ..."

#    Install the ALIAS software:
#
#    If the software is being installed from tape, rewind the tape drive,
#    position it to the proper software image and extract the contents of the
#    tape using su (allows use of tar 'o' option to set ownership on extraction.
#
#    The ALIAS software distribution is split into 3 tar images:
#
#        1) InstallAlias
#
#        2) Optional system support files
#
#        3) ALIAS software


#    Note that the variable INSFTW will be a null string ("") if non-render
#    software is being installed. In this case, all of the Alias software
#    will be installed. If render software is being installed, INSFTW will be
#    a list of specific files that make up a render installation. In this case,
#    only those files will be extracted from the distribution tape or "copied"
#    from the CD-ROM (via tar).

        mt -t $NRTAPE rew
        if ($status != 0) then
            echo ""
            echo "Error rewinding the tape."
            goto alias_tape_err
        endif
        mt -t $NRTAPE fsf 2
        if ($status != 0) then
            echo ""
            echo "Error advancing the tape to the $vers software."
            goto alias_tape_err
        endif

        echo ""
        echo "Extracting $vers from the tape ... This may take a few minutes"
        echo ""
        su $distname -c "tar xvof $NRTAPE $INSFTW"
        set st = $status
    else

#    If the Alias software is being installed from CD-ROM, "copy" the software
#    (via tar) from the appropriate directory on the CD-ROM.

        echo ""
        echo "Extracting $vers from the CD-ROM ... This may take a few minutes"
        echo ""
        su $distname -c "(chdir $ALIAS_CDPATH/$ALIAS;tar cf - .) | tar xvof - $INSFTW"
        set st = $status
    endif

#    If the tape or CD-ROM was read successfully, break out of the loop and
#    continue with the installation.

    if ($st == 0) break

    echo ""
    echo "The $vers software was not read correctly."
    echo ""

#    If the media was not read correctly, inform the user of the problem and ask
#    them if they wish to try to install the software again.

alias_tape_err:
    echo ""
    echo "It appears that there was a problem in reading the $almedia. You may have to"
    echo "attempt it 2 or 3 times before you're finally successful."
    echo ""
    echo -n "Do you wish to try reading the $almedia again? (yes/no): "

    while (1)
        set ans = $<
        if ("$ans" !~ [yY][eE][sS] && "$ans" !~ [nN][oO]) then
            echo -n "Please specify yes or no: "
        else
            break
        endif
    end
    if ($ans =~ [nN][oO]) goto userexit
end

#    The Alias software may be distributed on a tape or compact disk. When
#    the software is distributed on tape, it must be compressed in order for
#    all of it to fit on one tape. Since a compact disk has greater storage
#    capacity than a tape, there is no need to compress the software.
#    Consequently, if you are installing the software from a distribution tape
#    (TAPE is set), the individual files must be uncompressed after they are
#    extracted from the tape.

if ($?TAPE) then

#    If the main executable $sftwdir/bin/Alias is compressed, InstallAlias
#    uncompresses it first. Since all other files remain compressed while this
#    is done, it should not exceed the disk space InstallAlias has said is
#    necessary to install the software.

    unset cmsg
    if (-f $sftwdir/bin/Alias.Z) then
        echo ""
        echo "Uncompressing $vers software ..."
        set cmsg
        uncompress -f $sftwdir/bin/Alias
    endif

#   In order to uncompress the remainder of any compressed files, InstallAlias
#   runs a find command which uncompresses them (those with a .Z suffix).

    if (! $?cmsg) then
        echo ""
        echo "Uncompressing $vers software ..."
    endif
    find $sftwdir -type f -name "*.Z" -exec uncompress -f {} \; >& /dev/null
endif

#    If InstallAlias made a copy of the old Alias encryption file before the
#    new Alias software was installed, append its contents to the new encryption
#    file (/usr/alias/sys/install/en). This should allow the new Alias software
#    to run on completion of this script.
# 
#    Remove the saved encryption file after its contents have been added to
#    the new encryption file.

if (-f $SVEN) then
    cat $SVEN >> $symlink_to_alias/sys/install/en
    rm -f $SVEN
    echo ""
    echo ""
    echo 'The contents of the "saved" encryption file have been added to the new'
    echo "encryption file. The contents of this file should be sufficient to run"
    echo "the $vers software and need only be updated if you decide to"
    echo "purchase more software options."
endif

#    Fix permissions of the ALIAS software so that only the owner may modify
#    the files (remove write permissions for others), but everyone may read
#    them. When tar extracts files from tape or "copies" them from a CD-ROM
#    (via tar), it attempts to restore their original permission modes. The
#    value of the umask has no control on the modes of these files if we are
#    superuser.

echo ""
echo ""
echo "Fixing permissions of the $vers software."
find $sftwdir ! -type l -exec chmod go-w+r,u+rw {} \; >& /dev/null

#    If a demo account exists (have_demo flag is set) and InstallAlias is
#    running in guru mode, ask the installer if they wish to customize the
#    demo account to use the ALIAS software. If they say `yes' or InstallAlias
#    is not running in guru mode, customize the demo account to use the Alias
#    software.
#
#    Also determine the type of visual software which may be used to use the
#    Alias software. Currently, there are two such packages: Indigo Magic
#    and Workspace. If the machine is running a variant of IRIX 5, the machine
#    has Indigo Magic, else it has Workspace. The Indigo Magic software will
#    also be referred to as the desktop software throughout this script.

if ($?irix5) then
    set imagic
    set vsftw = desktop
else
    set vsftw = workspace
endif
if ($?have_demo) then
    echo ""
    set cust_demo
    if ($?guru_mode) then
        echo ""
        echo "Do you wish to customize the $demoname account to use the $vers"
        echo -n "software? (yes/no): "
        while (1)
            set ans = $<
            if ("$ans" !~ [yY][eE][sS] && "$ans" !~ [nN][oO]) then
                echo -n "Please specify yes or no: "
            else
                break
            endif
        end

#    If the installer elected to not customize the demo account, inform them
#    how it may be done at a later time.

        if ($ans =~ [nN][oO]) then
            unset cust_demo
            echo ""
            echo "If you later decide to customize the $demoname account to use the"
            echo "$vers software, you must login as $demoname and copy a few files"
            echo "to its home directory:"
            echo ""
            echo "    $symlink_to_alias/.cshrc"
            echo "    $symlink_to_alias/.login"
            echo "    $symlink_to_alias/.Xresources"
            echo "    $symlink_to_alias/.4Dwmrc"
            echo "    $symlink_to_alias/.mwmrc"
            echo ""
            if (! $?render_sftw) then
                echo "If you wish the $demoname account to use the IRIX $vsftw software, you"
                echo "may want to copy the files comprising the Alias $vsftw view to its home"
                echo "directory:"
                echo ""
                echo "    cp -r $symlink_to_alias/$vsftw  ~/.$vsftw"
                echo ""
                echo "This should only be done if the $vsftw software has been customized to"
                echo "recognize $vers based files and the $demoname account does not"
                echo "already have the $vsftw view installed."
                echo ""
            endif
            echo ""
            echo "If you wish to customize other user accounts to use the $vers"
            echo "software, you should copy the named files to each users home directory."
        endif
    endif

    if ($?cust_demo) then    
        echo ""
        echo "Customizing the environment in ${demoname}'s home directory to use the"
        echo "$vers software."

        chdir $demo_home

#    If the demo account's dotfiles (.cshrc, .login, .Xresources, .4Dwmrc
#    and .mwmrc) and/or the login icon file exist and an original copy of
#    each file has not been renamed to file.pre_alias, rename the dotfiles
#    to <file>.pre_alias (i.e.: .cshrc becomes .cshrc.pre_alias).

        foreach dotfile (.cshrc .login .Xresources .4Dwmrc .mwmrc .icons/login.icon)
            if (-f $dotfile && ! -f $dotfile.pre_alias) then
                mv $dotfile $dotfile.pre_alias
            endif

#    Add the original filename to the list of "saved system files". If
#    InstallAlias did not complete, the original dotfiles (.cshrc.pre_alias,
#    etc) may still exist and have to be "cleaned up" (renamed to filename= or
#    removed).

            set mod_files = ($demo_home/$dotfile $mod_files)
        end

#    Copy new .cshrc, .login, .Xresources, .4Dwmrc and .mwmrc files to the demo
#    account's home directory and fix ownerships. (These files set variables
#    that are key to the operation of the ALIAS software). Note that the
#    .mwmrc file is actually a link to the .4Dwmrc as their contents are
#    identical. Since it is a link, I don't have to fix its ownership.

        cp $sftwdir/{.cshrc,.login,.Xresources,.4Dwmrc} .
        ln .4Dwmrc .mwmrc
        chown $demoname.$demo_gid .login .cshrc .Xresources .4Dwmrc

#    If the .icons directory does not exist in the demo account's home
#    directory, create it and fix the permissions.

        if (! -d .icons) then
            mkdir -m 755 .icons
            chown $demoname.$demo_gid .icons
        endif

#    Copy the login icon from /usr/alias/.icons to the demo account's home
#    directory and fix the permissions.

        cp $sftwdir/.icons/login.icon .icons
        chown $demoname.$demo_gid .icons/login.icon

#    If there is a .AliasPrefs file in the demo account's home directory,
#    ask the user to ensure that it is not out of date with respect to the
#    ALIAS software (compare it with /usr/alias/.AliasPrefs).

        if (-f .AliasPrefs) then
            echo ""
            echo "It has been discovered that there is a .AliasPrefs file in ${demoname}'s home"
            echo "directory. This file may be out of date with respect to the $vers"
            echo "software and should be compared with $symlink_to_alias/.AliasPrefs for"
            echo "completeness."
        endif
    endif
endif

#    Search /etc/magic for entries which describe Alias format files. The
#    magic file contains a number of definitions which allow the file command
#    to identify a number of different file formats. If the entries do not
#    appear to be in the magic file and InstallAlias is running in guru mode,
#    ask the installer if they wish to add the entries to the file. If they say
#    `yes' or InstallAlias is not running in guru mode, the entries are added to
#    the magic file.

set aff = `grep "^#[ 	][ 	]*Alias format files:${DLR}" /etc/magic`
if ("$aff" == "") then
    echo ""
    echo ""
    echo -n "The file /etc/magic contains a number of"
    echo ' "definitions" which allow the file'
    echo "command to identify a number of different file formats."
    set mod_mfile
    if ($?guru_mode) then
        echo ""
        echo "Do you wish to add entries to the magic file which describe Alias format"
        echo -n "files? (yes/no): "
        while (1)
            set ans = $<
            if ("$ans" !~ [yY][eE][sS] && "$ans" !~ [nN][oO]) then
                echo -n "Please specify yes or no: "
            else
                break
            endif
        end
        if ($ans =~ [Nn][Oo]) unset mod_mfile
    endif
    if ($?mod_mfile) then
        echo ""
        echo "Modifying /etc/magic to allow the file command to identify Alias format files."
        ex - /etc/magic << EOF
        ${DLR}a
#
# Alias format files:
#
8	short		0x18		alias  pix  file
>0	short		x		(%4d *
>2	short		x		%4d)
>4	short		x		offset (%4d,
>6	short		x		%4d)
8	short		0x8		alias matte file
>0	short		x		(%4d *
>2	short		x		%4d)
>4	short		x		offset (%4d,
>6	short		x		%4d)
.
        w! /etc/magic
        q
EOF
    endif
endif

#    Conditionally enable virtual swap:
#
#    If the machine is running a variant of IRIX 5 and the vswap chkconfig
#    option (enable or disable virtual swap) is off, conditionally enable it.
#
#    If InstallAlias is running in guru mode, ask the installer if they wish
#    to enable virtual swap. If they say `yes' or InstallAlias is not running
#    in guru mode, enable virtual swap.

if ($?irix5) then
    chkconfig vswap
    if ($status != 0) then
        set en_vs
        if ($?guru_mode) then
            echo ""
            echo "Currently, virtual swap is disabled on this machine. Virtual swap space is"
            echo "used extensively by the $vers software when writing data files and"
            echo "performing renders. It must be enabled or the $vers software will"
            echo "not function correctly."
            echo ""
            echo -n "Do you wish to enable virtual swap on this machine? (yes/no): "
            while (1)
                set ans = $<
                if ("$ans" !~ [yY][eE][sS] && "$ans" !~ [nN][oO]) then
                    echo -n "Please specify yes or no: "
                else
                    break
                endif
            end
            if ($ans =~ [Nn][Oo]) unset en_vs
        endif
        if ($?en_vs) then
            echo ""
            echo "Enabling virtual swap ..."
            chkconfig vswap on
        endif
    endif

#    If virtual swap is enabled (the machine is running a variant of IRIX 5
#    and the vswap chkconfig option is on, determine the optimal virtual
#    swap space size:
#
#    Add the size of main memory (in blocks) and the total size of swap space
#    (in blocks) to arrive at the desired figure.

    chkconfig vswap
    if ($status == 0) then
        echo ""
        set VSWCFG = /etc/config/vswap.options
        set mmemMb = `hinv -t memory | awk '{print $4}'`
        @ mmemBl = $mmemMb * 2000
        set swspBl = `swap -l | awk 'BEGIN {sw = 0} {sw += $4} END {print sw}'`
        @ totBl = $mmemBl + $swspBl

#    Round total Blocks down to the nearest Megabyte
#
#    There are 1000 * 2 (blocks per kilobyte) blocks in a megabyte.

        @ MbBl = 1000 * 2
        @ totBl = ($totBl / $MbBl) * $MbBl

#    If the options file for virtual swap (/etc/config/vswap.options) does
#    not mexist, inform the installer of the problem. If InstallAlias is
#    running in guru mode, ask them if they wish to create a default options
#    file (vswap.options) for the virtual swap option. If they say `yes' or
#    InstallAlias is not running in guru mode, create the file with the amount
#    of virtual swap set to the default of 40 Megabytes (80000 blocks).

        if (! -f $VSWCFG) then
            @ defvsBl = 80000
            echo ""
            echo "The virtual swap chkconfig option (vswap) is on, but InstallAlias cannot"
            echo "find the options file that sets the size of virtual swap space"
            echo "($VSWCFG)."
            set crfile
            if ($?guru_mode) then
                echo ""
                echo -n "Do you wish to create an options file for the vswap option? (yes/no): "
                while (1)
                    set ans = $<
                    if ("$ans" !~ [Yy][Ee][Ss] && "$ans" !~ [Nn][Oo]) then
                        echo -n "Please specify yes or no: "
                    else
                        break
                    endif
                end
                if ($ans =~ [Nn][Oo]) unset crfile
            endif
            if ($?crfile) then
                echo ""
                echo "Creating default options file, $VSWCFG:t in $VSWCFG:h ..."
                cat >> $VSWCFG << EOF
#
# This file is used to the startup script /etc/init.d/swap
# to determine the amount of virtual swap to add. You can
# totally disable the addition of virtual swap by
# 'chkconfig vswap off'
# See swap(1M) for a discussion on virtual swap
#
vswaplen=$defvsBl
EOF
            endif
        endif

        if (-f $VSWCFG) then

#    Scan the options file for the current size of virtual swap. If there are
#    more than one `vswaplen=' lines, take the value from the last line.

            set currvs = `grep "^vswaplen=" $VSWCFG | awk -F= '{print $2}'`
            if ($#currvs > 1) then
                set currvs = $currvs[$#currvs]
            endif

#    If the value of vswaplen from the options file does not equal the optimum
#    value InstallAlias has calculated, conditionally edit the options file
#    and change the value of vswaplen to the optimum value.

            if ("$currvs" != "$totBl") then

#    Make a backup copy of the virutal swap options file.

                if (! -f $VSWCFG.pre_alias) then
                    cp $VSWCFG $VSWCFG.pre_alias
                endif
                set mod_files = ($mod_files $VSWCFG)

                @ oldsz = $currvs / 2000
                @ newsz = $totBl / 2000
                set chvs
                if ($?guru_mode) then
                    echo ""
                    echo "Your machine currently has $oldsz megabytes of virtual swap space. This swap"
                    echo "space has no physical representation (i.e.: it does not occupy any disk"
                    echo "space), but leads the IRIX operating system to believe it has more swap"
                    echo "space than it actually does. It permits large applications, such as the"
                    echo "$vers software to spawn a child process (i.e.: a render job)"
                    echo "without exhausting system resources (main memory and swap space) and"
                    echo "being killed as a result. If the system believes it has more swap space"
                    echo "than it actually does, it will not kill the $vers software when"
                    echo "it spawns a child process. The optimal size of virtual swap space is the"
                    echo "sum total of main memory and all physical swap partitions. For your machine,"
                    echo "total is $totBl blocks or $newsz megabytes. It is recommended that the size"
                    echo "of virtual swap space be set to that value."
                    echo ""
                    echo "Do you wish to change the size of virtual swap space to $newsz megabytes?"
                    echo -n "(yes/no): "
                    while (1)
                        set ans = $<
                        if ("$ans" !~ [Yy][Ee][Ss] && "$ans" !~ [Nn][Oo]) then
                            echo -n "Please specify yes or no: "
                        else
                            break
                        endif
                    end
                    if ($ans =~ [Nn][Oo]) then
                        unset chvs
                        echo ""
                        echo "If you later decide to change the size of the virtual swap space, login"
                        echo "as root and edit $VSWCFG, changing the last line to:"
                        echo ""
                        echo "    vswaplen=$totBl"
                        echo ""
                    endif
                endif
                if ($?chvs) then
                    echo ""
                    echo "Changing size of virtual swap space from $oldsz megabytes to $newsz megabytes .."
                    ex - $VSWCFG << EOF
                    ${DLR}c
vswaplen=$totBl
.
                    w!
                    q
EOF
                    echo ""
                    echo "This change will not take affect until the machine is rebooted."
                endif
            endif
        endif
    endif
endif

#    In order to support distributed rendering with the Alias software, a
#    render control directory must be created. This directory must be world
#    writable in order to allow any Alias user to write to the directory.
#
#    By default, the render control area will be /usr/alias/render_control,
#    but customers do have the option of creating a shared area at a later
#    time.

set rcdir = $symlink_to_alias/$RCDIR
chkconfig nfs
if ($status == 0) then

#    If the machine has NFS enabled, inform the installer that they may wish
#    to setup a common render control area which is equally accessible from
#    all machines which have NFS enabled. The details for this are in the
#    Alias documentation.

    echo ""
    echo "In order to support distributed rendering with the $vers software, a"
    echo "render control area must be created. This directory must be world writable in"
    echo "order to allow all users equal access to the render control area."
    echo ""
    echo "By default, the render control area will be $symlink_to_alias/$RCDIR."
    echo ""
    echo "Since you have the network file system (NFS) option enabled on your machine,"
    echo "you may be interested in setting up a common render control area which can be"
    echo "shared by other machines running NFS which have the Alias software installed."
    echo ""
    echo "For details on setting up a common render control area, consult the"
    echo "Installation and Release Notes and the V5.1 Addendum for more information"
    echo "on Distributed Render Control."
endif

#    Verify that the render control area exists and its permissions are
#    correct (equally accessible for everyone).

echo ""
if (! -d $rcdir) then
    echo "Creating render control area ..."
    su $distname -c "mkdir -m 777 -p $rcdir"
    if ($status != 0) then
        echo ""
        echo "An error occurred when creating the render control area ($rcdir)."
    endif
else
    echo "The render control area ($rcdir) already exists. Making it world"
    echo "readable, writable and examinable."
    chmod 777 $rcdir
endif

if ($?ALIAS_CDPATH) then

#    If InstallAlias is installing Alias software from a CD-ROM and a demo
#    account exists, conditionally install a set of tutorials in the home
#    directory of the demo account:
#
#    If InstallAlias is installing from a CD-ROM, there should be a set of
#    tutorial files in:
#
#        <mount point of CD-ROM>/Products/Common/3DCD/CourseWare
#
#    If the tutorial directory exists and there is a demo account whose home
#    filesystem has sufficient disk space for the tutorials, ask the installer
#    if they wish to install the tutorials in the demo accounts home directory.
#    If they say `yes', install the tutorials in user_data/CourseWare in the
#    demo accounts home directory.
#
#    If the tutorials are not installed (insufficient disk space or installer
#    disapproval about the installation), give instructions on how to install
#    the tutorials at a later time.

    if (-d $ALIAS_CDPATH/$CDIR/$DCLIB/$TUT && $?have_demo) then
        set fsdata = `$DF $demo_home | awk '$2 == "efs" { printf "%d %.2f %s", $5, $5 / 1024, $7 }'`
        unset inst_tut
        @ tut_reqd_kbspace = $tut_reqd_Mbspace * 1024
        if ($fsdata[1] > $tut_reqd_kbspace) then
            echo ""
            echo ""
            echo "There is $fsdata[2] Megabytes of free space on $fsdata[3] (host filesystem for the"
            echo "$demoname account). There is a set of tutorials on the distribution $almedia"
            echo "which occupy $tut_reqd_Mbspace Megabytes."
            echo ""
            echo "The purpose of these tutorials is to help the user learn the ALIAS software."
            echo ""
            echo "If you decide to install the tutorials, they will be installed in"
            echo "$demo_home/user_data/$TUT."
            echo ""
            echo -n "Do you wish to install the tutorials? (yes/no): "

            while (1)
                set ans = $<
                if ("$ans" !~ [yY][eE][sS] && "$ans" !~ [nN][oO]) then
                    echo -n "Please specify yes or no: "
                else
                    break
                endif
            end

#    If the user decides that they want the Tutorials installed in the demo
#    accounts home directory, verify that the user_data directory exists (use
#    su because the home directory may be on an NFS filesystem; root can't
#    create directories across NFS by default) then copy the tutorials (via
#    tar) from the CD-ROM to ~<demo account>/user_data.

            if ($ans =~ [yY][eE][sS]) then
                chdir $demo_home
                if (! -d user_data) then
                    su $demoname -c "mkdir user_data"
                endif
                chdir user_data
                while (1)
                    echo ""
                    echo "Extracting and installing the tutorials ..."
                    echo ""
                    su $demoname -c "(chdir $ALIAS_CDPATH/$CDIR/$DCLIB;tar cf - $TUT) | tar xvof -"

#    If the Tutorials are installed successfully, set inst_tut variable.

                    if ($status == 0) then
                        set inst_tut
                        break
                    endif

                    echo ""
                    echo "It appears that there was a problem in reading the $almedia. You may have to"
                    echo "attempt it 2 or 3 times before you're finally successful."
                    echo ""
                    echo -n "Do you wish to try reading the $almedia again? (yes/no): "

                    while (1)
                        set ans = $<
                        if ("$ans" !~ [yY][eE][sS] && "$ans" !~ [nN][oO]) then
                            echo -n "Please specify yes or no: "
                        else
                            break
                        endif
                    end
                    if ($ans =~ [nN][oO]) break
                end
            endif
        else
            echo ""
            echo "Aborting installation of the Tutorials due to insufficient disk space."
        endif

#    If the Tutorials were not installed, explain how to do it

        if (! $?inst_tut) then
            echo ""
            echo "If you later decide to install the Tutorials, the following instructions"
            echo "may be used to do so:"
            echo ""
            echo "      Insert the $vers distribution CD-ROM into the CD-ROM drive"
            echo "      and mount it:"
            echo ""
            echo "              login $demoname"
            if (! -d $demo_home/user_data) then
                echo "              mkdir user_data"
            endif
            echo "              cd <mount point of CD-ROM>/$CDIR/$DCLIB"
            echo "              cp -r $TUT $demo_home/user_data"
        else

#    If the tutorials were installed successfully, remove any write permissions
#    so that the tutorial files can't be modified.

            echo ""
            echo -n "Fixing permissions of the tutorials ..."
            find $demo_home/user_data/$TUT -type f -exec chmod -wx {} \;
        endif
    endif
    echo ""

#    If InstallAlias is installing Alias software from a CD-ROM and the 3DCD
#    Digital Content Library (a set of example files) exists, conditionally
#    copy the library examples to disk:
#
#    If /usr/alias/3DCD already exists, ask the installer if they wish to remove
#    it. If they `yes', remove the file/directory and continue with the
#    installation. If the installer says `no', don't touch /usr/alias/3DCD and
#    skip any further processing of the example files. This case should never
#    happen as the Alias software is not shipped with an existing 3DCD directory
#    in /usr/alias.
#
#    If /usr/alias/3DCD does not exist, do the following:
#
#    - If there is sufficient disk space for the example files (215Mb), ask the
#      installer if they wish to copy them from the CD-ROM to disk. If they say
#      `yes', ask them where they want the files installed and copy them to
#      disk. If the examples are not installed in /usr/alias/3DCD, create a
#      symbolic link, /usr/alias/3DCD which points to the directory where the
#      examples are installed.
#
#    - If there is insufficient disk space or the installer does not want to
#      copy the example files to disk or the desired location for the example
#      files (any location other than /usr/alias/3DCD) exists and the installer
#      doesn't want to remove it, form a symbolic link, /usr/alias/3DCD that
#      "points" to the library example files on the CD-ROM. The examples are
#      accessible (via this link) as long as the CD-ROM is mounted at its
#      current mount point:
#
#          /usr/alias/3DCD -> <mount point of CD-ROM>/Products/Common/3DCD

    if (-d $ALIAS_CDPATH/$CDIR/$DCLIB) then
        echo ""
        echo "Along with the $vers software, the Alias $almedia contains a set of"
        echo "examples called the 3DCD Digital Content Library."
        if (-e $sftwdir/$DCLIB || -l $sftwdir/$DCLIB) then

#    This shouldn't happen, but ...
#
#    If /usr/alias/3DCD exists, inform the installer that it must be removed
#    in order for the 3DCD examples to be installed.

            echo ""
            echo "The example files are normally installed in $symlink_to_alias/$DCLIB which already"
            echo "exists. If you wish to install the example files, $symlink_to_alias/$DCLIB must"
            echo "be removed."
            echo ""
            echo -n "Do you wish to remove $symlink_to_alias/$DCLIB? (yes/no): "
            while (1)
                set ans = $<
                if ("$ans" !~ [Yy][Ee][Ss] && "$ans" !~ [Nn][Oo]) then
                    echo -n "Please specify yes or no: "
                else
                    break
                endif
            end
            if ($ans =~ [Yy][Ee][Ss]) then
                echo ""
                echo "Removing $symlink_to_alias/$DCLIB."
                rm -fr $symlink_to_alias/$DCLIB
            endif
        endif

        if (-e $sftwdir/$DCLIB || -l $sftwdir/$DCLIB) then

#    If /usr/alias/3DCD still exists, the example files cannot be installed.

            echo ""
            echo "As $symlink_to_alias/$DCLIB still exists, the example files cannot be installed."
        else
            echo ""
            echo "If your machine has sufficient disk space for the examples, you may wish to"
            echo "copy them to your disk. But be warned, they are large ($dcl_reqd_Mbspace megabytes)."
            echo ""
            echo "Checking for sufficient disk space for the Digital Content Library examples ..."

#    Determine if there is sufficient disk space for the Digital Content
#    Library examples on a local filesystem.

            @ dcl_reqd_kbspace = $dcl_reqd_Mbspace * 1024

#    Inspect all writable local filesystems on the machine for sufficient disk
#    space for the Digital Content Library examples:
#
#    Work through the list of writable filesystems backwards (wlocal_fsys is
#    an array of writable filesystems in reverse order) as InstallAlias doesn't
#    want to include the root filesystem (/) as a candidate filesystem for the
#    installation if other filesystems have sufficient disk space. If a
#    filesystem is writable (not a CD-ROM) and has sufficient disk space, it
#    is a candidate filesystem for the installation of the example files.

            unset fsystems
            @ in = 1
            while ($in <= $#wlocal_fsys)
                set wfs = $wlocal_fsys[$in]
                set fsys_ds = `$DF $wfs | awk '$2 == "efs"  {print $5}'`
                if ($fsys_ds > $dcl_reqd_kbspace) then
                    if ($?fsystems) then
                        if ("$wfs" != "/") then
                            set fsystems = ($wfs $fsystems)
                        endif
                    else
                        set fsystems = $wfs
                    endif
                endif
                @ in++
            end

#    If there is at least one local fileystem that has sufficient disk space
#    for the examples, ask the installer if they wish to copy them to disk.

            unset cp_dcl
            echo ""
            if ($?fsystems) then
                echo "There is at least one filesystem on your disk which has sufficient free"
                echo "space for the Digital Content Library examples. If you decide not to copy"
                echo "the examples to your disk, InstallAlias will create a symbolic link,"
                echo -n "$symlink_to_alias/$DCLIB which"
                echo -n '"points" to '
                echo "the examples on the ${almedia}:"
                echo ""
                echo "    $symlink_to_alias/$DCLIB -> $ALIAS_CDPATH/$CDIR/$DCLIB"
                echo ""
                echo "As long as the $almedia is mounted at $ALIAS_CDPATH, the examples"
                echo "will be accessible."
                echo ""
                echo -n "Do you wish to copy the examples to your disk? (yes/no): "
                while (1)
                    set ans = $<
                    if ("$ans" !~ [yY][eE][sS] && "$ans" !~ [nN][oO]) then
                        echo -n "Please specify yes or no: "
                    else
                        break
                    endif
                end
                if ($ans =~ [Yy][Ee][Ss]) then
                    set cp_dcl
                endif
            else
                echo "There is insufficient disk space for the Digital Content Library examples on"
                echo "your disk."
                echo ""
                echo -n "InstallAlias will create a symbolic link, $symlink_to_alias/$DCLIB which "
                echo '"points" to'
                echo "the examples on the ${almedia}:"
                echo ""
                echo "    $symlink_to_alias/$DCLIB -> $ALIAS_CDPATH/$CDIR/$DCLIB"
                echo ""
                echo "As long as the $almedia is mounted at $ALIAS_CDPATH, the examples will be"
                echo "accessible."
            endif

            if ($?cp_dcl) then

#    If there is sufficient disk space for the Digital Content Library examples
#    and the installer wishes to copy them to disk, determine a suitable
#    filesystem for them.

                echo ""
                echo "Determining a host filesystem for the examples ..."

                unset dcldir
                @ index = 1
                while ($index <= $#fsystems)

#    If the host filesystem of the Alias software has sufficient disk space
#    for the examples, ask the installer if they wish to copy them to
#    /usr/alias/3DCD. If they say `yes', the examples will be copied to
#    /usr/alias/3DCD.

                    if ("$fsystems[$index]" == "$sftwfs") then
                        echo ""
                        echo "There is sufficient disk space for the Digital Content Library examples"
                        echo "in $sftwdir, the directory where the $vers software is"
                        echo "installed. You may wish to copy the examples to $sftwdir/$DCLIB"
                        echo "so that all Alias files are located in the same area."
                        echo ""
                        echo -n "As $symlink_to_alias"
                        echo -n ' "points" '
                        echo "to the $vers software in $sftwdir,"
                        echo "installing the examples in $symlink_to_alias/$DCLIB is equivalent to installing them"
                        echo "in $sftwdir/$DCLIB."
                        echo ""
                        echo -n "Do you wish to copy the examples to $symlink_to_alias/$DCLIB? (yes/no): "
                        while (1)
                            set ans = $<
                            if ("$ans" !~ [yY][eE][sS] && "$ans" !~ [nN][oO]) then
                                echo -n "Please specify yes or no: "
                            else
                                break
                            endif
                        end
                        if ($ans =~ [Yy][Ee][Ss]) set dcldir = $sftwdir/$DCLIB
                        break
                    endif
                    @ index++
                end

#    If the Digital Content Library examples will not be installed in
#    /usr/alias/3DCD, ask the installer on which filesystem they wish
#    to install them.

                if (! $?dcldir) then
                    if ($#fsystems != 1) then
                        echo ""
                        echo "The filesystems with sufficient disk space are:"
                        while (1)
                            echo ""
                            @ index = 1
                            while ($index <= $#fsystems)
                                echo $fsystems[$index] | sed "s/^/    /"
                                @ index++
                            end
                            echo ""
                            while (1)
                                echo -n "Please enter your choice: "
                                set pname = $<
                                set esftwfs = ($pname)
                                if ($#esftwfs == 1) break
                            end
                            @ index = 1
                            @ found = 0
                            while ($index <= $#fsystems && $found == 0)
                                if ("$fsystems[$index]" == "$esftwfs") then
                                    @ found++
                                else
                                    @ index++
                                endif
                            end
                            if ($found != 0) break

                            echo ""
                            echo "$esftwfs is not a valid choice. Please choose one of:"
                        end
                    else
                        set esftwfs = $fsystems
                        echo ""
                        echo "The only filesystem with sufficient disk space for the Digital Content"
                        echo "Library examples is $esftwfs."
                    endif

                    while (1)
                        unset bad_root bad_suffix
                        echo ""
                        echo "Where do you wish to install the Digital Content Library examples? (please"
                        echo -n "specify a full pathname): "
                        set pname = $<

#    Verify that the installer typed something meaningful.

                        set dcldir = ($pname)
                        if ($#dcldir != 1) continue

#    When the installer specifies a location for the Digital Content examples,
#    verify that:
#
#    - the directory is located in the filesystem that the installer approved
#    - the name of the directory is 3DCD (for identification purposes)
#
#    If any of these points are not met, InstallAlias warns the installer and
#    asks them to specify a location which matches the criteria.
#
#    Assuming everything goes okay, the shell variable dcldir will contain
#    the pathname of the directory where the examples will be installed.

#    Verify that the specified location is a full pathname (starts with /).
#    If this is not done here, root_fs will be incorrectly set to / below.

                        set pfc = `echo $dcldir | cut -c1`
                        if ("$pfc" != "/") then
                            echo ""
                            echo "$dcldir is not a full pathname. Please choose again."
                            continue
                        endif

                        @ i = 1
                        while ($i <= $#wlocal_fsys)
                            set wfs = $wlocal_fsys[$i]
                            set mtch = `echo $dcldir/ | grep "^$wfs/"`
                            if ($#mtch) then
                                set root_fs = $wfs
                                break
                            endif
                            @ i++
                        end
                        if (! $?root_fs) set root_fs = "/"

                        if ("$esftwfs" == "/") then
                            @ i = 1

#    If the root filesystem (/) is the filesystem on which the Digital Content
#    Library examples are being installed, verify that the install directory
#    specified by the installer does not reside on one of the other local
#    filesystems.

                            while ($i <= $#wlocal_fsys)
                                set fsname = $wlocal_fsys[$i]
                                if ("$fsname" != "/" && "$root_fs" == "$fsname") then
                                    set bad_root
                                    break
                                endif
                                @ i++
                            end
                        else
                            if ("$root_fs" != "$esftwfs") set bad_root
                        endif

                        set suffix = $dcldir:t
                        if ("$suffix" != $DCLIB) set bad_suffix
                        if ($?bad_root || $?bad_suffix) then
                            echo ""
                            echo ""
                            echo "$dcldir is an invalid choice for the location of the Digital Content"
                            echo "Library examples."
                            if ($?bad_root) then
                                echo ""
                                if ($#fsystems != 1) then
                                    echo "Since you have chosen to install the examples on $esftwfs, you must specify a"
                                    echo "location on that filesystem."
                                else
                                    echo "Since $esftwfs is the only filesystem with sufficient disk space, you must"
                                    echo "specify a location on that filesystem."
                                endif
                            endif
                            if ($?bad_suffix) then
                                echo ""
                                echo "For the purpose of identification, please specify a location whose pathname"
                                echo "ends with $DCLIB."
                            endif
                        else
                            break
                        endif
                    end
                endif

#    Verify that the planned directory for the examples does not exist. If
#    it exists, inform the user of its existence and how much disk space it
#    occupies, then give them the option to remove it. If they say `no',
#    inform them that the example files cannot be copied to the location
#    they specified and InstallAlias will create a symbolic link which points
#    to the 3DCD area on the CD-ROM:
#
#        /usr/alias/3DCD -> <mount point of CD-ROM>/Products/Common/3DCD
#
#    If they say `yes', remove the file/directory and continue.
#
#    Note that running `du' on a file does not provide any disk space
#    information and `ls -l' must be used instead.

                if (-e $dcldir) then
                    if (-d $dcldir) then
                        set dcl_sp = `$DU $dcldir | awk '{print $1}'`
                        set ftype = directory
                    else
                        set dcl_sp = `ls -l $dcldir | awk '{printf "%.2f", $5 / 1024}'`
                        set ftype = file
                    endif
                    echo ""
                    echo ""
                    echo "The $ftype $dcldir exists and contains $dcl_sp kilobytes. It is"
                    echo "strongly recommended that it be removed and replaced with the Digital"
                    echo "Content Library examples on the distribution $almedia."
                    echo ""
                    echo "If this $ftype is not removed (or renamed), the examples cannot be"
                    echo "installed in the location that you specified."
                    echo ""
                    echo -n "Do you wish to remove the $dcldir $ftype? (yes/no): "
                    while (1)
                        set ans = $<
                        if ("$ans" !~ [yY][eE][sS] && "$ans" !~ [nN][oO]) then
                            echo -n "Please specify yes or no: "
                        else
                            break
                        endif
                    end
                    echo ""
                    if ($ans =~ [nN][oO]) then
                        unset cp_dcl
                        echo "The example files will not be installed in $dcldir."
                        echo ""
                        echo -n "InstallAlias will create a symbolic link, $symlink_to_alias/$DCLIB which "
                        echo '"points" to'
                        echo "the examples on the ${almedia}:"
                        echo ""
                        echo "    $symlink_to_alias/$DCLIB -> $ALIAS_CDPATH/$CDIR/$DCLIB"
                        echo ""
                        echo "As long as the $almedia is mounted at $ALIAS_CDPATH, the examples will be"
                        echo "accessible."
                    else
                        echo "Removing $dcldir."
                        rm -fr $dcldir
                    endif
                endif
            endif

            if ($?cp_dcl) then

#    Verify that the location of the Digital Content Library examples exists.
#    A non-root user (using `su - $distname' below) will not be able to
#    create the 3DCD directory if the directory is not writable.

                mkdir -m 755 -p $dcldir
                if ($status != 0) then
                    set errmsg1 = "Cannot create directory ($dcldir)."
                    goto baderr
                endif
                chown $distname.$owner_gid $dcldir

#    If there is sufficient disk space for the 3DCD examples and the directory
#    where they are being installed doesn't exist (both verified above), copy
#    the examples from CD-ROM to disk (using tar to set ownerships and preserve
#    dates).

                echo ""
                echo "Copying Digital Content Library examples to disk ... (this will take several"
                echo "minutes)."
                echo ""
                chdir $dcldir:h
                su $distname -c "(chdir $ALIAS_CDPATH/$CDIR ; tar cf - $DCLIB) | tar xvopf -"

#    Remove any write permissions of the 3DCD example files so that they can't
#    be modified.

                echo ""
                echo -n "Fixing permissions of the example files ..."
                find $DCLIB -type f -exec chmod -wx {} \;

#    When the examples have been copied to disk, make a symbolic link in
#    /usr/alias which "points" to the examples on disk:
#
#        /usr/alias/3DCD -> /<pathname>/3DCD
#
#    Note this step is only performed if the examples are NOT copied to
#    /usr/alias (i.e.: /usr/alias/3DCD does not exist).

                if (! -d $symlink_to_alias/$DCLIB) then
                    echo ""
                    echo -n "Creating symbolic link, $symlink_to_alias/$DCLIB which"
                    echo ' "points" to the Digital Content'
                    echo "Library examples in $dcldir."
                    su $distname -c "ln -sf $dcldir $sftwdir"
                endif
            else

#    If there is insufficient disk space or the installer does not want to copy
#    the example files to disk or the desired location for the example files
#    (any location other than /usr/alias/3DCD) exists and the installer doesn't
#    want to remove it, form a symbolic link, /usr/alias/3DCD that "points" to
#    the library example files on the CD-ROM. The examples are accessible (via
#    this link) as long as the CD-ROM is mounted at its current mount point:
#
#        /usr/alias/3DCD -> <mount point of CD-ROM>/Products/Common/3DCD

                echo ""
                echo -n "Creating symbolic link, $symlink_to_alias/$DCLIB which"
                echo ' "points" to the Digital Content'
                echo "Library examples on the $almedia."
                su $distname -c "ln -sf $ALIAS_CDPATH/$CDIR/$DCLIB $sftwdir"
            endif
        endif
    endif
endif

#    If render software is being installed and a demo account exists, create
#    three directories in ~<demo account>/user_data/demo
#    (default ALIAS_RENDER_LOCATION):
#
#        mask
#        pix
#        sdl
#
#    then skip to the cleanup process. These directories are required for
#    remote rendering.

if ($?render_sftw) then
    if ($?have_demo) then
        chdir $demo_home
        foreach subdir (user_data user_data/demo user_data/demo/{mask,pix,sdl})
            if (-d $subdir) continue
            mkdir $subdir
            chown $demoname.$demo_gid $subdir
        end
    endif
    goto cleanup
endif

#    Conditionally setup the IRIX Workspace/Desktop:
#
#    There are two IRIX software packages which offer a user a graphical view
#    of the system. These are the IRIX Workspace and Indigo Magic (Also referred
#    to as the desktop software throughout this script). If the machine is an
#    Indy or the desktop chkconfig option is on, the machine has the Indigo
#    Magic software, else it has the Workspace software.
#
#    The following file is necessary for the customization of both the IRIX
#    Workspace and Indigo Magic software so that it recognizes Alias 3D based
#    files (i.e.: Alias executables and data files):
#
#        /usr/lib/filetype/install/Alias3D.ftr
#
#    It appears in the support system files area of the ALIAS software tape
#    or CD-ROM and contains a number of file type rules used by the workspace/
#    Indigo Magic software to identify Alias 3D based files.
#
#    If the installation is being performed on a machine with Indigo Magic,
#    some customization of the Indigo Magic software is required:
#
#    If InstallAlias adds new user accounts to a machine which has the Indigo
#    Magic software, some information servers must be informed of the new user
#    accounts. If the directoryserver or objectserver are running (chkconfig
#    values are on) and the file which starts them (/etc/init.d/cadmin) exists,
#    rebuild the user database. If this is not done, the server(s) will complain
#    when the new user(s) login and execute the Indigo Magic software.
#
#    If the installation is being performed on a machine with the workspace
#    software, its customization involves the modification of some files in
#    /usr/lib/workspace to customize the look of the workspace view.
#
#    If InstallAlias is running in guru mode, ask the installer if they wish to
#    customize the workspace/desktop software on the machine. If they say `no',
#    the software will not be customized.

echo ""
set cust_view
if ($?guru_mode) then
    echo ""
    echo "The next step of InstallAlias involves the customization of the IRIX"
    echo "$vsftw software to recognize $vers based files. This requires"
    echo "the installation of the following file:"
    echo ""
    echo "    /usr/lib/filetype/install/Alias3D.ftr"
    echo ""
    if ($?imagic) then
        echo "It contains a number of file type rules used by the desktop software to"
        echo "identify $vers based files (i.e.: the main Alias executable and"
        echo "data files)."
    else
        echo "and the modification of some files in /usr/lib/workspace. The above file"
        echo "contains a number of file type rules used by the workspace software to"
        echo "identify $vers based files (i.e.: the main Alias executable and"
        echo "data files)."
    endif
    echo ""
    echo "Do you wish to customize the $vsftw software to recognize $vers"
    echo -n "based files? (yes/no): "
    while (1)
        set ans = $<
        if ("$ans" !~ [yY][eE][sS] && "$ans" !~ [nN][oO]) then
            echo -n "Please specify yes or no: "
        else
            break
        endif
    end
    if ($ans =~ [nN][oO]) then
        echo ""
        echo "The IRIX $vsftw software will not be customized to recognize $vers"
        echo "based files."
        unset cust_view
    endif
endif

#    If InstallAlias is running in guru mode and the installer approved the
#    customization of the IRIX workspace/desktop software, do so.
#
#    These steps are also performed if InstallAlias is running in non-guru mode.

unset view_inst
if ($?cust_view) then
    while (1)
        echo ""
        if (! $?ALIAS_CDPATH) then
            echo "Positioning the tape to extract the Alias $vsftw file type rules file"
            echo "from the $vers software tape."
            mt -t $NRTAPE rew
            if ($status != 0) then
                echo ""
                echo "Error rewinding the tape."
                goto view_tape_err
            endif
            mt -t $NRTAPE fsf 1
            if ($status != 0) then
                echo ""
                echo "Error advancing the tape to the system support files."
                goto view_tape_err
            endif
            echo ""
            echo "Extracting and installing the Alias $vsftw file type rules file."
            echo ""

#    Extract the file from the distribution tape into a directory ($TMPDIR)
#    and move it to the correct location.

            chdir $TMPDIR
            tar xvof $NRTAPE Alias3D.ftr
            set st = $status
        else
            echo "Extracting and installing the Alias $vsftw file type rules file."
            echo ""

#    "Copy" the file from the distribution CD-ROM (via tar) into a directory
#    ($TMPDIR) and move it to the correct location.

            chdir $TMPDIR
            (chdir $ALIAS_CDPATH/$SYSFILES;tar cf - Alias3D.ftr) | tar xvof -
            set st = $status
        endif
        if ($st == 0) then
            set view_inst
            mv -f Alias3D.ftr /usr/lib/filetype/install
            break
        endif

view_tape_err:
        echo ""
        echo "It appears that there was a problem in reading the $almedia. You may have to"
        echo "attempt it 2 or 3 times before you're finally successful."
        echo ""
        echo -n "Do you wish to try reading the $almedia again? (yes/no): "

        while (1)
            set ans = $<
            if ("$ans" !~ [yY][eE][sS] && "$ans" !~ [nN][oO]) then
                echo -n "Please specify yes or no: "
            else
                break
            endif
        end
        if ($ans =~ [nN][oO]) break
   end

#    If the files were successfully installed, customize the workspace/desktop
#    software.

    if ($?view_inst) then
        echo ""
        echo "Customizing $vsftw software ..."
        echo ""

        if ($?imagic) then

#    If InstallAlias adds new user accounts to a machine which has the Indigo
#    Magic software, some information servers must be informed of the new user
#    accounts. If the  directoryserver or objectserver are running (chkconfig
#    values are on) and the file which starts them (/etc/init.d/cadmin) exists,
#    rebuild the user database. If this is not done, the server(s) will
#    complain when the new user(s) login and run the Indigo Magic software.

            unset dsvon osvon
            chkconfig directoryserver
            if ($status == 0) set dsvon

            chkconfig objectserver
            if ($status == 0) set osvon

            if ($?dsvon || $?osvon) then
                set CADINIT = /etc/init.d/cadmin
                if (-f $CADINIT && $?newuser) then
                    sh $CADINIT clean
                    sh $CADINIT start
                endif
            endif
        else

#    The file sgidefault.wsrc represents the default workspace view which
#    appears when workspace is invoked. Unfortunately, part of this view
#    messes up the workspace view supplied with the ALIAS software. Workspace
#    seems to merge this file and a user's workspace view causing "unpleasant"
#    results. I would rather not modify this file, but I don't have much
#    choice. This step is not done if installing on a machine with the Indigo
#    Magic software.

            set symlink_to_spaint = /usr/StudioPaint
            chdir /usr/lib/workspace
            cat $symlink_to_alias/workspace/database | sed "/$symlink_to_alias:t/d" | sed "/$symlink_to_spaint:t/d" | sed -n '/^b /,$p' > sgidefault.wsrc
            chmod 755 sgidefault.wsrc
        endif

#    Remove any Alias Studio based ftr files from /usr/lib/filetype/local.
#    The Alias Studio ftr file has been moved to /usr/lib/filetype/install.

        chdir /usr/lib/filetype/local
        foreach f (Alias.ftr Alias3D.ftr)
            if (! -f $f) continue
            rm -f $f
        end

        chdir /usr/lib/filetype

#    Run make unconditionally to compile the ftr files in /usr/lib/filetype.

        make -u >& /dev/null

#    If a demo account is being customized on a machine with the WorkSpace
#    software and the directories ~<demo account>/{.workspace,WorkSpace} do not
#    exist, copy the standard workspace directory from /usr/alias. If one (or
#    both) of the workspace directories exist, inform the installer how they
#    may install the new workspace files at a later time.
#
#    If a demo account is being customized on a machine with the Indigo Magic
#    software and both of the following directories do not exist:
#
#        ~<demo account>/.desktop
#        ~<demo account>/.desktop-<hostname>
#
#    copy the standard desktop directory from /usr/alias. If any of those
#    directories exists, inform the installer how they may customize the
#    desktop view at a later time.

        echo ""
        if ($?cust_demo) then
            if ($?imagic) then
                set hname = `hostname`
                if (-d $demo_home/.desktop || -d $demo_home/.desktop-$hname) then
                    echo "A desktop view already exists for $demoname. The standard Alias desktop view"
                    echo "has not been installed, but may be by performing the following steps:"
                    echo ""
                    echo "    login $demoname"
                    echo ""
                    echo "    Execute the following commands:"
                    echo ""
                    if (-d $demo_home/.desktop) then
                        echo "    rm -fr .desktop"
                    else
                        echo "    rm -fr .desktop-$hname"
                    endif
                    echo "    cp -r $symlink_to_alias/desktop .desktop"
                    echo ""
                    echo "The next time that $demoname logs in, the new desktop view will appear."
                else
                    echo "Creating a standard Alias desktop view for $demoname ..."
                    su - $demoname -c "cp -r $sftwdir/desktop $demo_home/.desktop"
                endif
            else
                if (-d $demo_home/.workspace || -d $demo_home/WorkSpace) then
                    echo "A workspace view already exists for $demoname. The standard Alias workspace view"
                    echo "has not been installed, but may be by performing the following steps:"
                    echo ""
                    echo "    login $demoname"
                    echo "    If the workspace starts up, exit it before continuing"
                    echo ""
                    echo "    Execute the following commands:"
                    echo ""
                    echo "    rm -fr .workspace WorkSpace"
                    echo "    cp -r $symlink_to_alias/workspace .workspace"
                    echo ""
                    echo "The next time that $demoname logs in, the new workspace view will appear."
                else
                    echo "Creating a standard Alias workspace view for $demoname ..."
                    su - $demoname -c "cp -r $sftwdir/workspace $demo_home/.workspace"
                endif
            endif
        endif
    endif
endif

#    If the IRIX workspace/desktop software was not customized, give some
#    hints to the installer how to do so.

if (! $?view_inst) then
    echo ""
    echo "The steps involved with customizing the IRIX $vsftw software are"
    echo "numerous and complex."
    if ($?guru_mode) then
        echo ""
        echo "If you have a good knowledge of C-shell and Unix, you may want to look"
        echo "at how InstallAlias customizes the IRIX $vsftw software to recognize"
        echo "$vers based files."
    endif
    echo ""
    echo "If you have further questions, contact Alias Assist for help."
endif

#    If InstallAlias is running in guru mode, ask the installer if they wish
#    to install two Alias icon files which indicate a stowed Alias executable.
#    There are two icon files, one for 4Dwm and one for mwm (Motif Window
#    Manager):
#
#        /usr/lib/images/Alias.icon
#        /usr/include/X11/bitmaps/alias_icon
#
#    If the installer says `no', the icon files are not installed.
#
#    If the installer says `yes' or InstallAlias is not running in guru mode,
#    install the icons in the correct locations.

set inst_icons
echo ""
if ($?guru_mode) then
    echo ""
    echo "Along with the $vers software, the distribution $almedia contains two"
    echo "icon files:"
    echo ""
    echo "    /usr/lib/images/Alias.icon"
    echo "    /usr/include/X11/bitmaps/alias_icon"
    echo ""
    echo "Each file is used by an X window manager to indicate a stowed Alias executable."
    echo "The first icon file is used by the 4Dwm window manager and the other by the"
    echo "Motif window manager (mwm)."
    echo ""
    echo -n "Do you wish to install the Alias icon files? (yes/no): "
    while (1)
        set ans = $<
        if ("$ans" !~ [yY][eE][sS] && "$ans" !~ [nN][oO]) then
            echo -n "Please specify yes or no: "
        else
            break
        endif
    end
    if ($ans =~ [nN][oO]) then
        echo ""
        echo "The Alias icon files will not be installed."
        unset inst_icons
    endif
endif

#    If InstallAlias is running in guru mode and the installer approved the
#    installation of the icon files, do so.
#
#    These steps are also performed if InstallAlias is running in non-guru mode.

unset icons_instd
if ($?inst_icons) then
    while (1)
        echo ""
        if (! $?ALIAS_CDPATH) then
            echo "Positioning the tape to extract the Alias icon files from the $vers"
            echo "software tape."
            mt -t $NRTAPE rew
            if ($status != 0) then
                echo ""
                echo "Error rewinding the tape."
                goto icon_tape_err
            endif
            mt -t $NRTAPE fsf 1
            if ($status != 0) then
                echo ""
                echo "Error advancing the tape to the system support files."
                goto icon_tape_err
            endif
            echo ""
            echo "Extracting and installing the Alias icon files."
            echo ""

#    Extract the files from the distribution tape into a directory ($TMPDIR)
#    and move them to their correct locations.

            chdir $TMPDIR
            tar xvof $NRTAPE Alias.icon alias_icon
            set st = $status
        else
            echo "Extracting and installing the Alias icon files."
            echo ""

#    "Copy" the files from the distribution CD-ROM (via tar) into a directory
#    ($TMPDIR) and move them to their correct locations.

            chdir $TMPDIR
            (chdir $ALIAS_CDPATH/$SYSFILES;tar cf - Alias.icon alias_icon) | tar xvof -
            set st = $status
        endif
        if ($st == 0) then
            set icons_instd
            mv -f Alias.icon /usr/lib/images
            mv -f alias_icon /usr/include/X11/bitmaps
            break
        endif

icon_tape_err:
        echo ""
        echo "It appears that there was a problem in reading the $almedia. You may have to"
        echo "attempt it 2 or 3 times before you're finally successful."
        echo ""
        echo -n "Do you wish to try reading the $almedia again? (yes/no): "

        while (1)
            set ans = $<
            if ("$ans" !~ [yY][eE][sS] && "$ans" !~ [nN][oO]) then
                echo -n "Please specify yes or no: "
            else
                break
            endif
        end
        if ($ans =~ [nN][oO]) break
   end
endif

#    If the Alias icon files were not installed, give some instructions on how
#    to do so:

if (! $?icons_instd) then
    echo ""
    echo "If you later decide to install the Alias icon files, the following instructions"
    echo "may be used to do so:"
    echo ""
    if ($?REMOTE_TAPE_HOST) then
        echo "      Verify that root can access the tape drive on ${REMOTE_TAPE_HOST}:"
        echo ""
        echo "      - the following entry appears in the .rhosts file in ${ruser}'s home"
        echo "        directory on ${REMOTE_TAPE_HOST}:"
        echo ""

        if ("$ruser" == "root") then
            echo "      $hostname"
            echo ""
            echo "      If the entry does not include your domain name (assuming you have a"
            echo "      domain name), be sure to include it as part of the hostname. This"
            echo "      entry should be removed after the icon files have been successfully"
            echo "      installed."
        else
            echo "      $hostname root"
            echo ""
            echo "      If the hostname portion of the entry ($hostname) does not include your"
            echo "      domain name (assuming you have a domain name), be sure to include"
            echo "      it as part of the hostname. This entry should be removed after the"
            echo "      icon files have been successfully installed."
        endif
        echo ""
        echo "      Insert the $vers distribution tape into ${REMOTE_TAPE_HOST}'s tape drive:"
    else if ($?ALIAS_CDPATH) then
        echo "      Insert the $vers distribution CD-ROM into the CD-ROM drive and"
        echo "      mount it:"
    else
        echo "      Insert the $vers distribution tape into the tape drive:"
    endif
    echo ""
    echo "                  login root"
    if ($?ALIAS_CDPATH) then
        echo "                  cd <mount point of CD-ROM>/$SYSFILES"
        echo "                  cp Alias.icon /usr/lib/images"
        echo "                  cp alias_icon /usr/include/X11/bitmaps"
    else
        echo "                  cd $TMPDIR"
        if ($?REMOTE_TAPE_HOST) then
            echo "                  mt -t $NRTAPE rew"
            echo "                  mt -t $NRTAPE fsf 1"
            echo "                  tar xvof $NRTAPE Alias.icon alias_icon"
        else
            echo "                  mt rew"
            echo "                  mt fsf 1"
            echo "                  tar xvo Alias.icon alias_icon"
        endif
        echo "                  mv -f Alias.icon /usr/lib/images"
        echo "                  mv -f alias_icon /usr/include/X11/bitmaps"
    endif
    echo ""
endif

#    If InstallAlias is installing Alias software from a CD-ROM, conditionally
#    install a set of support files for HyperHelp (a viewing tool for online
#    Alias documentation):
#
#    If InstallAlias is running in guru mode, ask the installer if they wish
#    to install the HyperHelp support files in /usr/lib. If they say `yes'
#    or InstallAlias is not running in guru mode, install the support files
#    in /usr/lib.
#
#    If the support files are not installed, give instructions how to install
#    them at a later time.

if ($?ALIAS_CDPATH) then
    set inst_hsf
    if ($?guru_mode) then
        echo ""
        echo "This version of the $vers software includes a help tool named"
        echo "HyperHelp. This tool allows you to view online Alias documentation. In"
        echo "order to support HyperHelp, a number of support files must be installed"
        echo "in /usr/lib."
        echo ""
        echo -n "Do you wish to install the HyperHelp support files? (yes/no): "
        while (1)
            set ans = $<
            if ("$ans" !~ [yY][eE][sS] && "$ans" !~ [nN][oO]) then
                echo -n "Please specify yes or no: "
            else
                break
            endif
        end
        if ($ans =~ [Nn][Oo]) unset inst_hsf
    endif

    if ($?inst_hsf) then
        cd /usr/lib
        while (1)
            echo ""
            echo "Extracting and installing the HyperHelp support files ..."
            echo ""
            (cd $ALIAS_CDPATH/$CDIR/$HELP; tar cf - .) | tar xvopf -
            if ($status == 0) then
                set hsf_instd
                break
            endif

            echo ""
            echo "It appears that there was a problem in reading the $almedia. You may have to"
            echo "attempt it 2 or 3 times before you're finally successful."
            echo ""
            echo -n "Do you wish to try reading the $almedia again? (yes/no): "
    
            while (1)
                set ans = $<
                if ("$ans" !~ [yY][eE][sS] && "$ans" !~ [nN][oO]) then
                    echo -n "Please specify yes or no: "
                else
                    break
                endif
            end
            if ($ans =~ [nN][oO]) break
        end
    endif

    if (! $?hsf_instd) then
        echo ""
        echo "If you later decide to install the HyperHelp support files, the following"
        echo "instructions may be used to do so:"
        echo ""
        echo "      Insert the $vers distribution CD-ROM into the CD-ROM drive and"
        echo "      mount it:"
        echo ""
        echo "                  login root"
        echo "                  cd <mount point of CD-ROM>/$CDIR/$HELP"
        echo "                  cp -r * /usr/lib"
        echo ""
    endif
endif

#    In order for grab and recon to access some video devices, they must
#    be setuid root. If InstallAlias is running in guru mode, ask the installer
#    if they wish to make grab and recon setuid root.

echo ""
set cust_vperiphs
if ($?guru_mode) then
    echo ""
    echo "In order to perform some Video I/O, the grab and recon utilities must be"
    echo "setuid root."
    echo ""
    echo -n "Do you wish to make grab and recon setuid root? (yes/no): "
    while (1)
        set ans = $<
        if ("$ans" !~ [yY][eE][sS] && "$ans" !~ [nN][oO]) then
            echo -n "Please specify yes or no: "
        else
            break
        endif
   end
   if ($ans =~ [nN][oO]) unset cust_vperiphs
endif

#    If the guru said yes or InstallAlias is not running in guru mode, customize
#    the permissions on recon and grab.

if ($?cust_vperiphs) then
    echo ""
    echo "Customizing peripherals software ..."

#    Video Peripherals stuff
#
#    Customize permissions on recon and grab standalones (owned by root and
#    setuid). InstallAlias actually makes IRIX 5 versions of grab and recon
#    setuid root).

    foreach file (grab.i5 recon.i5)
        if (-f $sftwdir/bin/$file) then
            chown root $sftwdir/bin/$file
            if ($status != 0) then
                echo ""
                echo "Error, cannot set ownership of $file to root"
            endif
            chmod 4755 $sftwdir/bin/$file
            if ($status != 0) then
                echo ""
                echo "Error, cannot make $file setuid root"
            endif
        else
            echo ""
            echo "Can't find $file in $sftwdir/bin."
        endif
    end
endif

#    If the machine is running a version of IRIX 4, setup the IEEE (gpib)
#    daemon and IEEE driver.

if ($?irix4) then

#    Make backup copies of the inetd config file and services file before
#    they are possibly modified.

    foreach fname (/usr/etc/inetd.conf /etc/services)
        if (-e $fname && ! -e $fname.pre_alias) cp $fname $fname.pre_alias
        set mod_files = ($mod_files $fname)
    end

#    Setup Alias gpib daemon:
#
#    Search the inetd configuration file for an entry for the gpib daemon. If
#    no entry is found and InstallAlias is running in guru_mode, ask the
#    installer if they wish to setup the gpib daemon. If they say yes or
#    InstallAlias is not running in guru mode, InstallAlias checks for an entry
#    for alias_gpibd in the services file as the first step in setting up the
#    gpib daemon.

    echo ""
    set install_gpibd
    set gpibd_inetd = `grep "^alias-gpibd[ 	]" /usr/etc/inetd.conf`
    if ($#gpibd_inetd == 0 && $?guru_mode) then
        echo ""
        echo "If you will be doing remote scanning with the $vers software, you"
        echo "will want to configure the gpib daemon on this machine. This may require"
        echo "modifications to the services file and the inetd configuration file."
        echo ""
        echo -n "Do you wish to configure the gpib daemon? (yes/no): "
        while (1)
            set ans = $<
            if ("$ans" !~ [yY][eE][sS] && "$ans" !~ [nN][oO]) then
                echo -n "Please specify yes or no: "
            else
                break
            endif
        end
        if ($ans =~ [nN][oO]) unset install_gpibd
    endif

    if ($?install_gpibd) then

#    Search the services file for an entry for the ALIAS gpib daemon. If such
#    an entry is not found, determine an unused port number:
#
#        If InstallAlias is running in guru mode and the installer wishes to
#        pick the port number, ask the installer for their choice and
#        verify that it is not already in use.
#
#        If InstallAlias is not running in guru mode or a guru did not pick a
#        port number, InstallAlias finds the first unused port <= 5999.
#
#    When a port number has been determined, a complete entry is added to
#    the services file.

        echo ""
        echo "Configuring the $vers gpib daemon to allow the ALIAS software to"
        echo "perform remote scanning."

        set gpibd_service = `grep "^alias-gpibd[ 	]" /etc/services`
        if ($#gpibd_service == 0) then
            unset gpibd_portnum
            if ($?guru_mode) then
                echo ""
                echo "There is no entry for the gpib daemon in the services file."
                echo -n "Do you wish to pick the port number? (yes/no): "
                while (1)
                    set ans = $<
                    if ("$ans" !~ [yY][eE][sS] && "$ans" !~ [nN][oO]) then
                        echo -n "Please specify yes or no: "
                    else
                        break
                    endif
                end
                if ($ans =~ [yY][eE][sS]) then
                    while (1)
                        echo ""
                        echo -n "Please specify an unused numeric port number: "
                        set num = $<
                        set port = ($num)
                        if ($#port != 1) continue
                        set service = `grep "^[^ 	]*[ 	]*${port}/tcp" /etc/services | awk '{print $1}'`
                        if ($#service != 0) then
                            echo ""
                            echo "The port number of $port is in use by the $service service."
                        else
                            break
                        endif
                    end
                    set gpibd_portnum = $port
                endif
            endif

#    If InstallAlias is not running in guru mode or is running in guru mode and
#    the installer did not pick a port number, InstallAlias picks an unused port
#    number.

            if (! $?gpibd_portnum) then
                echo ""
                echo "Determining a port number for the gpib daemon ..."

#    Set gpibd_portnum to a starting value (port number) and service to a
#    starting value, then loop until we find an unused port number. At the end
#    of the loop, increment the port number to arrive at the correct value.

                @ gpibd_portnum = 5999
                set service = "starting value"
                while ($#service != 0)
                    set service = `grep "[ 	]$gpibd_portnum/tcp" /etc/services`
                    @ gpibd_portnum--
                end
                @ gpibd_portnum++
            endif

            echo ""
            echo "Editing /etc/services and adding a line for the gpib daemon:"
            echo ""
            echo "    alias-gpibd   $gpibd_portnum/tcp   gpibd    #  Alias GPIB server"
            echo ""
            ex - /etc/services << EOF
            ${DLR}a

alias-gpibd	$gpibd_portnum/tcp	gpibd	# Alias GPIB server
.
            w! /etc/services
            q
EOF
        endif

#    If there is no entry for the gpib daemon in /usr/etc/inetd.conf, determine
#    the pathname of the daemon /usr/alias/etc/gpibd), add a complete entry to
#    the inetd configuration file and send the inetd process a hangup signal
#    which causes it to reread its configuration file and start servicing
#    requests for the Alias gpib daemon.

        if ($#gpibd_inetd == 0) then
            echo ""
            echo "Editing /usr/etc/inetd.conf and adding a line for the gpib daemon:"
            echo ""
            echo "    alias-gpibd  stream  tcp   nowait  root    $symlink_to_alias/etc/gpibd  gpibd"
            echo ""
            ex - /usr/etc/inetd.conf << EOF
            ${DLR}a
#
# Alias gpib daemon
#
alias-gpibd	stream  tcp     nowait  root    $symlink_to_alias/etc/gpibd	gpibd
# End of Alias entries
.
            w! /usr/etc/inetd.conf
            q
EOF
            killall 1 inetd
        else

#    If there is an entry for the gpib daemon in the inetd configuration file,
#    but the pathname of the daemon specified by the entry is not correct,
#    replace the entry with a new entry which specifies the correct pathname
#    (/usr/alias/etc/gpibd) and send the inetd process a hangup signal which
#    causes it to reread its configuration file.

            set gpibd_path = `echo $gpibd_inetd | awk '{print $6}'`
            if ("$gpibd_path" != $symlink_to_alias/etc/gpibd) then
                echo ""
                echo "Changing pathname of the gpib daemon specified in the inetd configuration file"
                echo "(/usr/etc/inetd.conf) from $gpibd_path to $symlink_to_alias/etc/gpibd."
                ex - /usr/etc/inetd.conf << EOF
        /^alias-gpibd[ 	]/c
alias-gpibd	stream  tcp     nowait  root    $symlink_to_alias/etc/gpibd	gpibd
.
                w! /usr/etc/inetd.conf
                q
EOF
                killall 1 inetd
            endif
        endif
    endif

#    In order for ALIAS software to use IEEE devices, the IRIX kernel must
#    have the IEEE driver installed. The driver consists of two files:
#
#        /usr/sysgen/master.d/gpib
#        /usr/sysgen/boot/gpib.o
#
#    These files will be installed under the following conditions:
#
#    - if InstallAlias is running in guru mode, InstallAlias asks the installer
#      if they wish to install the IEEE driver files. If the installer says
#      `yes' or InstallAlias is running in automatic mode, the installation
#      proceeds.
#    - if existing versions of the driver files are found, the driver files
#      from the ALIAS distribution tape or CD-ROM will be compared with the
#      existing files. If the files are the same (i.e. gpib.o from the tape or
#      CD-ROM is the same as gpib.o on disk), the file from the distribution
#      media is removed. If the files are different, the file from the
#      distribution media replaces the existing file, which is saved.
#    - if any of the IEEE driver files from the distribution media are
#      installed, a new IRIX kernel is built and the installer is instructed to
#      reboot the machine to start using the new kernel.
#    - if the kernel rebuild fails or InstallAlias was running in advanced mode
#      and the installer chose not to install the IEEE driver files,
#      InstallAlias gives the installer instructions how to install the IEEE
#      driver files and rebuild a new kernel by hand.

    echo ""
    echo ""
    echo "If you are planning to do any peripheral work with the $vers software"
    echo "and IEEE devices (i.e.: scanners, film recorders), your machine must have the"
    echo "correct IEEE driver installed in the IRIX kernel."

    set gpibo = $GPIB_OBJ:t
    set gpibm = $GPIB_MASTER:t
    echo ""
    echo "The two files which together, make up the IEEE driver are:"
    echo ""
    echo "    $GPIB_OBJ"
    echo "    $GPIB_MASTER"
    echo ""
    echo "The correct versions of these files must be installed in order to provide"
    echo "support for the IEEE devices. The file located in $GPIB_OBJ:h is the"
    echo "IEEE object file and the file located in $GPIB_MASTER:h is the master"
    echo "or kernel description file."
    echo ""
    echo "If older versions of these files exist, they will be compared with the same"
    echo "files from the $vers software $almedia. If they differ, the file(s)"
    echo "from the distribution $almedia will replace the existing version(s), which will"
    echo "be saved. If any of the files from the distribution $almedia are installed,"
    echo "InstallAlias will build a new IRIX kernel."

    set inst_driver

#    If InstallAlias is running in advanced mode, ask the installer if they wish
#    to install the IEEE driver. If they say `no', the IEEE driver files are
#    not installed. 

    if ($?guru_mode) then
        echo ""
        echo -n "Do you wish to install the files comprising the IEEE driver? (yes/no): "
        while (1)
            set ans = $<
            if ("$ans" !~ [yY][eE][sS] && "$ans" !~ [nN][oO]) then
                echo -n "Please specify yes or no: "
            else
                break
            endif
        end
        if ($ans =~ [Nn][Oo]) unset inst_driver
    endif

#    If the IEEE driver files are being installed, check for existing versions
#    of the files. If they exist, the driver files from the ALIAS distribution
#    tape or CD-ROM (which are extracted or "copied" into a temporary directory)
#    are compared with the existing driver files (i.e.: gpib.o from the
#    distribution media is compared with gpib.o from the disk). If the files
#    are the same, the version from the distribution media is removed (from the
#    temporary area). If the files are different, the version from the
#    distribution media is moved to one of the directories in /usr/sysgen
#    (gpib.o is moved to /usr/sysgen/boot and gpib is moved to
#    /usr/sysgen/master.d) and the original version is saved. If any of the
#    IEEE driver files from the distribution media are installed, a new IRIX
#    kernel is built and InstallAlias instructs the installer to reboot the
#    machine to start using the new kernel.

    if ($?inst_driver) then
        echo ""
        echo "InstallAlias will now verify that your machine has the IEEE driver installed."
        unset old_obj old_master pref_obj pref_master
        if (-f $GPIB_OBJ) set old_obj
        if (-f $GPIB_MASTER) set old_master

        if ($?old_obj && $?old_master) then
            echo ""
            echo "Existing versions of both the IEEE object file and master file have been found."
            echo ""
            echo "Versions of these files will be extracted from the $vers software"
            echo "$almedia into $TMPDIR and compared with the existing IEEE driver files."
        else
            if ($?old_obj || $?old_master) then
                echo ""
                echo -n "An existing version of the IEEE "
                if ($?old_obj) then
                    echo -n "object file"
                else
                    set pref_obj = $GPIB_OBJ:h
                endif
                if ($?old_master) then
                    echo -n "master file"
                else
                    set pref_master = $GPIB_MASTER:h
                endif
                echo " has been found."
                echo ""
                echo "New versions of the IEEE driver files will be extracted from the $vers"
                echo "software $almedia into $TMPDIR and either compared with a previous version of"
                echo "itself or installed in one of the directories in /usr/sysgen."
            else
                echo ""
                echo "There are no existing versions of the IEEE driver files on this machine."
                set pref_obj = $GPIB_OBJ:h
                set pref_master = $GPIB_MASTER:h
            endif
        endif

        chdir $TMPDIR
        while (1)
            if (! $?ALIAS_CDPATH) then
                echo ""
                echo "Positioning the tape to extract the IEEE driver files from the $vers"
                echo "software tape."
                mt -t $NRTAPE rew
                if ($status != 0) then
                    echo ""
                    echo "Error rewinding the tape."
                    goto gpib_tape_err
                endif
                mt -t $NRTAPE fsf 1
                if ($status != 0) then
                    echo ""
                    echo "Error advancing the tape to the system support files."
                    goto gpib_tape_err
                endif
            endif
            echo ""
            echo "Extracting IEEE driver files into $TMPDIR."
            echo ""

            if ($?ALIAS_CDPATH) then
                (chdir $ALIAS_CDPATH/$SYSFILES;tar cf - $gpibm $gpibo) | tar xvof -
                set st = $status
            else
                tar xvof $NRTAPE $gpibm $gpibo
                set st = $status
            endif
            if ($st == 0) break

gpib_tape_err:
            echo ""
            echo "It appears that there was a problem in reading the $almedia. You may have to"
            echo "attempt it 2 or 3 times before you're finally successful."
            echo ""
            echo -n "Do you wish to try reading the $almedia again? (yes/no): "
            while (1)
                set ans = $<
                if ("$ans" !~ [yY][eE][sS] && "$ans" !~ [nN][oO]) then
                    echo -n "Please specify yes or no: "
                else
                    break
                endif
            end
            if ($ans =~ [nN][oO]) then
                unset inst_driver
                rm -f $gpibm $gpibo
                break
            endif
        end

        if ($?inst_driver) then
            unset krebuild
            if (! $?pref_obj) then
                echo ""
                echo "Comparing the new version of the IEEE object file with the existing version."
                cmp -s $gpibo $GPIB_OBJ
                if ($status == 0) then
                    echo ""
                    echo "The new version of the object file is the same as the existing version and is"
                    echo "being removed."
                    rm $gpibo
                else
                    echo ""
                    echo "The two versions of the object file differ."
                    set pref_obj = $GPIB_OBJ:h
                endif
            endif

            if ($?pref_obj) then
                echo ""
                echo "The version of the IEEE object file from the $vers software $almedia is"
                echo "being installed in $GPIB_OBJ:h."
                if ($?old_obj) then
                    echo ""
                    echo "The existing version of the object file will be renamed to ${gpibo}= when the"
                    echo "installation completes."
                    if (! -f $GPIB_OBJ.pre_alias) then
                        mv $GPIB_OBJ $GPIB_OBJ.pre_alias
                    endif
                    set mod_files = ($mod_files $GPIB_OBJ)
                endif
                mv -f $gpibo $GPIB_OBJ
                chmod 444 $GPIB_OBJ
                chown bin.bin $GPIB_OBJ
                set krebuild
            endif

            if (! $?pref_master) then
                echo ""
                echo "Comparing the new version of the IEEE master file with the existing version."
                cmp -s $gpibm $GPIB_MASTER
                if ($status == 0) then
                    echo ""
                    echo "The new version of the master file is the same as the existing version and is"
                    echo "being removed."
                    rm $gpibm
                else
                    echo ""
                    echo "The two versions of the master file differ."
                    set pref_master = $GPIB_MASTER:h
                endif
            endif

            if ($?pref_master) then
                echo ""
                echo "The version of the IEEE master file from the $vers software $almedia is"
                echo "being installed in $GPIB_MASTER:h."
                if ($?old_master) then
                    echo ""
                    echo "The existing version of the master file will be renamed to ${gpibm}= when the"
                    echo "installation completes."
                    if (! -f $GPIB_MASTER.pre_alias) then
                        mv $GPIB_MASTER $GPIB_MASTER.pre_alias
                    endif
                    set mod_files = ($mod_files $GPIB_MASTER)
                endif
                mv -f $gpibm $GPIB_MASTER
                chmod 444 $GPIB_MASTER
                chown bin.bin $GPIB_MASTER
                set krebuild
            endif

            if ($?krebuild) then
                echo ""
                echo "Building a new IRIX kernel ..."

                lboot -u /unix.install >& /dev/null
                if ($status == 0) then
                    echo ""
                    echo "In order to start using the reconfigured operating system, you will have to"
                    echo "reboot the machine."
                else
                    echo ""
                    echo "An error occurred while reconfiguring the operating system. You may have to"
                    echo "reboot the machine a few times before the reconfiguration is successful. If the"
                    echo 'machine asks you "Automatically reconfigure the operating system (y or n) ?",'
                    echo 'make sure you answer "y". When the reconfiguration is successful, the machine'
                    echo 'will respond with "Reboot to start using the reconfigured kernel". When the'
                    echo "reboot is complete, your machine will be executing the reconfigured kernel."
                endif
            else
                echo ""
                echo "Your machine already has the IEEE driver installed."
            endif

        endif
    endif

#    If the operating system is valid, but the IEEE driver files from the
#    ALIAS distribution tape or CD-ROM were not installed correctly,
#    InstallAlias instructs the installer how to install the files and build
#    a new IRIX kernel by hand.

    if (! $?inst_driver) then
        set gpibopd = $GPIB_OBJ:h
        set gpibmpd = $GPIB_MASTER:h
        echo ""
        echo "If you later decide to install the IEEE driver files, the following"
        echo "instructions may be used to do so:"
        echo ""
        if ($?REMOTE_TAPE_HOST) then
            echo "      Verify that root can access the tape drive on ${REMOTE_TAPE_HOST}:"
            echo ""
            echo "      - the following entry appears in the .rhosts file in ${ruser}'s home"
            echo "        directory on ${REMOTE_TAPE_HOST}:"
            echo ""

            if ("$ruser" == "root") then
                echo "      $hostname"
                echo ""
                echo "      If the entry does not include your domain name (assuming you have a"
                echo "      domain name), be sure to include it as part of the hostname. This"
                echo "      entry should be removed after the driver files are successfully"
                echo "      installed."
            else
                echo "      $hostname root"
                echo ""
                echo "      If the hostname portion of the entry ($hostname) does not include your"
                echo "      domain name (assuming you have a domain name), be sure to include"
                echo "      it as part of the hostname. This entry should be removed after the"
                echo "      driver files are successfully installed."
            endif
            echo ""
            echo "      Insert the $vers distribution tape into ${REMOTE_TAPE_HOST}'s tape drive:"
        else if ($?ALIAS_CDPATH) then
            echo "      Insert the $vers distribution CD-ROM into the CD-ROM drive and"
            echo "      mount it:"
        else
            echo "      Insert the $vers distribution tape into the tape drive:"
        endif
        echo ""
        echo "                  login root"
        if ($?ALIAS_CDPATH) then
            echo "                  cd <mount point of CD-ROM>/$SYSFILES"
            echo "                  cp gpib $gpibmpd"
            echo "                  cp gpib.o $gpibopd"
            echo "                  cd $gpibopd:h"
            echo "                  chmod 444 $gpibmpd:t/gpib $gpibopd:t/gpib.o"
            echo "                  chown bin.bin $gpibmpd:t/gpib $gpibopd:t/gpib.o"
        else
            echo "                  cd $TMPDIR"
            if ($?REMOTE_TAPE_HOST) then
                echo "                  mt -t $NRTAPE rew"
                echo "                  mt -t $NRTAPE fsf 1"
                echo "                  tar xvof $NRTAPE gpib gpib.o"
            else
                echo "                  mt rew"
                echo "                  mt fsf 1"
                echo "                  tar xvo gpib gpib.o"
            endif
            echo "                  chmod 444 gpib gpib.o"
            echo "                  chown bin.bin gpib gpib.o"
            echo "                  mv -f gpib $gpibm"
            echo "                  mv -f gpib.o $gpibo"
        endif
        echo "                  lboot -u /unix.install"
        echo ""
        echo "and then reboot the machine to start using the new IRIX kernel. Remember"
        echo "the IEEE driver files are only for IRIX 4 machines."
    endif
endif

#    Inform the installer that they should install the Alias tablet drivers if
#    they are planning to use tablets with the Alias software. If the Alias
#    software is being installed from CD-ROM, inform the installer that they
#    may install tablet support via the master install script (Install) at the
#    top level of the CD-ROM.
#
#    If the Alias software is being installed from tape, InstallTablet will
#    have been extracted from the tape at the same time as InstallAlias. It may
#    be invoked after the successful installation of the Alias software.

echo ""
echo ""
echo "If you wish to use tablets with the $vers software, your machine must"
echo "be customized to recognize the tablets."
echo ""
echo "All this is performed by another installation script, $TABINST which"
if ($?ALIAS_CDPATH) then
    echo "may be invoked by choosing to install the Alias tablet drivers via the"
    echo "Install script at the top level of the CD-ROM ($ALIAS_CDPATH/Install)."
else
    echo "should have been extracted from the distribution $almedia at the same time as"
    echo "InstallAlias."
    echo ""
    echo "If you wish to install tablet support, this script should be run after the"
    echo "successful installation of the $vers software."
endif
echo ""
echo -n "For details on the use of $TABINST, see" 
echo ' "Installation Instructions for'
echo -n 'Alias Tablet Software" '
echo "in the Release Notes."

#    If the machine is running a variant of IRIX 4, conditionally install an
#    IEEE debugging tool, ibic, in /usr/sbin. If InstallAlias is running in
#    guru mode and the installer approves the installation, install ibic in
#    /usr/sbin.
#
#    If InstallAlias is running in non-guru mode and the machine is running a
#    variant of IRIX 4, automatically install ibic in /usr/sbin.

echo ""
echo ""
if ($?irix4) then
    set inst_ibic
    echo ""
    echo "In addition to the $vers software, the distribution $almedia contains a"
    echo "debugging program for the IEEE interface called ibic."
    if ($?guru_mode) then
        echo ""
        echo -n "Do you wish to install ibic? (yes/no): "
        while (1)
            set ans = $<
            if ("$ans" !~ [yY][eE][sS] && "$ans" !~ [nN][oO]) then
                echo -n "Please specify yes or no: "
            else
                break
            endif
        end
        if ($ans =~ [Nn][Oo]) then
            unset inst_ibic
        endif
    endif

#    If InstallAlias is not running in guru mode, or the guru said `yes' to the
#    installation of ibic, install the file in /usr/sbin.

    unset ibic_installed
    if ($?inst_ibic) then
        foreach file (/usr/sbin/ibic)
            if (-f $file && ! -f $file.pre_alias) then
                cp $file $file.pre_alias
            endif
            set mod_files = ($mod_files $file)
        end

#    Position the distribution tape and extract ibic into /usr/sbin.

        while (1)
            if (! $?ALIAS_CDPATH) then
                echo ""
                echo "Positioning the $vers software tape to extract ibic".
                mt -t $NRTAPE rew
                if ($status != 0) then
                    echo ""
                    echo "Error rewinding the tape."
                    goto extra_tape_err
                endif
                mt -t $NRTAPE fsf 1
                if ($status != 0) then
                    echo ""
                    echo "Error advancing the tape to the system support files."
                    goto extra_tape_err
                endif
            endif
            echo ""
            echo "Extracting and installing ibic in /usr/sbin ..."
            echo ""
            chdir /usr/sbin
            if ($?ALIAS_CDPATH) then
                (chdir $ALIAS_CDPATH/$SYSFILES;tar cf - ibic) | tar xvof -
                set st = $status
            else
                tar xvof $NRTAPE ibic
                set st = $status
            endif
            if ($st == 0) then
                set ibic_installed
                break
            endif

extra_tape_err:
            echo ""
            echo "It appears that there was a problem in reading the $almedia. You may have to"
            echo "attempt it 2 or 3 times before you're finally successful."
            echo ""
            echo -n "Do you wish to try reading the $almedia again? (yes/no): "
            while (1)
                set ans = $<
                if ("$ans" !~ [yY][eE][sS] && "$ans" !~ [nN][oO]) then
                    echo -n "Please specify yes or no: "
                else
                    break
                endif
            end
            if ($ans =~ [nN][oO]) break
        end
    endif

#    If ibic was not installed, explain how to do so.

    if (! $?ibic_installed) then
        echo ""
        echo "If you later decide to install ibic, the following instructions may be used"
        echo "to do so:"
        echo ""
        if ($?REMOTE_TAPE_HOST) then
            echo "    Verify that root can access the tape drive on ${REMOTE_TAPE_HOST}:"
            echo ""
            echo "      - the following entry appears in the .rhosts file in ${ruser}'s home"
            echo "        directory on ${REMOTE_TAPE_HOST}:"
            echo ""
    
            if ("$ruser" == "root") then
                echo "    $hostname"
                echo ""
                echo "    If the entry does not include your domain name (assuming you have a"
                echo "    domain name), be sure to include it as part of the hostname. This"
                echo "    entry should be removed after ibic is successfully installed."
            else
                echo "    $hostname root"
                echo ""
                echo "    If the hostname portion of the entry ($hostname) does not include your"
                echo "    domain name (assuming you have a domain name), be sure to include"
                echo "    it as part of the hostname. This entry should be removed after ibic"
                echo "    has been successfully installed."
            endif
            echo ""
            echo "    Insert the $vers distribution tape into ${REMOTE_TAPE_HOST}'s tape drive:"
        else if ($?ALIAS_CDPATH) then
            echo "    Insert the $vers distribution CD-ROM into the CD-ROM drive and"
            echo "    mount it:"
        else
            echo "    Insert the $vers distribution tape into the tape drive:"
        endif
        echo ""
        echo "              login root"
        if ($?ALIAS_CDPATH) then
            echo "              cd <mount point of CD-ROM>/$SYSFILES"
            echo "              cp ibic /usr/sbin"
        else
            echo "              cd /usr/sbin"
            if ($?REMOTE_TAPE_HOST) then
                echo "              mt -t $NRTAPE rew"
                echo "              mt -t $NRTAPE fsf 1"
                echo "              tar xvof $NRTAPE ibic"
            else
                echo "              mt rew"
                echo "              mt fsf 1"
                echo "              tar xvo ibic"
            endif
        endif
    endif
endif
echo ""

cleanup:

#    Check if any of the saved system files have been changed. If a file has not
#    been changed, remove the ".pre_alias" file; else rename the ".pre_alias"
#    file to a file ending with '=' and report the renaming [ i.e.: mv
#    /etc/passwd.pre_alias /etc/passwd= ].    

echo ""
foreach fname ($mod_files)
    if (-e $fname.pre_alias) then
        cmp -s $fname $fname.pre_alias
        if ($status == 0) then
            rm -f $fname.pre_alias
        else
            mv $fname.pre_alias ${fname}=
            echo "The original version of $fname has been renamed to ${fname:t}=."
        endif
    endif
end

#    Conditionally make install_en setuid and owned by the owner of the
#    Alias software:
#
#    In order for users other than the owner of the Alias software to add
#    encryption strings to the encryption file (/usr/alias/sys/insall/en),
#    install_en should be setuid and owned by the owner of the software.
#
#    If InstallAlias is running in guru mode, ask the installer if they
#    wish to make install_en setuid and owned by the owner of the Alias
#    software. If the installer says `yes' or InstallAlias is not running
#    in guru mode, install_en permissions are made setuid. The change in
#    ownership is unecessary since install_en is already owned by the owner
#    of the Alias software (ownership is set on extraction from the distribution
#    tape or CD-ROM).

echo ""
set suid_ien
if ($?guru_mode) then
    echo ""
    echo "In order to allow user accounts other than the owner of the $vers"
    echo "software ($distname) to add encryption strings to the ALIAS encryption file"
    echo "($symlink_to_alias/sys/install/en), the encryption string administration program"
    echo "(install_en) should be setuid and owned by $distname. If you don't like setuid"
    echo "programs, you may wish to disable this."
    echo ""
    echo -n "Do you wish to make install_en setuid and owned by $distname? (yes/no): "
    while (1)
        set ans = $<
        if ("$ans" !~ [yY][eE][sS] && "$ans" !~ [nN][oO]) then
            echo -n "Please specify yes or no: "
        else
            break
        endif
   end
   if ($ans =~ [nN][oO]) unset suid_ien
endif

if ($?suid_ien) then
    echo ""
    echo "Customizing permissions on encryption file administration program (install_en)."

    chmod 4755 $sftwdir/bin/install_en
    if ($status != 0) then
        echo ""
        echo "Error, cannot make install_en setuid"
    endif
else if ($?guru_mode) then

#    If install_en is not made setuid and owned by the owner of the Alias
#    software and InstallAlias is running in guru mode, inform the installer
#    that users other than the owner of the software will not be able to add
#    encryption strings to the encryption file unless the directory containing
#    the encryption file (/usr/alias/sys/install) is made writable and
#    examinable for everyone and the encryption file readable and writable for
#    everyone.
#
#    Ask the installer if they wish to make the directory and encryption file
#    writable for everyone. If the installer says `yes', make the directory and
#    encryption file writable; else inform the installer that only the owner of
#    the Alias software or root can add encryption strings to the encryption
#    file.

    echo ""
    echo "Since you chose not to make install_en setuid, user accounts other than the"
    echo "owner of the $vers software ($distname) cannot add encryption strings"
    echo "to the encryption file unless the directory containing the encryption file"
    echo "($symlink_to_alias/sys/install) is made writable and examinable for everyone and"
    echo "the encryption file readable and writable for everyone."
    echo ""
    echo "If this is not done, no one other than the owner of the $vers software"
    echo "(and root) can add encryption strings to the encryption file."
    echo ""
    echo -n "Do you wish to make $symlink_to_alias/sys/install and the encyption file writable? (yes/no): "
    while (1)
        set ans = $<
        if ("$ans" !~ [yY][eE][sS] && "$ans" !~ [nN][oO]) then
            echo -n "Please specify yes or no: "
        else
            break
        endif
    end
    echo ""
    if ($ans =~ [Yy][Ee][Ss]) then
        echo "Fixing permissions of $symlink_to_alias/sys/install and the encryption file."
        chmod +rwx $sftwdir/sys/install
        chmod +rw $sftwdir/sys/install/en
    else
        echo "No one other than the owner of the $vers software ($distname) and root is"
        echo "able to add encryption strings to the encryption file."
    endif
endif

#    If the en file is empty, run getid and advise the user to record the
#    output and contact Alias for an encrypted string.

unset emsg
if (-z $sftwdir/sys/install/en) then
    set emsg
    echo ""
    echo ""
    echo 'You will require an "encrypted string" (a code consisting of letters and'
    echo "digits) to enable the $vers software.  To obtain your encrypted"
    echo "string, please copy the system information shown below onto the Software"
    echo "Product Authorization Request (SPAR) form, then fax it to the number"
    echo "indicated on the form."

    echo ""
    $sftwdir/bin/getid | sed "s/^/	/"
    echo ""
endif

foreach tmpfile ($HOSTS_TMP $OERR $OUT)
    if (-f $tmpfile) rm -f $tmpfile
end

if (! $?ALIAS_CDPATH) then
    echo ""
    echo "Rewinding tape ..."
    mt -t $NRTAPE rew
endif

cat << EOF


     *************************************************************
     *                                           		 *
     *  Installation of the $vers software is complete	 * 
     *                                           		 *
     *************************************************************


EOF
echo ""
if ($?emsg) then
    echo "Once you have recorded the information displayed above, press <ENTER> to"
    echo -n "return to the main Install procedure: "
else
    echo -n "Press <ENTER> to return to the main Install procedure: "
endif
set a = $<
exit 0

baderr:
echo ""
echo "There has been an error in the installation procedure ..."
echo "Please record the error message and contact Alias Assist."
echo "This situation must be corrected before the installation can continue."
echo ""
echo "The error encountered was:"
echo ""
echo $errmsg1
echo $errmsg2
echo ""
foreach tmpfile ($HOSTS_TMP $OERR $OUT)
    if (-f $tmpfile) rm -f $tmpfile
end

if (! $?ALIAS_CDPATH) then
    echo "Rewinding tape ..."
    mt -t $NRTAPE rew
endif
echo ""
echo -n "Press <ENTER> to continue: "
set a = $<
exit

userexit:
echo ""
if ($?vers) then
    echo "Ok. Installation of the $vers software has been aborted. When you"
    echo "are ready to install the software, attempt the installation again."
else
    echo "Ok. Installation has been aborted. When you are ready to install the software,"
    echo "attempt the installation again."
endif
echo ""
clnout:

#    If the temporary files have been defined (tfd is set), they may be
#    safely accessed by their names. Otherwise, a shell `undefined variable'
#    error is encountered.

if ($?tfd) then
    foreach tmpfile ($HOSTS_TMP $OERR $OUT)
        if (-f $tmpfile) rm -f $tmpfile
    end
endif

if (! $?ALIAS_CDPATH) then
    if ($?TAPE) then
        echo "Rewinding tape ..."
        mt -t $TAPE rew
    endif
endif
echo ""
echo -n "Press <ENTER> to continue: "
set a = $<
exit
