verifypet

Stuff that has yet to be sorted into a category.
Post Reply
Message
Author
User avatar
Pizzasgood
Posts: 6183
Joined: Wed 04 May 2005, 20:28
Location: Knoxville, TN, USA

verifypet

#1 Post by Pizzasgood »

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: Select all

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: 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
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: 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
#
[size=75]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[/size]
[img]http://www.browserloadofcoolness.com/sig.png[/img]

User avatar
technosaurus
Posts: 4853
Joined: Mon 19 May 2008, 01:24
Location: Blue Springs, MO
Contact:

#2 Post by technosaurus »

This is a good script for unleashed too - maybe part of the expand tarballs,sh

User avatar
SirDuncan
Posts: 829
Joined: Sat 09 Dec 2006, 20:35
Location: Ohio, USA
Contact:

#3 Post by SirDuncan »

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

User avatar
Pizzasgood
Posts: 6183
Joined: Wed 04 May 2005, 20:28
Location: Knoxville, TN, USA

#4 Post by Pizzasgood »

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.
[size=75]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[/size]
[img]http://www.browserloadofcoolness.com/sig.png[/img]

Post Reply