#!/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 ups product was configured.
#

Name_Of_Ups=ups

Setups_Home=~products/etc

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

#
# 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 
# ~products/etc
#
    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
