gogs-version.sh 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #!/bin/bash
  2. # Version 0.1 - initial start of this localcheck
  3. # Installation
  4. # This file should be place on a/the Gogs (https://gogs.io) host in /usr/lib/check_mk_agent/local
  5. #
  6. # (optional) if you want the check to run on a different schedule (like once per hour) put it in a subdirectory of above path
  7. # named to the number of seconds of the interval wanted, so 3600/ for once an hour, 86400/ for once per day.
  8. #
  9. # Also do not forget to make this file executable with chmod +x /usr/lib/check_mk_agent/local/gogs-version.sh
  10. # (c) Michael Honkoop <mhonkoop@comsolve.nl>
  11. # License: GNU General Public License v2
  12. ######################
  13. # Configurable Parameters
  14. ######################
  15. # url to check releases against
  16. RELEASEURL="https://api.github.com/repos/gogs/gogs/releases"
  17. # basepath of where gogs is installed
  18. BASEPATH="/opt/gogs/"
  19. ######################
  20. # The code below should not be changed, unless you know EXACTLY what you are doing.
  21. # All configureable parameters are above this section.
  22. ######################
  23. # check if jq package is present on the system (required for this check)
  24. command -v jq >/dev/null 2>&1
  25. if [ $? -ne 0 ]; then
  26. echo "2 \"Gogs\" - Gogs localcheck requires jq package to be installed"
  27. exit 0
  28. fi
  29. # binary path
  30. GOGS_BIN="${BASEPATH}/gogs"
  31. # Check Gogs binary presence and report if not found
  32. if [[ ! -x "$GOGS_BIN" ]]; then
  33. echo "2 \"$SERVICE\" - Gogs executable not found: $GOGS_BIN check localcheck configuration."
  34. exit 0
  35. fi
  36. # Get current installed Gogs version-information
  37. GOGS_INSTALLED=$("$GOGS_BIN" --version | sed -nE 's/.*version ([0-9]+\.[0-9]+\.[0-9]+).*/\1/p')
  38. # Get latest avaiable version information.
  39. GOGS_AVAILABLE=$(curl -fsSL -H 'Accept: application/vnd.github+json' "$RELEASEURL" | jq -er 'map(select(.draft == false and .prerelease == false)) | .[0].tag_name' | sed 's/^v//')
  40. # Return status when latest version information could not be retrieved.
  41. if [[ -z "$GOGS_AVAILABLE" || "$GOGS_AVAILABLE" == "null" ]]; then
  42. echo "1 \"Gogs\" - No data received from release-URL, can not determine latest release-version."
  43. exit 0
  44. fi
  45. # Compare installed version to available version
  46. if [[ "$GOGS_INSTALLED" == "$GOGS_AVAILABLE" ]]; then
  47. echo "0 \"Gogs\" - Gogs version $GOGS_INSTALLED is up to date."
  48. elif [[ "$(printf '%s\n' "$GOGS_INSTALLED" "$GOGS_AVAILABLE" | sort -V | tail -n1)" == "$GOGS_AVAILABLE" ]]; then
  49. echo "1 \"Gogs\" - Update available: $GOGS_INSTALLED -> $GOGS_AVAILABLE"
  50. exit 0
  51. fi