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

48 lines
1.1 KiB
Bash
Executable file

#!/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 )"
if [ "$UPSTREAM_VERSION" = "$INSTALLED_VERSION" ]; then
echo "OK ($INSTALLED_VERSION / $UPSTREAM_VERSION)"
exit 0
else
echo "WARNING ($INSTALLED_VERSION / $UPSTREAM_VERSION)"
exit 1
fi