#!/bin/bash

# This script will set the following shell variables:
#   RELEASE_VERSION
#   BUILD_VERSION
#   HOST_SW_VERSION_STRING
#   PUSH_TOPO
#
# RELEASE_VERSION, BUILD_VERSION, and HOST_SW_VERSION_STRING
# are derived from the common git info script

DEFAULT_RELEASE_VERSION=0.0
DEFAULT_BUILD_VERSION=0
DEFAULT_VERSION_STRING="NoVersionFound"

if [ -e build_version_override ] ; then
  source build_version_override
else
    # Call common git_info script
    COMMON_SCRIPT_DIR=../../../common/scripts

    git_info=`python $COMMON_SCRIPT_DIR/git_info.py`

    # Turn the result into a bash array
    git_info=($git_info)

    # Set the host software version string to be equal to the
    # repository short build version
    if [ ${git_info[0]} == "SUCCESS" ]; then
        RELEASE_VERSION="${git_info[13]}.${git_info[14]}"
        BUILD_VERSION=${git_info[15]}
        HOST_SW_VERSION_STRING=${git_info[8]}
    else
        # Something failed - use default version information
        echo "python git_info.py failed - using default version string"
        RELEASE_VERSION=$DEFAULT_RELEASE_VERSION
        BUILD_VERSION=$DEFAULT_BUILD_VERSION
        HOST_SW_VERSION_STRING=$DEFAULT_VERSION_STRING
    fi
fi

# PUSH_TOPO is set to 1 when libxrandr version >= 1.2
#   (actually set to 0 if version 1.1, 1 otherwise)
Xmaj=`rpm -q libXrandr | head -n 1 | cut -d - -f 2 | cut -d . -f 1`
Xmin=`rpm -q libXrandr | head -n 1 | cut -d - -f 2 | cut -d . -f 2`
echo "libXrandr version reported as $Xmaj.$Xmin"
if [ $Xmaj == "1" ];
  then
  if [ $Xmin == "1" ];
  then
    export PUSH_TOPO=0
  else
    export PUSH_TOPO=1
  fi
else 
  export PUSH_TOPO=1
fi

export RELEASE_VERSION
export BUILD_VERSION
export HOST_SW_VERSION_STRING
echo "RELEASE_VERSION-BUILD_VERSION is ${RELEASE_VERSION}-${BUILD_VERSION}"
echo "HOST_SW_VERSION_STRING is $HOST_SW_VERSION_STRING"

