#!/bin/bash
#
# given the name of the package to review, this script gets the latest 
# package version on REVU and runs revu-report on it.
#
# Copyright (C) 2006 Raphaël Pinson <raphink@ubuntu.com>
#
# 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 2
# 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, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
#
# Contributors: Fathi Boudra <fboudra@free.fr>

APPNAME="REVU-Report";
VERSION="0.6.1";
AUTHOR="Raphaël Pinson <raphink@ubuntu.com>";

USAGE="$0 [--help || -h] package [url]";

PACKAGE=$1;
URL=$2;

source /var/lib/revu-tools/revu-tools-loadconfig

if [[ "$1" = "--help" || "$1" = "-h" ]]; then
        "$ECHO" "${APPNAME} v.${VERSION} by ${AUTHOR}";
        "$ECHO" "usage: ${USAGE}";
        exit 0;
fi


if [[ -z "$PACKAGE" ]]; then
        "$ECHO" "usage: ${USAGE}";
        exit 1;
fi


CURRENTDIR=`${PWD}`;

LASTDIR=`"$LS" "$REVUDIR" | "$GREP" "^${PACKAGE}-[0-9]*" | "$AWK" '{last=$0} END{print last}'`;

"$ECHO" "Reviewing package ${PACKAGE} from directory ${LASTDIR}"

cd "${REVUDIR}/${LASTDIR}";

if [[ -n "$URL" ]]; then
	${WGET} "$URL";
fi

${REVUREPORT};

cd "$CURRENTDIR";

exit 0;
