blog-image

Detecting your Matrix Server Upgrade

  • dHENRY
  • 23/02/2020
  • (Reading time : 3 mn)

(**) Translated with www.DeepL.com/Translator

Here you will find two methods to detect if your Matrix server needs to be updated. In both cases the expected results are :

  • [UPTODATE] 1: The server is up to date.
  • [UPTODATE] 0: Server needs to be updated

Mytinydc-automation

To perform this operation you must have the “mytinydc-automation” system see article

Create the robot “matrix-check-isserviceupgradable” with the command :

mytinydc-automation.sh -c matrix-check-isserviceupgradable

paste the following content into the editor “vi”, then save (ESC :wq).

#CHECK URLMATRIXSERVER url complète ex: https://matrix.mondomaine.com

# Dépendances
apt-get update
apt-get -y install curl

#Get des releases disponibles sur github
URLGITHUB="https://github.com/matrix-org/synapse/releases"
VERSIONS=`curl -kv $URLGITHUB 2>&1|grep "tag\/v"|sed -E "s/<[^>]*>//g"|sed -E "s/synapse//i"|grep -v "rc"`

# Keep the first
LATEST=""
for v in $VERSIONS
do
    LATEST="$v"
    break;
done
if [ "$LATEST" = "" ];then
    echo "[*ERR] - La dernière version connue de matrix est introuvable" >&2
    exit 1
fi
# Get de la realease de notre matrix
MVERSION=`curl -kv $URLMATRIXSERVER/_matrix/client/versions 2>&1|grep "Server: "|sed "s/^< Server: Synapse\///"|sed -E "s/\r//g"`
echo "[SERVER] $URLMATRIXSERVER"
echo "[VSERVER] v$MVERSION"
echo "[VMATRIX] $LATEST"
if [ "v$MVERSION" != "$LATEST" ];then
    echo "[UPTODATE] 0"
else
    echo "[UPTODATE] 1"
fi

Execution of the robot

mytinydc-automation.sh matrix-check-isserviceupgradable local URLMATRIXSERVER=[https://your Matrix domain url]

# Example : mytinydc-automation.sh matrix-check-isserviceupgradable local URLMATRIXSERVER=https://monmatrix.mondomaine.com

Is the server upgradable ?

Shell method

If you don’t use “mytinydc-automation”, create the shell /root/matrix-check-isserviceupgradable.sh :

vi /root/matrix-check-isserviceupgradable.sh

Paste this content into the “vi” editor:

#!/bin/bash
######################################################################
## Built with mytinydc-automation process - https://www.mytinydc.com
######################################################################
export APT_KEY_DONT_WARN_ON_DANGEROUS_USAGE="DontWarn"
export DEBIAN_FRONTEND="noninteractive"
export DATEBUILT="Sun Feb 23 18:07:14 CET 2020"
export SERVER="`uname -n`"
export PARAMSSH="-q -o UserKnownHostsFile=/dev/null -o PasswordAuthentication=no -o ConnectTimeout=5 -o StrictHostKeyChecking=no"
URLMATRIXSERVER="$1"
if [ "$1" = "" ];then
    echo "[ERR] Le paramètre N° 1 est manquant"
    echo "    - [Commentaire sur cette valeur]  url complète ex: https://matrix.mondomaine.com"
    exit 1
fi
# Dependances
apt-get update
ERR=$?
if [ "$ERR" != "0" ];then
    echo "[Automate] /var/lib/mytinydc/automates/matrix-check-isserviceupgradable/script.mtya" >&2
    echo "[Code Erreur] $ERR" >&2
    echo "[Serveur] $SERVER" >&2
    echo "[Commande] apt-get update" >&2
    
    exit $ERR
fi

apt-get -y install curl
ERR=$?
if [ "$ERR" != "0" ];then
    echo "[Automate] /var/lib/mytinydc/automates/matrix-check-isserviceupgradable/script.mtya" >&2
    echo "[Code Erreur] $ERR" >&2
    echo "[Serveur] $SERVER" >&2
    echo "[Commande] apt-get -y install curl" >&2
    
    exit $ERR
fi

#Get des releases disponibles sur github
URLGITHUB="https://github.com/matrix-org/synapse/releases"
VERSIONS=`curl -kv $URLGITHUB 2>&1|grep "tag\/v"|sed -E "s/<[^>]*>//g"|sed -E "s/synapse//i"|grep -v "rc"`
ERR=$?
if [ "$ERR" != "0" ];then
    echo "[Automate] /var/lib/mytinydc/automates/matrix-check-isserviceupgradable/script.mtya" >&2
    echo "[Code Erreur] $ERR" >&2
    echo "[Serveur] $SERVER" >&2
    echo "[Commande] VERSIONS=curl -kv $URLGITHUB 2>&1|grep 'tag\/v'|sed -E 's/<[^>]*>//g'|sed -E 's/synapse//i'|grep -v 'rc'" >&2
    
    exit $ERR
fi

##echo $VERSIONS
# Keep the first
LATEST=""
for v in $VERSIONS
do
    LATEST="$v"
ERR=$?
if [ "$ERR" != "0" ];then
    echo "[Automate] /var/lib/mytinydc/automates/matrix-check-isserviceupgradable/script.mtya" >&2
    echo "[Code Erreur] $ERR" >&2
    echo "[Serveur] $SERVER" >&2
    echo "[Commande] LATEST='$v'" >&2
    
    exit $ERR
fi

    break;
ERR=$?
if [ "$ERR" != "0" ];then
    echo "[Automate] /var/lib/mytinydc/automates/matrix-check-isserviceupgradable/script.mtya" >&2
    echo "[Code Erreur] $ERR" >&2
    echo "[Serveur] $SERVER" >&2
    echo "[Commande] break;" >&2
    
    exit $ERR
fi

done
if [ "$LATEST" = "" ];then
    echo "[*ERR] - La dernière version connue de matrix est introuvable" >&2
    exit 1
fi
# Get de la realease de notre matrix
MVERSION=`curl -kv $URLMATRIXSERVER/_matrix/client/versions 2>&1|grep "Server: "|sed "s/^< Server: Synapse\///"|sed -E "s/\r//g"`
ERR=$?
if [ "$ERR" != "0" ];then
    echo "[Automate] /var/lib/mytinydc/automates/matrix-check-isserviceupgradable/script.mtya" >&2
    echo "[Code Erreur] $ERR" >&2
    echo "[Serveur] $SERVER" >&2
    echo "[Commande] MVERSION=curl -kv $URLMATRIXSERVER/_matrix/client/versions 2>&1|grep 'Server: '|sed 's/^< Server: Synapse\///'|sed -E 's/\r//g'" >&2
    
    exit $ERR
fi

echo "[SERVER] $URLMATRIXSERVER"
echo "[VSERVER] v$MVERSION"
echo "[VMATRIX] $LATEST"
if [ "v$MVERSION" != "$LATEST" ];then
    echo "[UPTODATE] 0"
else
    echo "[UPTODATE] 1"
fi

Make it executable :

chmod 755 /root/matrix-check-isserviceupgradable.sh

Then perform the following :

/root/matrix-check-isserviceupgradable.sh [https://your Matrix domain url]

# Exemple : /root/matrix-check-isserviceupgradable.sh https://monmatrix.mondomaine.com

Is the server upgradable ?

If the result is :

[UPTODATE] 0 

You will need to update your server.

Going further

  • Create an automated system that sends an email upon detection of a necessary update (cron + email)

Document licence : Creative Commons (CC BY-NC-ND 4.0)

THIS DOCUMENTATION IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND AND DISTRIBUTED FOR EDUCATIONAL PURPOSES ONLY. THE AUTHOR, CONTRIBUTORS TO THIS DOCUMENTATION OR ©MYTINYDC.COM SHALL IN NO EVENT BE LIABLE FOR ANY DIRECT OR INDIRECT DAMAGE THAT MAY RESULT FROM THE APPLICATION OF THE PROCEDURES IMPLEMENTED IN THIS DOCUMENTATION, OR FROM THE INCORRECT INTERPRETATION OF THIS DOCUMENT.

(**) Translated with www.DeepL.com/Translator

Post a comment

Sorry, the answer to the Captcha question is incorrect
Thank you. The Mailman is on His Way :)
Sorry, don't know what happened. Please to try later :(
One field is not valid

Comments (not translated)

No comments