#!/bin/bash
#****** WN/WN-softver
# NAME
# WN-softver - Detect the version of software which is really installed on the WN. 
# To detect the version lcg-version, glite-version commands and the cat of the 
# /etc/emi-version file are tried and if the commands are not available the script 
# exits with an error.
#
# AUTHOR
#
# SAM Team same-devel[at]cern.ch
#
# LAST UPDATED
#
# 2011-09-22
#
# LANGUAGE
#
# bash
#
# SOURCE


versionFilter="^2\.[456789]|^3\.|^1\."

echo "Installed software version"

set -x
type="unknow"
mwver='error'
if type -f glite-version; then
    type="gLite"
    mwver=`glite-version`
elif [ -f /etc/emi-version ] ; then
    type="EMI"
    mwver=`cat /etc/emi-version`
elif type -f lcg-version; then
    type="LCG"
    mwver=`lcg-version`
else
    echo "ERROR: [glite|lcg|emi]-version was not found"
fi

set +x
echo "Version pattern: $versionFilter"
echo "Deducted middleware version: $type $mwver"
echo "summary: $type $mwver"
if ( echo $mwver | egrep -e $versionFilter > /dev/null 2>&1 ) ; then
    exit $SAME_OK
else
    exit $SAME_ERROR
fi

#****
