sha1sum-sh 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #!/bin/sh
  2. check=0
  3. status=0
  4. while [ x"$1" != x ]; do
  5. case $1 in
  6. -c)
  7. check=1
  8. shift
  9. continue;;
  10. --status)
  11. status=1
  12. shift
  13. continue;;
  14. -*)
  15. if [ $status = 0 ]; then
  16. echo "Unrecognized option $1" 1>&2
  17. fi
  18. exit 1
  19. ;;
  20. *)
  21. dst=$1
  22. shift
  23. continue;;
  24. esac
  25. done
  26. if [ x"$dst" = x ]; then
  27. if [ $status = 0 ]; then
  28. echo "Usage: $0 [<options>] <filename>" 1>&2
  29. fi
  30. exit 1
  31. fi
  32. if [ $check = 1 ]; then
  33. if [ -f $dst ]; then
  34. sum1=`cut -d' ' -f1 $dst`
  35. file=`cut -d' ' -f3 $dst`
  36. sum2=`openssl sha1 $file | cut -d' ' -f2`
  37. if [ x"$sum1" = x"$sum2" ]; then
  38. if [ $status = 0 ]; then
  39. echo "$dst: OK"
  40. fi
  41. exit 0
  42. else
  43. if [ $status = 0 ]; then
  44. echo "$dst: FAILED"
  45. fi
  46. exit 1
  47. fi
  48. else
  49. echo "$0: $dst: No such file or directory" 1>&2
  50. exit 1
  51. fi
  52. else
  53. if [ x"$status" = x1 ]; then
  54. echo "$0: the --status option is meaningful only when verifying checksums" 1>&2
  55. exit 1
  56. fi
  57. if [ -f $dst ]; then
  58. sum=`openssl sha1 $dst | cut -d' ' -f2`
  59. echo "$dst $sum"
  60. exit 0
  61. else
  62. echo "$0: $dst: No such file or directory" 1>&2
  63. exit 1
  64. fi
  65. fi