Skip to content

Instantly share code, notes, and snippets.

@RyanSquared
Created August 20, 2020 16:18
Show Gist options
  • Save RyanSquared/a83d290c745a13c115318be4b565421b to your computer and use it in GitHub Desktop.
Save RyanSquared/a83d290c745a13c115318be4b565421b to your computer and use it in GitHub Desktop.
#!/bin/bash
set -e
get_modtime() {
curl -qs https://hub.docker.com/v2/repositories/vandor2012/website/tags/ \
| jq -r '.results | map(select(.name == "latest")) | .[0].last_updated'
}
datetime_to_unix() {
date -d "$1" +%s
}
compare_dates() {
# compare_dates now before minutes
[[ $(("$2" - "$1")) -lt "$(( 60*$3 ))" ]]
return $?
}
get_hash() {
curl -qs https://hub.docker.com/v2/repositories/vandor2012/website/tags/ \
| jq -r '.results | map(select(.name == "latest")) | .[0].images[0].digest'
}
current_date="$(datetime_to_unix $(get_modtime))"
if compare_dates "$current_date" "$(date +%s)" 5; then
# less than 5 minutes
echo "Last updated less than 5 minutes ago."
exit 1
fi
old_hash="$(get_hash)"
echo "Old hash: $old_hash"
while [[ "$(get_hash)" = "$old_hash" ]]; do
sleep 5
done
echo "New hash: $(get_hash)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment