1 | #!/usr/bin/env bash
|
2 |
|
3 | # on NixOS: -U
|
4 | # on macOS: -p
|
5 | UNIV_OPT=$(if echo '' | shasum -U > /dev/null 2>&1; then echo '-U'; elif echo '' | shasum -p > /dev/null 2>&1; then echo '-p'; else echo ''; fi);
|
6 |
|
7 | check_file_in=$(echo "$@" | awk -v RS=' -' '/(c|-check) / {print $2}')
|
8 | # TODO: right now, we are only accepting input on stdin.
|
9 | # If we parse all the command line args, we could use something
|
10 | # like the following, except the file wouldn't necessarily be $1.
|
11 | #shasum "$UNIV_OPT" -a 1 -c "$check_file_out" < "${1:-/dev/stdin}"
|
12 |
|
13 | if [ -f "$check_file_in" ]; then
|
14 | check_file_out=$(mktemp -q)
|
15 | hash_value=$(awk '{print $1}' "$check_file_in")
|
16 | if [[ "$UNIV_OPT" -eq "-U" ]]; then
|
17 | echo "$hash_value U-" > "$check_file_out"
|
18 | elif [[ "$UNIV_OPT" -eq "-p" ]]; then
|
19 | echo "$hash_value ?-" > "$check_file_out"
|
20 | else
|
21 | echo "$hash_value -" > "$check_file_out"
|
22 | fi
|
23 |
|
24 | shasum "$UNIV_OPT" -a 1 -c "$check_file_out" < /dev/stdin
|
25 | else
|
26 | shasum "$UNIV_OPT" -a 1 | sed 's/\ .-/ ?-/' < /dev/stdin
|
27 | fi
|