-
Notifications
You must be signed in to change notification settings - Fork 2
/
common.sh
executable file
·35 lines (34 loc) · 990 Bytes
/
common.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/bin/bash
one_year_ago="$(date -d "1 year ago" +%s)"
parse-tags-js() {
is_empty=true
page_url="$(jq -r '.next' <<< "$tags_js")"
for result in $(jq -c '.results[]' <<< "$tags_js"); do
if ! date="$(date -d "$(jq -r '.last_updated' <<< "$result")" +%s)"; then
return 1
fi
if ! name="$(jq -r '.name' <<< "$result")"; then
return 1
fi
if (( date > one_year_ago )); then
echo "$name"
is_empty=false
fi
done
}
docker-tags(){
is_empty=false
image="library/$1"
page_url="https://registry.hub.docker.com/v2/repositories/${image}/tags/"
while [[ -n "$page_url" && "$page_url" != "null" && "$is_empty" != "true" ]]
do
if ! tags_js="$(curl -fsSL "$page_url")"; then
echo "curl $page_url failed" >&2
return 1
fi
if ! parse-tags-js; then
echo "parse json failed" >&2
return 1
fi
done
}