54 lines
1.5 KiB
Bash
Executable File
54 lines
1.5 KiB
Bash
Executable File
#!/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 games are up to date"
|
|
result=${UNKNOWN}
|
|
}
|
|
|
|
if [ "$#" -ne 0 ]; then
|
|
usage
|
|
else
|
|
game_outdated=-1
|
|
for game in $(ls -1d /srv/minetest.chapril.org/home/.minetest/games/*);
|
|
do
|
|
shortname=$(echo ${game} | cut -d "/" -f 7)
|
|
lastVersion=$(cd ${game} && git -c 'versionsort.suffix=-' ls-remote --exit-code --refs --sort='version:refname' --tags origin '*.*.*' | tail --lines=1 | cut --delimiter='/' --fields=3)
|
|
currentVersion=$(cd ${game} && git describe --tags --abbrev=0)
|
|
|
|
if [ "${currentVersion}" = "${lastVersion}" ]; then
|
|
result_msg=${result_msg}"\n${shortname} is up to date"
|
|
if [ ${game_outdated} -eq -1 ]; then
|
|
game_outdated=0
|
|
fi
|
|
else
|
|
result_msg=${result_msg}"\nnew version available for ${shortname}, current is ${currentVersion}, last is ${lastVersion}"
|
|
game_outdated=1
|
|
fi
|
|
done
|
|
if [ ${game_outdated} -eq 0 ]; then
|
|
echo "OK - all games are up to date"
|
|
result=${OK}
|
|
elif [ ${game_outdated} -eq -1 ]; then
|
|
echo "UNKNWON - error during script execution"
|
|
result=${UNKNOWN}
|
|
else
|
|
echo -e "WARNING - all games aren't up to date${result_msg}"
|
|
result=${WARNING}
|
|
fi
|
|
fi
|
|
|
|
exit $result
|
|
|