#!/bin/csh -f
#Tag 1024

#    Install: Master Alias Installation Script

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

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

#    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 software, the installation procedure must be"
    echo "run as root. At this time, you may specify the root password to continue"
    echo "with the installation. If your machine does not have a root password, you"
    echo "will not be prompted and the installation will continue. If you don't know"
    echo "the root password, you will have to find someone who does before the software"
    echo "can be installed."
    echo ""
    @ 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 ASTUD = 5
set REND = 6
set SPAINT = 7
set TABLETS = 8

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

top:

echo ""
echo "Which of the following products do you wish to install:"
echo ""
echo "    $STUD) Alias Studio V5.1.1"
echo "    $DES) Alias Designer V5.1.1"
echo "    $PANIM) Alias PowerAnimator V5.1.1"
echo "    $ANIM) Alias Animator V5.1.1"
echo "    $ASTUD) Alias AutoStudio V5.1.1"
echo "    $REND) Alias Render Software V5.1.1"
echo "    $SPAINT) Alias StudioPaint V1.1"
echo "    $TABLETS) Alias Tablet Drivers and Tablet Customization"
echo ""
echo "Please specify which product(s) you wish to install. If you wish to"
echo "install more than one product, separate each of your choices with a"
echo "space (Note that only one of products 1 to $REND may be specified). If"
echo "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 ASTUD3D REND3D
unset inst_spaint inst_tablets

@ inst_alias3d = 0
@ i = 1
while ($i <= $#choice)
    if ($choice[$i] == $SPAINT) then
        set inst_spaint
    else if ($choice[$i] == $TABLETS) then
        set inst_tablets
    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] == $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]."
    endif
    @ i++
end

#    If the installer indicates that they wish to install more than one of:
#
#        Alias Studio V5.1.1
#        Alias Designer V5.1.1
#        Alias PowerAnimator V5.1.1
#        Alias Animator V5.1.1
#        Alias AutoStudio V5.1.1
#        Alias Render Software V5.1.1
#
#    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 V5.1.1"
    echo "    Alias Designer V5.1.1"
    echo "    Alias PowerAnimator V5.1.1"
    echo "    Alias Animator V5.1.1"
    echo "    Alias AutoStudio V5.1.1"
    echo "    Alias Render Software V5.1.1"
    echo ""
    echo "may be installed. Please try again."
    goto top
endif

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

if ($?inst_spaint) then
    echo ""
    $cdir/InstallScripts/InstallSpaint $MFL
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
