#!/bin/csh -f
#Tag 1024

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


#    InstallTablet: The following steps are performed to install the tablet
#    drivers and configure the IRIX kernel to recognize them:
#
#    1) Set a default search path:
#
#       The components of the search path are directories that contain tools
#       which are used to load the tablet drivers.
#
#    2) Verify that the operating system is acceptable:
#
#       At the current time, this script supports tablet driver customization
#       and/or installation on machines with one of the following operating
#       systems:
#
#           IRIX 5.3
#           IRIX 6.2
#           IRIX 6.3
#           IRIX 6.4
#
#       If the operating system on this machine is not one of those operating
#       systems, inform the installer of the problem and exit.
#
#    3) Verify that the installer is root:
#
#       If the installer is not root, inform them that InstallTablet must be
#       run as root. Prompt them for the root password (via su) and execute
#       InstallTablet in a root subshell. If the installer fails to specify
#       the root password in 3 attempts, ask them to try again later and exit.
#
#    4) Determine where this script will place its working files. If /usr/tmp
#       is a directory and is writable, working files will go there; otherwise
#       they will be placed in /tmp.
#
#    5) Find the location of the ALIAS CD-ROM:
#
#       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 tablet
#       drivers will be installed from the Alias CD-ROM mounted at the location
#       specified by ALIAS_CDLOCN.
#
#       If ALIAS_CDLOCN is not set, InstallTablet 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, InstallTablet verifies the contents of the CD-ROM. If the
#       contents of the CD-ROM are valid, the installation continues, else
#       InstallTablet exits with an explanatory error message.
#
#       At the end of this step (assuming no errors have occurred),
#       InstallTablet will know the mount point of the CD-ROM player which
#       contains the Alias CD-ROM.
#
#    6) Inform the installer that the correct versions of the tablet drivers
#       must be installed in order for tablets to be used in conjunction with
#       the Alias software. Before the tablet drivers can be installed, this
#       script must verify that the operating system is acceptable.
#
#    7) If the machine is running IRIX 6.3 or 6.4, conditionally install
#       Alias|Wavefront's wacom tablet configuration file:
#
#       If the machine is running IRIX 6.3 or 6.4, inform the installer that
#       the tablet drivers are included with the system (in the eoe.sw.optinput
#       inst image), but the shipped wacom driver is not configured for use
#       with the Alias|Wavefront software.
#
#       Ask them if they wish to install the Alias|Wavefront wacom configuration
#       file, saying that the script will first verify that the tablet drivers
#       (actually eoe.sw.optinput) is installed and a wacom tablet is configured
#       on the machine (/dev/input/wacom) exists. If they say `no', exit, else
#       continue.
#
#       Verify that the tablet drivers (eoe.sw.optinput) is installed. If they
#       aren't installed, inform the installer and set a flag indicating the
#       error.
#
#       Verify that a wacom tablet is configured (check for /dev/input/wacom).
#       This indicates that a tablet has been installed and configured.
#
#       If both the drivers and tablet appear to be properly configured, install
#       the wacom tablet configuration file in /usr/lib/X11/input/config/wacom.
#
#       If we're installing on an R10000, add the following line to the wacom
#       tablet configuration file:
#
#           pressurecurve   "0,255"
#
#       so that the tablet will behave correctly.
#
#       Be sure to save the old version if it is different than the new version.
#
#       Goto step #18.
#
#    8) If the machine is running IRIX 5.3 or 6.2, prepare for the installation
#       of the tablet drivers:
#
#       If the machine is running the right version of IRIX 5 or IRIX 6.2, the
#       tablet master and object files are installed in /var/sysgen and the
#       kernel system file is /var/sysgen/system/gfx.sm.
#
#       Using the type of operating system as a key (IRIX 5.3 or IRIX 6.2),
#       determine the identifying suffix of the tablet drivers. This suffix
#       (irix5 or irix6) will be used to determine which version of the tablet
#       drivers should be installed.
#
#       A version of the wacom tablet driver from wacom is installed with the
#       Alias|Wavefront tablet drivers.
#       
#       If the operating system level is IRIX 5.3, add the wacom supplied
#       wacom driver to the list of tablet drivers to install. If the machine
#       is not running IRIX 5.3 and is running IRIX 6.2, the Wacom driver is
#       installed using inst instead.
#
#       For IRIX 6.2, we have several versions of the tablet drivers:
#
#       The following chart describes which set of drivers they get:
#
#         Processor     | Register bit size | tablet driver version installed
#         --------------+-------------------+--------------------------------
#            any type   |     32 bits       |     32-bit IP22 tablet drivers
#              IP26     |     64 bits       |     64-bit IP26 tablet drivers
#              IP28     |     64 bits       |     64-bit IP28 tablet drivers
#         not IP26|IP28 |     64 bits       |     64-bit IP22 tablet drivers
#
#       Additionally the 6.2 Wacom driver can be installed with inst for all
#       processors except for IP28.
#
#    9) In order for the ALIAS software to use tablets, the IRIX kernel must
#       have the correct versions of the tablet drivers installed and a kernel
#       system file modified. On all variants of IRIX 5 and IRIX 6, the files
#       comprising the tablet drivers are installed in /var/sysgen/boot and
#       master.d while the kernel system file that may be modified has a
#       pathname of /var/sysgen/system/gfx.sm.
#
#       After informing the installer of the requirements for the drivers, the
#       script asks them if they wish to install the drivers. If they say
#       `yes', the installation continues; else the script exits after minor
#       cleanup.
#
#       Assuming the installer approved the installation of the tablet drivers,
#       the following steps are performed:
#
#       If existing versions of the driver files are found, the driver files
#       from the ALIAS distribution CD-ROM will be compared with the existing
#       files. If the files are the same (i.e. aliaswacom.o from the CD-ROM is
#       the same as aliaswacom.o on disk), the file from the distribution CD-ROM
#       is removed (from where it was copied to disk). If the files are
#       different, the file from the distribution CD-ROM replaces the existing
#       file, which is saved.
#
#       If the kernel system file needs to be modified, a copy of the existing
#       version is saved first, then the file is modified.
#
#       If any of the tablet driver files from the distribution CD-ROM are
#       installed or the kernel system file is modified, a new IRIX kernel
#       will be built which incorporates the tablet drivers.
#
#   10) If any tablet drivers were added or the kernel system file was modified,
#       build a new IRIX kernel which recognizes the tablet drivers. If the
#       kernel build succeeds, the installer is instructed to reboot the
#       machine to start using the new kernel.
#
#       If the kernel rebuild fails, the installer is instructed to reboot
#       the machine and answer yes when asked if you wish to `Automatically
#       reconfigure the operating system'. When a new IRIX kernel is built,
#       it will recognize tablets.
#
#   11) In order for the X window system to interpret the tablet data correctly,
#       the correct version of:
#
#           /usr/lib/X11/input/config/tablet
#
#       must be installed.
#
#       If an existing version of the tablet configuration file is found, the
#       configuration file from the ALIAS distribution CD-ROM is compared with
#       the existing file. If the files are the same, the file from the
#       distribution CD-ROM is removed. If the files are different, the file
#       from the distribution CD-ROM replaces the existing file, which is saved.
#
#       There are two versions of the tablet configuration file, one for each
#       of Alias|Wavefront StudioPaint 3D, and other Alias|Wavefront 3D products
#       (i.e.: Studio). InstallTablet asks the installer which product they are
#       using, then "copies" the correct version of the configuration file from
#       the distribution CD-ROM (via tar) to disk.
#
#   12) Determine the type of tablet that the installer is using:
#
#       Ask the installer to indicate the maker of their tablet (one of Hitachi,
#       Kurta and Wacom). Once they have indicated the maker of their tablet,
#       list all supported tablets manufactured by that maker and ask the
#       installer to indicate the type of tablet they are installing support
#       for.
#
#   13) Configure wacom tablet configuration file:
#
#       Inform the installer that they may choose to use either the
#       Alias|Wavefront supplied wacom driver or the wacom supplied driver.
#       Ask them which driver they wish to use. If they indicate that they
#       wish to use the wacom driver, a Alias|Wavefront product specific (i.e.:
#       StudioPaint, Alias Studio) wacom tablet configuration file must be
#       installed in:
#
#           /usr/lib/X11/input/config/wacom
#
#       The product specfic version of the wacom configuration file (one for
#       StudioPaint, the second for all other cases) is extracted from the
#       CD-ROM into a temporary directory (i.e.: /tmp).
#
#       If we're installing on an R10000 running IRIX 6.2, add the following
#       line to that file:
#
#           pressurecurve   "0,255"
#
#       so that the tablet will behave correctly.
#
#       If an installed version of the wacom tablet configuration file is found,
#       the wacom tablet configuration file in the temporary directory is
#       compared with the installed file. If the files are the same, the file
#       in the temporary directory is removed. If the files are different, the
#       file from the temporary directory replaces the installed file, which is
#       saved.
#
#   14) Tweak the settings in the Alias|Wavefront tablet configuration file
#       for the wacom tablet:
#
#       If a wacom tablet is being installed, some further customization of
#       the tablet configuration file (/usr/lib/X11/input/config/tablet) is
#       necessary. For details, see the comments below.
#
#   15) Ask the installer on which serial port the tablet is connected to and
#       verify that it exists.
#
#   16) Cleanup old device files: 
#
#       Verify there is no old device file in /dev/input which pertains to the
#       serial port the tablet is connected to:
#
#       Find the major and minor numbers of the serial port the tablet is
#       connected to. Search /dev/input for a device file with the same
#       <major #, minor #> pair. If such a device file exists, inform the
#       installer that the device file is being removed and remove it.
#
#       Also remove /dev/input/altablet-* and /dev/input/wacom as the Alias
#       software can't handle multiple tablets.
#
#   17) Setup the tablet device link in /dev/input:
#
#       If the installer wishes to use the wacom driver, the name of the
#       link in /dev/input will be /dev/input/wacom, else the name of the link
#       will be /dev/input/altablet-<tablet name>.
#
#       Create the link between /dev/ttydX and /dev/input/<name> so that the
#       Alias software can use it. This identifes the serial port and type of
#       tablet to the Alias software, with the exception of the wacom
#       driver where the name of the link is /dev/input/wacom. In order for
#       the wacom driver (and possibly the other tablet drivers) to
#       determine the characteristics of the tablet, either the machine must
#       be rebooted (to install the tablet drivers) or the user must logout
#       and login again.
#
#       When the link has been created, make the serial port read/write by
#       everyone.
#
#   18) Rename changed system files:
#
#       Go though the "list of saved system files" (All files with a prefix of
#       ".pre_alias"). Compare each saved file with its namesake (minus the
#       ".pre_alias" suffix). If the two files are the same, remove the
#       ".pre_alias" file; else rename the ".pre_alias" file to its namesake
#       with a suffix of "=" (i.e.: mv /etc/passwd.pre_alias /etc/passwd=). The
#       files with a suffix of "=" represent the state of each file before the
#       tablet drivers were installed. As each file is renamed, it is reported
#       to the installer.
#
#   19) If a wacom tablet was installed and the tablet has dipswitches, remind
#       the installer that the dipswitches on the tablet have to be set
#       correctly or the tablet will not behave properly. For their benefit,
#       display the list of recommended settings.
#
#   20) If the tablet drivers were added to the system, remind the installer
#       about the state of the rebuilt IRIX kernel:
#
#       If the IRIX kernel rebuild was successful, remind the installer to
#       reboot the machine to install the new kernel.
#
#       If the IRIX kernel rebuild was not successful, remind the installer that
#       they may have to reboot the machine a few times before the rebuild
#       succeeds.
#
#   21) If the tablet drivers are already installed (a reboot is not required),
#       inform the installer that they have to logout and login again to allow
#       the X server to recognize the tablet.
#
#   22) Finish up:
#
#       Inform the installer that the installation is complete. 

unset tfd
onintr userexit

#   Variables used by InstallTablet

set ALHIT = aliashitachi
set ALKUR = aliaskurta
set ALWAC = aliaswacom
set ALTAB = altablet
set WAWAC = wacom
set ATABS = ($ALHIT $ALKUR $ALWAC $ALTAB)

set mod_files = ""
set DLR = '$'
set XTABLET = /usr/lib/X11/input/config/tablet # Tablet X config file
set WXTABLET = /usr/lib/X11/input/config/wacom # Wacom X config file

#    Different X tablet configuration files for StudioPaint and
#    the rest of the products (i.e.: Studio).

set XTABSTPA = tablet.spaint
set XTABDFLT = tablet.dflt
set NSTPA = 1
set NDFLT = 2

#    Tablet types

set THIT = 1 # Hitachi
set TKUR = 2 # Kurta
set TWAC = 3 # Wacom

#  Name of directory on CD-ROM containing tablet files (relative to CD-ROM
#  mount point).

set TABFILES = Products/Common/Tablet
set XCONFIG = $TABFILES/xconfig

#    Set the search path

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

#    At the current time, this script supports tablet driver customization
#    and/or installation on machines with one of the following operating
#    systems:
#
#        IRIX 5.3
#        IRIX 6.2
#        IRIX 6.3
#        IRIX 6.4
#
#    If the operating system on this machine is not one of those operating
#    systems, inform the installer of the problem and exit.

set IRIX5I = 5.3
set IRIX62I = 6.2
set IRIX63I = 6.3
set IRIX64I = 6.4
set acc_os = ($IRIX5I $IRIX62I $IRIX63I $IRIX64I)

set os = `uname -r`

@ i = 1
while ($i <= $#acc_os)
    if ("$os" == $acc_os[$i]) then
       set os_ok
       break
    endif
    @ i++
end

if (! $?os_ok) then
    echo ""
    echo "The tablet drivers are incompatible with the operating system on this machine."
    echo ""
    echo "The drivers are only supported with the following operating systems:"
    echo ""
    @ i = 1
    while ($i <= $#acc_os)
        echo "    IRIX $acc_os[$i]"
        @ i ++
    end
    echo ""
    echo "and your machine is running IRIX $os."
    echo ""
    echo "The tablet drivers cannot be installed."
    echo ""
    echo "If you have any questions on future tablet driver support for your"
    echo "machine, please contact Alias|Wavefront Assist for more information."
    set errmsg1 = "Tablet drivers are incompatible with operating system."
    goto baderr
endif

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

# Determine where InstallTablet 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
        if ($status == 0) exit 0
        @ i++
    end
    echo ""
    echo "Three attempts to specify the root password have failed. Please try again"
    echo "later."
    echo ""
    echo -n "Press <ENTER> to continue: "
    set a = $<
    exit 1
endif

#    Determine where the script will place its working files. If /usr/tmp is
#    a directory and is writable, working files will go there; otherwise they
#    will be placed in /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

set WTCFG = $TMPDIR/tablet.$$
set tfd

#    Find the location of the ALIAS CD-ROM:
#
#    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 tablet drivers will be
#    installed from the Alias CD-ROM mounted at the location specified by
#    ALIAS_CDLOCN.
#
#    If ALIAS_CDLOCN is not set, InstallTablet 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, InstallTablet verifies the contents of the CD-ROM. If the
#    contents of the CD-ROM are valid, the installation continues, else
#    InstallTablet exits with an explanatory error message.
#
#    At the end of this step (assuming no errors have occurred), InstallTablet
#    will know the mount point of the CD-ROM player which contains the
#    Alias CD-ROM.

if ($?ALIAS_CDLOCN) then
    set ALIAS_CDPATH = $ALIAS_CDLOCN
else
    echo ""
    echo "Before the tablet drivers can be installed, Install must determine where"
    echo "the ALIAS CD-ROM is located on your machine."

#    If ALIAS_CDLOCN is not set, InstallTablet has to know where the CD-ROM
#    is mounted. InstallTablet determines its mount point and asks the installer
#    if it is the correct location. If they say `no', InstallTablet asks them
#    where the CD-ROM is mounted.

    set pdir = `dirname $0`
    set pfc = `echo $pdir | cut -c1`
    if ("$pfc" == "/") then
        set cdir = $pdir
    else
        set cdir = $cwd
    endif

    echo ""
    echo -n "Is the CD-ROM mounted at $cdir? (yes/no): "
    while (1)
        set ans = $<
        if ("$ans" !~ [yY][eE][sS] && "$ans" !~ [nN][oO]) then
            echo -n "Please specify yes or no: "
        else
            break
        endif
    end
    if ($ans =~ [Yy][Ee][Ss]) then
        set ALIAS_CDPATH = $cdir
    else
        echo ""
        while (1)
            echo -n "Where is the CD-ROM mounted? (please specify a full pathname): "
            set pname = $<
            set ALIAS_CDPATH = ($pname)

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

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

#    If the tablet drivers are 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, InstallTablet
#    validates it:
#
#    Verify that the CD-ROM mount point specified by the installer exists, it
#    is a directory and the CD-ROM is mounted (actually, the pathname specified
#    by ALIAS_CDPATH contains the proper files to install the tablet drivers).

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

echo ""
echo "Installing the tablet drivers from a $almedia drive."

#    Prepare to install the tablet drivers

echo ""
echo "If you are planning to do any peripheral work with the new Alias|Wavefront"
echo "software and tablets, your machine must have the correct tablet drivers"
echo "installed in the IRIX kernel. Before proceeding with the installation,"
echo "Install must verify that your machine is running an operating system which"
echo "is compatible with the drivers."

set xpref = $XTABLET:h

#    If the directory hierarchy /usr/lib/X11/input/config does not exist,
#    create it.

if (! -d $xpref) mkdir -p $xpref

if ("$os" == $IRIX63I || "$os" == $IRIX64I) then

#    If the machine is running IRIX 6.3 or 6.4, inform the installer that the
#    tablet drivers are included with the system (in the eoe.sw.optinput inst
#    image), but the shipped wacom driver is not configured for use with the
#    Alias|Wavefront software.
#
#    Ask them if they wish to install the Alias|Wavefront wacom configuration
#    file, saying that the script will first verify that the tablet drivers
#    (actually eoe.sw.optinput) is installed and a wacom tablet is configured
#    on the machine (/dev/input/wacom) exists. If they say `no', exit, else
#    continue.
#
#    Verify that the tablet drivers (eoe.sw.optinput) is installed. If they
#    aren't installed, inform the installer and set a flag indicating the
#    error.
#
#    Verify that a wacom tablet is configured (check for /dev/input/wacom).
#    This indicates that a tablet has been installed and configured.
#
#    If both the drivers and tablet appear to be properly configured, install
#    the wacom tablet configuration file.

    set tsftw = "eoe.sw.optinput"
    echo ""
    echo ""
    echo "This machine is running IRIX $os. This operating system provides its own"
    echo "set of tablet drivers for the wacom family of tablets. The tablet drivers"
    echo -n 'are installed as part of the "Optional Input Devices '
    echo -n "($tsftw)"
    echo '"'
    echo "software subsystem."
    echo ""
    echo "However, in their default state, the tablet drivers are not properly"
    echo "configured for use with the Alias|Wavefront software."
    echo ""
    echo "This CD-ROM contains a configuration file for the wacom family of tablets"
    echo "which will properly configure the tablet drivers for use with the"
    echo "Alias|Wavefront software. If you wish to install the configuration file,"
    echo "Install will first verify that the tablet drivers are installed and a wacom"
    echo "tablet has been connected to this machine."
    echo ""
    echo "Do you wish to install the Alias|Wavefront wacom tablet configuration"
    echo -n "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 =~ [Nn][Oo]) goto bye

    echo ""
    echo ""
    set sftw = `versions $tsftw | tail -1 | awk '{print $2}'`
    if ("$sftw" != $tsftw) then
        echo "It appears as if the tablet drivers are not installed on this machine."
        echo ""
        echo -n 'Please install the: "Optional Input Devices '
        echo -n "($tsftw)"
        echo ' software'
        echo "subsystem from your IRIX $os distribution CD-ROM using inst or"
        echo "SoftwareManager (swmgr). This includes the tablet drivers."
        set bad
    else
        echo "The tablet drivers are installed."
    endif

    echo ""
    echo ""
    if (! -c /dev/input/wacom) then
        if ($?bad) then
            echo "After you have successfully installed the tablet drivers, a wacom"
            echo "tablet must be attached to this machine and properly configured."
        else
            echo "It appears that a wacom tablet has not been attached to this machine and"
            echo "properly configured."
        endif
        echo ""
        echo "Using the "System Manager" (from the System menu of the toolchest),"
        echo "establish a serial port connection between your SGI and the wacom tablet."
        set bad
    else
        echo "A wacom tablet is already configured on this machine."
    endif

    if ($?bad) then
        echo ""
        echo ""
        echo "The Alias|Wavefront wacom tablet configuration file cannot be installed"
        echo "until both the tablet drivers have been installed and a wacom tablet has"
        echo "been properly configured."
        echo ""
        echo "Once both of these requirements have been completed and verified, restart"
        echo "this procedure to install the tablet configuration file."
        goto bye
    endif

#   Set tmake variable in preparation for jumping to code below

    set tmake = $TWAC

#    Now that we've performed the needed verification, install the
#    Alias|Wavefront wacom tablet configuration file in
#    /usr/lib/X11/input/config. Be sure to save the old version if
#    it is different than the new version.

    set fname = wacom.spaint
    chdir $TMPDIR
    while (1)
        echo ""
        echo "Extracting wacom tablet configuration file from the CD-ROM into $TMPDIR."
        echo ""
    
        (cd $ALIAS_CDPATH/$XCONFIG;tar cf - $fname) | tar xvof -
        if ($status == 0) break

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

#    Determine which type of cpu is on the machine:
#
#    Some versions of hinv print a separate line for each processor on multi
#    processor machines and this can cause the following test to cack. In
#    order to avoid the error, we only look at the first line of the output
#    of `hinv -t cpu'. All the processors are the same speed, so this test
#    is safe.

    set proc = `hinv -t cpu | sed 1q | awk '{ print $3 }'`

#    If we're installing on an R10000, add the following line to the wacom
#    tablet configuration file:
#
#        pressurecurve   "0,255"
#
#    so that the tablet will behave correctly.

    if ("$proc" == "R10000") then
        ex - $TMPDIR/$fname << EOF
        /^}/i
        pressurecurve   "0,255"
.
w
q
EOF
    endif
    
    set replacet
    unset old_tconfig
    if (-f $WXTABLET) then
        cmp -s $WXTABLET $TMPDIR/$fname
        if ($status == 0) then
            echo ""
            echo "The correct version of the wacom tablet configuration file is already"
            echo "installed."
            rm $TMPDIR/$fname
            unset replacet
        else
            set old_tconfig
        endif
    endif
    
    if ($?replacet) then
        if ($?old_tconfig) then
            if (! -f $WXTABLET.pre_alias) then
                mv $WXTABLET $WXTABLET.pre_alias
            endif
            set mod_files = ($mod_files $WXTABLET)
        endif
        echo ""
        echo "Installing wacom tablet configuration file in $xpref."
        mv -f $TMPDIR/$fname $WXTABLET
    endif
    goto cleanup
endif

if ($os == $IRIX5I || $os == $IRIX62I) then

#    If the machine is running the right version of IRIX 5 or IRIX 6.2, the
#    tablet master and object files are installed in /var/sysgen and the kernel
#    system file is /var/sysgen/system/gfx.sm.

    set pref_tmaster = /var/sysgen/master.d
    set pref_tobj = /var/sysgen/boot
    set system = /var/sysgen/system/gfx.sm

#    Using the type of operating system as a key (IRIX 5 or IRIX 6), determine
#    the identifying suffix of the tablet drivers. This suffix (irix5 or irix6)
#    will be used to determine which version of the tablet drivers should be
#    installed.
#
#    If the operating system level is IRIX 5.3, add the wacom supplied
#    wacom driver to the list of tablet drivers to install. If the machine
#    is not running IRIX 5.3 and is running IRIX 6.2, the Wacom driver is
#    installed using inst instead.

    set wawacom
    set ATABS = ($WAWAC $ATABS)
    if ($os == $IRIX5I) then
        set vsuf = irix5
        set versdir = $vsuf
    else

#    For IRIX 6.2, we have several versions of the tablet drivers:
#
#    The following chart describes which set of drivers they get:
#
#         Processor     | Register bit size | tablet driver version installed
#         --------------+-------------------+--------------------------------
#            any type   |     32 bits       |     32-bit IP22 tablet drivers
#              IP26     |     64 bits       |     64-bit IP26 tablet drivers
#              IP28     |     64 bits       |     64-bit IP28 tablet drivers
#         not IP26|IP28 |     64 bits       |     64-bit IP22 tablet drivers
#
#    Additionally the 6.2 Wacom driver can be installed with inst for all
#    processors except for IP28.

        set vsuf = irix6
        set versdir = $vsuf

#    Determine the register bit size. We do this using the uname
#    command which prints IRIX64 on 64 bit machines and IRIX on 32 bit
#    machines.

        set rbitsize = `uname`
        if ($rbitsize == "IRIX") then
            set versdir = $versdir/K32
        else if ($rbitsize == "IRIX64") then

#    Now that we know we have a IRIX 6.2 machine with a 64-bit register
#    size, we have to look at the processor type to determine the correct
#    tablet drivers to install. If it's an IP26, we install the IP26 64-bit
#    tablet drivers, else if it's an IP28 we install the IP28 64-bit tablet
#    drivers, else we install the non-IP26 or IP28 (actually IP22) 64-bit
#    tablet drivers.

            set ptype = `hinv -c processor | head -1 | awk '{print $4}'`
            if ($ptype == "IP26") then
                set versdir = $versdir/IP26K64
            elif ($ptype == "IP28") then
                set versdir = $versdir/IP28K64
            else
                set versdir = $versdir/K64
            endif
        else
            echo ""
            echo "Unknown register bit size determined: $rbitsize."
            echo ""
            echo "Cannot continue with the installation."
            set errmsg1 = "Unknown register bit size."
            goto baderr
        endif
    endif
endif

if ($?vsuf) then
    echo ""
    echo "The operating system is acceptable."
endif

#    Attempt to install the tablet drivers.
#
#    In this case, tab_masters and tab_objs represent the names of the
#    tablet master and object files, while tab_vdmasters and tab_vdobjs
#    represent the names of the same files but with a version designator
#    attached (i.e.: irix5 or irix6). The latter variables are used
#    to "copy" the correct versions of the tablet drivers from the
#    distribution CD-ROM (via tar).
#
#    If the current operating system is IRIX 6.2, we defer to Wacom's
#    wacom tablet driver which is in inst format. In this case, we do
#    not add the filenames of the wacom master and object files to the
#    list of driver files to install and inspect.

set tab_masters = ""
set tab_objs = ""
set tab_vdmasters = ""
set tab_vdobjs = ""
@ i = 1
while ($i <= $#ATABS)
    if ($os != $IRIX62I || $ATABS[$i] != $WAWAC) then
        set tab_masters = ($ATABS[$i] $tab_masters)
        set tab_vdmasters = ($ATABS[$i].$vsuf $tab_vdmasters)
        set tab_objs = ($ATABS[$i].o $tab_objs)
        set tab_vdobjs = ($ATABS[$i].o.$vsuf $tab_vdobjs)
    endif
    @ i++
end

echo ""
echo "In order to install the tablet drivers, the correct versions of the following"
echo "files must be installed:"
echo ""
@ i = 1
while ($i <= $#tab_objs)
    echo "    $pref_tobj/$tab_objs[$i]"
    @ i++
end
@ i = 1
while ($i <= $#tab_masters)
    echo "    $pref_tmaster/$tab_masters[$i]"
    @ i++
end
echo ""
echo "and the file $system modified to recognize the drivers."
echo ""
echo "The files located in $pref_tobj are the tablet object files and the"
echo "files located in $pref_tmaster are the master or kernel description"
echo "files."
echo ""
echo "If older versions of these files exist, they will be compared with the same"
echo "files from the Alias|Wavefront software $almedia. If they differ, the file(s)"
echo "from the distribution $almedia will replace the existing version(s), which will"
echo "be saved. If any of the files from the distribution $almedia are installed or the"
echo "system file is modified, Install will build a new IRIX kernel which includes"
echo "the tablet drivers."

#    Ask the installer if they wish to install the tablet drivers. If they
#    say `no', the tablet driver files are not installed. 

echo ""
echo -n "Do you wish to install the tablet drivers? (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

#    If the tablet driver files are being installed, "copy" the tablet driver
#    files from the CD-ROM (via tar) into a temporary directory.

cd $TMPDIR
while (1)
    echo ""
    echo "Extracting Alias|Wavefront tablet driver files from the CD-ROM into $TMPDIR."
    echo ""

    (cd $ALIAS_CDPATH/$TABFILES/$versdir;tar cf - $tab_vdmasters $tab_vdobjs) | tar xvof -
    if ($status == 0) break

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

#    If running IRIX 6.2 install the Wacom driver with inst as well.
#
#    Verify that the installation succeeds by checking the exit status
#    of the inst process. If inst returns a non-zero exit status, run
#    the versions command to see if the wacom tablet drivers have been
#    installed. If the tablet drivers appear to be installed, continue
#    with the installation. If the tablet drivers do not appear to be
#    installed, inform the installer that the tablet drivers do not
#    appear to be installed. Ask the installer if they wish to reattempt
#    the installation. If they say `yes', reattempt the installation,
#    otherwise, gracefully exit this script.

if ($os == $IRIX62I) then
    while (1)
        echo ""
        echo "Installing wacom tablet drivers from the CD-ROM ..."
        echo ""

        inst -f $ALIAS_CDPATH/$TABFILES/irix6/Wacom/dist -a -I wac_drv,wac_cp
        if ($status == 0) break

        set OUT = $TMPDIR/inst.$$
        versions wac_drv wac_cp | sed 1d | grep ^I > $OUT
        if (! -z $OUT) then
            rm -f $OUT
            break
        endif
        rm -f $OUT

        echo ""
        echo ""
        echo ""
        echo "It appears that there was a problem in installing the wacom tablet drivers."
        echo "You may have to attempt it 2 or 3 times before you're finally successful."
        echo ""
        echo -n "Do you wish to try installing the tablet drivers 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
endif

#    If the tablet driver files were successfully "copied" from the
#    distribution CD-ROM, continue with the installation.
#
#    Verify that the correct versions of the tablet master and object files
#    are installed. Check the master files followed by the object files. The
#    same treatment applies to both sets of files. Foreach file in each
#    group:
#
#    - Check for an existing file in /var/sysgen/{master.d,boot}. If the file
#      is found, compare it with the "new" version from the distribution CD-ROM.
#      If the files are the same, remove the version that was extracted or
#      "copied" from the distribution CD-ROM.
#    - If the two files are different or the named file does not exist in
#      /var/sysgen/{master.d,boot}, the file from the distribution CD-ROM
#      is moved to the appropriate directory in /var/sysgen and renamed by
#      stripping its version designator (irix5 or irix6). If a new file
#      replaces an existing file, the existing file is saved as <filename>= at
#      the end of the script.
#
#    If any files from the distribution CD-ROM are installed in one of the
#    directories in /var/sysgen (boot and/or master.d), a new IRIX kernel will
#    be built.

unset krebuild
echo ""
echo ""
echo "The script will now verify that your machine has the correct versions of"
echo "the tablet drivers installed."
echo ""
echo "Checking the tablet master files."
cd $pref_tmaster
@ i = 1
while ($i <= $#tab_masters)
    set replacet
    unset old_tmaster
    set fname = $tab_masters[$i]
    if (-f $fname) then
        cmp -s $fname $TMPDIR/$fname.$vsuf
        if ($status == 0) then
            rm $TMPDIR/$fname.$vsuf
            unset replacet
        else
            set old_tmaster
        endif
    endif

    if ($?replacet) then
        if ($?old_tmaster) then
            if (! -f $fname.pre_alias) then
                mv $fname $fname.pre_alias
            endif
            set mod_files = ($mod_files $pref_tmaster/$fname)
        endif
        mv -f $TMPDIR/$fname.$vsuf $fname
        chmod 444 $fname
        chown bin.bin $fname
        set krebuild
    endif
    @ i++
end

echo ""
echo "Now the tablet object files."
echo ""
cd $pref_tobj
@ i = 1
while ($i <= $#tab_objs)
    set replacet
    unset old_tobj
    set fname = $tab_objs[$i]
    if (-f $fname) then
        cmp -s $fname $TMPDIR/$fname.$vsuf
        if ($status == 0) then
            rm $TMPDIR/$fname.$vsuf
            unset replacet
        else
            set old_tobj
        endif
    endif

    if ($?replacet) then
        if ($?old_tobj) then
            if (! -f $fname.pre_alias) then
                mv $fname $fname.pre_alias
            endif
            set mod_files = ($mod_files $pref_tobj/$fname)
        endif
        mv -f $TMPDIR/$fname.$vsuf $fname
        chmod 444 $fname
        chown bin.bin $fname
        set krebuild
    endif
    @ i++
end

#    If the kernel system file (/var/sysgen/system/gfx.sm) exists, verify that
#    there are entries for the various tablet drivers (aliashitachi aliaskurta
#    aliaswacom altablet) in the "USE: dial ..." line. Note that there may
#    be spaces between the word USE and the colon that we have to check for.

echo ""
echo "Verifying that the kernel system file recognizes the tablet drivers."
if (-f $system) then
    if (! -f $system.pre_alias) then
        cp $system $system.pre_alias
    endif
    set mod_files = ($mod_files $system)

    set sline = `grep "^USE[ 	]*: dial " $system`

#    If the pattern `USE: dial ' (start of line which lists tablet modules) is
#    not found in the kernel system file, add the following line to the file:
#
#    USE: aliashitachi aliaskurta aliaswacom altablet
#
#    and indicate that a new IRIX kernel should be built.

    if ("$sline" == "") then
        echo ""
        echo "Modifying the kernel system file to recognize the tablet drivers."
        ex - $system << EOF
        ${DLR}a
USE: $ATABS
.
        w! $system
        q
EOF
        set krebuild
    else

#    If the pattern `USE: dial' (start of line which lists tablet modules) is
#    found in the kernel system file, verify that it has entries for each of
#    the tablet drivers.

        set sysline = ""
        foreach tdriver ($ATABS)
            echo $sline | grep -s " $tdriver " >& /dev/null
            if ($status != 0) then
                echo $sline | grep -s " ${tdriver}${DLR}" >& /dev/null
                if ($status != 0) set sysline = "$sysline $tdriver"
            endif
        end

        if ("$sysline" != "") then
            echo ""
            echo "Modifying the kernel system file to recognize the tablet drivers."

            ex - $system << EOF
            /^USE[ 	]*: dial /c
${sline}${sysline}
.
            w! $system
            q
EOF
            set krebuild
        else
            echo ""
            echo "The kernel system file has been previously modified to recognize the tablet"
            echo "drivers."
        endif
    endif
else
    echo ""
    echo "Cannot find kernel system file ($system:t) in $system:h."
    echo ""
    if ($?krebuild) then
        echo ""
        echo "The tablet drivers have been installed, but a new IRIX kernel cannot be"
        echo "built due to the absence of the kernel system file."
    endif
    unset krebuild
endif

#   If any tablet drivers were added or the kernel system file was modified,
#   build a new IRIX kernel which recognizes the tablet drivers.

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

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

#    In order for the X window system to interpret the tablet data correctly,
#    the correct version of:
#
#        /usr/lib/X11/input/config/tablet
#
#    must be installed.
#
#    If an existing version of the tablet configuration file is found, the
#    configuration file from the ALIAS distribution CD-ROM is compared with the
#    existing file. If the files are the same, the file from the distribution
#    CD-ROM is removed. If the files are different, the file from the
#    distribution CD-ROM replaces the existing file, which is saved.
#
#    There are two versions of the tablet configuration file, one for
#    StudioPaint and the other for other Alias|Wavefront products
#    (i.e.: Studio).
#
#    InstallTablet asks the installer which product they are using and "copies"
#    the correct version of the configuration file from the CD-ROM (via tar).

echo ""
echo ""
echo "In addition to the installation of the tablet drivers, the X window system must"
echo "be told how to interpret the tablet data. This function is performed by the"
echo "following file:"
echo ""
echo "    $XTABLET"
echo ""
echo "There are two versions of this file, one for each of the following products:"
echo ""
echo "    $NSTPA) Alias|Wavefront StudioPaint"
echo "    $NDFLT) Alias|Wavefront 3D Product (i.e.: Power Animator)"
echo ""
echo -n "Please indicate which product you are using (1-$NDFLT): "
while (1)
    set choice = $<
    if ("$choice" !~ [12]) then
        echo -n "Please specify a number between 1 and ${NDFLT}: "
    else
        break
    endif
end

echo ""
echo "This script will now verify that the correct version of the tablet"
echo "configuration file is installed."

#    Based on the type of Alias product being installed, a specific tablet
#    config file will be "copied" from the CD-ROM.

if ($choice == $NSTPA) then
    set vers = "StudioPaint"
    set fname = $XTABSTPA
    set xtabsp
else
    set vers = "Alias 3D"
    set fname = $XTABDFLT
endif

cd $TMPDIR
while (1)
    echo ""
    echo "Extracting tablet configuration file from the CD-ROM into $TMPDIR."
    echo ""

    (cd $ALIAS_CDPATH/$XCONFIG;tar cf - $fname) | tar xvof -
    if ($status == 0) break

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

set replacet
unset old_tconfig
if (-f $XTABLET) then
    cmp -s $XTABLET $TMPDIR/$fname
    if ($status == 0) then
        echo ""
        echo "The correct version of the tablet configuration file is already installed."
        rm $TMPDIR/$fname
        unset replacet
    else
        set old_tconfig
    endif
endif

if ($?replacet) then
    if ($?old_tconfig) then
        if (! -f $XTABLET.pre_alias) then
            mv $XTABLET $XTABLET.pre_alias
        endif
        set mod_files = ($mod_files $XTABLET)
    endif
    echo ""
    echo "Installing new version of the configuration file in $xpref."
    mv -f $TMPDIR/$fname $XTABLET
endif

#    Ensure that the tablet configuration file is readable and writable
#    by all users.

chmod a+rw $XTABLET

#    Determine what type of tablet the installer is using:
#
#    Ask the installer to indicate the maker of their tablet (one of Hitachi,
#    Kurta and Wacom). Once they have indicated the maker of their tablet,
#    list all supported tablets manufactured by that maker and ask the installer
#    to indicate the type of tablet they are installing support for.

echo ""
echo "There are a number of different tablet types supported by the $vers"
echo "software. The makers of these tablets are:"
echo ""
echo "    $THIT) Hitachi"
echo "    $TKUR) Kurta"
echo "    $TWAC) Wacom"
echo ""
echo -n "Which type of tablet are you currently using? (1-3): "
while (1)
    set tmake = $<
    if ("$tmake" !~ [123]) then
        echo -n "Please specify a number between 1 and 3: "
    else
        break
    endif
end

if ($tmake == $THIT) then
    set H1111 = 1
    set H1111C = 2
    set H1515 = 3
    set H2222 = 4
    set H2920 = 5
    set H3624 = 6
    set H4030 = 7
    set H4836 = 8
    set H6044 = 9

    echo ""
    echo "The following hitachi tablets are supported by the $vers software:"
    echo ""
    echo -n "    $H1111) "
    echo 'Hitachi 11" by 11" tablet'
    echo -n "    $H1111C) "
    echo 'Hitachi 11" by 11" tablet (HDG-1111C)'
    echo -n "    $H1515) "
    echo 'Hitachi 15" by 15" tablet'
    echo -n "    $H2222) "
    echo 'Hitachi 22" by 22" tablet'
    echo -n "    $H2920) "
    echo 'Hitachi 29" by 20" tablet'
    echo -n "    $H3624) "
    echo 'Hitachi 36" by 24" tablet'
    echo -n "    $H4030) "
    echo 'Hitachi 40" by 30" tablet'
    echo -n "    $H4836) "
    echo 'Hitachi 48" by 36" tablet'
    echo -n "    $H6044) "
    echo 'Hitachi 60" by 44" tablet'
    echo ""
    echo -n "Please indicate which tablet you are currently using (1-9): "
    while (1)
        set tnum = $<
        if ("$tnum" !~ [123456789]) then
            echo -n "Please specify a number between 1 and 9: "
        else
            break
        endif
    end
    if ($tnum == $H1111) then
        set tstr = hitachi1111
    else if ($tnum == $H1111C) then
        set tstr = hitachi1111c
    else if ($tnum == $H1515) then
        set tstr = hitachi1515
    else if ($tnum == $H2222) then
        set tstr = hitachi2222
    else if ($tnum == $H2920) then
        set tstr = hitachi2920
    else if ($tnum == $H3624) then
        set tstr = hitachi3624
    else if ($tnum == $H4030) then
        set tstr = hitachi4030
    else if ($tnum == $H4836) then
        set tstr = hitachi4836
    else if ($tnum == $H6044) then
        set tstr = hitachi6044
    endif
else if ($tmake == $TKUR) then
    set K2418 = 1
    set K2424 = 2
    set K3624 = 3
    set K3630 = 4
    set K4836 = 5
    set K6042 = 6
    set K6648 = 7

    echo ""
    echo "The following kurta tablets are supported by the $vers software:"
    echo ""
    echo -n "    $K2418) "
    echo 'Kurta 24" by 18" tablet'
    echo -n "    $K2424) "
    echo 'Kurta 24" by 24" tablet'
    echo -n "    $K3624) "
    echo 'Kurta 36" by 24" tablet'
    echo -n "    $K3630) "
    echo 'Kurta 36" by 30" tablet"'
    echo -n "    $K4836) "
    echo 'Kurta 48" by 36" tablet'
    echo -n "    $K6042) "
    echo 'Kurta 60" by 42" tablet'
    echo -n "    $K6648) "
    echo 'Kurta 66" by 48" tablet'
    echo ""
    echo -n "Please indicate which tablet you are currently using (1-7): "
    while (1)
        set tnum = $<
        if ("$tnum" !~ [1234567]) then
            echo -n "Please specify a number between 1 and 7: "
        else
            break
        endif
    end
    if ($tnum == $K2418) then
        set tstr = kurta2418
    else if ($tnum == $K2424) then
        set tstr = kurta2424
    else if ($tnum == $K3624) then
        set tstr = kurta3624
    else if ($tnum == $K3630) then
        set tstr = kurta3630
    else if ($tnum == $K4836) then
        set tstr = kurta4836
    else if ($tnum == $K6042) then
        set tstr = kurta6042
    else if ($tnum == $K6648) then
        set tstr = kurta6648
    endif
else
    set W0806 = 1
    set W0906 = 2
    set W1212 = 3
    set W1515 = 4
    set W1812 = 5
    set W2518 = 6
    set W3525 = 7
    set W4735 = 8

    echo ""
    echo "The following wacom tablets are supported by the $vers software:"
    echo ""
    echo -n "    $W0806) "
    echo 'Wacom 8" by 6" tablet'
    echo -n "    $W0906) "
    echo 'Wacom 9" by 6" tablet'
    echo -n "    $W1212) "
    echo 'Wacom 12" by 12" tablet'
    echo -n "    $W1515) "
    echo 'Wacom 15" by 15" tablet'
    echo -n "    $W1812) "
    echo 'Wacom 18" by 12" tablet'
    echo -n "    $W2518) "
    echo 'Wacom 25" by 18" tablet'
    echo -n "    $W3525) "
    echo 'Wacom 35" by 25" tablet'
    echo -n "    $W4735) "
    echo 'Wacom 47" by 35" tablet'
    echo ""
    echo -n "Please indicate which tablet you are currently using (1-8): "
    while (1)
        set tnum = $<
        if ("$tnum" !~ [12345678]) then
            echo -n "Please specify a number between 1 and 8: "
        else
            break
        endif
    end
    if ($tnum == $W0806) then
        set tstr = wacom0806
    else if ($tnum == $W0906) then
        set tstr = wacom0906
    else if ($tnum == $W1212) then
        set tstr = wacom1212
    else if ($tnum == $W1515) then
        set tstr = wacom1515
    else if ($tnum == $W1812) then
        set tstr = wacom1812
    else if ($tnum == $W2518) then
        set tstr = wacom2518
    else if ($tnum == $W3525) then
        set tstr = wacom3525
    else if ($tnum == $W4735) then
        set tstr = wacom4735
    endif

#    If the wacom supplied version of the wacom tablet driver was installed,
#    inform the installer that they may choose to use either the Alias
#    supplied wacom driver or the wacom supplied driver. Ask them which
#    driver they wish to use. If they indicate that they wish to use the
#    wacom driver, a Alias product specific (i.e.: StudioPaint, Alias Studio)
#    wacom tablet configuration file must be installed in:
#
#        /usr/lib/X11/input/config/wacom
#
#    If an existing version of the wacom tablet configuration file is found,
#    the wacom tablet configuration file from the ALIAS distribution CD-ROM is
#    compared with the existing file. If the files are the same, the file
#    from the distribution CD-ROM is removed. If the files are different,
#    the file from the distribution CD-ROM replaces the existing file, which
#    is saved.
#
#    There are two versions of the tablet configuration file, one for
#    Alias StudioPaint and the other for other Alias products
#    (i.e.: Alias Studio). InstallTablet "copies" the correct version
#    of the configuration file from the CD-ROM (via tar).

    if ($?wawacom) then
        echo ""
        echo "Two versions of the wacom tablet driver have been installed on your machine,"
        echo "one supplied by Alias|Wavefront and a version of a driver from wacom. The"
        echo "wacom driver supports more functionality with Alias|Wavefront products,"
        echo "especially StudioPaint."
        echo ""
        echo -n "Do you wish to use the wacom driver to drive your tablet? (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 use_wacdr
            echo "Since you chose to use the wacom driver, another file, specific to"
            echo "this driver must be installed:"
            echo ""
            echo "    $WXTABLET"

            if ($?xtabsp) then
                set fname = wacom.spaint
            else
                set fname = wacom.dflt
            endif
            
            while (1)
                echo ""
                echo "Extracting wacom tablet configuration file from the CD-ROM into $TMPDIR."
                echo ""
            
                (cd $ALIAS_CDPATH/$XCONFIG;tar cf - $fname) | tar xvof -
                if ($status == 0) break
            
                echo ""
                echo "It appears that there was a problem in reading the $almedia. You may have to"
                echo "attempt it 2 or 3 times before you're finally successful."
                echo ""
                echo -n "Do you wish to try reading the $almedia again? (yes/no): "
                while (1)
                    set ans = $<
                    if ("$ans" !~ [yY][eE][sS] && "$ans" !~ [nN][oO]) then
                        echo -n "Please specify yes or no: "
                    else
                        break
                    endif
                end
                if ($ans =~ [nN][oO]) then
                    rm -f $fname
                    goto userexit
                endif
            end

#    Determine which type of cpu is on the machine:
#
#    Some versions of hinv print a separate line for each processor on multi
#    processor machines and this can cause the following test to cack. In
#    order to avoid the error, we only look at the first line of the output
#    of `hinv -t cpu'. All the processors are the same speed, so this test
#    is safe.

            set proc = `hinv -t cpu | sed 1q | awk '{ print $3 }'`

#    If we're installing on an R10000 running IRIX 6.2, add the following line
#    to the wacom tablet configuration file:
#
#        pressurecurve   "0,255"
#
#    so that the tablet will behave correctly.

            if ("$proc" == "R10000" && "$os" == $IRIX62I) then
                ex - $TMPDIR/$fname << EOF
                /^}/i
        pressurecurve   "0,255"
.
w
q
EOF
            endif
            
            set replacet
            unset old_tconfig
            if (-f $WXTABLET) then
                cmp -s $WXTABLET $TMPDIR/$fname
                if ($status == 0) then
                    echo ""
                    echo "The correct version of the wacom tablet configuration file is already"
                    echo "installed."
                    rm $TMPDIR/$fname
                    unset replacet
                else
                    set old_tconfig
                endif
            endif
            
            if ($?replacet) then
                if ($?old_tconfig) then
                    if (! -f $WXTABLET.pre_alias) then
                        mv $WXTABLET $WXTABLET.pre_alias
                    endif
                    set mod_files = ($mod_files $WXTABLET)
                endif
                echo ""
                echo "Installing wacom tablet configuration file in $xpref."
                mv -f $TMPDIR/$fname $WXTABLET
            endif
            
#    Ensure that the wacom tablet configuration file is readable and writable
#    by all users.
            
            chmod a+rw $WXTABLET
        else
            echo "Using the Alias|Wavefront wacom tablet driver."
        endif
    endif

#    Verify that the wacom tablet is a SD or UD series tablet. If it isn't
#    an SD or UD series wacom tablet, it cannot be used with the Alias
#    software.

    set shdsw
    echo ""
    echo "The Alias|Wavefront software supports only SD and UD series wacom tablets."
    echo ""
    echo -n "Is your tablet one of these two types? (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 $vers software only supports SD and UD series wacom tablets."
        echo ""
        echo "You cannot use your tablet with the $vers software."
        set errmsg1 = "The tablet is not a SD or UD series wacom tablet."
        goto baderr
    else

#    Make a working copy of the tablet configuration file which does not
#    include entries for pressure, button pressure or duplex. These entries
#    will be added if they are needed.

        egrep -v "^[ 	]*pressure|buttonpressure|duplex[ 	]*" $XTABLET > $WTCFG
        set WSD = 1
        set WUD = 2

#    If the tablet is one of the SD or UD series, determine to which series
#    the tablet belongs.

        echo ""
        echo "Which series of wacom tablet is your tablet:"
        echo ""
        echo "    $WSD) SD series wacom tablet"
        echo "    $WUD) UD series wacom tablet"
        echo ""
        echo -n "Please indicate which type of tablet you have (1-2): "
        while (1)
            set wts = $<
            if ("$wts" !~ [12]) then
                echo -n "Please specify 1 or 2: "
            else
                break
            endif
        end
        if ($wts == $WSD) then

#    If the customer is using an SD series wacom tablet, determine any specific
#    settings which need to made.

            echo ""
            echo -n "Are you using a pressure sensitive pen on your tablet? (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 customer is using a pressure sensitive pen, add pressure settings
#    to the working tablet configuration file.

            if ($ans =~ [Yy][Ee][Ss]) then
                ex - $WTCFG << EOF
                ${DLR}i
	pressure	"on"
	buttonpressure	"10"
.
w!
q
EOF
            else

#    If the customer is not using a pressure sensitive pen, indicate that
#    the pressure setting is off.

                ex - $WTCFG << EOF
                ${DLR}i
	pressure	"off"
.
w!
q
EOF
            endif
        else

#    If the customer is using a UD series wacom tablet, set the duplex and
#    buttonpressure settings to appropriate values. Also, indicate that
#    the dipswitch settings for the wacom tablets should not be shown.
#    This series of wacom tablet does not have dipswitches.

                ex - $WTCFG << EOF
                ${DLR}i
	duplex		"on"
	buttonpressure	"10"
.
w!
q
EOF
            unset shdsw
        endif

#    Overwrite the tablet configuration file with the freshly customized
#    working tablet configuration file.

        echo ""
        echo "Customizing the tablet configuration file for the wacom tablet."
        echo ""
        mv -f $WTCFG $XTABLET
    endif
endif

#    If the installer wishes to use the wacom driver, the name of the
#    link in /dev/input will be /dev/input/wacom, else the name of the link
#    will be /dev/input/altablet-<tablet name>.

if ($?use_wacdr) then
    set lname = "/dev/input/wacom"
else
    set lname = "/dev/input/altablet-$tstr"
endif

#    Determine on which serial port the tablet is connected

echo ""
echo -n "Which serial port is the tablet connected to? (specify the port number): "
while (1)
    unset badpn
    set pname = $<
    set portno = ($pname)

#    If the installer specifies a port identifer, verify that it is numeric.
#    If the identifer is numeric, verify that /dev/ttyd<identifer> exists.
#
#    If the installer does not specify a port identifier or supplies several
#    elements as a port identifer ($#portno != 1) or the port identifier is
#    not numeric, ask the installer to specify a numeric port number.

    if ($#portno == 1) then
        set jnk = `expr $portno : '[0-9]*\(.*\)'`
        if ($#jnk) set badpn
    else
        set badpn
    endif

    if ($?badpn) then
        echo -n "Please specify a serial port number: "
    else
        if (-c /dev/ttyd$portno) then
            break
        else
            echo "There is no serial port $portno listed in /dev."
            echo -n "Please specify an existing serial port number: "
        endif
    endif
end

#    Verify there is no old tablet device file in /dev/input which pertains
#    to the serial port the tablet is connected to:
#
#    Find the major and minor numbers of the serial port the tablet is
#    connected to. Search /dev/input for a device file with the same
#    <major #, minor #> pair. If such a device file exists, inform the
#    installer that the device file is being removed and remove it.

set maj = `ls -l /dev/ttyd$portno | awk -F"," '{print $1}' | awk '{print $5}'`
set min = `ls -l /dev/ttyd$portno | awk -F"," '{print $2}' | awk '{print $1}'`
if ($min < 10) then
    set majmin = "$maj,  $min"
else if ($min < 100) then
    set majmin = "$maj, $min"
else
    set majmin = "$maj,$min"
endif
set otname = `ls -l /dev/input | grep " $majmin " | awk -F"," '{print $2}' | awk '{print $5}'`

if ($#otname) then
    echo ""
    echo "Removing old tablet type hard link ($otname) in /dev/input."
    rm -f /dev/input/$otname
endif

#    Remove all tablet device files in /dev/input. The Alias software can't
#    handle multiple tablets so we have to ensure that only one tablet device
#    exists.

set nonomatch
rm -f /dev/input/altablet-* /dev/input/wacom
unset nonomatch

#    Create a hard link between /dev/ttyd<tablet port number> and
#    /dev/input/wacom (for the wacom tablet driver) or
#    /dev/input/altablet-<tablet type> (for the Alias tablet drivers).

echo ""
echo "Creating hard link between serial port $portno and $lname ..."
ln /dev/ttyd$portno $lname

#    After creating the hardlink between the serial port (/dev/ttydX) and
#    the correct file in /dev/input, make sure the device file is readable
#    and writable by everyone.

echo ""
echo "Making the serial port readable and writable by everyone ..."
chmod a+rw /dev/ttyd$portno

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

cleanup:

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

#    If a wacom tablet was installed and the tablet has dipswitches
#    (shdsw is set), remind the installer that the dipswitches on the
#    tablet have to be set correctly or the tablet will not behave
#    properly. For their benefit, display the list of recommended settings.

if ($tmake == $TWAC && $?shdsw) then
    echo ""
    echo "A wacom tablet has three sets of dipswitches. Verify that the switches on"
    echo "your tablet match those shown below or your tablet may not behave correctly:"
    echo ""
    echo "    +----------+---+---+---+---+---+---+---+---+"
    echo "    | Switch 1 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |"
    echo "    +----------+---+---+---+---+---+---+---+---+"
    echo "               |ON |ON |OFF|ON |ON |OFF|ON |ON |"
    echo "               +---+---+---+---+---+---+---+---+"
    echo ""
    echo "    +----------+---+---+---+---+---+---+---+---+"
    echo "    | Switch 2 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |"
    echo "    +----------+---+---+---+---+---+---+---+---+"
    echo "               |ON |ON |OFF|OFF|OFF|OFF|OFF|ON |"
    echo "               +---+---+---+---+---+---+---+---+"
    echo ""
    echo "    +----------+---+---+---+---+---+---+---+---+"
    echo "    | Switch 3 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |"
    echo "    +----------+---+---+---+---+---+---+---+---+"
    echo "               |ON |ON |OFF|OFF|ON |ON |ON |OFF|"
    echo "               +---+---+---+---+---+---+---+---+"
    echo ""
endif

#    If the tablet drivers were added to the system, remind the installer
#    about the state of the rebuilt IRIX kernel:
#
#    If the IRIX kernel rebuild was successful, remind the installer to reboot
#    the machine to install the new kernel.
#
#    If the IRIX kernel rebuild was not successful, remind the installer that
#    they may have to reboot the machine a few times before the rebuild
#    succeeds.

echo ""
echo ""
if ($?krebuild) then
    if ($?srb) then
        echo "Don't forget to reboot the machine to install the new IRIX kernel (which"
        echo "includes the tablet drivers)."
    else
        echo "Since the IRIX kernel rebuild failed, you may have to reboot the machine"
        echo "a few times before the kernel rebuild is successful. If the system asks"
        echo 'you "Automatically reconfigure the operating system (y or n) ?", make'
        echo "sure you answer yes. When the rebuild is successful, the system will"
        echo "prompt you to reboot the system. Be sure to do so. This will install the"
        echo "new IRIX kernel (which includes the tablet drivers)."
    endif
else

#    If the tablet drivers are already installed (a reboot is not required),
#    inform the installer that they have to logout and login again to allow
#    the X server to recognize the tablet.

    echo "Before the tablet will respond, you will have to logout and login. This allows"
    echo "the X server to recognize that a tablet has been added to the system."
endif
echo ""

echo ""
echo "The installation is complete."
echo -n "Press <ENTER> to continue: "
set a = $<

exit 0

userexit:
echo ""
echo "Ok. Installation has been aborted. When you are ready to install the tablet"
echo "drivers and configure your tablet setup, attempt the installation again."
echo ""

baderr:
if ($?errmsg1) then
    echo ""
    echo "There has been an error in the installation procedure ..."
    echo "Please record the error message and contact Alias|Wavefront Assist."
    echo "This situation must be corrected before the installation can continue."
    echo ""
    echo "The error encountered was:"
    echo ""
    echo $errmsg1
    echo ""
endif

if ($?tfd) then
    rm -f $WTCFG
endif

bye:
echo ""
echo -n "Press <ENTER> to continue: "
set a = $<
exit
