sha256.sh 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. #! /bin/sh
  2. # Copyright (C) 2019 ng0 <ng0@n0.is>
  3. #
  4. # This file is part of mescc-tools
  5. #
  6. # mescc-tools is free software; you can redistribute it and/or modify it
  7. # under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation; either version 3 of the License, or (at
  9. # your option) any later version.
  10. #
  11. # mescc-tools is distributed in the hope that it will be useful, but
  12. # WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with mescc-tools. If not, see <http://www.gnu.org/licenses/>.
  18. set -ex
  19. # It's bad to rely on the uname here, but it's a start.
  20. # What this does is to consider the major implementations of
  21. # sha256sum tools and their differences and call them
  22. # accordingly.
  23. sha256_check()
  24. {
  25. if [ "$(get_machine --OS)" = "Linux" ]; then
  26. LANG=C sha256sum -c "$1"
  27. elif [ "$(get_machine --OS)" = "NetBSD" ]; then
  28. sum -a SHA256 -n -c "$1"
  29. elif [ "$(get_machine --OS)" = "FreeBSD" ]; then
  30. sha256 -r -c "$1"
  31. else
  32. echo "Unsupported sha256 tool, please send a patch to support it"
  33. exit 77
  34. fi
  35. }