Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Mon 22 Sep 2014, 00:16
All times are UTC - 4
 Forum index » Advanced Topics » Additional Software (PETs, n' stuff) » Unsorted
verifypet
Moderators: deshlab, Flash, GuestToo, Ian, JohnMurga, Lobster
Post_new_topic   Reply_to_topic View_previous_topic :: View_next_topic
Page 1 of 1 Posts_count  
Author Message
Pizzasgood


Joined: 04 May 2005
Posts: 6270
Location: Knoxville, TN, USA

PostPosted: 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
View user's profile Send_private_message Visit_website 
technosaurus


Joined: 18 May 2008
Posts: 4351

PostPosted: 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
View user's profile Send_private_message 
SirDuncan


Joined: 09 Dec 2006
Posts: 836
Location: Ohio, USA

PostPosted: 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
View user's profile Send_private_message Visit_website 
Pizzasgood


Joined: 04 May 2005
Posts: 6270
Location: Knoxville, TN, USA

PostPosted: 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
View user's profile Send_private_message Visit_website 
Display_posts:   Sort by:   
Page 1 of 1 Posts_count  
Post_new_topic   Reply_to_topic View_previous_topic :: View_next_topic
 Forum index » Advanced Topics » Additional Software (PETs, n' stuff) » Unsorted
Jump to:  

Rules_post_cannot
Rules_reply_cannot
Rules_edit_cannot
Rules_delete_cannot
Rules_vote_cannot
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.0703s ][ Queries: 11 (0.0228s) ][ GZIP on ]