verifypkg.sh 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #!/bin/sh
  2. #(c) Copyright Barry Kauler 2009, puppylinux.com
  3. #2009 Lesser GPL licence v2 (http://www.fsf.org/licensing/licenses/lgpl.html).
  4. #called from /usr/local/petget/downloadpkgs.sh.
  5. #passed param is the path and name of the downloaded package.
  6. #100116 add support for .tar.bz2 T2 pkgs.
  7. #100616 add support for .txz slackware pkgs.
  8. #101225 bug fix, .pet was converted to .tar.gz, restore to .pet.
  9. export LANG=C
  10. . /etc/rc.d/PUPSTATE #this has PUPMODE and SAVE_LAYER.
  11. . /etc/DISTRO_SPECS #has DISTRO_BINARY_COMPAT, DISTRO_COMPAT_VERSION
  12. mkdir -p /tmp/petget #101225
  13. DLPKG="$1"
  14. DLPKG_BASE="`basename $DLPKG`" #ex: scite-1.77-i686-2as.tgz
  15. DLPKG_PATH="`dirname $DLPKG`" #ex: /root
  16. FLAG="ok"
  17. cd $DLPKG_PATH
  18. case $DLPKG_BASE in
  19. *.pet)
  20. #101225 bug fix, .pet was converted to .tar.gz, restore to .pet...
  21. DLPKG_MAIN="`basename $DLPKG_BASE .pet`"
  22. FULLSIZE=`stat --format=%s "${DLPKG_BASE}"`
  23. ORIGSIZE=`expr $FULLSIZE - 32`
  24. dd if="${DLPKG_BASE}" of=/tmp/petget/petmd5sum bs=1 skip=${ORIGSIZE} 2>/dev/null
  25. sync
  26. MD5SUM="`cat /tmp/petget/petmd5sum`"
  27. pet2tgz $DLPKG_BASE
  28. [ $? -ne 0 ] && FLAG="bad"
  29. if [ -f ${DLPKG_PATH}/${DLPKG_MAIN}.tar.gz ];then
  30. mv -f ${DLPKG_PATH}/${DLPKG_MAIN}.tar.gz ${DLPKG_PATH}/${DLPKG_MAIN}.pet
  31. echo -n "$MD5SUM" >> ${DLPKG_PATH}/${DLPKG_MAIN}.pet
  32. fi
  33. ;;
  34. *.deb)
  35. DLPKG_MAIN="`basename $DLPKG_BASE .deb`"
  36. dpkg-deb --contents $DLPKG_BASE
  37. [ $? -ne 0 ] && FLAG="bad"
  38. ;;
  39. *.tgz)
  40. DLPKG_MAIN="`basename $DLPKG_BASE .tgz`" #ex: scite-1.77-i686-2as
  41. gzip --test $DLPKG_BASE > /dev/null 2>&1
  42. [ $? -ne 0 ] && FLAG="bad"
  43. ;;
  44. *.txz)
  45. DLPKG_MAIN="`basename $DLPKG_BASE .txz`" #ex: scite-1.77-i686-2as
  46. xz --test $DLPKG_BASE > /dev/null 2>&1
  47. [ $? -ne 0 ] && FLAG="bad"
  48. ;;
  49. *.tar.gz)
  50. DLPKG_MAIN="`basename $DLPKG_BASE .tar.gz`" #ex: acl-2.2.47-1-i686.pkg
  51. gzip --test $DLPKG_BASE > /dev/null 2>&1
  52. [ $? -ne 0 ] && FLAG="bad"
  53. ;;
  54. *.tar.bz2) #100116
  55. DLPKG_MAIN="`basename $DLPKG_BASE .tar.bz2`"
  56. bzip2 --test $DLPKG_BASE > /dev/null 2>&1
  57. [ $? -ne 0 ] && FLAG="bad"
  58. ;;
  59. esac
  60. if [ "$FLAG" = "bad" ];then
  61. rm -f $DLPKG_BASE > /dev/null 2>&1
  62. rm -f ${DLPKG_MAIN}.tar.gz > /dev/null 2>&1
  63. exit 1
  64. fi
  65. ###END###