#!/bin/sh
#
# verify update file checksums
#
# used by remote swupdate
#
# $1 = filename of file to check
# $2 = filename of file with sums
# $3 = full path to program to run to generate sums (e.g. /usr/bin/sha1sum)
#
# Compute the hash of file $1, compare the result with what's stored in
# file $2.
#
# should be run from /tmp or /tmp/XXXXX
#
# Example: rmt_cmp_sums images/rfs_image.ubifs images/SHA1SUMS /usr/bin/sha1sum
#

set -e

# run sha1sum <file>
outfile1=$(mktemp -p /tmp)
$3 $1 > $outfile1

outfile2=$(mktemp -p /tmp)
pattern="  $1\$"
/bin/grep -E "$pattern" $2 > $outfile2

cmp -s $outfile1 $outfile2
status=$?

rm -rf $outfile1
rm -rf $outfile2

return $status
