#!/bin/sh
#
# Free Packaging Test Script
# Copyright (C) 2010-2018 by Thomas Dreibholz
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
# Contact: dreibh@iem.uni-due.de

PACKAGE=`cat Makefile | grep PORTNAME= | sed -e "s/PORTNAME=//g" | tr -d "\t"`
UPSTREAM_VERSION=`cat Makefile | grep PORTVERSION= | sed -e "s/PORTVERSION=//g" | tr -d "\t"`
CATEGORY=`cat Makefile | grep CATEGORIES= | sed -e "s/CATEGORIES=//g" | tr -d "\t"`

echo "######################################################################"
echo "PACKAGE:          $PACKAGE"
echo "UPSTREAM_VERSION: $UPSTREAM_VERSION"
echo "CATEGORY:         $CATEGORY"
echo "######################################################################"


PACKAGING_FILES="Makefile distinfo pkg-descr pkg-plist"

if [ -e $PACKAGE.diff ] ; then
   rm $PACKAGE.diff
fi

for file in $PACKAGING_FILES ; do
   if [ -e /usr/ports/$CATEGORY/$PACKAGE/$file -a -e $file ] ; then
      diff -uN /usr/ports/$CATEGORY/$PACKAGE/$file $file >>$PACKAGE.diff
   else
      if [ -e /usr/ports/$CATEGORY/$PACKAGE/$file ] ; then
         echo >&2 "ERROR: Unable to compare /usr/ports/$CATEGORY/$PACKAGE/$file and $file"
         exit 1
      fi
   fi
done

colordiff <$PACKAGE.diff
echo ""
echo "Results written to $PACKAGE.diff"
