1
0

gogs-version.sh 3.3 KB

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