#!/bin/bash
# Script d'affichage des infos de version d'une application
# Portage de getinfoversion.sh from OTU8000v2
#
# La syntax avec RESCUE a été gradée pour compatibilité : le rescue est la partition non utilisée
#

#set -x

# Get partition information
#source /etc/platform.conf
source /etc/otu/otuparts.sh
[ -f /etc/profile.d/40_otu_platform.sh ] && source /etc/profile.d/40_otu_platform.sh

APPDIR=/acterna/release/bin
ACTERNADIR=/etc/acterna

RESCUE_PART=/mnt/fs/unused_part
# Keep usage here, easier to find :)
usage () {
   echo "usage:  $0 [-r] application_name"
   exit 1
}

# Get commandline options
while getopts [r:] opt
do
    case "$opt" in
      r) RESCUE=yes
         APPFILE="$OPTARG".ver
         ;;
      \?) usage;;
    esac
done

# Check parameter
if [ "$RESCUE" == "yes" ]
then
   if [ -z $RESCUE_PART ] ; then
	  echo "ERROR : Recue file system not mounted"
	  exit 1
   fi
   ACTERNADIR=${RESCUE_PART}$ACTERNADIR
   APPDIR=${RESCUE_PART}$APPDIR
else
   if [ $# -eq 1 ];
   then
       APPFILE="$1".ver
   else
       echo "ERROR : You must specify an application file name"
       exit 1
   fi
fi

# Check .ver file
VERFILE=""

if [ -e $ACTERNADIR/$APPFILE ]; then
    VERFILE=$ACTERNADIR/$APPFILE
elif [ -e $APPDIR/$APPFILE ]; then
    VERFILE=$APPDIR/$APPFILE
else
    echo "ERROR : $APPFILE not found"
    exit 1
fi

# Create string
INFOVER=$(grep -v "^#" $VERFILE | tr "\n" ";" | sed '$ s/;*$//')
echo $CFG_PLATFORM_NAME";"$INFOVER

exit 0
