43 lines
821 B
Bash
Raw Normal View History

#!/usr/bin/env bash
set -o pipefail
LIB_SRC=${LIB_SRC:-$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)}
2025-06-18 09:49:45 -03:00
# shellcheck source=./src/config.bash
source "${LIB_SRC}/config.bash"
if ! command -v sha1sum > /dev/null; then
echoerr "Error: sha1sum is required for computing file hashes"
exit 1
fi
OUTPUTS=${OUTPUTS:-$(mktemp -d)} || exit 1
OUTPUTS=$(realpath "$OUTPUTS") || exit 1
clh_output_folder() {
echo "${OUTPUTS}/$1"
}
2025-06-19 19:58:13 -03:00
clh_clear_outputs() {
rm -rf "${OUTPUTS}" || true
}
echoerr() {
echo "$@" >&2
2025-06-17 17:51:12 -03:00
}
await() {
local pid=$1 timeout=${2:-30} start="${SECONDS}"
2025-06-17 17:51:12 -03:00
while kill -0 "$pid"; do
if ((SECONDS - start > timeout)); then
echoerr "Error: timeout waiting for process $pid to exit"
return 1
fi
2025-06-17 17:51:12 -03:00
sleep 0.1
done
return 0
}
sha1() {
sha1sum "$1" | cut -d ' ' -f 1 || return 1
}