pet2tgz 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #!/bin/sh
  2. #by BarryK 2006 for Puppy Linux v2.13+
  3. #passed param is file to be converted.
  4. #converts a .pet file to .tar.gz.
  5. #131122 support xz compressed pets (see dir2pet, installpkg.sh)
  6. chmod +w "$1" #make it writable.
  7. FULLSIZE=`stat --format=%s "${1}"`
  8. ORIGSIZE=`expr $FULLSIZE - 32`
  9. ##doing it this way have to remove dd stdout msg (preceded by a '+')...
  10. ##um, cut and sed are really intended for working on text files, may have to
  11. ##do this differently (in case have a corrupted file with non-char bytes on end)...
  12. #MD5SUM="`dd if="${1}" bs=1 skip=${ORIGSIZE} 2>/dev/null | cut -f 1 -d '+' | sed -e 's/[^0-9a-zA-Z]/0/g'`" #md5sum to stdout.
  13. #do it this indirect way instead...
  14. #determine the compression, extend test to 'XZ'
  15. file -b "$1" | grep -i -q "^xz" && EXT=xz || EXT=gz #131122 #140108 add -i for 'XZ'
  16. dd if="${1}" of=/tmp/petmd5sum bs=1 skip=${ORIGSIZE} 2>/dev/null
  17. sync
  18. MD5SUM="`md5sum /tmp/petmd5sum | cut -f 1 -d ' '`"
  19. #truncate is a little app I wrote. format: truncate newsize filename
  20. truncate $ORIGSIZE "$1"
  21. [ $? -ne 0 ] && exit 1
  22. sync
  23. #NEWMD5SUM="`md5sum "$1" | cut -f 1 -d ' '`"
  24. md5sum "$1" | cut -f 1 -d ' ' > /tmp/newpetmd5sum
  25. sync
  26. #get rid of trailing newline char...
  27. truncate 32 /tmp/newpetmd5sum
  28. NEWMD5SUM="`md5sum /tmp/newpetmd5sum | cut -f 1 -d ' '`"
  29. rm -f /tmp/petmd5sum
  30. rm -f /tmp/newpetmd5sum
  31. NEWNAME="`echo -n "${1}" | sed -e "s/\\.pet$/\\.tar\\.$EXT/g"`" #131122
  32. mv -f $1 $NEWNAME
  33. [ ! "$MD5SUM" = "$NEWMD5SUM" ] && exit 1
  34. exit 0