Skip to content

Instantly share code, notes, and snippets.

@Roy-Orbison
Last active October 22, 2025 05:39
Show Gist options
  • Select an option

  • Save Roy-Orbison/e7a24ad07475d8af140b6f8900efbb62 to your computer and use it in GitHub Desktop.

Select an option

Save Roy-Orbison/e7a24ad07475d8af140b6f8900efbb62 to your computer and use it in GitHub Desktop.

Revisions

  1. Roy-Orbison revised this gist Oct 22, 2025. No changes.
  2. Roy-Orbison revised this gist Oct 22, 2025. 1 changed file with 15 additions and 9 deletions.
    24 changes: 15 additions & 9 deletions mattermost-version-check
    Original file line number Diff line number Diff line change
    @@ -11,16 +11,21 @@ if [ "${MM_TEAM_ED:-0}" -gt 0 ]; then
    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_checksum=$(
    awk -v ed=$ed -v esr="${MM_ESR:-0}" '
    latest=$(
    awk -v ed=$ed -v esr=$esr "$(cat <<-'EOAWK'
    BEGIN {
    preamble = 1
    RS = "$|Mattermost " ed " Edition v"
    FS = "\n"
    RS = "\n +Mattermost " ed " Edition v"
    FS = "\n +-"
    }
    preamble {
    preamble=0
    @@ -29,7 +34,7 @@ latest_checksum=$(
    {
    if (esr && !match($1, /\(ESR\)/))
    next
    v = gensub(/[[:space:]].*/, "", "g", $1)
    v = gensub(/[[:space:]].*/, "", 1, $1)
    if (!match($3, "SHA-256")) {
    print "no checksum found"
    exit 1
    @@ -39,12 +44,13 @@ latest_checksum=$(
    printf "%s\t%s\t%s\n", v, u, c
    exit
    }
    ' <<-EOT
    $index
    EOT
    EOAWK
    )" <<-EORST
    $index
    EORST
    )
    read -r version_latest archive checksum <<-EOT
    $latest_checksum
    $latest
    EOT

    if [ "$version_current" != "$version_latest" ]; then
  3. Roy-Orbison revised this gist Aug 28, 2025. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion mattermost-version-check
    Original file line number Diff line number Diff line change
    @@ -12,7 +12,7 @@ else
    ed=Enterprise
    fi

    index=https://github.com/mattermost/docs/raw/refs/heads/master/source/product-overview/version-archive.rst
    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=$(
  4. Roy-Orbison renamed this gist Aug 15, 2025. 1 changed file with 0 additions and 0 deletions.
  5. Roy-Orbison revised this gist Aug 15, 2025. 1 changed file with 47 additions and 16 deletions.
    63 changes: 47 additions & 16 deletions mattermost-esr-version-check.sh
    Original file line number Diff line number Diff line change
    @@ -1,26 +1,57 @@
    #!/bin/sh
    set -e

    mm_hook=https://you-mm-server.example/hooks/abcdefghijklmnopqrstuvwxyz
    mm_channel=@your_username
    version_current=$(
    sudo -u "${MM_USER:-mattermost}" "${MM_BIN:-/opt/mattermost/bin/mattermost}" version | \
    grep -Pio '^version:\s*\K\S+'
    )

    read -r latest checksum <<-EOSH
    $(curl --no-progress-meter https://docs.mattermost.com/about/version-archive.html | \
    tr '\r\n' ' ' | \
    perl -ne 'print "$1\t$2\n" if m/<dt\b[^<]+?\bTeam\b[^<]+<[^<]+?\bESR\b(?:(?!<dt\b).)+?>\K(https:\/\/releases.mattermost.com\/[^\s<]+).*?\b([[:xdigit:]]{64})\b/'
    )
    EOSH
    if ! [ "$latest" ]; then
    echo Could not determine latest version >&2
    exit 1
    if [ "${MM_TEAM_ED:-0}" -gt 0 ]; then
    ed=Team
    else
    ed=Enterprise
    fi
    version_current=$(sudo -u mattermost /opt/mattermost/bin/mattermost version | grep -Pio '^version:\s*\K\S+')
    version_latest=$(printf '%s\n' "$latest" | grep -Po '/\K\d+\.\d+\.\d+(?=/)')

    index=https://github.com/mattermost/docs/raw/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
    curl -sS --json @- "$MM_HOOK" <<-EOJSON > /dev/null
    {
    "channel": "$mm_channel",
    "text": ":information_source: Mattermost upgrade available: [v$version_latest]($latest)\\nChecksum: \`$checksum\`\\n"
    "channel": "$MM_CHANNEL",
    "text": ":information_source: Mattermost upgrade available: [v$version_latest]($archive)\\nChecksum: \`$checksum\`\\n"
    }
    EOJSON
    fi
  6. Roy-Orbison created this gist Nov 15, 2024.
    26 changes: 26 additions & 0 deletions mattermost-esr-version-check.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,26 @@
    #!/bin/sh

    mm_hook=https://you-mm-server.example/hooks/abcdefghijklmnopqrstuvwxyz
    mm_channel=@your_username

    read -r latest checksum <<-EOSH
    $(curl --no-progress-meter https://docs.mattermost.com/about/version-archive.html | \
    tr '\r\n' ' ' | \
    perl -ne 'print "$1\t$2\n" if m/<dt\b[^<]+?\bTeam\b[^<]+<[^<]+?\bESR\b(?:(?!<dt\b).)+?>\K(https:\/\/releases.mattermost.com\/[^\s<]+).*?\b([[:xdigit:]]{64})\b/'
    )
    EOSH
    if ! [ "$latest" ]; then
    echo Could not determine latest version >&2
    exit 1
    fi
    version_current=$(sudo -u mattermost /opt/mattermost/bin/mattermost version | grep -Pio '^version:\s*\K\S+')
    version_latest=$(printf '%s\n' "$latest" | grep -Po '/\K\d+\.\d+\.\d+(?=/)')

    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]($latest)\\nChecksum: \`$checksum\`\\n"
    }
    EOJSON
    fi