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.

81 lines
1.9 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 - 2008 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. if [ "$bzfile" = "$gzfile" ]; then
  45. tmpfile=
  46. effective=$( $extractor < $gzfile | cksum - | cut -f1 -d' ' )
  47. else
  48. mkdir -p 'tmp/'
  49. tmpfile="tmp/down.$$.dat"
  50. effective=$( $extractor < $gzfile | tee "$tmpfile" | cksum - | cut -f1 -d' ' )
  51. fi
  52. case "$expected" in
  53. X) echo "Ignoring Checksum ($effective)." ;;
  54. 0) echo "Missing Checksum ($effective)." ;;
  55. *) if [ "$effective" != "$expected" ]; then
  56. echo "Wrong Checksum!"
  57. echo "Moving to $gzfile.cksum-err ($effective)."
  58. mv "$gzfile" "$gzfile.cksum-err"
  59. [ -z "$tmpfile" ] || rm -f "$tmpfile"
  60. exit 1
  61. else
  62. echo "OK."
  63. fi
  64. esac
  65. if [ -n "$tmpfile" ]; then
  66. case "$format" in
  67. raw) mv -f "$tmpfile" "$bzfile"
  68. ;;
  69. *) bzip2 < "$tmpfile" > "$bzfile"
  70. rm -f "$gzfile" "$tmpfile"
  71. ;;
  72. esac
  73. fi