#!/bin/csh -f

##
## awupdate.Alias3D
##
## This command sets an standard user's environment such 
## that the Alias|Wavefront specific environment is properly
## set when the user logs in. This command need only be run
## once per AW user, after installation of new AW software.
##
## NOTE: only for 'csh' or 'tcsh' login-shell users.
##
## JNC - 29AUG95  
##  1995 Alias|Wavefront
##

# Where are we?

set pdir = `dirname $0`
set pname = $0
set template_dir = $pdir/skel

if ($#argv) then
    set users = ($*)
else
    set users = `whoami`
endif

#    Determine what product string to use in the echos to the user

set type = $pname:e
if ("$type" == "spaint") then
    set vers = "StudioPaint"
else
    set vers = "Alias"
endif

foreach auser ($users)

    if (! -d ~$auser) then
        echo ""
        echo "The $auser account does not appear to have a home directory."
        echo ""
        echo "It cannot be customized to use the $vers software."
        exit 1
    endif

    set tmp = .env_`date +%b%d`
    set a   = 1
    set save_dir = $tmp

    while (-e ~$auser/$save_dir)
        set save_dir = $tmp.$a
        @ a++
    end

    mkdir ~$auser/$save_dir >& /dev/null

    if ($status) then
        echo ""
        echo "Failed to make backup directory ~$auser/$save_dir"
        echo ""
        continue
    endif
    set rmsvdir

    cd $template_dir

    echo ""
    echo "Copying $vers 3D dot files ..."
    echo ""
    foreach f (.??* *)

#    Copy configuration files, saving pre-existing if necessary

        if (-e ~$auser/$f) then
            cmp -s $f ~$auser/$f
            if ($status == 0) continue
            echo "Saving original copy of ~$auser/$f as ~$auser/$save_dir/$f"
            mv ~$auser/$f ~$auser/$save_dir/$f
            unset rmsvdir
        endif

        if (-d $f) then
            cp -r $f ~$auser/$f
        else
            cp $f ~$auser/$f
        endif
    end

#    If no files were moved to the save directory, remove it.

    if ($?rmsvdir) then
        rmdir ~$auser/$save_dir
    endif
end
exit 0
