| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- # Version 0.1 - initial start of this localcheck
- # Installation
- # This file should be place on a/the Gogs (https://gogs.io) host in /usr/lib/che ck_mk_agent/local
- #
- # (optional) if you want the check to run on a different schedule (like once per hour) put it in a subdirectory of above path
- # named to the number of seconds of the interval wanted, so 3600/ for once an ho ur, 86400/ for once per day.
- #
- # Also do not forget to make this file executable with chmod +x /usr/lib/check_m k_agent/local/gogs-version.sh
- # (c) Michael Honkoop <mhonkoop@comsolve.nl>
- # License: GNU General Public License v2
- ######################
- # Configurable Parameters
- ######################
- # url to check releases against
- RELEASEURL="https://api.github.com/repos/gogs/gogs/releases"
- # basepath of where gogs is installed (no trailing slash-forward)
- BASEPATH="/opt/gogs"
- # Gogs executable
- GOGS_BIN="${BASEPATH}/gogs"
- # Service name
- SERVICE="Gogs"
- ######################
- # The code below should not be changed, unless you know EXACTLY what you are doi ng.
- # All configureable parameters are above this section.
- ######################
- # check if jq package is present on the system (required for this check)
- command -v jq >/dev/null 2>&1
- if [ $? -ne 0 ]; then
- echo "2 \"$SERVICE\" - $SERVICE localcheck requires jq package to be install ed"
- exit 0
- fi
- # Check Gogs binary presence and report if not found
- if [[ ! -x "$GOGS_BIN" ]]; then
- echo "2 \"$SERVICE\" - Gogs executable not found: $GOGS_BIN check localcheck configuration."
- exit 0
- fi
- # Get current installed Gogs version-information
- GOGS_INSTALLED=$("$GOGS_BIN" --version | sed -nE 's/.*version ([0-9]+\.[0-9]+\.[ 0-9]+).*/\1/p')
- if [[ -z "$GOGS_INSTALLED" ]]; then
- echo "3 \"$SERVICE\" - Gogs executable found, but returned no valid version"
- exit 0
- fi
- # Get latest avaiable version information.
- GOGS_AVAILABLE=$(curl -fsSL -H 'Accept: application/vnd.github+json' "$RELEASEUR L" | jq -er 'map(select(.draft == false and .prerelease == false)) | .[0].tag_na me' | sed 's/^v//')
- # Return status when latest version information could not be retrieved.
- if [[ -z "$GOGS_AVAILABLE" || "$GOGS_AVAILABLE" == "null" ]]; then
- echo "1 \"$SERVICE\" - No data received from release-URL, can not determine latest release-version."
- exit 0
- fi
- # Compare installed version to available version
- if [[ "$GOGS_INSTALLED" == "$GOGS_AVAILABLE" ]]; then
- echo "0 \"$SERVICE\" - Gogs version $GOGS_INSTALLED is up to date."
- elif [[ "$(printf '%s\n' "$GOGS_INSTALLED" "$GOGS_AVAILABLE" | sort -V | tail -n 1)" == "$GOGS_AVAILABLE" ]]; then
- echo "1 \"$SERVICE\" - Update available: $GOGS_INSTALLED -> $GOGS_AVAILABLE"
- exit 0
- fi
|