verifypet-0.1.pet
This works because all proper .pet packages have a md5sum built in. They are simply .tar.gz files with md5sums appended to the end of them. Those md5sums can be pulled out with 'tail':
Code: Select all
tail -c 32 pkitchensink-4.2.pet
Therefor, I wrote this:
Code: Select all
#!/bin/sh
#verifypet by Pizzasgood
#checks the md5sum on a .pet package
RET=0
FAILED=0
TOTAL=0
while [ "$1" ]; do
if [ -f "$1" ]; then
TOTAL=$[$TOTAL+1]
FULLSIZE=$(stat --format=%s "${1}")
ORIGSIZE=$(expr $FULLSIZE - 32)
ORIGSUM=$(tail -c 32 "$1")
NEWSUM=$(head -c $ORIGSIZE "$1" | md5sum | cut -f 1 -d ' ')
if [ "$NEWSUM" = "$ORIGSUM" ]; then
echo "$(basename "$1"): OK"
else
echo "$(basename "$1"): FAILED"
RET=1
FAILED=$[$FAILED+1]
fi
else
echo "verifypet: can't open '$1': No such file or directory"
RET=1
fi
shift
done
[ $RET = 1 ] && echo "verifypet: WARNING: $FAILED of $TOTAL computed checksums did NOT match"
exit $RET
Code: Select all
# verifypet verifypet-0.1.pet
verifypet-0.1.pet: OK
# echo "asdfaf" >> verifypet-0.1.pet
# verifypet verifypet-0.1.pet
verifypet-0.1.pet: FAILED
verifypet: WARNING: 1 of 1 computed checksums did NOT match
#