-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathchecker.sh
89 lines (73 loc) · 3.16 KB
/
checker.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/bin/bash
token=""
# below will check wether to use discord or gotify
# and wether to use english of french language
if [[ "$token" =~ "https://discord.com/api/webhooks" ]] ; then
server=discord
else
server=gotify
fi
if [ "`env | grep fr_FR`" != "" ] ; then
lang=fr
else
lang=en
fi
# below will remove duplicates
docker ps --format "{{.Image}}" | sort -u > images.list
list=""
while read line ; do
# below is needed for images such as debian/postgres/... that can only be accessed with library/[image_name] url
if [ "`echo $line | grep \/`" == "" ] ; then
line=library/$line
fi
# belows is needed because linuxserver images will output with ghcr.io/ appended to the name and that needs to be cut
image=`echo $line | cut -d : -f 1 | sed 's/ghcr.io\///' | sed 's/lscr.io\///'`
tag=`echo $line | cut -d : -f 2 | sed 's/ghcr.io\///' | sed 's/lscr.io\///'`
last_updated=""
page=1
# below adds by default the tag 'latest' to the images that are without tag, same way docker does
if [ "$tag" == "$image" ] ; then
tag="latest"
fi
repo=`curl --silent "https://hub.docker.com/v2/repositories/$image/tags?page=$page"`
# below is needed for non-docker hub images
if [ "$repo" == "{\"count\":0,\"next\":null,\"previous\":null,\"results\":[]}" ] ; then
last_updated="1970-01-01T00:00:00.000000Z"
elif [ "$repo" == "{\"detail\": \"Object not found\"}" ] ; then
last_updated="1970-01-01T00:00:00.000000Z"
fi
# below is necessary because most images will get multiple pages and your tag might not be on the first.
# I limited page to 100 because so far I never saw a request needing more that a dozen pages, and without
# a limit the loop could, should a bug arise, last forever.
while [ "$last_updated" == "" ] && [ "$page" -lt 100 ] ; do
repo=`curl --silent "https://hub.docker.com/v2/repositories/$image/tags?page=$page"`
last_updated=`echo $repo | jq --arg tag "$tag" '.results[] | select(.name==$tag) | .last_updated'`
# sleep below in order to reduce requests frequency
sleep 2
((page+=1))
done
# below comparison will give as a result updates from the last 24h ( 86400s )
# change '86400' to another value to increase or reduce that search time
current_epoch=$(expr "$(date '+%s')" - 86400)
last_updated_epoch=$(date -d $(echo $last_updated | cut -d \" -f 2) '+%s')
if [ "$lang" == "en" ] ; then
nope="No update for $line since yesterday."
else
nope="Pas de mise à jour pour $line depuis hier."
fi
if [ "$last_updated_epoch" \> "$current_epoch" ] ; then
list=$list$(echo "\n\n\`$line\`")
else
echo $nope
fi
done < images.list
if [ "$lang" == "en" ] ; then
text=\""An update is available for :$(echo $list)"\"
else
text=\""Une mise à jour est disponible pour :$(echo $list)"\"
fi
if [ "$server" == "discord" ] ; then
curl -H "Content-Type: application/json" -d "{\"username\": \"Methatronc\",\"embeds\":[{\"description\": $text, \"title\":\"Docker Image Update Checker\", \"color\":2960895}]}" $token
else
curl -H "Content-Type: application/json" -X POST $token -d "{\"title\":\"Docker Image Update Checker\",\"message\":$text,\"priority\":5,\"extras\":{\"client::display\":{\"contentType\":\"text/markdown\"}}}"
fi