Created
December 6, 2021 14:49
-
-
Save berghaus/8a9b969e0956ad8dc706658d01104f9d to your computer and use it in GitHub Desktop.
Scriped called by Dynafed when storage backend does not support Want-Digest header
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 | |
# Input arguments: | |
# $1 Signed GET URL | |
# $2 Checksum Type (md5, adler32, ...) | |
# | |
# Output: | |
# Should stdout with the format (no quotations): | |
# ">>>>> HASH 123124\n" | |
# we are going to use some storage stats toolage | |
source /opt/storage_stats/bin/activate | |
URL="$1" | |
HASH_TYPE=$(echo "$2" | tr '[:upper:]' '[:lower:]') | |
STORAGE="$(sed 's:^.*//::' <<< "$URL" | sed 's:/.*$::')" | |
ENDPOINT="$(grep -r $STORAGE /etc/ugr/ | awk '{print $3}')" | |
DIGEST="$(dynafed-storage checksums get --loglevel INFO --logfile /var/log/checksums.log -e $ENDPOINT -u $URL -t $HASH_TYPE)" | |
if [[ "$DIGEST" != "None" ]] | |
then | |
printf ">>>>> HASH %s\n" "${DIGEST}" | |
exit 0 | |
fi | |
case $HASH_TYPE in | |
adler32 | md5 ) | |
DIGEST=$(curl --silent -k -XPOST "http://dynafed-checksum-util.cern.ch/${HASH_TYPE}" --data-urlencode url="$URL") | |
DIGEST=$(echo "$DIGEST" | tr -cd '[:alnum:]') | |
dynafed-storage checksums put --loglevel INFO --logfile /var/log/checksums.log -e "$ENDPOINT" -u "$URL" -t "$HASH_TYPE" --checksum "$DIGEST" | |
printf ">>>>> HASH %s\n" "${DIGEST}" | |
;; | |
*) | |
echo "Hash type not implemented: $HASH_TYPE" | |
;; | |
esac | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment