2015-11-18 17:23:35 +01:00
|
|
|
#!/bin/bash
|
2017-02-04 19:14:21 +01:00
|
|
|
|
2017-10-11 12:13:37 +02:00
|
|
|
#=================================================
|
|
|
|
# GENERIC START
|
|
|
|
#=================================================
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
#=================================================
|
|
|
|
|
2017-02-04 19:20:51 +01:00
|
|
|
source /usr/share/yunohost/helpers
|
2015-11-18 17:23:35 +01:00
|
|
|
|
2017-10-11 12:13:37 +02:00
|
|
|
#=================================================
|
|
|
|
# MANAGE SCRIPT FAILURE
|
|
|
|
#=================================================
|
|
|
|
|
2017-10-10 13:00:33 +02:00
|
|
|
# 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
|
|
|
|
#=================================================
|
|
|
|
|
2017-10-10 14:26:45 +02:00
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
2017-02-04 19:20:51 +01:00
|
|
|
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)/.."
|
2017-10-12 12:47:51 +02:00
|
|
|
final_path="/var/www/$app"
|
|
|
|
data_path="/home/yunohost.app/$app"
|
2016-04-17 18:35:42 +02:00
|
|
|
version=$(cat "$root_path/VERSION")
|
|
|
|
archive_filename="mattermost-$version.tar.gz"
|
|
|
|
|
2017-10-11 12:13:37 +02:00
|
|
|
#=================================================
|
2017-10-11 12:20:00 +02:00
|
|
|
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
# Backup the current version of the app
|
|
|
|
ynh_backup_before_upgrade
|
2017-10-12 12:47:51 +02:00
|
|
|
|
|
|
|
# If the upgrade fails…
|
2017-10-11 12:20:00 +02:00
|
|
|
ynh_clean_setup () {
|
2017-10-12 12:47:51 +02:00
|
|
|
# Stop attempting to restart the app
|
|
|
|
if $(sudo systemctl -q is-active "$app"); then
|
|
|
|
sudo systemctl stop "$app"
|
|
|
|
fi
|
|
|
|
# Restore the backup
|
2017-10-11 12:20:00 +02:00
|
|
|
ynh_restore_upgradebackup
|
|
|
|
# Remove the temporary archive
|
|
|
|
sudo rm -f "$archive_filename"
|
2015-11-18 17:23:35 +01:00
|
|
|
}
|
2017-10-11 12:20:00 +02:00
|
|
|
|
|
|
|
# Exit if an error occurs during the execution of the script
|
|
|
|
ynh_abort_if_errors
|
2015-11-18 17:23:35 +01:00
|
|
|
|
2017-10-11 12:13:37 +02:00
|
|
|
#=================================================
|
2017-10-11 12:20:00 +02:00
|
|
|
# DOWNLOAD SOURCE
|
2017-10-11 12:13:37 +02:00
|
|
|
#=================================================
|
|
|
|
|
2016-04-17 18:35:42 +02:00
|
|
|
archive_url="https://releases.mattermost.com/${version}/mattermost-team-${version}-linux-amd64.tar.gz"
|
2017-02-04 19:20:51 +01:00
|
|
|
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
|
|
|
|
#=================================================
|
|
|
|
|
2017-10-12 12:47:51 +02:00
|
|
|
# Stop the server (if the app is already using systemd)
|
|
|
|
if $(sudo systemctl -q is-active "$app"); then
|
|
|
|
sudo systemctl stop "$app"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Legacy, for older versions of this app which used supervisor
|
|
|
|
if [ -f "/etc/supervisor/conf.d/${app}.conf" ]; then
|
|
|
|
sudo supervisorctl stop "$app"
|
|
|
|
sudo rm -f "/etc/supervisor/conf.d/${app}.conf"
|
|
|
|
fi
|
2017-09-12 11:59:47 +02:00
|
|
|
|
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
|
2017-02-04 19:20:51 +01:00
|
|
|
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-12 12:47:51 +02:00
|
|
|
#=================================================
|
|
|
|
# NGINX CONFIGURATION
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
ynh_add_nginx_config
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SYSTEMD CONFIGURATION
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
ynh_add_systemd_config
|
|
|
|
|
2017-10-12 14:51:54 +02:00
|
|
|
#=================================================
|
|
|
|
# ADVERTISE SERVICE IN ADMIN PANEL
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
sudo yunohost service add "$app" --log "/var/log/${app}.log"
|
|
|
|
|
2017-10-11 12:13:37 +02:00
|
|
|
#=================================================
|
|
|
|
# SPECIFIC UPGRADE STEPS
|
|
|
|
#=================================================
|
|
|
|
|
2017-10-10 13:34:43 +02:00
|
|
|
# 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
|
|
|
|
#=================================================
|
|
|
|
|
2017-10-12 12:47:51 +02:00
|
|
|
sudo chown -R mattermost:www-data "$final_path"
|
|
|
|
sudo chown -R mattermost:www-data "$data_path"
|
|
|
|
|
|
|
|
sudo touch "/var/log/mattermost.log"
|
|
|
|
sudo chown mattermost:adm "/var/log/mattermost.log"
|
2015-11-18 17:23:35 +01:00
|
|
|
|
2017-10-11 12:13:37 +02:00
|
|
|
#=================================================
|
|
|
|
# RELOAD NGINX
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
sudo service nginx reload
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# START SERVER
|
|
|
|
#=================================================
|
2017-07-21 22:08:33 +02:00
|
|
|
|
2017-10-12 12:47:51 +02:00
|
|
|
sudo systemctl start "$app"
|