Created
December 2, 2019 13:44
-
-
Save x42en/5457cb970d0277945b303a8a5e15476e to your computer and use it in GitHub Desktop.
Mattermost Entreprise Edition upgrade automation tool
This file contains 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/bash | |
echo "..:: Mattermost Upgrade ::.." | |
function usage { | |
echo "Usage: $0 [VERSION NUMBER]" | |
exit 1 | |
} | |
INSTALLDIR='/opt' | |
VERSION=$1 | |
if [[ -z $VERSION ]]; then | |
usage | |
fi | |
CURRENT=$(${INSTALLDIR}/mattermost/bin/mattermost version | grep "Build Number:" | awk '{print $NF}') | |
echo "[+] Current installed version is ${CURRENT}" | |
if [[ "${VERSION}" == "${CURRENT}" ]]; then | |
echo "[!] You are already on latest version..." | |
exit 0 | |
fi | |
cd /tmp/ | |
echo "[+] Download Mattermost v${VERSION}" | |
URL="https://releases.mattermost.com/${VERSION}/mattermost-${VERSION}-linux-amd64.tar.gz" | |
CORRECT=$(curl --head --write-out %{http_code} --silent --output /dev/null ${URL}) | |
if [[ "${CORRECT}" -ne '200' ]]; then | |
echo "[!] This version does not exists!" | |
exit 1 | |
fi | |
wget -q ${URL} | |
echo "[+] Extract to mattermost-update" | |
tar -xf mattermost*.gz --transform='s,^[^/]\+,\0-upgrade,' | |
echo "[+] Stop Mattermost service" | |
service mattermost stop | |
echo "[+] Migrate new files" | |
cd ${INSTALLDIR} | |
cp -ra mattermost/ mattermost-back-$(date +'%F-%H-%M')/ | |
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 | xargs rm -r | |
mv mattermost/plugins/ mattermost/plugins~ | |
mv mattermost/client/plugins/ mattermost/client/plugins~ | |
chown -hR mattermost:mattermost /tmp/mattermost-upgrade/ | |
cp -an /tmp/mattermost-upgrade/. mattermost/ | |
rm -rf /tmp/mattermost-upgrade/ | |
echo "[+] Reinstall plugins" | |
cd ${INSTALLDIR}/mattermost | |
rsync -au plugins~/ plugins | |
rm -rf plugins~ | |
rsync -au client/plugins~/ client/plugins | |
rm -rf client/plugins~ | |
echo "[+] Restart services" | |
service mattermost start | |
echo "[+] Remove /tmp files" | |
rm /tmp/mattermost-${VERSION}-linux-amd64.tar.gz | |
echo "[+] All done!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment