mirror of
https://github.com/YunoHost-Apps/mattermost_ynh.git
synced 2024-09-03 19:36:29 +02:00
130 lines
4.6 KiB
Bash
130 lines
4.6 KiB
Bash
#!/bin/bash
|
|
|
|
source _common.sh
|
|
source /usr/share/yunohost/helpers
|
|
|
|
#=================================================
|
|
# ENSURE DOWNWARD COMPATIBILITY
|
|
#=================================================
|
|
|
|
# Save the language used if not present
|
|
# FIXME: maybe replace with: ynh_app_setting_set_default --key=language --value="en"
|
|
if [ -z "${language:-}" ]; then
|
|
language="en"
|
|
ynh_app_setting_set --key=language --value=$language
|
|
fi
|
|
|
|
# If version setting doesn't exist
|
|
# FIXME: maybe replace with: ynh_app_setting_set_default --key=version --value="Team"
|
|
if [ -z "${version:-}" ]; then
|
|
version="Team"
|
|
ynh_app_setting_set --key=version --value=$version
|
|
fi
|
|
|
|
#=================================================
|
|
# MIGRATING DATABASE
|
|
#=================================================
|
|
|
|
# Check if using MariaDB
|
|
# This migration should be done before the upgrade
|
|
if mysqlshow | grep -q "^| $db_name "; then
|
|
# Mattermost recommands PostgreSQL over MySQL (and doesn't support MariaDB at all)
|
|
# Migrate the database from MySQL/MariaDB to PostgreSQL
|
|
remove_psql_in_case_of_error=1
|
|
mariadb-to-pg
|
|
fi
|
|
|
|
#=================================================
|
|
# STOP SYSTEMD SERVICE
|
|
#=================================================
|
|
ynh_script_progression "Stopping $app's systemd service..."
|
|
|
|
ynh_systemctl --service=$app --action=stop --log_path=systemd
|
|
|
|
#=================================================
|
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
|
#=================================================
|
|
ynh_script_progression "Upgrading source files..."
|
|
|
|
# Create a temporary directory
|
|
tmpdir="$(mktemp -d)"
|
|
|
|
# Backup the config file and local plugins in the temp dir
|
|
cp -a "$install_dir/config/config.json" "$tmpdir/config.json"
|
|
cp -ar "$install_dir/plugins" "$tmpdir/plugins"
|
|
|
|
# Remove the app directory securely
|
|
ynh_safe_rm "$install_dir"
|
|
|
|
if [ "$version" = "Enterprise" ]; then
|
|
ynh_setup_source --dest_dir="$install_dir" --source_id="enterprise"
|
|
elif [ "$version" = "Team" ]; then
|
|
ynh_setup_source --dest_dir="$install_dir" --source_id="main"
|
|
fi
|
|
|
|
# Copy the admin saved settings and plugins from tmp directory to final path
|
|
cp -a "$tmpdir/config.json" "$install_dir/config/config.json"
|
|
|
|
cp -ar --no-clobber "$tmpdir/plugins" "$install_dir/"
|
|
|
|
# Remove the tmp directory securely
|
|
ynh_safe_rm "$tmpdir"
|
|
|
|
chmod -R o-rwx "$install_dir"
|
|
chown -R $app:www-data "$install_dir"
|
|
|
|
#=================================================
|
|
# REAPPLY SYSTEM CONFIGURATIONS
|
|
#=================================================
|
|
ynh_script_progression "Upgrading system configurations related to $app..."
|
|
|
|
# Create a dedicated NGINX config
|
|
ynh_config_add_nginx
|
|
|
|
# Create a dedicated systemd config
|
|
ynh_config_add_systemd
|
|
|
|
yunohost service add $app --description="Collaboration platform built for developers" --log="/var/log/$app/$app.log"
|
|
|
|
# Use logrotate to manage app-specific logfile(s)
|
|
ynh_config_add_logrotate
|
|
|
|
#=================================================
|
|
# Fix old migrations
|
|
#=================================================
|
|
# Crazy fix for old unupgraded version
|
|
# IMPORTANT: THIS fix should be done after setup new sources and running Mattermost
|
|
if ynh_app_upgrading_from_version_before 5.37.1~ynh1
|
|
then
|
|
read -r -d '' fix_old_version_sql << EOM
|
|
ALTER TABLE ChannelMembers ALTER COLUMN mentioncountroot SET DEFAULT '0'::bigint;
|
|
UPDATE ChannelMembers SET mentioncountroot=0 WHERE mentioncountroot IS NULL;
|
|
ALTER TABLE ChannelMembers ALTER COLUMN msgcountroot SET DEFAULT '0'::bigint;
|
|
UPDATE ChannelMembers SET msgcountroot=0 WHERE msgcountroot IS NULL;
|
|
ALTER TABLE Channels ALTER COLUMN totalmsgcountroot SET DEFAULT '0'::bigint;
|
|
UPDATE Channels SET totalmsgcountroot=0 WHERE totalmsgcountroot IS NULL;
|
|
UPDATE SidebarCategories SET collapsed=False where collapsed IS NULL;
|
|
UPDATE SidebarCategories SET muted=False where muted IS NULL;
|
|
UPDATE SidebarCategories set sorting = 'manual' where sorting='';
|
|
UPDATE SidebarCategories set sorting = 'manual' where sorting IS NULL;
|
|
EOM
|
|
|
|
ynh_psql_db_shell <<< "$fix_old_version_sql"
|
|
|
|
# Note: it's possible that some instances need other fixes
|
|
# If nothing is displayed in the sidebar it may be needed to change the Id of SidebarCategories...
|
|
fi
|
|
|
|
#=================================================
|
|
# START SYSTEMD SERVICE
|
|
#=================================================
|
|
ynh_script_progression "Starting $app's systemd service..."
|
|
|
|
# Start a systemd service
|
|
ynh_systemctl --service=$app --action=start --log_path=systemd --wait_until="Started Mattermost"
|
|
|
|
#=================================================
|
|
# END OF SCRIPT
|
|
#=================================================
|
|
|
|
ynh_script_progression "Upgrade of $app completed"
|