status.chapril.org-tools/monitoring/check_statuschaprilorg_update

40 lines
779 B
Plaintext
Raw Normal View History

2020-12-26 22:11:51 +01:00
#!/bin/bash
#
json=$(curl -s https://status.chapril.org/api/v1/version)
#
regexp='.*"data":\s*"([^"]+)".*'
if [[ $json =~ $regexp ]]; then
currentVersion=${BASH_REMATCH[1]}
else
currentVersion=
fi
#
regexp='.*"tag_name":\s*"v([^"]+)".*'
if [[ $json =~ $regexp ]]; then
lastVersion=${BASH_REMATCH[1]}
else
lastVersion=
fi
#echo "$currentVersion"
#echo "$lastVersion"
if [ -z "$currentVersion" ]; then
echo "WARNING : current version not found."
result=1
elif [ -z "$lastVersion" ]; then
echo "WARNING : last version not found."
result=1
elif [ $currentVersion = $lastVersion ]; then
echo "OK"
result=0
else
echo "WARNING : new version available, current is $currentVersion, last is $lastVersion."
result=1
fi
exit $result