Files
UltraGrid/.github/scripts/get-etag.sh
Martin Pulec 194cb695e3 GH scripts: add -f to curl
to catch 4xx HTTP errors (curls returns 0 otherwise)
2025-07-15 09:20:42 +02:00

22 lines
470 B
Bash
Executable File

#!/bin/sh -ux
# Prints to stdout ETag for given URL.
# If failed to obtain and $2=optional the particular tag is replaced with a keyword NOTFOUND
output=$1
url=$2
optional=${3-}
ETAG=$(curl -ILf "$url" | grep -i '^etag' | sed 's/.*"\(.*\)".*/\1/')
if [ "$ETAG" ]; then
printf '%s=' "$output"
printf '%s\n' "$ETAG" | sed 's/[^-._A-Za-z0-9]/_/g'
exit 0
fi
if [ "$optional" = optional ]; then
echo "$1=NOTFOUND"
exit 0
fi
exit 1