#! /bin/sh
# $Id: hook-download,v 1.2 2003/11/22 03:00:14 ensc Exp $

# Copyright (C) 2003 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
#  
# 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; version 2 of the License.
#  
# 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.


## hook-download <url> <pathname>
## expected env: MD5SUM_FILE

test -s "$MD5SUM_FILE" || {
    echo $"No md5sums specified, skipping check" >&2
    exit 0
}


tmp=$(mktemp /tmp/fedbuild.md5sum.XXXXXX)
trap "rm -f $tmp" EXIT

grep "[\\t ]$1\$" "$MD5SUM_FILE" | sed -e "s!\([\\t ]\)$1\$!\1-!" >$tmp

if ! test -s "$tmp"; then
    echo $"No md5sum for '$1' specified; skipping check" >&2
else
    LANG=C md5sum -c --status "$tmp" <"$2" || {
	printf $"\
************
* ERROR: Checksum mismatch for
*   %s
* Expected: '%s'
* Got:      '%s'
*
" "$1" "$(read a b <$tmp; echo $a;)" "$(md5sum <$2 | { read a b; echo $a; })"
	exit 1
    } >&2
fi


