56 lines
1.5 KiB
Plaintext
56 lines
1.5 KiB
Plaintext
|
|
||
|
#!/bin/bash
|
||
|
#
|
||
|
# Nagios plugin to check paste version
|
||
|
#
|
||
|
# Author : Obitanz <hb+chapril@unenieme.eu>
|
||
|
# Date : 17 Jul 2023
|
||
|
#
|
||
|
|
||
|
OK=0
|
||
|
WARNING=1
|
||
|
CRITICAL=2
|
||
|
UNKNOWN=3
|
||
|
|
||
|
function usage() {
|
||
|
echo "Usage : $0"
|
||
|
echo "This script check if minetest mods are up to date"
|
||
|
result=${UNKNOWN}
|
||
|
}
|
||
|
|
||
|
# INFO
|
||
|
# 3 mods actuels : filter, xban2, whitelist
|
||
|
# les 2 premiers n'utilisent pas les tags ==> possible d'utiliser les commit pour déterminer si du nouveau
|
||
|
# le 3e utilise les tags, ça semble se coller aux derniers commit
|
||
|
# git rev-parse HEAD pour avoir le hash du dernier commit local
|
||
|
# git ls-remote origin | head -1 | cut -d " " -f 1
|
||
|
|
||
|
if [ "$#" -ne 0 ]; then
|
||
|
usage
|
||
|
else
|
||
|
mod_outdated=0
|
||
|
for mod in $(ls -1d /srv/minetest.chapril.org/home/.minetest/mods/*);
|
||
|
do
|
||
|
shortname=$(echo ${mod} | cut -d "/" -f 7)
|
||
|
lastCommit=$(cd ${mod} && git ls-remote origin | head -1 | cut -d " " -f 1)
|
||
|
currentCommit=$(cd ${mod} && git rev-parse HEAD)
|
||
|
|
||
|
if [ "${currentVersion}" = "${lastVersion}" ]; then
|
||
|
result_msg=${result_msg}"\n${shortname} is up to date"
|
||
|
else
|
||
|
result_msg=${result_msg}"\nnew version available for ${shortname}, current is ${currentVersion}, last is ${lastVersion}"
|
||
|
mod_outdated=1
|
||
|
fi
|
||
|
done
|
||
|
if [ ${mod_outdated} -eq 0 ]; then
|
||
|
echo "OK - all mods are up to date"
|
||
|
result=${OK}
|
||
|
else
|
||
|
echo -e "WARNING - all mods aren't up to date${result_msg}"
|
||
|
result=${WARNING}
|
||
|
fi
|
||
|
fi
|
||
|
|
||
|
exit $result
|
||
|
|