Added version upgrade detection script (#5053).

This commit is contained in:
Christian P. MOMON 2020-12-28 18:11:51 +01:00 committed by root
parent 3b37ef607f
commit 66f5e0da5d

View File

@ -0,0 +1,56 @@
#!/bin/bash
# Copyright (C) 2020 Christian Pierre Momon <christian@momon.org>
#
# This file is part of qrcode.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/>.
#
#
line=$(grep libreqrVersion /var/www/qrcode.chapril.org/inc.php)
regexp='.*"([^"]+)".*'
if [[ $line =~ $regexp ]]; then
currentVersion=${BASH_REMATCH[1]}
else
currentVersion=
fi
#
line=$(curl -s -X GET "https://code.antopie.org/api/v1/repos/miraty/libreqr/releases" -H "accept: application/json" | jshon |grep tag_name | head -1)
regexp='.*"([1234567890.]+)".*'
if [[ $line =~ $regexp ]]; then
lastVersion=${BASH_REMATCH[1]}
else
lastVersion=
fi
#echo "[$currentVersion]"
#echo "[$lastVersion]"
if [ -z "$currentVersion" ]; then
echo "WARNING : current version not found."
result=1
elif [ -z "$lastVersion" ]; then
echo "WARNING : last version not found."
result=1
elif [ "$currentVersion" = "$lastVersion" ]; then
echo "OK $currentVersion"
result=0
else
echo "WARNING : new version available, current is $currentVersion, last is $lastVersion."
result=1
fi
exit $result