Last active
September 21, 2023 04:21
-
-
Save tcely/0de3da1cd08d83902673 to your computer and use it in GitHub Desktop.
replace 'sha256sum -c' with openssl / cmp in bash
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
sha256sumc () | |
{ | |
local err file hash out rc=0; | |
while IFS=' ' read -r hash file; do | |
file="${file#[*]}"; | |
out="$(openssl dgst -sha256 -r "$file" 2>/dev/null)" && cmp -s <(echo "$out") <(printf -- '%s *%s\n' "$hash" "$file") && printf -- '%s: OK\n' "$file" || { | |
printf -- '%s: FAILED' "$file"; | |
err="$(openssl dgst -sha256 -r "$file" 2>&1 >/dev/null)"; | |
if [[ "$err" =~ ': No such file or directory'$'\n' ]]; then | |
printf -- ' %s' 'open or read'; | |
fi; | |
printf -- '\n'; | |
rc=1 | |
}; | |
done <"${1:-/dev/stdin}" || rc=$?; | |
return $rc | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment