Upgrading a Mattermost Server
is not complicated, but requires some steps that can be mostly automated. I’m watching ‘Releases only’ on the GitHub repository
to get a notification when a new version is available and start the script manually.
Below script assumes, that Mattermost is installed at the default location /opt/mattermost
. The script first greps the current download link from the official Mattermost Download page
, displays the found link and asks if it should continue. Rest should be self-explanatory (see echo messages).
April 24, 2023: Updated the script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
| #!/bin/bash
# Version: 2023-04-24
# Mattermost documentation: https://docs.mattermost.com/upgrade/upgrading-mattermost-server.html
# Mattermost download: https://mattermost.com/download/
# Variables
currentVersion=$(curl -v --silent https://mattermost.com/download/ 2>&1 | grep 'release-info' -A 2 | grep -Eo '[[:digit:]]+.[[:digit:]]+.[[:digit:]]+')
echo 'Current version is:' $currentVersion
downloadLink="https://releases.mattermost.com/${currentVersion}/mattermost-${currentVersion}-linux-amd64.tar.gz"
echo 'Download link is:' $downloadLink
fileName=${downloadLink##*/}
echo 'File name is:' $fileName
# Continue?
read -p 'Do you want to continue (y/n)?' decision
# Start
if [ "$decision" = "y" ]; then
echo 'Moving to /tmp'
cd /tmp
echo 'Downloading latest version'
wget $downloadLink
echo 'Extracting files'
tar -xf mattermost*.gz --transform='s,^[^/]\+,\0-upgrade,'
echo 'Stopping mattermost service'
sudo systemctl stop mattermost
echo 'Backing up current files'
cd /opt
cp -ra mattermost/ mattermost-back-$(date +'%F-%H-%M')/
echo 'Removing all files except special directories from within the current mattermost directory'
find mattermost/ mattermost/client/ -mindepth 1 -maxdepth 1 \! \( -type d \( -path mattermost/client -o -path mattermost/client/plugins -o -path mattermost/config -o -path mattermost/logs -o -path mattermost/plugins -o -path mattermost/data \) -prune \) | sort | sudo xargs rm -r
echo 'Copying the new files to your install directory and remove the temporary files'
cp -an /tmp/mattermost-upgrade/. mattermost/
echo 'Changing ownership of new files and folders'
chown -hR mattermost:mattermost mattermost/
echo 'Starting mattermost service'
sudo systemctl start mattermost
echo 'Removing downloaded file'
rm -r /tmp/mattermost-upgrade/
rm /tmp/$fileName
echo 'Finished.'
else
echo 'Exiting.'
fi
|