#!/bin/sh
# $Id: test-packaging 1342 2012-02-10 18:34:09Z dreibh $
#
# Free Packaging Test Script
# Copyright (C) 2010-2017 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 "######################################################################"


if [ -e work ] ; then
   rm -rf work
fi
rm -f ${PACKAGE}-${UPSTREAM_VERSION}.txz
find /usr/ports/packages -name "${PACKAGE}*.txz" | xargs rm -f


echo "1. ###### make deinstall ##############################################" && \
make deinstall && \
echo "2. ###### make install ################################################" && \
make install && \
echo "3. ###### make package ################################################" && \
make package && \
echo "4. ###### make deinstall ##############################################" && \
make deinstall && \
echo "5. ###### pkg add #####################################################" && \
if [ -e ${PACKAGE}-${UPSTREAM_VERSION}.txz ] ; then
   mkdir /usr/ports/packages /usr/ports/packages/All
   cp ${PACKAGE}-${UPSTREAM_VERSION}.txz /usr/ports/packages/All
fi
pkg add /usr/ports/packages/All/${PACKAGE}-${UPSTREAM_VERSION}.txz && \
echo "6. ###### make deinstall ##############################################" && \
make deinstall && \
echo "7. ###### make reinstall ##############################################" && \
make reinstall && \
echo "8. ###### make package ################################################" && \
make package && \
echo "9. ###### tar tzvf *.txz ##############################################" && \
tar tzvf /usr/ports/packages/All/${PACKAGE}-${UPSTREAM_VERSION}.txz && \
echo "====== Successfully completed! ======"
