#!/bin/csh -f
#Tag 1024

#    Install: Master Alias Installation Script

if (! $?inscript) then
    echo ""
    echo ""
    echo "                    Alias|Wavefront Installation Script"
    echo ""
    setenv inscript
endif

#   Explicity set the command search path in case some sites have
#   weird search paths.

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

# Determine where the CD-ROM is mounted.

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

#    Set the environment variable, ALIAS_CDLOCN to the mount point of the
#    Alias|Wavefront CD-ROM. This variable will be used by the other install
#    scripts to determine the mount point of the CD-ROM.

setenv ALIAS_CDLOCN $cdir
set os = `uname -r`

#    Older versions of inst (IRIX 5.3) generate confusing errors when a
#    remote CD-ROM is mounted on the local machine. If the local machine
#    is running IRIX 5.3, a remotely mounted CD-ROM is being used for the
#    installation of the software and the local mount point of the CD-ROM
#    begins with /CDROM, warn the installer that this setup is known to
#    cause installation problems and they should choose a different local
#    mount point before continuing.

if ("$os" == "5.3") then
    set mtinfo = `df $cdir | awk '$2 != "Type" {printf "%s %s\n", $2, $7}'`
    set fstype = $mtinfo[1]
    set mtpoint = $mtinfo[2]
    if ("$fstype" == "nfs" && $mtpoint =~ "/CDROM*") then
        echo ""
        echo "This machine is running IRIX 5.3 and is using another machine's CD-ROM drive"
        echo "to install the Alias|Wavefront software. The local mount point of the CD-ROM"
        echo "drive is $mtpoint. Previous customer installations using this configuration"
        echo "are known to fail when the local mount point of the Alias|Wavefront CD-ROM"
        echo "begins with /CDROM. Please unmount the Alias|Wavefront CD-ROM from this"
        echo "machine and remount it using a local mount point not beginning with /CDROM."
        echo ""
        echo "For example, an acceptable local mount point is /cdrom."
        echo ""
        echo ""
        echo -n "Press <ENTER> to continue: "
        set a = $<
        exit 1
    endif
endif

#    Verify that the installer is root:
#
#    If the installer is not root, inform them that the installation process
#    must be run as root. Prompt them for the root password (via su) and
#    execute the install script 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|Wavefront software, the installation procedure"
    echo "must be run as root. At this time, you may specify the root password to"
    echo "continue with the installation. If your machine does not have a root password,"
    echo "you will not be prompted and the installation will continue. If you don't know"
    echo "the root password, you will have to find someone who does before the software"
    echo "can be installed."
    echo ""
    @ i = 1
    while ($i <= 3)
        su - root -c "$cmd $argv"
        if ($status == 0) exit 0
        @ i++
    end
    echo ""
    echo "Three attempts to specify the root password have failed. Please try again"
    echo "later."
    echo ""
    echo -n "Press <ENTER> to continue: "
    set a = $<
    exit 1
endif

#    Determine if the installation(s) should be run in advanced (guru) mode:
#
#    If this script is called with the `-g' flag, all installations will
#    be performed in advanced mode (where applicable).

set MFL = ()
if ($#argv == 1) then
    if ("$1" == "-g") then
        set MFL = "-g"
    endif
endif

set STUD = 1
set DES = 2
set PANIM = 3
set ANIM = 4
set WANIM = 5
set ASTUD = 6
set REND = 7
set TABLETS = 8
set ACCT = 9

#    Ask the installer which product(s) they wish to install

top:

echo ""
echo "Which of the following Alias|Wavefront products do you wish to install:"
echo ""
echo "     $STUD) Alias|Wavefront Studio V8.2"
echo "     $DES) Alias|Wavefront Designer V8.2"
echo "     $PANIM) Alias|Wavefront PowerAnimator V8.2"
echo "     $ANIM) Alias|Wavefront Animator V8.2"
echo "     $WANIM) Alias|Wavefront Web|Animator V8.2"
echo "     $ASTUD) Alias|Wavefront AutoStudio V8.2"
echo "     $REND) Alias|Wavefront Render-Only Software V8.2"
echo "     $TABLETS) Alias|Wavefront Tablet Drivers and Tablet Customization"
echo "     $ACCT) Create/Update an Alias|Wavefront Demo Account"
echo ""
echo "Please specify which product(s) you wish to install. If you wish to"
echo "install more than one option, separate each of your choices with a"
echo "space. (A maximum of one of products $STUD to $REND may be specified, and"
echo "none, any or all of options $TABLETS and $ACCT)."
echo ""
echo "Option $ACCT is automatically executed if one of options 1-$REND are chosen."
echo ""
echo "If you do not wish to install any of the above products, leave the line"
echo "blank and press <ENTER>."

echo ""
echo -n "Please specify your choice(s): "

set ans = $<
set choice = ($ans)

#    If the installer did not specify any products to install, exit

if ($#choice == 0) then
    echo ""
    echo -n "Press <ENTER> to continue: "
    set a = $<
    exit 0
endif

#    Unset all the variables used for indicating which product(s) are to be
#    installed. This code serves two purposes:
#
#    - ensure the environment variables being used are not already set
#      (inherited from parent process).
#    - if the installer makes a mistake when choosing which products to
#      install, Install asks them to specify their choices again. The
#      variables must be unset to indicate that no products have been
#      chosen yet.

unsetenv STUD3D DES3D PANIM3D ANIM3D WANIM3D ASTUD3D REND3D
unset inst_tablets do_acct

@ inst_alias3d = 0
@ i = 1
while ($i <= $#choice)
    if ($choice[$i] == $TABLETS) then
        set inst_tablets
    else if ($choice[$i] == $ACCT) then
        set do_acct
    else if ($choice[$i] == $STUD) then
        @ inst_alias3d++
        setenv STUD3D 1
    else if ($choice[$i] == $DES) then
        @ inst_alias3d++
        setenv DES3D 1
    else if ($choice[$i] == $PANIM) then
        @ inst_alias3d++
        setenv PANIM3D 1
    else if ($choice[$i] == $ANIM) then
        @ inst_alias3d++
        setenv ANIM3D 1
    else if ($choice[$i] == $WANIM) then
        @ inst_alias3d++
        setenv WANIM3D 1
    else if ($choice[$i] == $ASTUD) then
        @ inst_alias3d++
        setenv ASTUD3D 1
    else if ($choice[$i] == $REND) then
        @ inst_alias3d++
        setenv REND3D 1
    else
        echo ""
        echo "Illegal product specification: $choice[$i]. Please try again."
        goto top
    endif
    @ i++
end

#    If the installer indicates that they wish to install more than one of:
#
#        Alias Studio V8.2
#        Alias Designer V8.2
#        Alias PowerAnimator V8.2
#        Alias Animator V8.2
#        Alias Web|Animator V8.2
#        Alias AutoStudio V8.2
#        Alias Render Software V8.2
#
#    inform them that only one of the products may be installed and ask
#    them to choose again.

if ($inst_alias3d > 1) then
    echo ""
    echo "Only one of:"
    echo ""
    echo "    Alias Studio V8.2"
    echo "    Alias Designer V8.2"
    echo "    Alias PowerAnimator V8.2"
    echo "    Alias Animator V8.2"
    echo "    Alias Web|Animator V8.2"
    echo "    Alias AutoStudio V8.2"
    echo "    Alias Render Software V8.2"
    echo ""
    echo "may be installed. Please try again."
    goto top
endif

#    If the installer chose to install one of the Alias products
#    and create/update an Alias user account, unset the "do account"
#    flag to prevent setupacct from being executed after it was executed
#    as part of a Alias software installation.
        
if ($inst_alias3d != 0 && $?do_acct) then
    unset do_acct
endif   

if ($inst_alias3d != 0) then
    echo ""
    $cdir/InstallScripts/InstallAlias $MFL
endif

if ($?do_acct) then
    echo ""
    setenv on_cd
    $cdir/Products/Alias3D/alias/bin/setupacct
endif

if ($?inst_tablets) then
    echo ""
    $cdir/InstallScripts/InstallTablet
endif

echo ""
echo "The installations are complete."
echo ""
echo -n "Press <ENTER> to continue: "
set a = $<
exit 0
