blog-image

Détecter la mise à niveau de votre serveur Matrix

  • dHENRY
  • 23/02/2020
  • (Durée de lecture : 4 mn)

Vous trouverez ici deux méthodes permettant de détecter si votre serveur Matrix doit être mis à jour. Dans ces deux cas les résulats attendus sont :

  • [UPTODATE] 1 : Le serveur est à jour
  • [UPTODATE] 0 : Le serveur doit être mis à jour

Automate mytinydc-automation

Pour exécuter cette opération vous devez disposer du système “mytinydc-automation” voir l’article

Créer l’automate “matrix-check-isserviceupgradable” avec la commande :

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

coller le contenu qui suit dans l’éditeur “vi”, puis enregistrer (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 -i "server: "|sed "s/^< server: Synapse\///i"|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

Exécution de l’automate

mytinydc-automation.sh matrix-check-isserviceupgradable local URLMATRIXSERVER=[https://votre url de domaine Matrix]

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

Le serveur est il upgradable ?

Méthode par shell

Si vous n’utilisez pas “mytinydc-automation”, créer le shell /root/matrix-check-isserviceupgradable.sh :

vi /root/matrix-check-isserviceupgradable.sh

Coller ce contenu dans l’éditeur “vi”:

#!/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 -i "server: "|sed "s/^< server: Synapse\///i"|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 -i 'server: '|sed 's/^< server: Synapse\///i'|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

Le rendre exécutable :

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

Puis exécuter le comme suit :

/root/matrix-check-isserviceupgradable.sh [https://votre url de domaine Matrix]

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

Le serveur est il upgradable ?

Si le résultat obtenu est :

[UPTODATE] 0

Vous allez devoir procéder à la mise à jour de votre serveur.

Aller plus loin

  • Créer un système automatisé qui envoie un email lors de la détection d’une mise à jour nécessaire (cron + email)

Licence de ce document : Creative Commons (CC BY-NC-ND 4.0)

CETTE DOCUMENTATION EST LIVRÉE “EN L’ÉTAT”, SANS GARANTIE D’AUCUNE SORTE ET DISTRIBUÉE DANS UN BUT ÉDUCATIF EXCLUSIVEMENT. L’AUTEUR, CONTRIBUTEURS DE CETTE DOCUMENTATION OU ©MYTINYDC.COM NE SAURAIENT EN AUCUN CAS ÊTRE TENUS RESPONSABLES DES DOMMAGES DIRECTS OU INDIRECTS POUVANT RÉSULTER DE L’APPLICATION DES PROCÉDURES MISES EN ŒUVRE DANS CETTE DOCUMENTATION, OU DE LA MAUVAISE INTERPRÉTATION DE CE DOCUMENT.

Poster un commentaire

Désolé, la réponse à la question Captcha est incorrecte
Désolé, votre session a expiré ou votre navigateur refuse l'unique cookie de ce site.
Merci. le message est dans le tuyau :)
Désolé, il y a un problème dans le tuyau, veuillez réessayer plus tard :(
Un champs est invalide

Commentaires (non traduits)

Pas de commentaires