The time now is Thu 23 May 2013, 19:44
All times are UTC - 4 |
| Author |
Message |
Pizzasgood

Joined: 04 May 2005 Posts: 6270 Location: Knoxville, TN, USA
|
Posted: Thu 04 Dec 2008, 23:08 Post subject:
verifypet |
|
This is a simple script to verify the integrity of .pet files, without extra md5sums. All it needs is the package itself.
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: | | tail -c 32 pkitchensink-4.2.pet |
But that's the checksum of the .tar.gz file before the checksum was appended, so you can't verify the file by simply running md5sum on it. You have to look at the file minus those last 32 bytes, which can be done with head once you know the filesize.
Therefor, I wrote this:
| Code: | #!/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 |
You can pass this multiple .pet files and it will check them all. It doesn't mind spaces, so long as you quote or escape them. The .pet package I linked to above contains this script in /usr/bin/verifypet.
| Code: | # 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
# |
_________________ Between depriving a man of one hour from his life and depriving him of his life there exists only a difference of degree. --Muad'Dib

|
|
Back to top
|
|
 |
technosaurus

Joined: 18 May 2008 Posts: 3843
|
Posted: Thu 04 Dec 2008, 23:22 Post subject:
|
|
This is a good script for unleashed too - maybe part of the expand tarballs,sh
|
|
Back to top
|
|
 |
SirDuncan

Joined: 09 Dec 2006 Posts: 836 Location: Ohio, USA
|
Posted: Thu 04 Dec 2008, 23:52 Post subject:
|
|
Now that's a handy little script. Good job Pizzasgood!
_________________ Be brave that God may help thee, speak the truth even if it leads to death, and safeguard the helpless. - A knight's oath
|
|
Back to top
|
|
 |
Pizzasgood

Joined: 04 May 2005 Posts: 6270 Location: Knoxville, TN, USA
|
Posted: Fri 05 Dec 2008, 00:14 Post subject:
|
|
The pet2tgz script already checks the checksum. However, it doesn't display any error messages, and still trims off the checksum to give you a .tar.gz file. The only way to know it failed is to check the return code (echo $?). If it returns a 1 the package didn't match.
In the expandtarballs.sh script, it uses pet2tgz, and it does already check and output an error message if it is wrong.
But it doesn't look like PETget checks. At least, it didn't say anything when I created and installed a corrupt package.
_________________ Between depriving a man of one hour from his life and depriving him of his life there exists only a difference of degree. --Muad'Dib

|
|
Back to top
|
|
 |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|