#!/bin/sh
#
#================== Copyright Notice =====================
# 
#Copyright (c) 1990 Universities Research Association, Inc.
#                  All Rights Reserved
# 
#=========================================================
#
# The primary functionality of the startup script is to provide the
# basic ups environment for the products which will be started as a
# result of sourcing the appropriate file.  No attempt is made to
# determine that the file being sourced is appropriate in other then
# name.
#
# The algorithm employed here looks in the PRODUCTS environment
# variable for directories of the form /.../.upsfiles/startup,
# /.../startup, or /.../../startup for startup files of the
# form $Node.products or $MACH_OS.products.  Where $Node is the
# unqualified name of the machine on which the script is executing and 
# $MACH_OS is the base level operating system name as returned by uname -s.  
#
# Only the first such file is sourced from the first directory in which 
# one is found. 
#
# The startup script was generated when ups was configured.
#

Script_Prefix=setups

Setups_Home=~products/etc

Ups_DB_Path=/fnal/ups/db

BootStrap_Dir=/fnal/ups/db/.upsfiles/configure/v4_3_Linux+2_

Setup_List=/fnal/ups/db/.upsfiles/startup

if test -x /bin/echo
then
    ECHO=/bin/echo
elif test  -x /usr/bin/echo
then
    ECHO=/usr/bin/echo
else
    ECHO=echo
fi

# ===== DO NOT EDIT BELOW THIS LINE  ====  DO NOT REMOVE THIS LINE ====

Setups_Current=1

if test $Setups_Current = 0
then
    Setups_Home=$BootStrap_Dir
fi

if test `echo $Setups_Home|cut -c1` != '/'
then
    TeMp=/tmp
    if test x${TMPDIR:-} != x
    then
        TeMp=$TMPDIR
    fi
    for sh in bash ksh ash sh
    do
	if test -x /usr/bin/${sh}
	then
	    Name_Of_Sh=/usr/bin/${sh}
	    break
	elif test -x /bin/${sh}
	then
	    Name_Of_Sh=/bin/${sh}
	    break
	fi
    done
    cat <<XxEoF >$TeMp/Ash_$$
#!${Name_Of_Sh}
eval dir=\$1
$ECHO \$dir
XxEoF
    chmod +x $TeMp/Ash_$$
    Setups_Home=`(unset ENV; $TeMp/Ash_$$ $Setups_Home )`
    rm -f $TeMp/Ash_$$ 
fi

# 
# set the appropriate environmental variables for root 
# 
if test x${PATH:-} != x
then
    PATH=$PATH:/bin:/usr/bin
else
    PATH=/bin:/usr/bin
fi
if test ! -f $Setups_Home/${Script_Prefix}.sh
then
    echo '****' $Name_Of_Ups initialization file 
    echo '****' $Setups_Home/${Script_Prefix}.sh not found
    exit 1
else	
    . $Setups_Home/${Script_Prefix}.sh
fi
                                              
Node=`uname -n|cut -f1 -d'.'`               
                                              
MACH_OS=`uname -s`                          
if test `echo $MACH_OS|cut -c1-4` = IRIX    
then                                          
    MACH_OS=IRIX                              
fi                                            

Boot_Start='yes'
#Boot_Start=`grep -i UPS_START $Ups_DB_Path/.upsfiles/dbconfig|grep -v '^#'|cut -f2 -d'='|sed 's% %%g'|tr 'A-Z' 'a-z'`
if test x${Boot_Start:-} = xyes
then
                                              
#for starts in $Startup_Home
for starts in `echo ${PRODUCTS}|tr ':' ' '`
do
    starts_dir=$starts
    if test ! -d $starts_dir
    then
	continue
    fi
    if test -d $starts/.upsfiles/startup
    then
	starts_dir=$starts/.upsfiles/startup
    elif test -d $starts/startup
    then
        starts_dir=$starts/startup
    elif test -d $starts/../startup
    then
        starts_dir=$starts/../startup
    fi
    started='0';
#
# execute the appropriate node.products file
#
    if test -f $starts_dir/$Node.products
    then 
	. $starts_dir/$Node.products
	started='1'
#
# execute the appropriate flavor.products file
# 
    elif test -f $starts_dir/$MACH_OS.products
    then
	. $starts_dir/$MACH_OS.products
	started='1'
    fi 
    if test $started = '1'
    then
	break
    fi
done
#
# If we made it this far, we found nothing to start
# Report the fact.
#
if test $started = '0'
then
    cat <<EoF
    '****'
    '****' No startup files were found - nothing done.
    '****'
EoF
fi
fi
