Last active
August 28, 2025 02:05
-
-
Save Roy-Orbison/e7a24ad07475d8af140b6f8900efbb62 to your computer and use it in GitHub Desktop.
Shell script to check for latest version of Mattermost Server. Select Team Edition an, including patch releases.
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 | |
index=https://raw.githubusercontent.com/mattermost/docs/refs/heads/master/source/product-overview/version-archive.rst | |
index=$(curl --no-progress-meter "$index") | |
[ "$index" ] | |
latest_checksum=$( | |
awk -v ed=$ed -v esr="${MM_ESR:-0}" ' | |
BEGIN { | |
preamble = 1 | |
RS = "$|Mattermost " ed " Edition v" | |
FS = "\n" | |
} | |
preamble { | |
preamble=0 | |
next | |
} | |
{ | |
if (esr && !match($1, /\(ESR\)/)) | |
next | |
v = gensub(/[[:space:]].*/, "", "g", $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 | |
} | |
' <<-EOT | |
$index | |
EOT | |
) | |
read -r version_latest archive checksum <<-EOT | |
$latest_checksum | |
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 |
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_USER
andMM_BIN
, if you did not use the defaults.