Skip to content

Instantly share code, notes, and snippets.

@Roy-Orbison
Last active August 28, 2025 02:05
Show Gist options
  • Save Roy-Orbison/e7a24ad07475d8af140b6f8900efbb62 to your computer and use it in GitHub Desktop.
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.
#!/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
@Roy-Orbison
Copy link
Author

Call with env vars like so:

MM_HOOK=https://your-mm-server.example/hooks/abcdefghijklmnopqrstuvwxyz \
	MM_CHANNEL=@your_username \
	MM_TEAM_ED=1 \
	MM_ESR=1 \
	mattermost-version-check

But probably best to put them in a "config" file then source it:

(set -a && . ./.mm-vc-env && mattermost-version-check)

You can override the system user account and path to binary with MM_USER and MM_BIN, if you did not use the defaults.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment