#! /bin/sh
#
#  Script: get_d0_release.sh
#  Author: John Ellison
#    Date: 3 March 2001
#   Usage:  get_d0_release.sh arg1
#           where arg1 = version of D0RunII product required
# Purpose: 
# This script queries www-d0.fnal.gov for the requested
# distribution release and installs it.  It installs D0RunII and
# D0RunII-bin and prints out a list of optional products that are not
# already installed but may be needed 
#
. /usr/local/etc/setups.sh   
setup upd

if [ -z "$1" ]
then
    echo "Usage: get_d0_release.sh version"
    exit
else
    version=$1
fi

date
echo "########### Step 1, checking for D0RunII $version release:"
if test "`upd list -K+ -h www-d0.fnal.gov D0RunII $version -q dist`" != ""
then
    echo "$version release found. Proceeding..."
else
    echo "$version release not found on www-d0.fnal.gov. Exiting."
    exit
fi

# quit now if this version is already installed
if test "`ups list -aK+  D0RunII $version`" != "" 
then 
    echo "D0RunII" $version "is already installed! Exiting." 
    exit 
fi

echo "########### Step 2, installing D0RunII" $version
upd install -h www-d0.fnal.gov D0RunII $version -q dist -G'-c'

echo "########### Step 3, declaring to ups database"
ups declare D0RunII $version -z /d0dist/dist/upsdb -m D0RunII.table -f NULL -r /d0dist/dist/releases/$version
ups declare D0RunII $version -z /d0dist/dist/upsdb -m D0RunII.table -f NULL -r /d0dist/dist/releases/$version -q build

echo "########### Step 4, installing binaries"
upd install -h www-d0.fnal.gov D0RunII-bin $version -q IRIX6-KCC_3_4 -G'-c' 

echo "########### NOTE: the following optional packages may be needed:"
infile=/d0dist/dist/releases/$version/D0reldb/D0-glpkgs
while read prod ver q1 q2 q3
do
# filter out -j option
    if test "x$q1" = "x-j"; then q1=""; fi
    if test "x$q2" = "x-j"; then q2=""; fi
    if test "x$q3" = "x-j"; then q3=""; fi   

    if test "`ups list -K+ $prod $ver $q1 $q2 $q3`" = ""
    then
	echo "$prod $ver $q1 $q2 $q3"
    fi
done < $infile    
echo "########### Done..."












