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).
October 15, 2021: Updated the script to work with the new Mattermost download page
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
55
56
57
58
59
60
61
62
63
64
65
66
| #!/bin/bash
# Mattermost documentation: https://docs.mattermost.com/administration/upgrade.html
# Mattermost download: https://mattermost.com/deploy/
# Variables
downloadLink=$(curl -v --silent https://mattermost.com/deploy/ 2>&1 | grep 'https://releases.mattermost.com/.*/mattermost-[[:digit:]].*-linux-amd64.tar.gz' | sed 's/.* value=\"\(.*\)\".*/\1/' | sed 's/\?src\=dl//')
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 'Removing the plugins directories so they do not interfere with the upgrade'
mv mattermost/plugins/ mattermost/plugins~
mv mattermost/client/plugins/ mattermost/client/plugins~
echo 'Changing ownership of the new files before copying them'
chown -hR mattermost:mattermost /tmp/mattermost-upgrade/
echo 'Copying the new files to your install directory and remove the temporary files'
cp -an /tmp/mattermost-upgrade/. mattermost/
rm -r /tmp/mattermost-upgrade/
echo 'Starting mattermost service'
sudo systemctl start mattermost
echo 'Upgrade your config.json schema and continue then! (Open the System Console and change a setting, then revert it. This should enable the Save button for that page. Click Save. Refresh the page.)'
read -p 'Continue?'
echo 'Reinstating the plugins directories, then restart the mattermost service'
cd /opt/mattermost
rsync -au plugins~/ plugins
rm -rf plugins~
rsync -au client/plugins~/ client/plugins
rm -rf client/plugins~
sudo systemctl restart mattermost
echo 'Removing downloaded file'
rm /tmp/$fileName
echo 'Finished.'
else
echo 'Exiting.'
fi
|