#!/bin/sh -x
# Gets Debian and Emdebian binary package versions
# 
# root@ant:/home/toolchain/trunk.new# rmadison binutils | grep -w arm | grep unstable | cut -d"|" -f2 | tr -d ' '
# 2.18.1~cvs20080103-7
# root@ant:/home/toolchain/trunk.new# apt-cache show binutils-arm-linux-gnu | grep ^Version: | cut -d: -f2 | tr -d ' '
# 2.18.1~cvs20080103-7


# Configuration variables

source conf_vars.sh

# Package name
PKG=$1
ARCH=$2

# Default values
DEB_VERSION=4.0
EM_VERSION=0.0

# Finds Debian version 
DEB_VERSION=`rmadison $PKG | grep -w $ARCH | grep $SUITE | cut -d'|' -f2 | tr -d ' '`
# Finds package under emdebian repository
case $ARCH in
	armel)
	EM_VERSION=`apt-cache show $PKG-arm-linux-gnueabi | grep ^Version: | cut -d: -f2 | tr -d ' '`
	;;
	*)
	EM_VERSION=`apt-cache show $PKG-$ARCH-linux-gnu | grep ^Version: | cut -d: -f2 | tr -d ' '`
	;;
esac

dpkg --compare-versions $DEB_VERSION le $EM_VERSION
aux=`echo $?`


if [ ! -n $EM_VERSION ]; then
	echo "FLAG: 1"
	echo "$ARCH $PKG - out of sync"
elif [ $aux = 0 ]; then
# Compares both versions
	echo "FLAG: 0"
	echo "$ARCH $PKG - in sync"
else
	echo "FLAG: 1"
	echo "$ARCH $PKG - out of sync"
fi
echo "DEB_VERSION: $DEB_VERSION"
echo " EM_VERSION: $EM_VERSION"

