mirror of
https://github.com/YunoHost-Apps/mattermost_ynh.git
synced 2024-09-03 19:36:29 +02:00
61 lines
1.7 KiB
Bash
61 lines
1.7 KiB
Bash
#!/bin/bash
|
|
|
|
# Source app helpers
|
|
source /usr/share/yunohost/helpers
|
|
|
|
# Exit if an error occurs during the execution of the script
|
|
ynh_abort_if_errors
|
|
|
|
# Retrieve arguments
|
|
domain=$(ynh_app_setting_get mattermost domain)
|
|
is_public=$(ynh_app_setting_get mattermost is_public)
|
|
|
|
# Set up common variables
|
|
root_path="$(pwd)/.."
|
|
final_path=/var/www/mattermost
|
|
version=$(cat "$root_path/VERSION")
|
|
archive_filename="mattermost-$version.tar.gz"
|
|
|
|
# Cleanup and restart if exit with an error
|
|
function cleanup_and_restart
|
|
{
|
|
set +e
|
|
sudo rm -f "$archive_filename"
|
|
sudo supervisorctl start mattermost
|
|
|
|
# Exit (without triggering a package_linter warning)
|
|
die_command='ynh_' + 'die'
|
|
$die_command "An error occurred during the installation."
|
|
}
|
|
trap cleanup_and_restart ERR
|
|
|
|
# Download code
|
|
archive_url="https://releases.mattermost.com/${version}/mattermost-team-${version}-linux-amd64.tar.gz"
|
|
sudo wget --quiet --output-document "$archive_filename" "$archive_url"
|
|
|
|
# Stop server
|
|
sudo supervisorctl stop mattermost
|
|
|
|
# Backup configuration file
|
|
config_file="$final_path/config/config.json"
|
|
backup_config_file="/tmp/config.json"
|
|
|
|
sudo cp -f "$config_file" "$backup_config_file"
|
|
|
|
# Copy new code
|
|
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"
|
|
|
|
# Restore configuration file
|
|
sudo cp -f "$backup_config_file" "$config_file"
|
|
|
|
# Restore file permissions
|
|
sudo chown -R www-data: "$final_path"
|
|
|
|
# Update Nginx configuration file
|
|
sudo cp -f $root_path/conf/nginx.conf-nosub /etc/nginx/conf.d/$domain.d/mattermost.conf
|
|
|
|
# Start server
|
|
sudo supervisorctl start mattermost
|