#!/bin/sh

# Check that all files that should have the current version agree on it

PC_PATH=mce.pc
PC_VERS=$(grep '^Version:' $PC_PATH |sed -e 's/^.*:[[:space:]]*//')

DEB_PATH=debian/changelog
DEB_VERS=$(head -1 $DEB_PATH | sed -e 's/^.*(//' -e 's/).*$//')

SPEC_PATH=${RPM_SOURCE_DIR:-rpm}/${RPM_PACKAGE_NAME:-mce-headers}.spec
SPEC_VERS=$(grep '^Version:' $SPEC_PATH |sed -e 's/^.*:[[:space:]]*//')

RES=0


if [ "$DEB_VERS" != "$PC_VERS" ]; then
  echo >&2 "$PC_PATH $PC_VERS vs $DEB_PATH $DEB_VERS"
  RES=1
fi

if [ "$SPEC_VERS" != "$PC_VERS" ]; then
  echo >&2 "$PC_PATH $PC_VERS vs $SPEC_PATH $SPEC_VERS"
  RES=1
fi


if [ $RES != 0 ]; then
  echo >&2 "Conflicting package versions"
fi

exit $RES
