#!/bin/sh
# Copyright (c) 1998 Universities Research Association, Inc.
#       All Rights Reserved
#
#
# This material resulted from work developed under a Government Contract and
# is subject to the following license:  The Government retains a paid-up,
# nonexclusive, irrevocable worldwide license to reproduce, prepare derivative
# works, perform publicly and display publicly by or for the Government,
# including the right to distribute to other Government contractors.  Neither
# the United States nor the United States Department of Energy, nor any of
# their employees, makes any warranty, express or implied, or assumes any
# legal liability or responsibility for the accuracy, completeness, or
# usefulness of any information, apparatus, product, or process disclosed, or
# represents that its use would not infringe privately owned rights.
#

Setups_Flag=SETUPS_DIR

StartUp_Flag=UPS_START

Setups_Products_Init_File=upsdb_list

Setups_Products_Script=setups_products_init.sh

Ups_Dir=$UPS_PROD_DIR

Name_Of_Ups=$UPS_PROD_NAME

Script_Prefix=set${Name_Of_Ups}

Setups_Advanced_Sh_Str="bash ksh ash sh"

#Setups_Products_Init_Default="\${Node}/products/ups_database \
#				/usr/products/ups_database \
#				/afs/fnal/ups/db"

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

if test x${Test_Prod_Dir:-} != x
then
    Ups_Dir=$Test_Prod_Dir
fi

error=0
if test x${Ups_Dir:-} = x
then
    echo UPS_PROD_DIR not set.  Configure exiting.
    error=1
fi

if test x${Name_Of_Ups:-} = x
then
    echo UPS_PROD_NAME not set. Configure exiting.
    error=1
fi

if test x${UPS_PROD_FLAVOR:-} = x
then
    echo UPS_PROD_FLAVOR not set. Configure exiting.
    error=1
fi

if test x${UPS_PROD_VERSION:-} = x
then
    echo UPS_PROD_VERSION not set.  Configure exiting.
    error=1
fi

if test x${Ups_DB_Path:-} = x
then
    echo Ups_DB_Path not set. Configure exiting.
    error=1
fi

if test $error = 1
then
    exit 1
fi
b_slash='\'
Node=`uname -n|cut -f1 -d'.'`

BootStrap_Dir=$Ups_DB_Path/.upsfiles/configure/${UPS_PROD_VERSION}_${UPS_PROD_FLAVOR}_${UPS_PROD_QUALIFIERS:-}

#
# Parse the SETUPS_PATH from the dbconfig file
#
if test -f $Ups_DB_Path/.upsfiles/dbconfig
then
    Setups_Home=`grep -i $Setups_Flag $Ups_DB_Path/.upsfiles/dbconfig|grep -v '#'|cut -f2 -d'='|sed 's% %%g'`
fi
if test x${Setups_Home:-} = x
then
    echo '**' $Setups_Flag not defined in $Ups_DB_Path/.upsfiles/dbconfig
    echo '**' Using /usr/local/etc
    Setups_Home=/usr/local/etc
else
    echo '**' $Setups_Flag defined as $Setups_Home in 
    echo '**' $Ups_DB_Path/.upsfiles/dbconfig
fi
if test -x /bin/echo
then
    ECHO=/bin/echo
elif test  -x /usr/bin/echo
then
    ECHO=/usr/bin/echo
else
    ECHO=echo
fi

Setups_Products_List_Home=$Setups_Home

if test `echo $Setups_Home|cut -c1` != '/'
then
    TeMp=/tmp
    if test x${TMPDIR:-} != x
    then
        TeMp=$TMPDIR
    fi
    for sh in $Setups_Advanced_Sh_Str
    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_Products_List_Home=`$TeMp/Ash_$$ $Setups_Home`
    rm -f $TeMp/Ash_$$
fi

if test ! -f $Setups_Products_List_Home/$Setups_Products_Init_File
then
    echo '****' $Setups_Products_List_Home/$Setups_Products_Init_File does not exist
    echo '****' Ups cannot be configured.
    echo '-------------------------------'
    echo Please copy $UPS_PROD_DIR/ups/$Setups_Products_Init_File.template
    echo to $Setups_Home/$Setups_Products_Init_File 
    echo and edit it as appropriate before reconfiguring ups.
    exit 1
fi

#
# determine the location for the startup and shutdown files.
# The startup and shutdown scripts need not live in the same
# directory as the startup and shutdown lists.
#

Startup_Home=${Ups_DB_Path}/.upsfiles

Configure_Date=`date`

if test ! -d $BootStrap_Dir
then
    mkdir -p $BootStrap_Dir
    if test ! -d $BootStrap_Dir
    then
	echo '****' Unable to create $BootStrap_Dir
	echo '****'
	echo '****' $Name_Of_Ups configure failure
	exit 1
    fi
fi

cp $UPS_PROD_DIR/ups/configure $BootStrap_Dir/.Write_Test
if test ! -f $BootStrap_Dir/.Write_Test
then
    echo '****' Unable to write to $BootStrap_Dir
    echo '****'
    echo '****' $Name_Of_Ups configure failure
    exit 1
fi
rm -f $BootStrap_Dir/*
if test -f $BootStrap_Dir/.write_Test
then
    echo ''
    echo '****' WARNING:  Cannot remove files from $BootStrap_Dir
    echo '****'           Configure may fail.  Continuing .......
    echo ''
fi
type_test=x`ls -l /usr/local/bin/funame|cut -c1-10|sed 's% %%g'|cut -c1`
if test $type_test = 'xl'
then
    echo ''
    echo '**' WARNING: Please ensure that /usr/local/bin/funame is linked
    echo '**           to' $UPS_PROD_DIR/bin/funame
    echo ''
elif test $type_test != 'x'
then
    echo ''
    echo '**' WARNING: Please convert /usr/local/bin/funame to become a symbolic link
    echo '**           to' $UPS_PROD_DIR/bin/funame
    echo ''
fi
type_Test=x`ls -l /usr/local/bin/dropit|cut -c1-10|sed 's% %%g'|cut -c1`
if test $type_test = 'xl'
then
    echo ''
    echo '**' WARNING: Please ensure that /usr/local/bin/dropit is linked
    echo '**           to' $UPS_PROD_DIR/bin/dropit
    echo ''
elif test $type_test != 'x'
then
    echo ''
    echo '**' WARNING: Please convert /usr/local/bin/dropit to become a symbolic link
    echo '**           to' $UPS_PROD_DIR/bin/dropit
    echo ''
fi
#
#
# Create the local copy of the cache file.
# This file MUST be a fresh copy to avoid complications.
#
if test -f $BootStrap_Dir/set${Name_Of_Ups}.cache.${UPS_PROD_FLAVOR}
then
    rm -f $BootStrap_Dir/set${Name_Of_Ups}.cache.${UPS_PROD_FLAVOR}
    if test -f $BootStrap_Dir/set${Name_Of_Ups}.cache.${UPS_PROD_FLAVOR}
    then
	echo '****' Unable to replace cache file in $BootStrap_Dir.
	echo '****' Existing copy could not be removed.
	echo '****' $Name_Of_Ups configure failure.
	exit 1
    fi
fi
cat <<XEoF >$BootStrap_Dir/set${Name_Of_Ups}.cache.${UPS_PROD_FLAVOR}
#
# This file was created when ${Name_Of_Ups} ${UPS_PROD_VERSION} 
# was configured on $Node.
# ${Configure_Date}
#
$UPS_PROD_DIR
XEoF

chmod +rx $BootStrap_Dir/set${Name_Of_Ups}.cache.${UPS_PROD_FLAVOR}

#
if test ! -x $BootStrap_Dir/$Setups_Products_Script
then
echo '**' Creating $BootStrap_Dir/$Setups_Products_Script
#
# Create the script to create PRODUCTS.  
#
cat <<XEoF >$BootStrap_Dir/$Setups_Products_Script 
#!/bin/sh
#
# Copyright (c) 1998 Universities Research Association, Inc.
#       All Rights Reserved
#
#
# This material resulted from work developed under a Government Contract and
# is subject to the following license:  The Government retains a paid-up,
# nonexclusive, irrevocable worldwide license to reproduce, prepare derivative
# works, perform publicly and display publicly by or for the Government,
# including the right to distribute to other Government contractors.  Neither
# the United States nor the United States Department of Energy, nor any of
# their employees, makes any warranty, express or implied, or assumes any
# legal liability or responsibility for the accuracy, completeness, or
# usefulness of any information, apparatus, product, or process disclosed, or
# represents that its use would not infringe privately owned rights.
#
# The $Setups_Products_Script script uses the information in the 
# $Setups_Home/$Setups_Products_Init_File which was 
# edited when $Name_Of_Ups database was established, if present.  
# If this information is missing, the $Setups_Products_Script 
# will default to a string created when $Name_Of_Ups was configured.
# This may not be entirely suitable in all cases.
#
# This script was generated when $Name_Of_Ups was configured.
#

BootStrap_Dir=$BootStrap_Dir

Products_String_File=$Setups_Products_Init_File

#Setups_Products_Init_Default="$Setups_Products_Init_Default"

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

if test \`echo \$Setups_Home|cut -c1\` != '/'
then
    TeMp=/tmp
    if test x\${TMPDIR:-} != x
    then
	TeMp=\$TMPDIR
    fi
    for sh in $Setups_Advanced_Sh_Str
    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=${b_slash}\$1
\$ECHO ${b_slash}\$dir
XxEoF
    chmod +x \$TeMp/Ash_\$$
    Setups_Home=\`(unset ENV; \$TeMp/Ash_\$$ \$Setups_Home )\`
    rm -f \$TeMp/Ash_\$$ 
fi

Products_List_Home=\$Setups_Home

Setups_Current=0

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

# 
# Define the node variables.  They're all the same, in case the user goofs.
#
Node=\`uname -n|cut -f1 -d'.'\`
node=\$Node; NODE=\$Node
#
# Find one of the PRODUCTS strings.  There should be several copies.
# the one in $Setups_Home is preferred.
# Other wise use the default created at configure time.
#
if test -r \$Products_List_Home/\$Products_String_File
then
    Products_String=\`cat \$Products_List_Home/\$Products_String_File|grep -v '^#'\`
    Products_String="\${UPS_EXTRA_DIR} \${Products_String}"
#elif test -r \$BootStrap_Dir/\$Products_String_File
#then
#    Products_String=\`cat \$BootStrap_Dir/\$Products_String_File|grep -v '^#'\`
#    Products_String="\${UPS_EXTRA_DIR} \${Products_String}"
else
#    Products_String="\${UPS_EXTRA_DIR} \${Setups_Products_Init_Default}"
    echo \$Products_List_Home/\$Products_String_File not found.
    echo ups was not properly configured.
    exit 1 
fi
#Products_String="\${Products_String:-} ${Ups_DB_Path:-}"
#
# Search the PRODUCTS string for existing directories.  They only 
# count if they exist.  Format the result as a UPSII PRODUCTS
# environment variable.
#
prod_set=no
for Prod in \${Products_String}
do
    TeMp=/tmp
    if test x\${TMPDIR:-} != x
    then
        TeMp=\$TMPDIR
    fi
    if test \`echo \$Prod|cut -c1\` != '/'
    then
    	for sh in $Setups_Advanced_Sh_Str
    	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=${b_slash}\$1
\$ECHO ${b_slash}\$dir
XxEoF
        chmod +x \$TeMp/Ash_\$$
        Prod=\`(unset ENV; \$TeMp/Ash_\$$ \$Prod )\`
        rm -f \$TeMp/Ash_\$$ 
    fi
    if test -d \$Prod
    then
	if test \$prod_set = no
        then
	    PRODUCTS=\$Prod
	    prod_set=yes

        elif test \`echo \$PRODUCTS|grep -c \$Prod\` = "0"
        then
	    PRODUCTS=\${PRODUCTS}:\${Prod}
	fi
    fi
done
#
# output the result as an eval string which will set the PRODUCTS environment
# variable in the invoking shell.  NOTE: this is shell family sensitive.
#
if test x\`echo \${PRODUCTS:-}|cut -c1\` = x/
then
    if test \$UPS_SHELL = sh
    then
        cat <<EoF
        PRODUCTS=\$PRODUCTS; export PRODUCTS;
EoF
    elif test \$UPS_SHELL = csh
    then
        cat <<EoF
        setenv PRODUCTS "\$PRODUCTS";
EoF
    fi
fi
XEoF
#
# End of the creation of the PRODUCTS script
#
# Make it executable.
#
chmod +x $BootStrap_Dir/$Setups_Products_Script
fi
#
#
# Create the setups.csh file in the bootstrap directory.
#
if test ! -f $BootStrap_Dir/${Script_Prefix}.csh
then
echo '**' Creating $BootStrap_Dir/${Script_Prefix}.csh
cat <<XEoF >$BootStrap_Dir/${Script_Prefix}.csh
#!/bin/csh
#
# Copyright (c) 1998 Universities Research Association, Inc.
#       All Rights Reserved
#
#
# This material resulted from work developed under a Government Contract and
# is subject to the following license:  The Government retains a paid-up,
# nonexclusive, irrevocable worldwide license to reproduce, prepare derivative
# works, perform publicly and display publicly by or for the Government,
# including the right to distribute to other Government contractors.  Neither
# the United States nor the United States Department of Energy, nor any of
# their employees, makes any warranty, express or implied, or assumes any
# legal liability or responsibility for the accuracy, completeness, or
# usefulness of any information, apparatus, product, or process disclosed, or
# represents that its use would not infringe privately owned rights.
#
# The ${Script_Prefix}.csh script is designed to be sourced at shell invocation
# including the time of login.  It uses several other scripts located
# in $Setups_Home to determine the 
# PRODUCTS and UPS_DIR environment variables. 

# This script is sourced by the fermi.csh files to bootstrap the
# ups working environment and aliases.
# If you need to reestablish missing aliases in a subshell process,
# use the following code:
#    source \`\${UPS_DIR}/bin/ups setup ups\`
# 
# This script and all the scripts utilized are created when a version 
# of $Name_Of_Ups is configured.
#
# The scripts utilized by the ${Script_Prefix}.csh script are:
# 
#    $Setups_Home/$Setups_Products_Script
#
#    $Setups_Home/${Script_Prefix}.common,
#     as a last resort.
#
#    $Setups_Home/set${Name_Of_Ups}.cache.'<flavor>' 
#    is used to determine the UPS_DIR variable.
#

set Setups_Home=$Setups_Home

set BootStrap_Dir=$BootStrap_Dir

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


set Setups_Current=0

if ( \$Setups_Current == 0 ) then
    set Setups_Home=\$BootStrap_Dir
endif

setenv SETUPS_DIR \$Setups_Home

setenv Setups_Home \$Setups_Home

set Name_Of_Ups=$Name_Of_Ups
setenv UPS_SHELL csh
#
# Determine probable flavor names for the version of $Name_Of_Ups
# which would execute on this platform.
#
setenv MACH_OS \`uname -s\`
set mach=\`echo \$MACH_OS|cut -c1-4\`
if ( \$mach == IRIX ) setenv MACH_OS IRIX
set Flavor=\$MACH_OS'+'\`uname -r|cut -f1 -d'.'\`
if ( \$MACH_OS == AIX ) set Flavor=\$MACH_OS'+'\`uname -v\`
if ( \$MACH_OS == HP-UX ) set Flavor=\$MACH_OS'+'\`uname -r|cut -f2 -d'.'\`
#
# Define the PRODUCTS variable, if needed
#
if (  ! \$?PRODUCTS ) then
    if ( -x \${Setups_Home}/$Setups_Products_Script ) then
        eval \`\${Setups_Home}/$Setups_Products_Script\`
    endif
endif
if ( \$?UPS_DIR ) then
    if ( x\`echo \$UPS_DIR|cut -c1\` != x/ ) then
        unsetenv UPS_DIR
        unset UPS_DIR
    endif
else
    unsetenv UPS_DIR
    unset UPS_DIR
endif
#
# Attempt to determine the file name of the cached ups information from the 
# naming convention and the probable flavors which might execute correctly
# on the platform executing this script.  If found, utilize it to define
# a usable UPS_DIR.
#
if ( \$?PRODUCTS && ! \$?UPS_DIR ) then
    foreach fl ( \$Flavor \$MACH_OS NULL )
        if ( -r \${Setups_Home}/set\${Name_Of_Ups}.cache.\${fl} ) then
	    setenv UPS_DIR \`cat \$Setups_Home/set\${Name_Of_Ups}.cache.\${fl}|grep -v '^#'\`
            if ( \$?UPS_DIR ) then
               if ( -d \$UPS_DIR ) then
	             break
                else
                    unsetenv UPS_DIR
                endif
            endif
        endif
    end
endif
#
# If we have been unsuccessful so far, search the possible products 
# databases for some $Name_Of_Ups which might execute on the this platform.
#
# This process, although thorough, is very time consuming.
#
if ( ! \$?UPS_DIR ) then
    if ( -x \$Setups_Home/${Script_Prefix}.common ) then
	eval \`\$Setups_Home/${Script_Prefix}.common\`
    endif
endif
#
# If everything failed, report same and return.
#
# DO NOT EXIT - this might be the login shell.
#
if (! \$?UPS_DIR ) then
    echo '****'
    echo '**** Unable to initialize the UPSII environment'
    echo '****'
else
#
# If we have successfully managed to find a usable version of $Name_Of_Ups,
# give this version of $Name_Of_Ups the information  found so far and let it 
# determine the BEST version.
#
# This extra step ensures that the appropriate $Name_Of_Ups search order
# is followed to arive at the final result.  It also is the step executed
# even when PRODUCTS and UPS_DIR are known at entry.  The $Name_Of_Ups 
# setup script may set aliases which are NOT inherited by sub-shells.
#
#
    source \`\$UPS_DIR/bin/ups setup \$Name_Of_Ups\`
endif
#
# Because this is designed to be sourced, it is nice to unset the local
# shell variables
#
unset NODE
unset node
unset BootStrap_Dir
unset Setups_Current

unset mach
unset fl
unset Flavor
unset Setups_Home
unset Name_Of_Ups
unsetenv Setups_Home
XEoF
fi
#
#
# Create, if necessary, the setups.sh script
#
if test ! -f $BootStrap_Dir/${Script_Prefix}.sh
then
echo '**' Creating $BootStrap_Dir/${Script_Prefix}.sh
cat <<XEoF >$BootStrap_Dir/${Script_Prefix}.sh
#!/bin/sh
#
# Copyright (c) 1998 Universities Research Association, Inc.
#       All Rights Reserved
#
#
# This material resulted from work developed under a Government Contract and
# is subject to the following license:  The Government retains a paid-up,
# nonexclusive, irrevocable worldwide license to reproduce, prepare derivative
# works, perform publicly and display publicly by or for the Government,
# including the right to distribute to other Government contractors.  Neither
# the United States nor the United States Department of Energy, nor any of
# their employees, makes any warranty, express or implied, or assumes any
# legal liability or responsibility for the accuracy, completeness, or
# usefulness of any information, apparatus, product, or process disclosed, or
# represents that its use would not infringe privately owned rights.
#
# The ${Script_Prefix}.sh script is designed to be sourced at shell invocation
# including the time of login.  It uses several other scripts located in  
# $Setups_Home to determine the 
# PRODUCTS and UPS_DIR environment variables.This script and all the 
# scripts utilized are created when a version of $Name_Of_Ups is configured.

# This script is sourced by the fermi.sh files to bootstrap the
# ups working environment and aliases.
# If you need to reestablish missing aliases in a subshell process,
# use the following code:
#    . \`\${UPS_DIR}/bin/ups setup ups\`
# 
# NOTE: The '.' in the preceeding line is significant.
#
# The scripts utilized by the ${Script_Prefix}.sh script are:
# 
#    $Setups_Home/$Setups_Products_Script
#
#    $Setups_Home/${Script_Prefix}.common,
#    as a last resort.
#
#    $Setups_Home/set${Name_Of_Ups}.cache.'<flavor>' 
#    is used to determine the value of UPS_DIR.
#    
#
# ===		SYS ADMIN AREA		=====
#
# The following shell variables are defined here:
#
#       Setups_Home
#
#       Name_Of_Ups
#
# Please check their values and change, if necessary, following
# their descriptions below.
#
#
# Because the shell languages manage to lose the filename
# of the file being sourced the Setups_Home variable
# exists to assist in installing the codes on non Fermilab
# machines.  Change this to the directory in which the
# setups.* scripts live.

Setups_Home=$Setups_Home

# Name_Of_Ups should always be ups at Fermilab, unless in beta test

Name_Of_Ups=$Name_Of_Ups

BootStrap_Dir=$BootStrap_Dir
  
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 ===


if test \`echo \$Setups_Home|cut -c1\` != '/'
then
    TeMp=/tmp
    if test x\${TMPDIR:-} != x
    then
        TeMp=\$TMPDIR
    fi
    for sh in $Setups_Advanced_Sh_Str
    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=${b_slash}\$1
\$ECHO ${b_slash}\$dir
XxEoF
    chmod +x \$TeMp/Ash_\$$
    Setups_Home=\`(unset ENV; \$TeMp/Ash_\$$ \$Setups_Home )\`
    rm -f \$TeMp/Ash_\$$ 
fi

export Setups_Home

Setups_Current=0

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

SETUPS_DIR=\$Setups_Home; export SETUPS_DIR

UPS_SHELL=sh; export UPS_SHELL
#
# Determine probable flavor names for the version of $Name_Of_Ups
# which would execute on this platform.
#
Node=\`uname -n|cut -f1 -d'.'\`
MACH_OS=\`uname -s\`
if test \`echo \$MACH_OS|cut -c1-4\` = IRIX
then
    MACH_OS=IRIX
fi
export MACH_OS
Flavor=\$MACH_OS'+'\`uname -r|cut -f1 -d'.'\`
if test \$MACH_OS = AIX
then
    Flavor=\$MACH_OS'+'\`uname -v\`
fi
if test \$MACH_OS = HP-UX
then
    Flavor=\$MACH_OS'+'\`uname -r|cut -f2 -d'.'\`
fi
if test x\`echo \${UPS_DIR:-}|cut -c1\` = x/
then
    if test ! -d \$UPS_DIR
    then
	unset UPS_DIR
    fi
else
	unset UPS_DIR
fi
#
# Attempt to define the PRODUCTS variable.
#
if test x\`echo \${PRODUCTS:-}|cut -c1\` != x/
then
    if test -x \${Setups_Home}/$Setups_Products_Script 
    then
        eval \`(unset ENV;\${Setups_Home}/$Setups_Products_Script)\`
    fi   
fi
#
# Attempt to determine the file name of the cached ups information from the 
# naming convention and the probable flavors which might execute correctly
# on the platform executing this script.  If found, utilize it to define
# a UPS_DIR.
#
if test x\`echo \${PRODUCTS:-}|cut -c1\` = x/ -a x\$UPS_DIR = x
then
    for fl in \$Node \$Flavor \$MACH_OS NULL
    do
        if test -r \$Setups_Home/set\${Name_Of_Ups}.cache.\${fl}
        then
            UPS_DIR=\`cat \$Setups_Home/set\${Name_Of_Ups}.cache.\${fl}|grep -v '^#'\`
        fi
        if test x\${UPS_DIR:-} != x
        then
            if test -d \$UPS_DIR
            then
                break
            else
                unset UPS_DIR
            fi
        fi
   done
fi
#
# If we have been unsuccessful so far, search the possible products 
# databases for some $Name_Of_Ups which might execute on this platform.
#
# This process, although thorough, is very time consuming.
#
if test x\${UPS_DIR:-} = x
then
    if test -x \$Setups_Home/${Script_Prefix}.common
    then
        eval \`(unset ENV;\$Setups_Home/${Script_Prefix}.common sh)\`
    fi
fi
if test x\${UPS_DIR:-} != x
then
#
# If we have successfully managed to find a usable version of $Name_Of_Ups,
# give this version of $Name_Of_Ups the information  found so far and let it 
# determine the BEST version.
#
# This extra step ensures that the appropriate $Name_Of_Ups search order is
# followed to arive at the final result.  It also is the step executed even
# when PRODUCTS and UPS_DIR are known at entry.  The $Name_Of_Ups setup script
# may define functions which are NOT inherited by sub-shells.
#
	. \`\$UPS_DIR/bin/ups setup \$Name_Of_Ups\`
else
#
# If everything failed, report same and return.
#
# DO NOT EXIT - this might be the login shell.
#
	echo '****'
	echo '**** Unable to initialize UPSII environment'
	echo '****'
fi
#
# Because this is designed to be "sourced", its nice to unset the shell
# variables.
#
unset Node
unset BootStrap_Dir
unset Setups_Current
unset fl
unset Flavor
unset Setups_Home
unset BootStrap_Dir
unset Name_Of_Ups
XEoF
#
# End of the creation of the setups.sh script.  
#
fi
#
#
# Create the startup and shutdown scripts.
#
 
Boot_Start='yes'
#Boot_Start=`grep -i $StartUp_Flag $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 Start_Or_Stop in startup shutdown
do
rm -f $BootStrap_Dir/ups_${Start_Or_Stop}
echo '**' Creating $BootStrap_Dir/ups_${Start_Or_Stop}
cat <<XEoF >$BootStrap_Dir/ups_${Start_Or_Stop}
#!/bin/sh
#
#================== Copyright Notice =====================
# 
#Copyright (c) 1990 Universities Research Association, Inc.
#                  All Rights Reserved
# 
#=========================================================
#
# The primary functionality of the $Start_Or_Stop 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/${Start_Or_Stop},
# /.../${Start_Or_Stop}, or /.../../${Start_Or_Stop} for ${Start_Or_Stop} 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 $Start_Or_Stop script was generated when $Name_Of_Ups was configured.
#

Script_Prefix=$Script_Prefix

Setups_Home=$Setups_Home

Ups_DB_Path=$Ups_DB_Path

BootStrap_Dir=$BootStrap_Dir

Setup_List=${Ups_DB_Path}/.upsfiles/${Start_Or_Stop}

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=0

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 $Setups_Advanced_Sh_Str
    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=${b_slash}\$1
\$ECHO ${b_slash}\$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 $StartUp_Flag \$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/$Start_Or_Stop
    then
	starts_dir=\$starts/.upsfiles/$Start_Or_Stop
    elif test -d \$starts/$Start_Or_Stop
    then
        starts_dir=\$starts/$Start_Or_Stop
    elif test -d \$starts/../$Start_Or_Stop
    then
        starts_dir=\$starts/../$Start_Or_Stop
    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 $Start_Or_Stop files were found - nothing done.
    '****'
EoF
fi
fi
XEoF
chmod 0771 $BootStrap_Dir/ups_${Start_Or_Stop}
done
fi
#
#
# Create the setups.common.  It is sincerely hoped that 
# this will never be needed.
#
# IT IS  V E R  Y    S   L    O     W
#
if test ! -r $BootStrap_Dir/${Script_Prefix}.common
then
    echo '**' Creating $BootStrap_Dir/${Script_Prefix}.common
    cat <<XEoF > $BootStrap_Dir/${Script_Prefix}.common 
#!/bin/sh 
# Copyright (c) 1998 Universities Research Association, Inc.
#       All Rights Reserved
#
#
# This material resulted from work developed under a Government Contract and
# is subject to the following license:  The Government retains a paid-up,
# nonexclusive, irrevocable worldwide license to reproduce, prepare derivative
# works, perform publicly and display publicly by or for the Government,
# including the right to distribute to other Government contractors.  Neither
# the United States nor the United States Department of Energy, nor any of
# their employees, makes any warranty, express or implied, or assumes any
# legal liability or responsibility for the accuracy, completeness, or
# usefulness of any information, apparatus, product, or process disclosed, or
# represents that its use would not infringe privately owned rights.
#
# Setups common
#
# This is the work-horse of the setupsII family.  The primary
# function is to determine where the "current" version of ups
# suitable to be executed on the resident node is located.
#
# This file was created by the $Name_Of_Ups configure script when
# $Name_Of_Ups was installed.
#
#
#
# ===			SYS ADMIN AREA 			===
#
# The following shell variables are defined here:
#
#	Setups_Home_Dir
#
#	Setups_Product_Init_File
#
#	Name_Of_Ups
#
# Please check their values and change, if necessary, following 
# their descriptions below.
#
#	
# Because the shell languages manage to lose the filename
# of the file being sourced, the Setups_Home_Dir variable
# exists to assist in installing the codes on non Fermilab
# machines.  Change this to the directory in which the
# setups.* scripts live.

Setups_Home_Dir=\$Setups_Home

Setups_Product_Init_File=$Setups_Products_Init_File

Name_Of_Ups=$Name_Of_Ups

BootStrap_Dir=$BootStrap_Dir
#
# The following sets the default value for the product_string.
# Later logic will attempt to find the value defined when 
# the database was initialized
#

#Product_String="$Setups_Products_Init_Default $Ups_DB_Path"

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

Setups_Current=0

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

Shell=\$UPS_SHELL

Node=\`uname -n|cut -f1 -d'.'\`

if test -r \$Setups_Home_Dir/\$Setups_Product_Init_File
then
	Product_String=\`cat \$Setups_Home_Dir/\$Setups_Product_Init_File|grep -v '^#'\`
fi
#
# Determine a likely flavor to search for.  The actual search 
# should find something useful on this platform.
#
MACH_OS=\`uname -s\`
if test \`echo \$MACH_OS|cut -c1-4\` = IRIX
then
    MACH_OS=IRIX
fi
export MACH_OS
r=\`uname -r|cut -f1 -d'.'\`
if test \$MACH_OS = AIX
then
    r=\`uname -v\`
fi
if test \$MACH_OS = HP-UX
then
    r=\`uname -v|cut -f2 -d'.'\`
fi
Flavor_Wanted=\${MACH_OS}+\${r}
# 
# All right.  Now $Name_Of_Ups is still a $Name_Of_Ups product
# as such it must live in a PRODUCTS database.
#
# Find the PRODUCTS databases.
#
if test "x\`echo \${PRODUCTS:-}|cut -c1\`" != "x/"
then
    prodset=no
    for Prod in \$Product_String
    do
        if test -d \$Prod
        then
	    if test \$prodset = no
            then
		PRODUCTS=\$Prod
		prodset=yes
            elif test \`echo \$PRODUCTS|grep -c \$Prod\` = "0"
            then
                PRODUCTS="\$PRODUCTS' '\${Prod}"
            fi
        fi
    done
fi
#
# Now for the time consuming search of the PRODUCTS for an 
# appropriate 'current' version of $Name_Of_Ups.
#
if test "x\`echo \${PRODUCTS:-}|cut -c1\`" = "x/"
then
    PRODUCTS=\`echo \$PRODUCTS|tr ':' ' '\`
    prodset=no
    for Prod in \${PRODUCTS}
    do
	if test \$prodset = no
	then
	    Pstr_new=\$Prod
	    prodset=yes
	else
	    Pstr_new="\${Pstr_new}':'\${Prod}"
	fi
#
# It is legal to declare ups to its database with a relative chain
# On the off chance that this was done, parse out the PROD_DIR_PREFIX
# from the dbconfig file.
#
	if test -r \$Prod/.upsfiles/dbconfig
	then
	    Ups_Pre=\`grep -i PROD_DIR_PREFIX  \$Prod/.upsfiles/dbconfig|grep -v '#'|cut -f2 -d'='|sed 's% %%g'\`
	fi
	if test -r \$Prod/\${Name_Of_Ups}/current.chain
	then
	    Parse_curr=\$Prod/\${Name_Of_Ups}/current.chain
	    while read string
	    do	
		key=\`echo \$string|cut -f1 -d'=' -s|tr 'a-z' 'A-Z'|sed 's% %%g'\`
		val=\`echo \$string|cut -f2 -d'=' -s|cut -f1 -d'#'|sed 's% %%g'\`
		if test x\${val} != x
		then
		    if test "\$key" = "FLAVOR"
		    then
			FLAVOR=\$val
		    elif test "\$key" = "VERSION"
		    then
			VERSION=\$val
		    fi
		fi
		if test x\${VERSION} != x -a x\${FLAVOR} != x
		then
		    if test \$FLAVOR = \$Flavor_Wanted -o \$FLAVOR = \$MACH_OS
		    then
			Ups_Version_File=\${VERSION}.version
			Ups_Flavor=\$FLAVOR
			Ups_Version=\$VERSION
			Parse_ver=\$Prod/\${Name_Of_Ups}/\$Ups_Version_File
        		while read string
        		do
            		    key=\`echo \$string|cut -f1 -d'='|tr 'a-z' 'A-Z'|sed 's% %%g'\`
            		    val=\`echo \$string|cut -f2 -d'=' -s|cut -f1 -d'#'|sed 's% %%g'\`
            		    if test "x\${key}" = xFLAVOR
            		    then
                		FLAVOR=\$val
            		    fi
            		    if test "x\${key}" = xPROD_DIR
            		    then
                		PROD_DIR=\$val
            		    fi
            		    if test x\${FLAVOR} != x -a x\${PROD_DIR} != x
            		    then
                		if test \$FLAVOR = \$Ups_Flavor
                		then
				    First_C=\`echo \$PROD_DIR|cut -c1\`
				    if test x\${First_C} != "x/"
				    then
					PROD_DIR=\${Ups_Pre}/\${PROD_DIR}
				    fi
				    if test ! -d \$PROD_DIR
				    then
					continue
				    fi
                    		    UPS_DIR=\$PROD_DIR;export UPS_DIR
				    export PRODUCTS
    				    if test \$Shell = 'sh'
    				    then
        				cat <<EoF
        				PRODUCTS="\${Pstr_new}"; export PRODUCTS;
        				UPS_DIR=\$UPS_DIR; export UPS_DIR;
EoF
    				    elif test \$Shell = 'csh'
    				    then
        				cat <<EoF
        				setenv PRODUCTS "\${Pstr_new}";
        				setenv UPS_DIR \$UPS_DIR;
EoF
    				    else
        				cat <<EoF
        				echo '**';
        				echo '**' Shell class "\$Shell" unknown;
        				echo '**';
EoF
				    fi
				    touch /tmp/.__SeTuPs_.\$$
                    		    break	# exit while read version file
                		fi
            		    FLAVOR=''
            		    PROD_DIR=''
            		    fi
        		done < \$Parse_ver
			rm -f /tmp/VSeTuPs.\$$
			if test -r /tmp/.__SeTuPs_.\$$
			then
			    break	# exit while read current.chain
			fi
		    fi
		    FLAVOR=''
		    VERSION=''
		fi
	    done < \$Parse_curr
	    rm -f /tmp/.SeTuPs.\$$
	    if test -r /tmp/.__SeTuPs_.\$$
	    then
		break	# Exit for Prod
	    fi
        fi
    done        # End of for Prod

rm -f /tmp/.__SeTuPs_.\$$
fi
XEoF
#
# End of the creation phase of setups.common
fi
# Make setups.common executable
#
chmod +x $BootStrap_Dir/${Script_Prefix}.common
#
#
#                        U P S   S U B - D I R E C T O R Y
#
# Begin the creation phase for the usual ups scripts
#
# Create the current script
#
if test -r $BootStrap_Dir/current
then
    rm -f $BootStrap_Dir/current
fi
echo '**' Creating $BootStrap_Dir/current
cat <<XEoF >$BootStrap_Dir/current
#!/bin/sh
# Copyright (c) 1998 Universities Research Association, Inc.
#       All Rights Reserved
#
#
# This material resulted from work developed under a Government Contract and
# is subject to the following license:  The Government retains a paid-up,
# nonexclusive, irrevocable worldwide license to reproduce, prepare derivative
# works, perform publicly and display publicly by or for the Government,
# including the right to distribute to other Government contractors.  Neither
# the United States nor the United States Department of Energy, nor any of
# their employees, makes any warranty, express or implied, or assumes any
# legal liability or responsibility for the accuracy, completeness, or
# usefulness of any information, apparatus, product, or process disclosed, or
# represents that its use would not infringe privately owned rights.
#
# Current script for $Name_Of_Ups
#
# This file is created by the $Name_Of_Ups product configure script.
#
# The primary function of this script is to copy the files from 
# the bootstrap sub-directory of the $Name_Of_Ups product to the 
# $Setups_Home 
# directory, if needed.
#

Name_Of_Ups=$Name_Of_Ups

Setups_Home=$Setups_Home

Startup_Home=$Startup_Home

BootStrap_Dir=$BootStrap_Dir

# Setups_Products_Init_File=$Setups_Products_Init_File

# Setups_Products_Script=$Setups_Products_Script

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

Ups_Dir=$UPS_PROD_DIR

if test x\${Test_Prod_Dir} != x
then
    Ups_Dir=\$Test_Prod_Dir
fi

error='0'
if test ! -f \$BootStrap_Dir/${Script_Prefix}.common
then
    echo '****' Configure script has failed or was not executed.
    echo '****' \$Name_Of_Ups current script cannot execute.
    exit 1
fi

if test \`echo \$Setups_Home|cut -c1\` != '/'
then
    TeMp=/tmp
    if test x\${TMPDIR:-} != x
    then
        TeMp=\$TMPDIR
    fi
    for sh in $Setups_Advanced_Sh_Str
    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=${b_slash}\$1
\$ECHO ${b_slash}\$dir
XxEoF
    chmod +x \$TeMp/Ash_\$$
    Setups_Home=\`(unset ENV; \$TeMp/Ash_\$$ \$Setups_Home )\`
    rm -f \$TeMp/Ash_\$$ 
fi

if test ! -d \$Setups_Home
then
    mkdir \$setups_Home
fi

if test ! -d \$Setups_Home
then
    echo '****' Unable to create \$Setups_Home
    exit 1
fi
#
# If the $Setups_Home
# is in AFS space, 
# force it to the read/write area.
#
# The following algorithm is known to be overly simplistic
# A better one is in the works
# However, this should work most of the time at Fermilab
#
cp $UPS_PROD_DIR/ups/configure \$Setups_Home/.Write_Test
if test ! -f \$Setups_Home/.Write_Test
then
    Setups_Home=\`echo \$Setups_Home|sed 's%/afs/fnal/products%/afs/.fnal.gov/products%'\`
    Setups_Home=\`echo \$Setups_Home|sed 's%/afs/fnal.gov/products%/afs/.fnal.gov/products%'\`
fi
cp $UPS_PROD_DIR/ups/configure \$Setups_Home/.Write_Test
if test ! -f \$Setups_Home/.Write_Test
then
    echo '****' Unable to write to \$Setups_Home
    echo '****' \$Name_Of_Ups current script failure
    exit 1
else
    rm -f \$Setups_Dir/.Write_Test
    chmod +rx \$Setups_Home
fi
#
# Mark ALL BootStrap files current.
#
rm -f /tmp/ups_cur_\$$
for filex in \$BootStrap_Dir/set* \$BootStrap_Dir/ups*
do
#    ed -  \$filex <\$BootStrap_Dir/zzzzzzzzzz >/dev/null
    sed -e 's/Setups_Current=0/Setups_Current=1/' \$filex >/tmp/ups_cur_\$$
    cp /tmp/ups_cur_\$$ \$filex
    rm /tmp/ups_cur_\$$
done
#
# Move all the files from the bootstrap directory to 
# $Setups_Home
# Only move the files which have changed
#
    for filex in \$BootStrap_Dir/set*
    do
        Diff_rc='0'
	file=\`echo \$filex|sed "s%\$BootStrap_Dir/%%"\`
        if test ! -f \$Setups_Home/\$file
        then
            Diff_rc='1'
        else
            diff -b \$BootStrap_Dir/\$file \$Setups_Home/\$file >/dev/null
            Diff_rc=\$?
        fi
        if test \$Diff_rc != '0'
        then
	    echo '**' Copying \$file to \$Setups_Home
	    if test -f \$Setups_Home/\$file
	    then
		cp  \$Setups_Home/\$file \$Setups_Home/\${file}.BAK
	    fi
            cp \$BootStrap_Dir/\$file \$Setups_Home
	    if test \$? != '0'
	    then
		error='1'
		echo '****' An error has prevented the copy of
		echo '****' \$BootStrap_Dir/\$file to 
		echo '****' \$Setups_Home
	    fi
	    chmod +x \$Setups_Home/\$file
	else
	    echo '**' \$file identical to \$Setups_Home/\$file - not copied.
        fi
    done

if test \$error = '1'
then
    echo '**** Error(s) have caused the current script to fail'
    exit 1
fi
#
# Copy the startup and shutdown scripts to their final
# resting place. This is sensitive to the structure
# of the directory path.  Sub-directories may need to
# be to be created.
#
for Start_Or_Stop in startup shutdown
do
    if test -f \$BootStrap_Dir/ups_\${Start_Or_Stop}
    then
	if test \`echo \$Startup_Home|grep -c '.upsfiles'\` != 0
	then
 	    if test ! -d \$Startup_Home/\$Start_Or_Stop
	    then
	        mkdir \$Startup_Home/\$Start_Or_Stop
	    fi
	    echo '**' Copying ups_\${Start_Or_Stop} to \$Startup_Home/\$Start_Or_Stop
    	    cp \$BootStrap_Dir/ups_\${Start_Or_Stop} \$Startup_Home/\${Start_Or_Stop}/ups_\${Start_Or_Stop}
            cp  \$BootStrap_Dir/ups_\${Start_Or_Stop} \$Startup_Home/\${Start_Or_Stop}/ups_\${Start_Or_Stop}.sh       
            cp  \$BootStrap_Dir/ups_\${Start_Or_Stop} \$Startup_Home/\${Start_Or_Stop}/ups_\${Start_Or_Stop}.csh
	    chmod +x \$Startup_Home/\${Start_Or_Stop}/ups_\${Start_Or_Stop}
	    chmod +x \$Startup_Home/\${Start_Or_Stop}/ups_\${Start_Or_Stop}.csh
	    chmod +x \$Startup_Home/\${Start_Or_Stop}/ups_\${Start_Or_Stop}.sh
	else
	    cp  \$BootStrap_Dir/ups_\${Start_Or_Stop} \$Startup_Home/ups_\${Start_Or_Stop}
	    cp  \$BootStrap_Dir/ups_\${Start_Or_Stop} \$Startup_Home/ups_\${Start_Or_Stop}.sh 
	    cp  \$BootStrap_Dir/ups_\${Start_Or_Stop} \$Startup_Home/ups_\${Start_Or_Stop}.csh 
	    chmod +x \$Startup_Home/ups_\${Start_Or_Stop}
	    chmod +x \$Startup_Home/ups_\${Start_Or_Stop}.csh
	    chmod +x \$Startup_Home/ups_\${Start_Or_Stop}.sh
	fi     
   fi
done

echo '**' Current script completed successfully
    
XEoF
#
# End of the creation of the current script
#
# Make it executable
#
chmod +x $BootStrap_Dir/current
#
#
# Create the uncurrent script
#
    rm -f $BootStrap_Dir/uncurrent
echo '**' Creating $BootStrap_Dir/uncurrent
cat <<XEoF >$BootStrap_Dir/uncurrent
#!/bin/sh
# Copyright (c) 1998 Universities Research Association, Inc.
#       All Rights Reserved
#
#
# This material resulted from work developed under a Government Contract and
# is subject to the following license:  The Government retains a paid-up,
# nonexclusive, irrevocable worldwide license to reproduce, prepare derivative
# works, perform publicly and display publicly by or for the Government,
# including the right to distribute to other Government contractors.  Neither
# the United States nor the United States Department of Energy, nor any of
# their employees, makes any warranty, express or implied, or assumes any
# legal liability or responsibility for the accuracy, completeness, or
# usefulness of any information, apparatus, product, or process disclosed, or
# represents that its use would not infringe privately owned rights.
#
# The ups product uncurrent script
#
# The goal of this script is to prevent the overlapping of cache data.
# One of the problems with the caching of setups data is that the data
# could wind up pointing to a non-current product instance.  The
# instance might even have been removed.
#
# This script attempts to remove the cache file associated with the
# product flavor.  The uncurrent phase of ups will make the instance
# non-current.
#
# Should the removal phase fail, an error message will be printed
# with a suggested course of action.
#
# This file was created when the $Name_Of_Ups product was configured.
#

Name_Of_Ups=$Name_Of_Ups

Setups_Home=$Setups_Home

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=0

if test \$Setups_Current = 0
then
    echo '****' \$Name_Of_Ups \$UPS_PROD_VERSION \$UPS_PROD_FLAVOR
    echo '****' is not current.
    exit
fi

if test \`echo \$Setups_Home|cut -c1\` != '/'
then
    TeMp=/tmp
    if test x\${TMPDIR:-} != x
    then
        TeMp=\$TMPDIR
    fi
    for sh in $Setups_Advanced_Sh_Str
    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=${b_slash}\$1
\$ECHO ${b_slash}\$dir
XxEoF
    chmod +x \$TeMp/Ash_\$$
    Setups_Home=\`(unset ENV; \$TeMp/Ash_\$$ \$Setups_Home )\`
    rm -f \$TeMp/Ash_\$$ 
fi

#
# Don't  try to remove a non-existant file
#
if test ! -f \$Setups_Home/set\${Name_Of_Ups}.cache.\${UPS_PROD_FLAVOR}
then
    exit 0
fi

#
#Remove the setups.cache file from 
# $Setups_Home
#
    rm -f \$Setups_Home/set\${Name_Of_Ups}.cache.\${UPS_PROD_FLAVOR}
if test -f \$Setups_Home/set\${Name_Of_Ups}.cache.\${UPS_PROD_FLAVOR}
then
#
# If we can't remove the file, print error message and fail.
#
    echo '****' Cannot remove \$Setups_Home/set\${Name_Of_Ups}.cache.\${UPS_PROD_FLAVOR}
    echo '****' Insuffient privilege.
    echo '****'
    echo '****' If this is being executed as part of the process of making 
    echo '****' \$Name_Of_Ups current, the current script is also likely to fail.
    echo '****'
    echo '****' Please notify your System Administrator.
    echo '****'
    echo '****' \$Name_Of_Ups uncurrent script failed
#    exit 1
fi
XEoF
#
# End of creation of uncurrent
#
# Make it executable
#
chmod +x $BootStrap_Dir/uncurrent
#
# Create the unconfigure script
#
rm -f $BootStrap_Dir/unconfigure
echo '**' Creating $BootStrap_Dir/unconfigure
cat <<XEoF >$BootStrap_Dir/unconfigure
#!/bin/sh
# Copyright (c) 1998 Universities Research Association, Inc.
#       All Rights Reserved
#
#
# This material resulted from work developed under a Government Contract and
# is subject to the following license:  The Government retains a paid-up,
# nonexclusive, irrevocable worldwide license to reproduce, prepare derivative
# works, perform publicly and display publicly by or for the Government,
# including the right to distribute to other Government contractors.  Neither
# the United States nor the United States Department of Energy, nor any of
# their employees, makes any warranty, express or implied, or assumes any
# legal liability or responsibility for the accuracy, completeness, or
# usefulness of any information, apparatus, product, or process disclosed, or
# represents that its use would not infringe privately owned rights.
#
# $Name_Of_Ups unconfigure script
#
#
# This script undoes the activity of the configure script.  
#
# It only need to know the BootStrap_Dir as defined at configure time.
#
# This script was created when $Name_Of_Ups was configured
#
# ==== DO NOT EDIT BELOW THIS LINE ===== DO NOT REMOVE THIS LINE ===
#
# The real code ( 1 line - This could be incorporated in the table file )
if test -d $BootStrap_Dir
then
	echo '**' Removing the $BootStrap_Dir directory
	rm -rf $BootStrap_Dir
	if test -d $BootStrap_Dir
	then
	    echo '****' Unconfigure failed to remove $BootStrap_Dir
	    echo '****' Please remove this directory manually.
	    echo ' '
	fi
fi
XEoF
#
# End of creation of unconfigure
#
# Make it executable
#
chmod +x $BootStrap_Dir/unconfigure
#
# Whew 
#
echo '**'
echo '**' $Name_Of_Ups $UPS_PROD_VERSION has been successfully configured
echo '**'
