UNPKG

993 BPlain TextView Raw
1#!/usr/bin/env bash
2
3# on NixOS: -U
4# on macOS: -p
5UNIV_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
7check_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
13if [ -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
25else
26 shasum "$UNIV_OPT" -a 1 | sed 's/\ .-/ ?-/' < /dev/stdin
27fi