Merge bitcoin/bitcoin#26772: contrib: fix sha256 check in install_db4.sh for FreeBSD

22e9afe40d987f4f90bc8469f9475df138fe6261 use sha256 command instead of sha256sum on FreeBSD (Murray Nesbitt)

Pull request description:

  The FreeBSD version of `sha256sum` takes different arguments than the GNU version.

  The `sha256_check` function in `contrib/install_db4.sh` has code specific to FreeBSD, however it doesn't get reached because while the `sha256sum` command does exist on FreeBSD, it is incompatible and results in an error:

  ```
  sha256sum: option requires an argument -- c
  usage: sha256sum [-pqrtx] [-c file] [-s string] [files ...]
  ```

  This change moves the FreeBSD-specific code before the check for the `sha256sum` command.

  Fixes: #26774

Top commit has no ACKs.

Tree-SHA512: 2485e2e7d8fdca3b072b29fb22bbdfd69e520740537b331b33c64cc645b63da712cfa63a23bdf039bbc92a6558fc7bf03323a51784bf601ff360ff0ef59506c8
This commit is contained in:
fanquake 2023-01-04 10:19:57 +00:00 committed by pasta
parent df2f533aaf
commit 7f2b934089
No known key found for this signature in database
GPG Key ID: 52527BEDABE87984

View File

@ -32,16 +32,15 @@ check_exists() {
sha256_check() { sha256_check() {
# Args: <sha256_hash> <filename> # Args: <sha256_hash> <filename>
# #
if check_exists sha256sum; then if [ "$(uname)" = "FreeBSD" ]; then
echo "${1} ${2}" | sha256sum -c # sha256sum exists on FreeBSD, but takes different arguments than the GNU version
sha256 -c "${1}" "${2}"
elif check_exists sha256sum; then
echo "${1} ${2}" | sha256sum -c
elif check_exists sha256; then elif check_exists sha256; then
if [ "$(uname)" = "FreeBSD" ]; then echo "${1} ${2}" | sha256 -c
sha256 -c "${1}" "${2}"
else
echo "${1} ${2}" | sha256 -c
fi
else else
echo "${1} ${2}" | shasum -a 256 -c echo "${1} ${2}" | shasum -a 256 -c
fi fi
} }