#!/bin/csh
#Tag 1024

#    Alinfo: Alias information gathering script

#    This script deliberately does not use the `-f' startup flag. Without it,
#    the user's .cshrc file is parsed, which allows shell aliases to be defined,
#    then displayed using the csh alias builtin command.

onintr bye

#    Before the script contaminates the user's shell environment, get the
#    output of set.

set > /tmp/set.$$
env > /tmp/env.$$
set setout = /tmp/set.$$
set envout = /tmp/env.$$

#    Set a fairly extensive command search path

set path = (/usr/bsd /usr/bin /usr/sbin /usr/lbin /bin /etc /sbin /usr/etc /usr/gfx)
set pname = $0
set pname = $pname:t
set VERS = 1.0
set hname = `hostname`
set wai = `whoami`

set symlink_to_alias = /usr/aw/alias

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 OUT = $TMPDIR/ALINFO.$wai@$hname

#    If the script is being executed by the superuser (root), explain that
#    it will gather system information pertaining to the local machine.
#
#    If one (or more) user accounts are having problems using the software,
#    explain that the script should be run by one of those users(s) in order
#    to ensure that any account specific information is collected.

set whoami = `id | cut -c6-11`
if ("$whoami" == "(root)") then
    echo ""
    echo "Since the $pname utility is being run by the superuser (root), it will"
    echo "gather system information concerning this specific machine. If you are"
    echo "having problems using the Alias|Wavefront software using one (or more)"
    echo "user account(s), you should execute this utility while logged into one"
    echo "of those user accounts, so that information specific to the user account"
    echo "may be recorded."
    echo ""
    echo -n "Do you wish to continue gathering system information? (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
endif

echo ""
echo "This utility will gather user and system information, writing it to the file"
echo "$OUT for later examination."
echo ""

if (-f $OUT) then
    echo ""
    echo "The file $OUT already exists. If you continue"
    echo "with the execution of this utility, $OUT will"
    echo "be overwritten."
    echo ""
    echo -n "Do you wish to continue gathering system information? (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
endif

echo "" > $OUT
echo "ALIAS|WAVEFRONT INFORMATION SCRIPT OUTPUT (Version $VERS) FOR $wai@${hname}:" >> $OUT
echo "" >> $OUT
echo "Contact information:" >> $OUT
echo "" >> $OUT

#    Prompt for the full name of the user and output it to the information
#    output file.

echo ""
while (1)
    echo -n "Please enter your full name: "
    set fname = $<
    set nels = $#fname
    if ($nels != 0) break
end

echo "Full Name: $fname" >> $OUT

#    Prompt for the company name of the user and output it to the information
#    output file.

while (1)
    echo -n "Please enter your company name: "
    set cname = $<
    set nels = $#cname
    if ($nels != 0) break
end

echo "Company Name: $cname" >> $OUT

#    Prompt for an email address for the user and output it to the information
#    output file.

echo -n "Please enter your email address (if any): "
set email = $<
set nels = $#email
if ($nels == 0) then
    set email = "None"
endif

echo "Email address: $email" >> $OUT
echo "" >> $OUT

#    Execute a series of user and system commands, echoing both the command
#    name and output to the information output file.

echo ""
echo "Executing the following commands as $wai@${hname}:"
echo ""
foreach cmd ("id -a" alias env set "tail errlog" "ls -al $HOME" "$symlink_to_alias/bin/getid -iv" "ls -l /usr/aw" "ls -l /usr/aw/COM2.0/bin" "ls -l /usr/aw/COM2.0/lib" "ls -l $symlink_to_alias/lib" "uname -aR" sysinfo hinv chkconfig "ls -l /dev/input" "versions -n" "lmutil lmhostid" "cat /var/flexlm/aw.dat")
    echo "    $cmd"
    set ncmd = ($cmd)
    set nels = $#ncmd
    set cmdname = $ncmd[1]

#    Determine the full pathname of the user or system level command for
#    inclusion in the information output file.

    set fpn = `which $cmdname`
    if ($#fpn == 1) then
        set ncmd[1] = $fpn
    endif
    echo "" >> $OUT
    echo "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=" >> $OUT
    echo "" >> $OUT
    echo $ncmd >> $OUT
    echo "" >> $OUT

#    Execute each user or system level command, saving its output in the
#    information output file. Remember that the output of the "set" and
#    "env" commands was generated above before the users shell environment
#    was contaminated.

    if ("$cmd" == "set") then
        cat $setout >> $OUT
        rm -f $setout
        continue
    else if ("$cmd" == "env") then
        cat $envout >> $OUT
        rm -f $envout
        continue
    endif
    $ncmd >>& $OUT
end

echo ""
echo ""
echo "In order to speed up a response to your problem, either email this file:"
echo ""
echo "    $OUT"
echo ""
echo "to Alias|Wavefront Assist (hotline@aw.sgi.com) or fax it to 416-362-1276."
echo "Email is preferred due to the large size of the file. Thank you."
echo ""

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