#!/bin/csh -f
#Tag 1024

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

# InstallSpaint: loads the contents of the ALIAS StudioPaint Software and
#                customizes the user environment so that the software can
#                be run. The StudioPaint Software tape contains 4 separate
#                tar images:
#
#               - Installation tools
#
#               - Optional system support files
#
#               - StudioPaint software
#
#               - StudioPaint example files
#
#           while the StudioPaint Software area on the Alias CD-ROM contains
#           a hierarchy of files dealing with StudioPaint:
#
#               - Optional system support files
#
#               - StudioPaint software
#
#               - StudioPaint example files
#
#           and 3 install tools:
#
#               - Install       (master install script)
#
#               - InstallSpaint (installs StudioPaint software)
#
#               - InstallTablet (customizes Alias tablet setup)
#
#    The following steps are performed to install the StudioPaint software:
#
#    1) Set a default search path:
#
#       The components of the search path are directories that contain tools
#       which are used to load the StudioPaint software.
#
#    2) Verify that the installer is root:
#
#       If the installer is not root, inform them that InstallSpaint must be
#       run as root. Prompt them for the root password (via su) and execute
#       InstallSpaint 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) Determine if the installer is a guru. If InstallSpaint runs in guru
#       mode, it may ask some detailed questions about how the installation of
#       the StudioPaint software should proceed. It will try not to assume
#       anything.
#
#       If InstallSpaint 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.
#
#       Once the installer makes their choice of which mode to install the
#       StudioPaint software in, InstallSpaint informs them of their choice.
#
#       The choice of whether to run in guru mode is indicated by the `-g'
#       flag on the command line. If the flag is present, InstallSpaint runs
#       in guru mode.
#
#    4) Determine where InstallSpaint will place its working files. Search for
#       a writable temporary directory among the following directories:
#
#           /var/tmp
#           /usr/tmp
#           /tmp
#
#       InstallSpaint will place its temporary files in one of these
#       directories.
#
#    5) 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.
#
#    6) Determine the type of media from which the StudioPaint software will be
#       installed:
#
#       The StudioPaint 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 StudioPaint
#       software will be installed from the Alias CD-ROM mounted at the location
#       specified by ALIAS_CDLOCN.
#
#       If ALIAS_CDLOCN is not set, InstallSpaint asks the installer if they
#       wish to install the software from a CD-ROM. If they say `yes',
#       InstallSpaint 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, InstallSpaint verifies the contents of the CD-ROM. If the
#       contents of the CD-ROM are valid, the installation continues, else
#       InstallSpaint exits with an explanatory error message. After the
#       CD-ROM has been validated, InstallSpaint runs `getid -i' to display
#       machine dependent information and asks the installer to compare it
#       against the requirements for StudioPaint software listed in the
#       documentation. The installer should make sure their machine meets the
#       suggested requirements. InstallSpaint then asks the installer if they
#       wish to continue with the installation. If they say `yes', the
#       installation continues, else InstallSpaint exits.
#
#       If the StudioPaint software is not being installed from CD-ROM,
#       InstallSpaint 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, InstallSpaint asks them if the tape drive is connected to the
#       machine. If they say `yes', InstallSpaint (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, InstallSpaint asks them if
#       they wish to install the software using a remote tape drive. If they say
#       `no', InstallSpaint 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,
#       InstallSpaint 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, InstallSpaint 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,
#       InstallSpaint 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, InstallSpaint (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),
#       InstallSpaint will know the type of media to use for the installation
#       of the StudioPaint software (CD-ROM or tape) and its location (CD-ROM
#       mount point or tape device names for rewinding and non-rewinding tape
#       devices).
#
#    7) Verify that the machine is acceptable to run the StudioPaint software:
#
#       The StudioPaint software is only supported on machines with VGX (or
#       higher) graphics class. The current requirements are:
#
#       Hardware/Graphics combinations
#       ------------------------------
#       Crimson VGX, Power Series VGX (4D/nn0 VGX)
#       Crimson VGXT, Power Series VGXT (4D/nn0 VGXT)
#       Crimson RE, Power Series RE (4D/nn0 RE)
#       Onyx VTX, REII
#
#       where RE means Reality Engine Graphics.
#
#       Each machine must be running IRIX 5.2 (or higher) and the execution
#       only ImageVision software (il_eoe.sw) must be installed as well.
#
#       InstallSpaint must decide if the installers machine is suitable for the
#       installation of the StudioPaint software. If the installer's machine
#       meets the above requirements, the installation continues. If a match is
#       not found, the installer is informed of the requirements they are
#       lacking  and asked if they wish to continue with the installation. If
#       the installer says `yes', the installation continues; else InstallSpaint
#       exits.
#
#    8) Get a copy of the old StudioPaint encryption file:
#
#       If the encryption file is not empty, make a copy of it. Since some old
#       StudioPaint encryption strings work with the new StudioPaint software,
#       InstallSpaint will append the contents of the copied encryption file to
#       the new encryption file after the new StudioPaint software is installed
#       (see step #19).
#
#    9) Save any system files that may be modified during an attempt to install
#       the StudioPaint software:
#
#       Foreach filename, if filename.pre_aliassp does not exist, copy filename
#       to filename.pre_aliassp.
#
#       When the installation succeeds, the saved files reflect the state of the
#       system before the StudioPaint software was installed.
#
#       The files affected by this step are:
#
#           /etc/passwd
#           /usr/lib/X11/xdm/Xservers
#
#   10) Find all filesystems that have sufficient free disk space for the
#       StudioPaint 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).
#
#       If there are no filesystems with sufficient disk space (> 10Mb), echo
#       an error message and exit.
#
#   11) Choose the host filesystem and directory for the StudioPaint 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
#       StudioPaint software is to be installed ($sftwfs).
#
#       Once it has been determined on what filesystem the StudioPaint 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 StudioPaint software in
#       /<dir>/alias_spYYMM, 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 StudioPaint 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 StudioPaint 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 InstallSpaint would like to install the software.
#
#       and alias_spYYMM is a directory indicating the StudioPaint software and
#       its release date.
#
#       If the installer doesn't want to install the software in
#       /<dir>/alias_spYYMM, ask them where they do want it.
#
#       When the installer specifies a location for the StudioPaint software,
#       verify that:
#
#       - the directory is located in the filesystem that the installer approved
#       - the name of the directory is alias_spYYMM (for identification
#         purposes)
#
#       If any of these points are not met, InstallSpaint 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 StudioPaint software will be
#       installed, pending installer approval.
#
#   12) Verify that the home directory for the StudioPaint software does not
#       exist:
#
#       The StudioPaint software will be loaded in a directory specified by the
#       installer, that ends with alias_spYYMM. If this directory already exists
#       (i.e.: if StudioPaint software has been installed), InstallSpaint will
#       ask the installer for approval to remove the directory and replace it
#       with the StudioPaint software on the distribution media. If they say
#       `no', explain the situation and exit; else remove the file/directory
#       and continue with the installation.
#
#   13) Create a symbolic link between the home of the StudioPaint software and
#       /usr/StudioPaint (i.e: /usr/StudioPaint ->  /usr/alias_spYYMM):
#
#       If /usr/StudioPaint is a symbolic link and it's target is the home of
#       the StudioPaint software, the link is correct.
#
#       If /usr/StudioPaint exists (and it is not a symbolic link to the home
#       of the StudioPaint 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/StudioPaint and form a symbolic link from /usr/StudioPaint to the
#       home of the StudioPaint software.
#
#   14) Create/Verify an account for the owner of the StudioPaint software:
#
#       This section of InstallSpaint operates in one of two modes; guru and
#       non-guru modes.
#
#       If InstallSpaint is running in guru mode, the installer has the ability
#       to specify who should own the StudioPaint software when it is installed.
#
#       If InstallSpaint 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 StudioPaint 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 InstallSpaint will pick the
#         value if they do not.
#       - If the installer does not specify the numeric userid for the user,
#         InstallSpaint 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/StudioPaint
#         for the home directory so that the account acts as a administrator for
#         the StudioPaint 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 StudioPaint 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 StudioPaint 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', InstallSpaint exits; else ask them who should own the
#         StudioPaint software. This process is repeated until an owner for the
#         software is found or InstallSpaint 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/StudioPaint, where /usr/StudioPaint is a
#         symbolic link to the directory containing the StudioPaint 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 set 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/StudioPaint (symbolic link
#       to the StudioPaint 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).
#
#   15) If InstallSpaint is using a remote tape drive to install the StudioPaint
#       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
#       InstallSpaint) 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,
#       InstallSpaint informs you of the problem and exits.
#
#   16) Conditionally create a demo account for the StudioPaint software:
#
#       This section of InstallSpaint operates in one of two modes; guru and
#       non-guru modes.
#
#       If InstallSpaint is running in guru mode, ask the installer if they wish
#       to create a demo account for the StudioPaint software. If they say
#       `yes', a demo account will be verified/created. If they say `no',
#       InstallSpaint continues without a demo account.
#
#       if InstallSpaint 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 InstallSpaint will pick the
#         value if they do not.
#       - If the installer does not specify the numeric userid for the user,
#         InstallSpaint 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
#         StudioPaint 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', InstallSpaint
#         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:
#
#       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 set 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 StudioPaint 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 StudioPaint 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 StudioPaint 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).
#
#   17) If the home directory for the StudioPaint software does not exist,
#       create it and fix the permissions.
#
#   18) Install the StudioPaint software:
#
#       Change directories to the home of the StudioPaint 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 #14). This sets the ownership of all StudioPaint
#       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', InstallSpaint reattempts the
#       installation; else abort the installation and exit.
#
#   19) If InstallSpaint made a copy of the old StudioPaint encryption file
#       before the new software was installed (see step #8), append its contents
#       to the new encryption file (/usr/StudioPaint/sys/install/en). This
#       should allow the new StudioPaint software to run on completion of this
#       script.
# 
#       Remove the saved encryption file after its contents have been added to
#       the new encryption file.
#
#   20) Fix permissions of the StudioPaint 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.
#
#   21) Setup/Clean the demo account's home directory:
#
#       If a demo account exists (have_demo flag is set) and InstallSpaint is
#       running in guru mode, ask the installer if they wish to customize it
#       to use the StudioPaint software. If they say `no', InstallSpaint
#       informs the installer how to customize the account at a later time. If
#       they say `yes' or InstallSpaint is not running in guru mode, customize
#       the demo account to use the StudioPaint software.
#
#       If the demo account's dotfiles (.cshrc, .login, .Xresources, .4Dwmrc)
#       exist and an original copy of each file has not been renamed to
#       file.pre_aliassp, rename the dotfiles to <file>.pre_aliassp (i.e.:
#       .cshrc becomes .cshrc.pre_aliassp). Add the original filename to the
#       list of "saved system files". If InstallSpaint did not complete, the
#       original dotfiles (.cshrc.pre_aliassp, .login.pre_aliassp,
#       .Xresoures.pre_aliassp, .4Dwmrc.pre_aliassp) may still exist and have
#       to be "cleaned up" (renamed to filename= or removed) when InstallSpaint
#       successfully completes.
#
#       Copy the new .cshrc, .login, .Xresources and .4Dwmrc files to the demo
#       account's home directory and fix ownerships. (These files set variables
#       that are key to the operation of the StudioPaint software).
#
#   22) Conditionally setup the IRIX Desktop:
#
#       The following file is necessary for the customization of the desktop
#       software (formally known as Indigo Magic) so that it recognizes
#       StudioPaint based files:
#
#           /usr/lib/filetype/install/Alias.StudioPaint.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
#       Indigo Magic software to identify StudioPaint based files.
#
#       If InstallSpaint 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 InstallSpaint is running in guru mode, ask the installer if they wish
#       to customize the desktop software on the machine. If they say `no', the
#       software will not be customized.
#
#       If InstallSpaint is running in guru mode and the installer approved the
#       customization of the IRIX desktop software, or InstallSpaint is not
#       running in guru mode, customize the IRIX 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 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/StudioPaint. If any of
#       those directories exists, inform the installer how they may customize
#       the desktop view at a later time.
#
#       If the Desktop (Indigo Magic) software was not customized, give some
#       hints to the installer how to do so.
#
#   23) Conditionally verify that the main X display (:0) is running in 24-bit
#       TrueColor mode:
#
#       In order for the main X display (:0) to operate in 24-bit TrueColor
#       mode, the attributes line for the display must contain the following
#       strings:
#
#           -class TrueColor
#           -depth 24
#
#       If one (or both) strings are not present, InstallSpaint conditionally
#       edits the Xservers file (/usr/lib/X11/xdm/Xservers) and adds the
#       missing string(s) to the line for display 0. If InstallSpaint is running
#       in guru mode, it asks the installer if the display should operate in
#       24-bit TrueColor mode. If the installer says `yes' or InstallSpaint is
#       not running in guru mode, the attribute line for the display is
#       modified.
#
#   24) Conditionally install the StudioPaint Application Defaults X resources
#       file in /usr/lib/X11/app-defaults:
#
#       If InstallSpaint is running in guru mode, ask the installer if they
#       wish to install the StudioPaint X resources file in
#       /usr/lib/X11/app-defaults. If they say `yes' or the InstallSpaint
#       is not running in guru mode, extract the X resources file from CD-ROM
#       or tape and install it in /usr/lib/X11/app-defaults.
#
#       If the file is not installed, inform the installer how to do so at a
#       later time.
#
#   25) Conditionally install additional ImageVision file format descriptions:
#
#       Alias provides three files which enable the StudioPaint software to
#       recognize Alias based files (through ImageVision). The file formats
#       recognized are:
#
#           Alias pix files
#           compressed Alias files
#           Alias Eclipse files
#
#       In order to allow StudioPaint to recognize these files, the following
#       files must be installed:
#
#           /usr/lib/ImageVision/filefmt/libilALIAS.so
#           /usr/lib/ImageVision/filefmt/libilAliasCompress.so
#           /usr/lib/ImageVision/filefmt/libilAliasEclipse.so
#
#       If InstallSpaint is running in guru mode, ask the installer if they wish
#       to install the files.
#
#       If the installer says `yes' or InstallSpaint is not running in guru
#       mode, the files are installed.
#
#       If the  files are not installed, InstallSpaint gives instructions how
#       to do so at a later time.
#
#   26) 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 StudioPaint software. If
#       the software is being installed from CD-ROM, inform the installer that
#       they may install tablet support via the master install script (Install).
#
#       If the StudioPaint software is being installed from tape, InstallTablet
#       will have been extracted from the tape at the same time as
#       InstallSpaint. It may be invoked after the successful installation of
#       the StudioPaint software.
#
#   27) Rename changed system files:
#
#       Go though the "list of saved system files" (All files with a prefix of
#       ".pre_aliassp"). Compare each saved file with its namesake (minus the
#       ".pre_aliassp" suffix). If the two files are the same, remove the
#       ".pre_aliassp" file; else rename the ".pre_aliassp" file to its namesake
#       with a suffix of "=" (i.e.: mv /etc/passwd.pre_aliassp /etc/passwd=).
#       The files with a suffix of "=" represent the state of each file before
#       the StudioPaint software was installed. As each file is renamed, it is
#       reported to the installer.
#
#   28) Conditionally make install_en setuid and owned by the owner of the
#       StudioPaint software:
#
#       In order for users other than the owner of the StudioPaint software
#       to add encryption strings to the encryption file
#       (/usr/StudioPaint/sys/insall/en), install_en should be setuid and owned
#       by the owner of the software.
#
#       If InstallSpaint is running in guru mode, ask the installer if they wish
#       to make install_en setuid and owned by the owner of the StudioPaint
#       software. If the installer says `yes' or InstallSpaint 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 StudioPaint 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
#       StudioPaint software and InstallSpaint 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/StudioPaint/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 StudioPaint software or root can add encryption strings to
#       the encryption file.
#
#   29) If the en file for StudioPaint (/usr/StudioPaint/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.
#
#   30) Finish up:
#
#       Remove any working files used during the installation of the StudioPaint
#       software. Inform the installer that the StudioPaint software has been
#       installed, then exit.
#

#    The variable tfd (Temporary Files Defined) is used to indicate if the
#    temporary files used by InstallSpaint 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)

#    Verify that the installer is root:
#
#    If the installer is not root, inform them that InstallSpaint must be
#    run as root. Prompt them for the root password (via su) and execute
#    InstallSpaint 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 StudioPaint software, the InstallSpaint"
    echo "procedure must be run as root. At this time, you may specify the root"
    echo "password to continue with the installation. If your machine does not"
    echo "have a root password, you will not be prompted and the installation"
    echo "will continue. If you don't know the root password, you will have to"
    echo "find someone who does before the software can be installed."
    echo ""

# Determine where InstallSpaint 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
endif

#    The StudioPaint software will be installed in a directory named
#    alias_spYYMM (where YYMM are the year and month of the release).

set dir = alias_sp9405
set vers = "ALIAS StudioPaint"
set spaint_reqd_Mbspace = 20 # Megabytes required by StudioPaint software

#    Determine if the installer is a guru:
#
#    If InstallSpaint runs in guru mode, it may ask some detailed questions
#    about how the installation of the ALIAS StudioPaint software should
#    proceed. It will try not to assume anything.
#
#    If InstallSpaint 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 InstallSpaint is called with a `-g' flag, it runs in guru mode.

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

#    Set variables required by InstallSpaint

set distname = dist # default owner of the ALIAS StudioPaint software
set demoname = aldemo # username of default demo account
set symlink_to_spaint = /usr/StudioPaint # symbolic link to latest StudioPaint
set owner_uid = 60  # minimum value of dist's uid when chosen by InstallSpaint
set demo_uid = 400 # minimum value of demo account's uid chosen by InstallSpaint
set BASE_OS = 52 # IRIX 5.2 numerically
set BASE_IL = 1011009700 # timestamp for il_eoe.sw (ImageVision)

set default_gid = 20
set DLR = '$'

#    The StudioPaint software is only supported on machines with VGX (or higher)
#    graphics class. The current hardware/graphics requirements are:
#
#    Hardware/Graphics combinations
#    ------------------------------
#    Crimson VGX, Power Series VGX (4D/nn0 VGX)
#    Crimson VGXT, Power Series VGXT (4D/nn0 VGXT)
#    Crimson RE, Power Series RE (4D/nn0 RE)
#    Onyx VTX, RE2
#
#    with all running IRIX 5.2 (or higher) The execution only ImageVision
#    subsystem must be installed as well (il_eoe).

#    Determine where InstallSpaint 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 InstallSpaint

set HOSTS_TMP = $TMPDIR/alhosts.$$
set OERR = $TMPDIR/aloerr.$$
set OUT = $TMPDIR/alout.$$
set XRESDIR = /usr/lib/X11/app-defaults
set XSVS = /usr/lib/X11/xdm/Xservers
set SVEN = $TMPDIR/svd_en.pre_aliassp

#    Name of Tablet installation script
set TABINST = InstallTablet

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

set TOP = Products/StudioPaint
set SYSFILES = $TOP/sys
set SPAINT = $TOP/StudioPaint

#    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 $XSVS"

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

umask 022

#    Determine by which type of media the StudioPaint software will be
#    installed:
#
#    The StudioPaint 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 StudioPaint software
#    will be installed from the Alias CD-ROM mounted at the location specified
#    by ALIAS_CDLOCN.
#
#    If ALIAS_CDLOCN is not set, InstallSpaint asks the installer if they wish
#    to install the software from a CD-ROM. If they say `yes', InstallSpaint
#    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, InstallSpaint verifies the contents of the CD-ROM. If the
#    contents of the CD-ROM are valid, the installation continues, else
#    InstallSpaint exits with an explanatory error message.
#
#    If the StudioPaint software is not being installed from CD-ROM,
#    InstallSpaint asks the installer if they are installing from tape. If they
#    say `no', InstallSpaint 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, InstallSpaint asks them if the tape drive is connected to the
#    machine. If they say `yes', InstallSpaint (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, InstallSpaint asks them if they wish
#    to install the software using a remote tape drive. If they say `no',
#    InstallSpaint 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, InstallSpaint 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, InstallSpaint 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, InstallSpaint 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,
#    InstallSpaint (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), InstallSpaint
#    will know the type of media to use for the installation of the StudioPaint
#    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 StudioPaint 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 InstallSpaint can install the $vers software, it must"
    echo "determine 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 StudioPaint software will be installed from:
#
#    Ask the installer if they wish to install the StudioPaint software from a
#    CD-ROM. If they say `yes', InstallSpaint has to know where the CD-ROM is
#    mounted. InstallSpaint determines its mount point and asks the installer
#    if it is the correct location. If they say `no', InstallSpaint 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)
                if ($#ALIAS_CDPATH == 1) break
            end
        endif
    endif
endif

if ($?ALIAS_CDPATH) then

#    If the ALIAS StudioPaint 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, InstallSpaint
#    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 proper files to install the Alias StudioPaint
#    software).

    if (-e $ALIAS_CDPATH) then
        if (-d $ALIAS_CDPATH) then
            set valid_cd
            foreach adir ($SYSFILES $SPAINT)
                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"
            echo "the 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 StudioPaint 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 StudioPaint 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 "Are you installing the $vers software from a tape"
    echo -n "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"
        unset 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 StudioPaint
#    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 InstallSpaint 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 StudioPaint 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). InstallSpaint will"
                echo "verify that it (and its non-rewinding version) exist and are accessible before"
                echo "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, InstallSpaint 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
#    InstallSpaint 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 InstallSpaint 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 StudioPaint 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"
            echo -n "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
            if ($ans =~ [Yy][Ee][Ss]) then

#    Given that the Alias StudioPaint software is being installed using a remote
#    tape drive, InstallSpaint 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, InstallSpaint 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, InstallSpaint requires"
                echo "three 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, InstallSpaint 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 "InstallSpaint 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 InstallSpaint 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 InstallSpaint: "
                    set puser = $<
                    set ruser = ($puser)
                    if ($#ruser == 1) break
                end

#    Before InstallSpaint 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 "InstallSpaint 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, InstallSpaint checks for
#    the existence of /dev/tape and /dev/nrtape by `mt stat'ing them. If no
#    errors occur when `mt stat'ing them, InstallSpaint 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,
#    InstallSpaint verifies that the tape exists and is rewindable (minor number
#    is even). Given the major and minor numbers of the rewindable device,
#    InstallSpaint 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 StudioPaint 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 "InstallSpaint 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, InstallSpaint 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
#    InstallSpaint 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 InstallSpaint 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"
            echo "installation 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"
    echo "software from CD-ROM or tape. In order to install the software, you must"
    echo "choose one of 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

#    Currently, the Alias StudioPaint software is supported on a limited
#    number of combinations of hardware, graphics class and operating system
#    level:
#
#    Host Type                                     Operating System
#    ---------                                     ----------------
#    Crimson VGX, Power Series VGX (4D/nn0 VGX)    Irix 5.2 (or higher)
#    Crimson VGXT, Power Series VGXT (4D/nn0 VGXT) Irix 5.2 (or higher)
#    Crimson RE, Power Series RE (4D/nn0 RE)       Irix 5.2 (or higher)
#    Onyx VTX, REII                                Irix 5.2 (or higher)
#
#    where RE is Reality Engine Graphics.
#
#    InstallSpaint must decide if the installers machine is suitable for the
#    installation of the StudioPaint software.
#
#    As well as an acceptable machine and operating system level, the machine
#    must have an acceptable version of ImageVision installed.

#    Determine the processor type, graphics class and operating system level
#    of the machine.

set proc = `uname -m`
set gclass = `hinv -c graphics | awk '{print $1}'`
set os = `uname -r | sed 's/[^0-9]//g' | cut -c1-2`
set il_lev = `versions -n il_eoe.sw | awk '$2 == "il_eoe.sw" {print $3}'`

#    If the machine is an Onyx (processor type IP19), determine if the graphics
#    class and operating system level are acceptable for the installation of
#    the StudioPaint software.

if ("$proc" == "IP19") then
    if ("$gclass" == "VTX") then
        set gr_ok
    else if ("$gclass" == "RealityEngine") then
        set gr_ok
    else if ("$gclass" == "RealityEngineII") then
        set gr_ok
    endif

#    If the machine is a Crimson (processor type IP17) or a high end Power
#    Series machine (IP7), determine if the graphics class and operating system
#    level are acceptable for the installation of the StudioPaint software.

else if ("$proc" == IP17 || "$proc" == IP7) then
    if ("$gclass" == "VGX") then
        set gr_ok
    else if ("$gclass" == "VGXT") then
        set gr_ok
    else if ("$gclass" == "RealityEngine") then
        set gr_ok
    else if ("$gclass[1]" == "RealityEngineII") then
        set gr_ok
    endif
endif

#    Verify that the installed operating system is IRIX 5.2 (or higher)

if ("$os" >= $BASE_OS) then
    set os_ok
endif

#    Verify that the machine has ImageVision installed and the installed
#    version is the correct version (its timestamp is >= the base level).

if ($#il_lev) then
    if ("$il_lev" >= $BASE_IL) then
        set il_ok
    endif
else
    set no_il
endif

#    If the hardware/graphics check or os check or ImageVision verifications
#    failed, inform the installer of the problem(s) and ask them if they wish
#    to continue with the installation.

if (! $?gr_ok || ! $?os_ok || ! $?il_ok) then
    echo ""
    echo "The $vers software is currently supported on machines with the"
    echo "following combinations of hardware and graphics:"
    echo ""
    echo "     Hardware | Graphics Class "
    echo "  ------------+----------------"
    echo "  Power Series|      VGX       "
    echo "  Power Series|      VGXT      "
    echo "  Power Series| Reality Engine "
    echo "     Crimson  |      VGX       "
    echo "     Crimson  |      VGXT      "
    echo "     Crimson  | Reality Engine "
    echo "     Onyx     |      VTX       "
    echo "     Onyx     |Reality Engine 2"
    echo ""
    echo "each of which must be running IRIX 5.2 (or a higher release of the operating"
    echo "system) and also have ImageVision installed."
    echo ""
    @ fails = 0
    if (! $?gr_ok) then
        @ fails++
        echo ""
        echo "The combination of hardware and graphics on your machine does not match any"
        echo "of those in the above table."
    endif
    if (! $?os_ok) then
        @ fails++
        echo ""
        echo "The operating system on your machine is IRIX `uname -r`, not IRIX 5.2 as required."
    endif
    if (! $?il_ok) then
        @ fails++
        echo ""
        if ($?no_il) then
            echo "The required ImageVision software (il_eoe.sw) is not installed on your machine."
        else
            echo "While you have ImageVision installed on your machine, it is not the correct"
            echo "version. It must be ImageVision V2.3."
        endif
    endif
    echo ""
    echo "The $vers software may not function correctly on this machine"
    echo -n "unless"
    if ($fails > 1) then
        echo -n " these problems are "
    else
        echo -n " this problem is "
    endif
    echo "corrected."
    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]) goto userexit
endif

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

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

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

foreach fname ($mod_files)

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

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

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

@ spaint_reqd_kbspace = $spaint_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 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
#    StudioPaint 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 > $spaint_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 $spaint_reqd_Mbspace megabytes). Please free sufficient disk space and"
    echo "attempt the installation again. Consider removing any old software to free"
    echo "sufficient disk space. If you are unable to find enough space, ask Alias"
    echo "Assist for assistance."
    echo ""
    echo -n "Press <ENTER> to continue: "
    set a = $<
    exit
endif

#    Determine the filesystem on which to install ALIAS StudioPaint:
#
#    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"
    echo "software is $sftwfs."
endif

#    The StudioPaint software will be installed on the root filesystem (/) only
#    if no other writable filesystems have sufficient disk space.
#
#    If the 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, InstallSpaint 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"
        echo "$swstr directory which is where InstallSpaint would like to install the"
        echo "$vers software. You may choose to install the software at"
        echo "any location on the filesystem."
    endif
else
    set swstr = $sftwfs
endif

#    Once it has been determined on what filesystem the ALIAS StudioPaint
#    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"
echo "or $swstr/u/$dir."

#    Ask the installer if they wish to install the ALIAS StudioPaint software
#    in /<dir>/alias_spYYMM, 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 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 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 InstallSpaint would like to install the StudioPaint software.
#
#    and alias_spYYMM is a directory indicating the Alias StudioPaint software
#    and its release date.
#
#    If they doesn't want to install the software in /<dir>/alias_spYYMM, 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 StudioPaint software,
#    verify that:
#
#    - the directory is located in the filesystem that the installer approved
#    - the name of the directory is alias_spYYMM (for identification purposes)
#
#    If any of these points are not met, InstallSpaint 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 StudioPaint 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 StudioPaint
#    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 StudioPaint
#    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 StudioPaint 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 StudioPaint
#    software and /usr/StudioPaint (i.e: /usr/StudioPaint -> /usr/alias_spYYMM):
#
#    If /usr/StudioPaint is a symbolic link and its target is the home of the
#    StudioPaint software, the link is correct. 
#
#    Note that /usr/StudioPaint may be a symbolic link to a relative pathname.
#    If so (no leading slash), prepend the root directory of symlink_to_spaint
#    (/usr) to the pathname to determine the full pathname of the link.

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

#    This code is executed if a symbolic link from /usr/StudioPaint to the home
#    of the StudioPaint software does not exist:
#
#    If /usr/StudioPaint 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/StudioPaint and form a symbolic link from
#    /usr/StudioPaint to the home of the StudioPaint 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_sp) then
    if (-e $symlink_to_spaint || -l $symlink_to_spaint) then
        echo ""
        echo ""
        if (-l $symlink_to_spaint) then

#    At this point, we know that /usr/StudioPaint is a symbolic link whose
#    target is not the home directory of the StudioPaint 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_spaint is a symbolic link to"
            echo -n "$target. The purpose of $symlink_to_spaint "

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

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

#    If the target of /usr/StudioPaint is not null (i.e: $target !=
#    /usr/) and is a directory, inform the installer that the new software
#    replaces the old software.

            if ("$target" != "$symlink_to_spaint:h/" && -d $target) then
                echo ""
                echo "You may remove the software in $target as it has been replaced by"
                echo "this release. If you have any questions about this, contact Alias Assist"
                echo "for details."
            endif
        else

#    In this case, /usr/StudioPaint 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 StudioPaint software. Unlike the previous
#    section of code, the amount of disk space occupied by /usr/StudioPaint 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_spaint) then
                set al_sp = `$DU $symlink_to_spaint | awk '{print $1}'`
                set ftype = directory
            else
                set al_sp = `ls -l $symlink_to_spaint | awk '{printf "%.2f",$5 / 1024}'`
                set ftype = file
            endif
            echo "The $ftype $symlink_to_spaint exists and contains $al_sp kilobytes. The purpose"

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

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

        echo ""
        echo -n "Do you wish to remove $symlink_to_spaint ? (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_spaint must be removed (or renamed) for the installation to succeed."
            goto baderr
        endif
        rm -fr $symlink_to_spaint
    endif
    ln -s $sftwdir $symlink_to_spaint
    if ($status != 0) then
        echo ""
        set errmsg1 = "Cannot form symbolic link from $symlink_to_spaint to $sftwdir"
        goto baderr
    endif
endif

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

if ($?guru_mode) then

    unset have_owner
    while (! $?have_owner)

#    Ask the guru who should own the StudioPaint 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 StudioPaint 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 InstallSpaint 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. InstallSpaint will ask you if you"
                echo "wish to specify a value for each field of the entry. If you say no, InstallSpaint"
                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, InstallSpaint 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,
#    InstallSpaint 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, InstallSpaint asks for the group
#    identifer and verifies that it is valid.
#
#    If the user indicates that they do not want to choose the group,
#    InstallSpaint 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, InstallSpaint 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/StudioPaint
#    for the home directory so that the account acts as a administrator
#    for the StudioPaint 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_spaint."
                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 StudioPaint 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 StudioPaint 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 should 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 StudioPaint 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 InstallSpaint; 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"
                echo -n "you say no, InstallSpaint 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 InstallSpaint in guru mode, verify/install
#    the dist account. When the StudioPaint 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/StudioPaint,
#    where /usr/StudioPaint is a symbolic link to the directory containing the
#    StudioPaint software. At this point of the installation, the symbolic link
#    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_spaint}:/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_spaint

#    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/StudioPaint (symbolic link to
#    StudioPaint software), verify that it exists and the permissions are
#    correct.

if ("$owner_home" != "$symlink_to_spaint") 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"
                echo "$vers 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 StudioPaint
#    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 StudioPaint software is root, no verification is
#    necessary as it was done at the start of InstallSpaint.

    if ($owner_uid != 0) then

#    In order for the non-root owner of the StudioPaint 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,
#    InstallSpaint 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 "InstallSpaint, 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 InstallSpaint is running in guru mode, ask the installer if they wish to
#    create a demo account for the StudioPaint 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 InstallSpaint 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. InstallSpaint will ask you if"
                    echo "you wish to specify a value for each field of the entry. If you say no,"
                    echo "InstallSpaint 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, InstallSpaint 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,
#    InstallSpaint 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, InstallSpaint asks for the group
#    identifer and verifies that it is valid.
#
#    If the user indicates that they do not want to choose the group,
#    InstallSpaint 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, InstallSpaint 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 should 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, InstallSpaint 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 InstallSpaint 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 StudioPaint software
#    ($sftwfs) as a candidate for the home filesystem for the demo account,
#    subtract the size of the 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 -= $spaint_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 (/), InstallSpaint 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 StudioPaint 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"
                echo "software 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"
            echo "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
#    StudioPaint 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 StudioPaint 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"
                echo "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 StudioPaint 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 StudioPaint 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 StudioPaint 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 StudioPaint software distribution is split into 3 tar images:
#
#        1) InstallSpaint
#
#        2) Optional system support files
#
#        3) StudioPaint software
#

        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"
        set st = $status
    else

#    If the StudioPaint software is being installed from CD-ROM, "copy" the
#    StudioPaint software from a directory on the CD-ROM to disk (via tar).

        echo ""
        echo "Extracting $vers from the CD-ROM ... This may take a few minutes"
        echo ""
        su $distname -c "(chdir $ALIAS_CDPATH/$SPAINT;tar cf - .) | tar xvof -"
        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

#    If InstallSpaint made a copy of the old StudioPaint encryption file before
#    the new software was installed, append its contents to the new encryption
#    file (/usr/StudioPaint/sys/install/en). This should allow the new
#    StudioPaint 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_spaint/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 StudioPaint 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,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 and InstallSpaint is running in guru mode, ask the
#    installer if they wish to customize it to use the StudioPaint software. If
#    they say `yes' or InstallSpaint is not running in guru mode, customize the
#    demo account to use the Alias software (StudioPaint and other Alias
#    products).

set vsftw = desktop
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_spaint/.cshrc"
            echo "    $symlink_to_spaint/.login"
            echo "    $symlink_to_spaint/.Xresources"
            echo "    $symlink_to_spaint/.4Dwmrc"
            echo ""
            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_spaint/$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 ""
            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)
#    exist and an original copy of each file has not been renamed to
#    file.pre_aliassp, rename the dotfiles to <file>.pre_aliassp (i.e.: .cshrc
#    becomes .cshrc.pre_aliassp).

        foreach dotfile (.cshrc .login .Xresources .4Dwmrc)
            if (-f $dotfile && ! -f $dotfile.pre_aliassp) then
                mv $dotfile $dotfile.pre_aliassp
            endif

#    Add the original filename to the list of "saved system files". If
#    InstallSpaint did not complete, the original dotfiles (.cshrc.pre_aliassp,
#    .login.pre_aliassp, .Xresources.pre_aliassp, .4Dwmrc.pre_aliassp) 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 and .4Dwmrc to the demo account's
#    home directory and fix ownerships. (These files set variables that are key
#    to the operation of the StudioPaint software).

        cp $sftwdir/{.cshrc,.login,.Xresources,.4Dwmrc} .

        chown $demoname.$demo_gid .login .cshrc .Xresources .4Dwmrc
    endif
endif

#    Conditionally setup the IRIX Desktop:
#
#    The following file is necessary for the customization of the IRIX desktop
#    software (formally known as Indigo Magic) so that it recognizes StudioPaint
#    based files:
#
#        /usr/lib/filetype/install/Alias.StudioPaint.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 Indigo
#    Magic software to identify StudioPaint based files.
#
#    If InstallSpaint 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 InstallSpaint is running in guru mode, ask the installer if they wish to
#    customize the 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 InstallSpaint 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/Alias.StudioPaint.ftr"
    echo ""
    echo "It contains a number of file type rules used by the desktop software to"
    echo "identify $vers based files (i.e.: the main StudioPaint executable"
    echo "and layer stacks)."
    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"
        echo "$vers based files."
        unset cust_view
    endif
endif

#    If InstallSpaint is running in guru mode and the installer approved the
#    customization of the IRIX desktop software, do so.
#
#    These steps are also performed if InstallSpaint 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 StudioPaint $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 StudioPaint $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 Alias.StudioPaint.ftr
            set st = $status
        else
            echo "Extracting and installing the StudioPaint $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 - Alias.StudioPaint.ftr) | tar xvof -
            set st = $status
        endif
        if ($st == 0) then
            set view_inst
            mv -f Alias.StudioPaint.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 desktop software.

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

#    If InstallSpaint 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

#    Remove the Alias StudioPaint ftr file from /usr/lib/filetype/local. The
#    ftr file has been moved to /usr/lib/filetype/install.

        chdir /usr/lib/filetype/local
        foreach f (Alias.StudioPaint.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 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/StudioPaint. 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
            set hname = `hostname`
            if (-d $demo_home/.desktop || -d $demo_home/.desktop-$hname) then
                echo "A desktop view already exists for $demoname. The standard StudioPaint desktop"
                echo "view 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_spaint/desktop .desktop"
                echo ""
                echo "The next time that $demoname logs in, the new desktop view will appear."
            else
                echo "Creating a standard StudioPaint desktop view for $demoname ..."
                su - $demoname -c "cp -r $sftwdir/desktop $demo_home/.desktop"
            endif
        endif
    endif
endif

#    If the IRIX 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 InstallSpaint 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

#    Conditionally verify that the main X display (:0) is running in 24-bit
#    TrueColor mode:
#
#    In order for the main X display (:0) to operate in 24-bit TrueColor mode,
#    the attributes line for the display must contain the following strings:
#
#        -class TrueColor
#        -depth 24
#
#    If one (or both) strings are not present, InstallSpaint conditionally
#    edits the Xservers file (/usr/lib/X11/xdm/Xservers) and adds the
#    missing string(s) to the line for display 0. If InstallSpaint is running
#    in guru mode, it asks the installer if the display should operate in
#    24-bit TrueColor mode. If the installer says `yes' or InstallSpaint is
#    not running in guru mode, the attribute line for the display is modified.

if (-f $XSVS) then

    foreach str ("-class TrueColor" "-depth 24")
        set sfnd

#    Search for each string in the middle of a line:
#
#        <blank>|<tab><STRING><blank>|<tab>
#
#    or at the end of a line:
#
#        <blank>|<tab><STRING>

        grep -s "[ 	]${str}[ 	]" $XSVS >& /dev/null
        if ($status != 0) then
            grep -s "[ 	]$str${DLR}" $XSVS >& /dev/null
            if ($status != 0) unset sfnd
        endif
        if (! $?sfnd) then
            if ($?newstr) then
                set newstr = "$newstr $str"
            else
                set newstr = " $str"
            endif
        endif
    end

#    Determine how many display entries are in the Xservers file

    set ndsply = `grep -c "^:[0-9]" $XSVS`
else
    echo ""
    echo "Cannot find Xservers file ($XSVS). Unable to examine file."
endif

#    If one (or both) strings are missing from the Xservers file, conditionally
#    add the string(s). If InstallSpaint is running in guru mode, ask the
#    installer if they wish to add the string(s) to the Xservers file. If they
#    say `yes' or InstallSpaint is not running in guru mode, modify the
#    Xservers file such that both strings are present.

if ($?newstr) then
    set modxs
    echo ""
    echo "In order for the $vers software to function correctly, the"
    echo "X server should be running in 24-bit TrueColor mode. In order to do this,"
    echo "the Xservers file ($XSVS) must be modified. If the"
    echo "Xservers file is modified, the machine will have to be rebooted in order"
    echo "to start the X server running in 24-bit TrueColor mode."
    if ($?guru_mode) then
        echo ""
        echo -n "Do you wish to place the X server in 24-bit TrueColor mode? (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 modxs
    endif

    if ($?modxs) then
        echo ""
        echo "Modifying the Xservers file ($XSVS) to place the X server"
        echo "in 24-bit TrueColor mode."
        ex - $XSVS << EOF
        /^:0[ 	]/s/${DLR}/$newstr/
        w!
        q
EOF

        echo ""
        echo "Don't forget to reboot the machine to start the X server running in"
        echo "24-bit TrueColor mode."
    else
        echo ""
        echo "If you later decide to place the X server in 24-bit TrueColor mode, edit the"
        echo "following file:"
        echo ""
        echo "    $XSVS"
        echo ""
        echo "and verify that the following strings appear somewhere in the line describing"
        echo "the main display (begins with :0):"
        echo ""
        echo "    -class TrueColor"
        echo "    -depth 24"
        echo ""
        echo "This display is probably your main console. After editing the file, the"
        echo "machine should be rebooted to start the X server running the display in"
        echo "24-bit TrueColor mode."
    endif
    echo ""

#    If the machine appears to have more than one X display (multiple lines
#    beginning with :<number), instruct the installer how to place the other
#    display(s) in 24-bit TrueColor mode.

    if ($?ndsply) then
        if ($ndsply > 1) then
            echo ""
            echo "Note that the InstallSpaint procedure has attempted to place the main"
            echo "display (:0) in 24 bit TrueColor mode. This display is probably your"
            echo "main console. As your machine appears to have multiple displays, you"
            echo "may wish to place another of the display(s) in the same mode. Edit the"
            echo "following file:"
            echo ""
            echo "    $XSVS"
            echo ""
            echo "and search for the line pertaining to the display you are interested"
            echo "in (begins with :<display number>). Verify that the following strings"
            echo "appear somewhere in the line:"
            echo ""
            echo "    -class TrueColor"
            echo "    -depth 24"
            echo ""
            echo "After modifying the file, the machine should be rebooted to start the"
            echo "X server running that display in 24-bit TrueColor mode."
        endif
    endif
endif

#    Install the StudioPaint Application Defaults X resources file in
#    /usr/lib/X11/app-defaults.

echo ""
set inst_xres
if ($?guru_mode) then
    echo ""
    echo "The $vers software requires a default set of X window resources."
    echo "These resources are set in the file StudioPaint which should be installed"
    echo "in $XRESDIR. If this file is not installed, the"
    echo "$vers software will not work."
    echo ""
    echo "Do you wish to install the StudioPaint X window resources in"
    echo -n "$XRESDIR? (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_xres
endif

#    The file StudioPaint contains a number of X window resources. It should
#    be installed in /usr/lib/X11/app-defaults.

unset xres_installed
if ($?inst_xres) then
    while (1)
        if (! $?ALIAS_CDPATH) then
            echo ""
            echo "Positioning the tape to extract the StudioPaint X resources file from the"
            echo "$vers software tape."
            mt -t $NRTAPE rew
            if ($status != 0) then
                echo ""
                echo "Error rewinding the tape."
                goto xres_tape_err
            endif
            mt -t $NRTAPE fsf 1
            if ($status != 0) then
                echo ""
                echo "Error advancing the tape to the system support files."
                goto xres_tape_err
            endif
        endif
        echo ""
        echo "Extracting and installing the StudioPaint X window resources file."
        echo ""

#    Change directories to /usr/lib/X11/app-defaults and extract the X window
#    resources file from the distribution tape or CD-ROM.

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

xres_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 StudioPaint X window resources file was not installed, inform the
#    installer how to do so.

if (! $?xres_installed) then
    echo ""
    echo "If you later decide to install the StudioPaint X window resources file, the"
    echo "following 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 X window resources file is"
            echo "      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 the"
            echo "      X window resources file is successfully installed."
        endif
        echo ""
        echo "      Insert the $vers distribution tape into ${REMOTE_TAPE_HOST}'s"
        echo "      tape drive:"
    else if ($?ALIAS_CDPATH) then
        echo "      Insert the $vers distribution CD-ROM into the CD-ROM player"
        echo "      and 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 StudioPaint $XRESDIR"
    else
        echo "                  cd $XRESDIR"
        if ($?REMOTE_TAPE_HOST) then
            echo "                  mt -t $NRTAPE rew"
            echo "                  mt -t $NRTAPE fsf 1"
            echo "                  tar xvof $NRTAPE StudioPaint"
        else
            echo "                  mt rew"
            echo "                  mt fsf 1"
            echo "                  tar xvo StudioPaint"
        endif
    endif
    echo ""
endif

#    Conditionally Install the Alias file format description files which allow
#    StudioPaint to recognize Alias format files.

echo ""
echo ""
echo "In order for the $vers software to manipulate the following Alias"
echo "format files:"
echo ""
echo "    Alias pix files"
echo "    Compressed Alias files"
echo "    Alias Eclipse files"
echo ""
echo "the following files must be installed:"
echo ""
echo "    /usr/lib/ImageVision/filefmt/libilALIAS.so"
echo "    /usr/lib/ImageVision/filefmt/libilAliasCompress.so"
echo "    /usr/lib/ImageVision/filefmt/libilAliasEclipse.so"
echo ""
echo "These files allow the $vers software to read and write those file"
echo -n "formats via the ImageVision software. "

#    If InstallSpaint is running in guru mode, ask the installer if they wish
#    to install the files.
#
#    If the installer says `yes' or InstallSpaint is not running in guru mode,
#    the files are installed.


set inst_alff
echo ""
if ($?guru_mode) then
    echo ""
    echo "Do you wish to install the files that allow the $vers software to"
    echo -n "read and write Alias format 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_alff
endif

if ($?inst_alff) then
    while (1)
        if (! $?ALIAS_CDPATH) then
            echo ""
            echo "Positioning the tape to extract and install the files ..."
            mt -t $NRTAPE rew
            if ($status != 0) then
                echo ""
                echo "Error rewinding the tape."
                goto alff_tape_err
            endif
            mt -t $NRTAPE fsf 1
            if ($status != 0) then
                echo ""
                echo "Error advancing the tape to the system support files."
                goto alff_tape_err
            endif
        endif
        echo ""
        echo "Extracting and installing the files."
        echo ""

#    Change directories to /usr/lib and extract the files from the distribution
#    tape or CD-ROM.

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

alff_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 files which enable StudioPaint to manipulate Alias format files
#    were not installed, inform the installer how to do so.

if (! $?alff_installed) then
    echo ""
    echo ""
    echo "If you later decide to install the files which allow the $vers"
    echo "software to read and write Alias format 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 files have been"
            echo "      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 the"
            echo "      files have been successfully installed."
        endif
        echo ""
        echo "      Insert the $vers distribution tape into ${REMOTE_TAPE_HOST}'s"
        echo "      tape drive:"
    else if ($?ALIAS_CDPATH) then
        echo "      Insert the $vers distribution CD-ROM into the CD-ROM player"
        echo "      and 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 -r ImageVision /usr/lib"
    else
        echo "              cd /usr/lib"
        if ($?REMOTE_TAPE_HOST) then
            echo "              mt -t $NRTAPE rew"
            echo "              mt -t $NRTAPE fsf 1"
            echo "              tar xvof $NRTAPE ImageVision"
        else
            echo "              mt rew"
            echo "              mt fsf 1"
            echo "              tar xvo ImageVision"
        endif
    endif
    echo ""
endif

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

echo ""
echo ""
echo "If you wish to use tablets with the $vers software, your machine"
echo "must 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 "InstallSpaint."
    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."
echo ""
echo ""

cleanup:

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

echo ""
foreach fname ($mod_files)
    if (-e $fname.pre_aliassp) then
        cmp -s $fname $fname.pre_aliassp
        if ($status == 0) then
            rm -f $fname.pre_aliassp
        else
            mv $fname.pre_aliassp ${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
#    StudioPaint software:
#
#    In order for users other than the owner of the StudioPaint software to add
#    encryption strings to the encryption file (/usr/StudioPaint/sys/insall/en),
#    install_en should be setuid and owned by the owner of the software.
#
#    If InstallSpaint is running in guru mode, ask the installer if they wish
#    to make install_en setuid and owned by the owner of the StudioPaint
#    software. If the installer says `yes' or InstallSpaint 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
#    StudioPaint 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 $vers encryption"
    echo "file ($symlink_to_spaint/sys/install/en), the encryption string administration"
    echo "program (install_en) should be setuid and owned by $distname. If you don't like"
    echo "setuid 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 StudioPaint
#    software and InstallSpaint 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/StudioPaint/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 StudioPaint 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_spaint/sys/install) is made writable and examinable for everyone"
    echo "and the encryption file readable and writable for everyone."
    echo ""
    echo "If this is not done, no one other than the owner of the $vers"
    echo "software (and root) can add encryption strings to the encryption file."
    echo ""
    echo "Do you wish to make $symlink_to_spaint/sys/install and the encyption file"
    echo -n "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_spaint/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"
        echo "root is 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
