Last active
October 22, 2025 05:39
-
-
Save Roy-Orbison/e7a24ad07475d8af140b6f8900efbb62 to your computer and use it in GitHub Desktop.
Shell script to check for latest version of Mattermost Server, including patch releases, optionally filtered to Team Edition and/or ESR.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/sh | |
| set -e | |
| version_current=$( | |
| sudo -u "${MM_USER:-mattermost}" "${MM_BIN:-/opt/mattermost/bin/mattermost}" version | \ | |
| grep -Pio '^version:\s*\K\S+' | |
| ) | |
| if [ "${MM_TEAM_ED:-0}" -gt 0 ]; then | |
| ed=Team | |
| else | |
| ed=Enterprise | |
| fi | |
| if [ "${MM_ESR:-0}" -gt 0 ]; then | |
| esr=1 | |
| else | |
| esr=0 | |
| fi | |
| index=https://raw.githubusercontent.com/mattermost/docs/refs/heads/master/source/product-overview/version-archive.rst | |
| index=$(curl --no-progress-meter "$index") | |
| [ "$index" ] | |
| latest=$( | |
| awk -v ed=$ed -v esr=$esr "$(cat <<-'EOAWK' | |
| BEGIN { | |
| preamble = 1 | |
| RS = "\n +Mattermost " ed " Edition v" | |
| FS = "\n +-" | |
| } | |
| preamble { | |
| preamble=0 | |
| next | |
| } | |
| { | |
| if (esr && !match($1, /\(ESR\)/)) | |
| next | |
| v = gensub(/[[:space:]].*/, "", 1, $1) | |
| if (!match($3, "SHA-256")) { | |
| print "no checksum found" | |
| exit 1 | |
| } | |
| u = gensub(/^[^`]*`+|`.*/, "", "g", $2) | |
| c = gensub(/^[^`]*`+|`.*/, "", "g", $3) | |
| printf "%s\t%s\t%s\n", v, u, c | |
| exit | |
| } | |
| EOAWK | |
| )" <<-EORST | |
| $index | |
| EORST | |
| ) | |
| read -r version_latest archive checksum <<-EOT | |
| $latest | |
| EOT | |
| if [ "$version_current" != "$version_latest" ]; then | |
| curl -sS --json @- "$MM_HOOK" <<-EOJSON > /dev/null | |
| { | |
| "channel": "$MM_CHANNEL", | |
| "text": ":information_source: Mattermost upgrade available: [v$version_latest]($archive)\\nChecksum: \`$checksum\`\\n" | |
| } | |
| EOJSON | |
| fi |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Call with env vars like so:
But probably best to put them in a "config" file then source it:
You can override the system user account and path to binary with
MM_USERandMM_BIN, if you did not use the defaults.