OpenSDE Framework (without history before r20070)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

75 lines
1.8 KiB

  1. # --- SDE-COPYRIGHT-NOTE-BEGIN ---
  2. # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
  3. #
  4. # Filename: lib/sde-download/validate.sh
  5. # Copyright (C) 2006 The OpenSDE Project
  6. #
  7. # More information can be found in the files COPYING and README.
  8. #
  9. # This program is free software; you can redistribute it and/or modify
  10. # it under the terms of the GNU General Public License as published by
  11. # the Free Software Foundation; version 2 of the License. A copy of the
  12. # GNU General Public License can be found in the file COPYING.
  13. # --- SDE-COPYRIGHT-NOTE-END ---
  14. if [ $# -ne 3 ]; then
  15. echo "Usage: $0 <original> <ours> <checksum>"
  16. exit 2
  17. fi
  18. gzfile="$1"
  19. bzfile="$2"
  20. expected="$3"
  21. if [ ! -f "$gzfile" ]; then
  22. echo "File '$gzfile' not found."
  23. exit 1
  24. fi
  25. # extractor
  26. case "${gzfile##*.}" in
  27. bz2|tbz2|tbz)
  28. format=bzip2
  29. extractor=bunzip2 ;;
  30. gz|tgz) format=gzip
  31. extractor=gunzip ;;
  32. tar) format=tar
  33. extractor=cat ;;
  34. Z) format=Z
  35. extractor=uncompress
  36. # gunzip may be an alternative for uncompress
  37. if ! type -p $uncompress 2>&1 > /dev/null; then
  38. extractor=gunzip
  39. fi ;;
  40. *) format=raw
  41. extractor=cat ;;
  42. esac
  43. echo -n "cksum-test ($format): $gzfile... "
  44. mkdir -p 'tmp/'
  45. efective=$( $extractor < $gzfile | tee tmp/down.$$.dat | cksum - | cut -f1 -d' ' )
  46. case "$expected" in
  47. X) echo "Ignoring Checksum ($efective)." ;;
  48. 0) echo "Missing Checksum ($efective)." ;;
  49. *) if [ "$efective" != "$expected" ]; then
  50. echo "Wrong Checksum!"
  51. echo "Moving to $gzfile.cksum-err ($efective)."
  52. mv "$gzfile" "$gzfile.cksum-err"
  53. rm tmp/down.$$.dat
  54. exit 1
  55. else
  56. echo "OK."
  57. fi
  58. esac
  59. case "$format" in
  60. raw) mv -f tmp/down.$$.dat "$bzfile"
  61. ;;
  62. *) bzip2 < tmp/down.$$.dat > "$bzfile"
  63. if [ "$gzfile" != "$bzfile" ]; then
  64. rm -f "$gzfile"
  65. fi
  66. rm -f tmp/down.$$.dat
  67. ;;
  68. esac