valise.chapril.org-tools/monitoring/check_valisechaprilorg_update

77 lines
1.9 KiB
Plaintext
Raw Normal View History

#! /bin/bash
#
2020-06-30 11:27:12 +02:00
# 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.
# ================================================
# Configuration data
NEXTCLOUD_ROOT="/var/www/valise.chapril.org"
# Returns script usage
function usage()
{
echo "Usage: $(basename $0)"
}
# Main entry point
2020-06-30 12:06:23 +02:00
# By default, we assume to fail
EXIT_RESULT=1
# 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
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
echo "OK"
EXIT_RESULT=0
else
echo ${UPDATE_LIST}
fi
fi
fi
exit ${EXIT_RESULT}