Dépôt d'outils pour le service valise.chapril.org. https://valise.chapril.org/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

89 lines
2.2 KiB

#! /bin/bash
#
# Copyright (C) 2020 Laurent Poujoulat <lpoujoulat@april.org>
#
# This file is part of valise.chapril.org
#
# This script is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# ================================================
# This checks for updates of nextcloud components.
# If any update is present, they are listed in human readable form on stdout, and 1 is returned,
# and if everything is OK, tell it on stdout "OK", and returns 0.
#
# This is a Nagios plugin and thus follows its return code standards
# ================================================
# Configuration data
NEXTCLOUD_ROOT="/var/www/valise.chapril.org"
# Constants for return codes
readonly NS_OK=0
readonly NS_WARNING=1
readonly NS_CRITICAL=1
readonly NS_UNKNOWN=1
# Returns script usage
function usage()
{
echo "Usage: $(basename $0)"
}
# Main entry point
# By default, we assume to fail
EXIT_RESULT=${NS_UNKNOWN}
# Usage check
if [ "$#" -ne 0 ]
then
usage
else
# Currently, nor the serverinfo API, nor the occ command has a clean way of checking both the core and apps update status
# So we trick this by calling the occ update:check command and processing the output
cd ${NEXTCLOUD_ROOT}
UPDATE_LIST=$(sudo -u www-data php occ update:check)
if [ $? != 0 ]
then
EXIT_RESULT=${NS_CRITICAL}
echo "Failed to check Nextcloud update"
else
# OK, we have the human readable status, let's process it
echo ${UPDATE_LIST} | grep -q "Everything up to date"
if [ $? == 0 ]
then
EXIT_RESULT=${NS_OK}
echo "OK"
else
EXIT_RESULT=${NS_WARNING}
echo ${UPDATE_LIST}
fi
fi
fi
exit ${EXIT_RESULT}