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
|
|
|
|
|
2024-01-07 15:52:20 +01:00
|
|
|
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' )"
|
2020-05-13 20:07:50 +02:00
|
|
|
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
|
|
|
|
2024-01-07 15:52:20 +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
|
2024-01-07 15:52:20 +01:00
|
|
|
echo "WARNING ($INSTALLED_VERSION / $UPSTREAM_VERSION)"
|
2020-01-09 17:30:21 +01:00
|
|
|
exit 1
|
|
|
|
fi
|