1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/mattermost_ynh.git synced 2024-09-03 19:36:29 +02:00
mattermost_ynh/scripts/upgrade

111 lines
3.3 KiB
Text
Raw Normal View History

2015-11-18 17:23:35 +01:00
#!/bin/bash
2017-10-11 12:13:37 +02:00
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source /usr/share/yunohost/helpers
2015-11-18 17:23:35 +01:00
2017-10-11 12:13:37 +02:00
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
2017-10-11 12:13:37 +02:00
#=================================================
# LOAD SETTINGS
#=================================================
app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get mattermost domain)
is_public=$(ynh_app_setting_get mattermost is_public)
2015-11-18 17:23:35 +01:00
2016-04-17 18:35:42 +02:00
root_path="$(pwd)/.."
final_path=/var/www/mattermost
version=$(cat "$root_path/VERSION")
archive_filename="mattermost-$version.tar.gz"
2017-10-11 12:13:37 +02:00
#=================================================
# ACTIVE TRAP
#=================================================
2015-11-18 17:23:35 +01:00
function cleanup_and_restart
{
set +e
sudo rm -f "$archive_filename"
2015-11-18 17:23:35 +01:00
sudo supervisorctl start mattermost
# Exit (without triggering a package_linter warning)
die_command='ynh_' + 'die'
$die_command "An error occurred during the installation."
2015-11-18 17:23:35 +01:00
}
2016-04-17 17:57:47 +02:00
trap cleanup_and_restart ERR
2015-11-18 17:23:35 +01:00
2017-10-11 12:13:37 +02:00
#=================================================
# STANDARD UPGRADE STEPS
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
2016-04-17 18:35:42 +02:00
archive_url="https://releases.mattermost.com/${version}/mattermost-team-${version}-linux-amd64.tar.gz"
sudo wget --quiet --output-document "$archive_filename" "$archive_url"
2015-11-18 17:23:35 +01:00
2017-10-11 12:13:37 +02:00
#=================================================
# STOP SERVER
#=================================================
sudo supervisorctl stop mattermost
2017-10-11 12:13:37 +02:00
#=================================================
# BACKUP CONFIGURATION FILE
#=================================================
2016-04-17 18:35:42 +02:00
config_file="$final_path/config/config.json"
backup_config_file="/tmp/config.json"
sudo cp -f "$config_file" "$backup_config_file"
2015-11-18 17:23:35 +01:00
2017-10-11 12:13:37 +02:00
#=================================================
# COPY NEW CODE
#=================================================
2016-04-17 18:35:42 +02:00
sudo rm -rf "$final_path"
sudo mkdir -p "$final_path"
sudo tar -xvz --file "$archive_filename" --directory "$final_path" --strip-components 1
sudo rm -f "$archive_filename"
2015-11-18 17:23:35 +01:00
2017-10-11 12:13:37 +02:00
#=================================================
# RESTORE CONFIGURATION FILE
#=================================================
2016-04-17 18:35:42 +02:00
sudo cp -f "$backup_config_file" "$config_file"
2015-11-18 17:23:35 +01:00
2017-10-11 12:13:37 +02:00
#=================================================
# SPECIFIC UPGRADE STEPS
#=================================================
# Fix log FileLocation path (changed in Mattermost 3.8, makes Mattermost >= 4.2 crash)
# https://docs.mattermost.com/administration/changelog.html#release-v3-8-3
sudo sed -i "s|\"FileLocation\": \"/var/log/mattermost.log\"|\"FileLocation\": \"/var/log\"|g" "$config_file"
2017-10-11 12:13:37 +02:00
#=================================================
# RESTORE FILE PERMISSIONS
#=================================================
2016-04-17 18:35:42 +02:00
sudo chown -R www-data: "$final_path"
2015-11-18 17:23:35 +01:00
2017-10-11 12:13:37 +02:00
#=================================================
# RELOAD NGINX
#=================================================
sudo service nginx reload
#=================================================
# START SERVER
#=================================================
2015-11-18 17:23:35 +01:00
sudo supervisorctl start mattermost