1
0
Fork 0
scripts-admin-quickndirty-p.../nagios/check_gitea_version.sh

49 lines
1.1 KiB
Bash
Raw Permalink Normal View History

2020-01-09 17:30:21 +01:00
#!/bin/sh
# Quick and dirty NRPE script to check if
# the local version of Gitea is up to date.
# Stop at first uncatched error
set -e
usage() {
cat <<EOF
$0 -H hostname -I address
TODO: write the rest :)
EOF
}
while getopts H:I: f; do
case "$f" in
'H')
HOSTNAME="$OPTARG"
;;
'I')
HOSTADDRESS="$OPTARG"
# If there is some ":" in the adress, we treat it as IPv6
if echo "$HOSTADDRESS" | grep ":" >/dev/null 2>&1; then
HOSTADDRESS="[$HOSTADDRESS]"
fi
;;
\?)
usage
exit 1
;;
esac
done
INSTALLED_VERSION="$( wget -O - --header="Host: $HOSTNAME" --no-check-certificate -q "https://$HOSTADDRESS/api/v1/version" | sed -n 's/{"version":"\([^"]\+\)"}/\1/p' )"
UPSTREAM_VERSION="$( wget -q -O - "https://dl.gitea.io/gitea/" | egrep -- '<a href="/gitea/[0-9]+\.[0-9]+\.[0-9]+/?"' | egrep -o "[0-9]+\.[0-9]+\.[0-9]+" | sort --version-sort | tail -n 1 )"
2020-01-09 17:30:21 +01:00
if [ "$UPSTREAM_VERSION" = "$INSTALLED_VERSION" ]; then
echo "OK ($INSTALLED_VERSION / $UPSTREAM_VERSION)"
2020-01-09 17:30:21 +01:00
exit 0
else
echo "WARNING ($INSTALLED_VERSION / $UPSTREAM_VERSION)"
2020-01-09 17:30:21 +01:00
exit 1
fi