2015-11-18 17:23:35 +01:00
|
|
|
#!/bin/bash
|
2017-02-04 19:14:21 +01:00
|
|
|
set -eu # exit on error ; treat unset variables as error
|
|
|
|
|
2017-02-04 19:20:51 +01:00
|
|
|
# Source app helpers
|
|
|
|
source /usr/share/yunohost/helpers
|
2015-11-18 17:23:35 +01:00
|
|
|
|
|
|
|
# Retrieve arguments
|
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
|
|
|
# Set up common variables
|
|
|
|
root_path="$(pwd)/.."
|
|
|
|
final_path=/var/www/mattermost
|
|
|
|
version=$(cat "$root_path/VERSION")
|
|
|
|
archive_filename="mattermost-$version.tar.gz"
|
|
|
|
|
2015-11-18 17:23:35 +01:00
|
|
|
# Cleanup and restart if exit with an error
|
|
|
|
function cleanup_and_restart
|
|
|
|
{
|
|
|
|
set +e
|
2017-09-12 12:00:26 +02:00
|
|
|
sudo rm -f "$archive_filename"
|
2015-11-18 17:23:35 +01:00
|
|
|
sudo supervisorctl start mattermost
|
2017-02-04 19:20:51 +01:00
|
|
|
|
|
|
|
# Exit (without triggering a package_linter warning)
|
2017-09-12 12:00:10 +02:00
|
|
|
die_command='ynh_' + 'die'
|
2017-02-04 19:20:51 +01:00
|
|
|
$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
|
|
|
|
|
|
|
# Download code
|
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-09-12 11:59:47 +02:00
|
|
|
# Stop server
|
|
|
|
sudo supervisorctl stop mattermost
|
|
|
|
|
2015-11-18 17:23:35 +01: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
|
|
|
|
|
|
|
# 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
|
|
|
|
|
|
|
# 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
|
|
|
|
|
|
|
# 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-07-21 22:08:33 +02:00
|
|
|
# Update Nginx configuration file
|
|
|
|
sudo cp -f $root_path/conf/nginx.conf-nosub /etc/nginx/conf.d/$domain.d/mattermost.conf
|
|
|
|
|
2015-11-18 17:23:35 +01:00
|
|
|
# Start server
|
|
|
|
sudo supervisorctl start mattermost
|