#!/bin/bash
# 
# Helper script for git to list the tags in a nightly or RPM installation
# This script is opportunistic rather than general. It only works after
# you setup a release and will use the best method to find out what
# package is installed.
#

[ -n "${TDAQ_INST_PATH}" ] || { echo "No release is set up"; exit 1; }

case ${TDAQ_INST_PATH} in
   /cvmfs/atlas.cern.ch/*)
      rpmdb=$(dirname $(dirname $(dirname ${TDAQ_INST_PATH})))/.rpmdb
      [ -d ${rpmdb} ] || { echo "RPM db not found"; exit 1; }
      for pkg in $@
      do
        echo -n "$pkg "
        rpm --dbpath ${rpmdb} -qa ${CMTRELEASE}_${pkg}_${CMTCONFIG}* | sed -e "s;${CMTRELEASE}_${pkg}_${CMTCONFIG}-;;" -e 's;-1.noarch$;;' | tr '_' '-'
      done | column -t
      ;;
   *)
      (cd $TDAQ_INST_PATH/.. && git submodule status $@ | cut -d' ' -f3- | tr -d '[()]' | column -t)
      ;;
esac
