Created
July 18, 2019 14:40
-
-
Save elpatron68/6cf4d5b4970860b6dc02a26877f0dbcc to your computer and use it in GitHub Desktop.
Parse latest Mattermost download url and launch update process.
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
import re | |
import os | |
import io | |
import requests | |
import subprocess | |
try: | |
os.remove('index.html') | |
except: | |
pass | |
# https://mattermost.com/download/ seems to redirect to another url - Python requests returns "forbidden" so we use wget here | |
subprocess.call(['wget', 'https://mattermost.com/download/']) | |
f = io.open("index.html", mode="r", encoding="utf-8") | |
test_str = f.read() | |
f.close() | |
regex = r'https:\/\/releases\.mattermost\.com\/\d+\.\d+\.\d+\/mattermost-team-\d+\.\d+\.\d+-linux-amd64\.tar\.gz' | |
match = '' | |
try: | |
match = re.findall(regex, test_str)[0] | |
except: | |
pass | |
if match != '': | |
os.environ["URL"] = match | |
print('Found Mattermost download URL:') | |
print(match) | |
print('') | |
print('Starting update script') | |
input("Press Enter to continue...") | |
subprocess.call(['sh','./mm-update.sh']) | |
else: | |
print('Something went wrong.') |
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/sh | |
cd /tmp | |
wget $URL | |
tar -xf mattermost*.gz --transform='s,^[^/]\+,\0-upgrade,' | |
sudo systemctl stop mattermost | |
cd ~/ | |
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 | sudo xargs rm -r | |
mv mattermost/plugins/ mattermost/plugins~ | |
mv mattermost/client/plugins/ mattermost/client/plugins~ | |
cp -an /tmp/mattermost-upgrade/. mattermost/ | |
rm -r /tmp/mattermost-upgrade/ | |
cd ~/mattermost | |
sudo systemctl start mattermost | |
rsync -au plugins~/ plugins | |
rm -rf plugins~ | |
rsync -au client/plugins~/ client/plugins |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment