68 lines
1.5 KiB
Bash
68 lines
1.5 KiB
Bash
#!/bin/bash
|
|
# Author: Cpm
|
|
# License: GNU AGPLv3+
|
|
# Nagios plugin to check Forgejo version
|
|
|
|
function usage
|
|
{
|
|
echo "Usage : $0"
|
|
}
|
|
|
|
function get_gitea_local_version
|
|
{
|
|
local result
|
|
|
|
local DOMAIN_URL="$1"
|
|
|
|
result=$(curl -6 -s -X GET "${DOMAIN_URL}/api/v1/version" -H "accept: application/json" | egrep -Eo "[[:digit:].-]+")
|
|
|
|
echo "$result"
|
|
}
|
|
|
|
function get_last_version_from_gitea
|
|
{
|
|
local result
|
|
|
|
local DOMAIN_URL="$1"
|
|
local OWNER="$2"
|
|
local REPO_NAME="$3"
|
|
|
|
local result=$(curl -s -X GET "${DOMAIN_URL}/api/v1/repos/${OWNER}/${REPO_NAME}/releases" -H "accept: application/json" | jshon |grep tag_name | head -1 | egrep -Eo "[[:digit:].-]+")
|
|
|
|
echo "$result"
|
|
}
|
|
|
|
function get_forgejo_last_version
|
|
{
|
|
local result
|
|
|
|
result=$(get_last_version_from_gitea "https://codeberg.org" "forgejo" "forgejo")
|
|
|
|
echo "$result"
|
|
}
|
|
|
|
|
|
#
|
|
if [ "$#" -ne 0 ]; then
|
|
usage
|
|
else
|
|
localVersion=$(get_gitea_local_version "https://forge.a-lec.org")
|
|
#echo "Local version = $localVersion"
|
|
|
|
lastVersion=$(get_forgejo_last_version)
|
|
#echo "Last version = $lastVersion"
|
|
|
|
if [[ -z $localVersion ]]; then
|
|
echo "Bad local version value."
|
|
elif [[ -z $lastVersion ]]; then
|
|
echo "Bad last version value."
|
|
elif [ $localVersion = $lastVersion ]; then
|
|
echo "OK"
|
|
result=0
|
|
else
|
|
echo "WARNING : new version available, current is $localVersion, last is $lastVersion."
|
|
result=1
|
|
fi
|
|
fi
|
|
exit $result
|