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.

83 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 - 2011 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. xz) format=xz
  33. extractor=unxz ;;
  34. tar) format=tar
  35. extractor=cat ;;
  36. Z) format=Z
  37. extractor=uncompress
  38. # gunzip may be an alternative for uncompress
  39. if ! type -p $uncompress 2>&1 > /dev/null; then
  40. extractor=gunzip
  41. fi ;;
  42. *) format=raw
  43. extractor=cat ;;
  44. esac
  45. echo -n "cksum-test ($format): $gzfile... "
  46. if [ "$bzfile" = "$gzfile" ]; then
  47. tmpfile=
  48. effective=$( $extractor < $gzfile | cksum - | cut -f1 -d' ' )
  49. else
  50. mkdir -p 'tmp/'
  51. tmpfile="tmp/down.$$.dat"
  52. effective=$( $extractor < $gzfile | tee "$tmpfile" | cksum - | cut -f1 -d' ' )
  53. fi
  54. case "$expected" in
  55. X) echo "Ignoring Checksum ($effective)." ;;
  56. 0) echo "Missing Checksum ($effective)." ;;
  57. *) if [ "$effective" != "$expected" ]; then
  58. echo "Wrong Checksum!"
  59. echo "Moving to $gzfile.cksum-err ($effective)."
  60. mv "$gzfile" "$gzfile.cksum-err"
  61. [ -z "$tmpfile" ] || rm -f "$tmpfile"
  62. exit 1
  63. else
  64. echo "OK."
  65. fi
  66. esac
  67. if [ -n "$tmpfile" ]; then
  68. case "$format" in
  69. raw) mv -f "$tmpfile" "$bzfile"
  70. ;;
  71. *) bzip2 < "$tmpfile" > "$bzfile"
  72. rm -f "$gzfile" "$tmpfile"
  73. ;;
  74. esac
  75. fi