1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/mattermost_ynh.git synced 2024-09-03 19:36:29 +02:00
This commit is contained in:
Éric Gaspar 2024-06-22 21:41:44 +02:00
parent d0e543b226
commit 6e0ea8868d
9 changed files with 106 additions and 147 deletions

3
.gitignore vendored
View file

@ -1,2 +1,5 @@
.vagrant
*~
~.sw[op]
.DS_Store

View file

@ -18,6 +18,7 @@ code = "https://github.com/mattermost/mattermost-server"
[integration]
yunohost = ">= 11.2"
helpers_version = "2.1"
architectures = ["amd64", "armhf", "arm64"]
multi_instance = true

View file

@ -1,7 +1,7 @@
#!/bin/bash
#=================================================
# COMMON VARIABLES
# COMMON VARIABLES AND CUSTOM HELPERS
#=================================================
# We want Mattermost emails to be sent from the main domain
@ -9,19 +9,15 @@
# and not the subdomain or secondary domain used for Mattermost.
main_domain=$(cat /etc/yunohost/current_host)
#=================================================
# PERSONAL HELPERS
#=================================================
mariadb-to-pg() {
ynh_print_info --message="Migrating to PostgreSQL database..."
ynh_print_info "Migrating to PostgreSQL database..."
# Retrieve MySQL user and password
mysqlpwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd)
mysqlpwd=$(ynh_app_setting_get --key=mysqlpwd)
mysql_db_user="$db_user"
if ynh_mysql_connect_as --user="mmuser" --password="$mysqlpwd" 2> /dev/null <<< ";"; then
if ynh_mysql_db_shell <<< ";"; then
# On old instances db_user is `mmuser`
mysql_db_user="mmuser"
fi
@ -32,21 +28,25 @@ mariadb-to-pg() {
ynh_write_var_in_file --file="$install_dir/config/config.json" --key="DataSource" --value="postgres://$db_user:$db_pwd@localhost:5432/$db_name?sslmode=disable&connect_timeout=10" --after="SqlSettings"
cat "$install_dir/config/config.json"
pushd $install_dir
ynh_systemd_action --service_name="$app" --action="stop"
ynh_systemctl --service="$app" --action="stop"
set +e
sudo -u $app timeout --preserve-status 300 "./bin/mattermost"
ynh_exec_as_app timeout --preserve-status 300 "./bin/mattermost"
if [ "$?" != "0" ] && [ "$?" != "143" ] ; then
ynh_die --message="Failed to run Mattermost to create PostgreSQL database tables" --ret_code=1
ynh_die "Failed to run Mattermost to create PostgreSQL database tables" --ret_code=1
fi
set -e
popd
# Some fixes to let the MariaDB -> PostgreSQL conversion working
ynh_psql_execute_as_root --sql='DROP INDEX public.idx_fileinfo_content_txt;' --database=$db_name
ynh_psql_execute_as_root --sql='DROP INDEX public.idx_posts_message_txt;' --database=$db_name
ynh_mysql_execute_as_root --sql="ALTER TABLE mattermost.Users DROP COLUMN IF EXISTS acceptedtermsofserviceid;" --database=$db_name
ynh_mysql_execute_as_root --sql="ALTER TABLE mattermost.SharedChannelRemotes DROP COLUMN IF EXISTS description;" --database=$db_name
ynh_mysql_execute_as_root --sql="ALTER TABLE mattermost.SharedChannelRemotes DROP COLUMN IF EXISTS nextsyncat;" --database=$db_name
ynh_psql_db_shell <<< "'DROP INDEX public.idx_fileinfo_content_txt;'
ynh_psql_db_shell <<< "'DROP INDEX public.idx_posts_message_txt;'
ynh_mysql_db_shell <<< "ALTER TABLE mattermost.Users DROP COLUMN IF EXISTS acceptedtermsofserviceid;"
ynh_mysql_db_shell <<< "ALTER TABLE mattermost.SharedChannelRemotes DROP COLUMN IF EXISTS description;"
ynh_mysql_db_shell <<< "ALTER TABLE mattermost.SharedChannelRemotes DROP COLUMN IF EXISTS nextsyncat;"
# Focalboard is broken in Mattermost 7.3.0
if ynh_compare_current_package_version --comparison eq --version 7.3.0~ynh1
@ -81,24 +81,18 @@ EOT
pgloader $tmpdir/commands.load
# Rebuild INDEX
ynh_psql_execute_as_root --sql='CREATE INDEX idx_fileinfo_content_txt ON public.fileinfo USING gin (to_tsvector('\''english'\''::regconfig, content))' --database=$db_name
ynh_psql_execute_as_root --sql='CREATE INDEX idx_posts_message_txt ON public.posts USING gin (to_tsvector('\''english'\''::regconfig, (message)::text));' --database=$db_name
ynh_psql_db_shell <<< "'CREATE INDEX idx_fileinfo_content_txt ON public.fileinfo USING gin (to_tsvector('\''english'\''::regconfig, content))'
ynh_psql_db_shell <<< "'CREATE INDEX idx_posts_message_txt ON public.posts USING gin (to_tsvector('\''english'\''::regconfig, (message)::text));'
if ynh_compare_current_package_version --comparison eq --version 7.3.0~ynh1
then
# There is a problem with version 7.3.0 and the database migration.
# More information here: https://forum.mattermost.com/t/migrating-from-mariadb-to-postgresql-db/14194/6
ynh_psql_execute_as_root --sql="DELETE FROM db_migrations WHERE version=92;" --database=$db_name
ynh_psql_db_shell <<< ""DELETE FROM db_migrations WHERE version=92;"
fi
# Remove the MariaDB database
ynh_mysql_remove_db --db_user=$mysql_db_user --db_name=$db_name
# FIXME ynh_mysql_drop_db && ynh_mysql_drop_user --db_user=$mysql_db_user --db_name=$db_name
}
#=================================================
# EXPERIMENTAL HELPERS
#=================================================
#=================================================
# FUTURE OFFICIAL HELPERS
#=================================================

View file

@ -6,42 +6,39 @@
source /usr/share/yunohost/helpers
#=================================================
# DECLARE DATA AND CONF FILES TO BACKUP
#=================================================
ynh_print_info --message="Declaring files to be backed up..."
ynh_print_info "Declaring files to be backed up..."
#=================================================
# BACKUP THE APP MAIN DIR
#=================================================
ynh_backup --src_path="$install_dir"
ynh_backup "$install_dir"
#=================================================
# BACKUP THE APP DATA
#=================================================
ynh_backup --src_path="$data_dir" --is_big
ynh_backup "$data_dir"
#=================================================
# SYSTEM CONFIGURATION
#=================================================
ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf"
ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf"
ynh_backup --src_path="/etc/logrotate.d/$app"
ynh_backup "/etc/logrotate.d/$app"
ynh_backup --src_path="/etc/systemd/system/$app.service"
ynh_backup "/etc/systemd/system/$app.service"
#=================================================
# BACKUP THE DATABASE
#=================================================
ynh_print_info --message="Backing up the database..."
ynh_print_info "Backing up the database..."
ynh_psql_dump_db --database="$db_name" > db.sql
ynh_psql_dump_db > db.sql
#=================================================
# END OF SCRIPT
#=================================================
ynh_print_info --message="Backup script completed for $app. (YunoHost will then actually copy those files to the archive)."
ynh_print_info "Backup script completed for $app. (YunoHost will then actually copy those files to the archive)."

View file

@ -1,55 +1,45 @@
#!/bin/bash
#=================================================
# GENERIC STARTING
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# STANDARD MODIFICATIONS
#=================================================
# STOP SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Stopping a systemd service..." --weight=4
ynh_script_progression "Stopping $app's systemd service..."
ynh_systemd_action --service_name=$app --action=stop --log_path="systemd"
ynh_systemctl --service=$app --action=stop --log_path="systemd"
#=================================================
# MODIFY URL IN NGINX CONF
#=================================================
ynh_script_progression --message="Updating NGINX web server configuration..." --weight=2
ynh_script_progression "Updating NGINX web server configuration..."
ynh_change_url_nginx_config
ynh_config_change_url_nginx
#=================================================
# EDIT MATTERMOST CONFIG
#=================================================
# MODIFY A CONFIG FILE
#=================================================
ynh_script_progression --message="Modifying a config file..." --weight=3
ynh_script_progression "Updating configuration..."
# Main config File
ynh_replace_string --match_string="\"SiteURL\": \".*\"" --replace_string="\"SiteURL\": \"https://${new_domain}${new_path}\"" --target_file="$install_dir/config/config.json"
ynh_replace_string --match_string="\"FeedbackEmail\": \".*\"" --replace_string="\"FeedbackEmail\": \"no-reply@${new_domain}\"" --target_file="$install_dir/config/config.json"
ynh_replace --match="\"SiteURL\": \".*\"" --replace="\"SiteURL\": \"https://${new_domain}${new_path}\"" --file="$install_dir/config/config.json"
ynh_replace --match="\"FeedbackEmail\": \".*\"" --replace="\"FeedbackEmail\": \"no-reply@${new_domain}\"" --file="$install_dir/config/config.json"
ynh_store_file_checksum --file="$install_dir/config/config.json"
ynh_store_file_checksum "$install_dir/config/config.json"
#=================================================
# GENERIC FINALISATION
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting a systemd service..." --weight=2
ynh_script_progression "Starting $app's systemd service..."
# Start a systemd service
ynh_systemd_action --service_name=$app --action=start --log_path=systemd --line_match="Started Mattermost"
ynh_systemctl --service=$app --action=start --log_path=systemd --wait_until="Started Mattermost"
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Change of URL completed for $app" --last
ynh_script_progression "Change of URL completed for $app"

View file

@ -1,18 +1,12 @@
#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
ynh_script_progression --message="Setting up source files..." --weight=3
ynh_script_progression "Setting up source files..."
# Download, check integrity, uncompress and patch the source from app.src
@ -31,23 +25,23 @@ chown -R $app:www-data "$install_dir"
#=================================================
# MODIFY A CONFIG FILE
#=================================================
ynh_script_progression --message="Modifying a config file..." --weight=3
ynh_script_progression "Updating configuration..."
smtp_user_pwd=$(ynh_string_random --length=24)
url=https://$domain$path
ynh_add_config --template="config.json" --destination="$install_dir/config/config.json"
ynh_config_add --template="config.json" --destination="$install_dir/config/config.json"
#=================================================
# SYSTEM CONFIGURATION
#=================================================
ynh_script_progression --message="Adding system configurations related to $app..." --weight=1
ynh_script_progression "Adding system configurations related to $app..."
# Create a dedicated NGINX config
ynh_add_nginx_config
ynh_config_add_nginx
# Create a dedicated systemd config
ynh_add_systemd_config
ynh_config_add_systemd
yunohost service add $app --description="Collaboration platform built for developers" --log="/var/log/$app/$app.log"
@ -56,20 +50,20 @@ mkdir -p /var/log/$app
chown $app -R "/var/log/$app"
# Setup logrotate
ynh_use_logrotate
ynh_config_add_logrotate
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting a systemd service..." --weight=2
ynh_script_progression "Starting $app's systemd service..."
# Start a systemd service
ynh_systemd_action --service_name=$app --action=start --log_path=systemd --line_match="Started Mattermost"
ynh_systemctl --service=$app --action=start --log_path=systemd --wait_until="Started Mattermost"
#=================================================
# CREATE ADMIN AND FIRST TEAM
#=================================================
ynh_script_progression --message="Create the first administrator and team..." --weight=1
ynh_script_progression "Create the first administrator and team..."
team_name=$(echo "$team_display_name" | iconv -f utf8 -t ascii//TRANSLIT//IGNORE | sed -e 's/[^[:alnum:]]/-/g' | tr -s '-' | tr A-Z a-z)
bin_mmctl="$install_dir/bin/mmctl"
@ -78,16 +72,16 @@ email=$(ynh_user_get_info --username=$admin --key=mail)
export MMCTL_LOCAL=true
export MMCTL_LOCAL_SOCKET_PATH="/var/run/${app}/mattermost_local.socket"
ynh_exec_warn_less sudo --preserve-env -u $app "$bin_mmctl" user create --username "$admin" --email "$email" --password "$password" --locale "$language" --email-verified --system-admin
ynh_exec_warn_less sudo --preserve-env -u $app "$bin_mmctl" team create --name "$team_name" --display_name "$team_display_name" --email "$email"
ynh_exec_warn_less sudo --preserve-env -u $app "$bin_mmctl" team users add "$team_name" "$admin"
ynh_hide_warnings sudo --preserve-env -u $app "$bin_mmctl" user create --username "$admin" --email "$email" --password "$password" --locale "$language" --email-verified --system-admin
ynh_hide_warnings sudo --preserve-env -u $app "$bin_mmctl" team create --name "$team_name" --display_name "$team_display_name" --email "$email"
ynh_hide_warnings sudo --preserve-env -u $app "$bin_mmctl" team users add "$team_name" "$admin"
# Disable mmctl passwordless access
ynh_replace_string '"EnableLocalMode": true' '"EnableLocalMode": false' "$install_dir/config/config.json"
ynh_systemd_action --service_name=$app --action=restart --log_path=systemd --line_match="Started Mattermost"
ynh_replace '"EnableLocalMode": true' '"EnableLocalMode": false' "$install_dir/config/config.json"
ynh_systemctl --service=$app --action=restart --log_path=systemd --wait_until="Started Mattermost"
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Installation of $app completed" --last
ynh_script_progression "Installation of $app completed"

View file

@ -1,11 +1,5 @@
#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
@ -13,27 +7,28 @@ source /usr/share/yunohost/helpers
# REMOVE SYSTEM CONFIGURATIONS
#=================================================
# REMOVE SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Removing system configurations related to $app..." --weight=1
ynh_script_progression "Removing system configurations related to $app..."
# Remove the service from the list of services known by YunoHost (added from `yunohost service add`)
if ynh_exec_warn_less yunohost service status $app >/dev/null
if ynh_hide_warnings yunohost service status $app >/dev/null
then
ynh_script_progression --message="Removing $app service..." --weight=1
ynh_script_progression "Removing $app service..."
yunohost service remove $app
fi
# Stop the server, and remove the dedicated systemd config
ynh_remove_systemd_config
ynh_config_remove_systemd
# Remove the app-specific logrotate config
ynh_remove_logrotate
ynh_config_remove_logrotate
# Remove the dedicated NGINX config
ynh_remove_nginx_config
ynh_config_remove_nginx
# Remove the log file
ynh_secure_remove --file="/var/log/$app"
#REMOVEME? (Apps should not remove their log dir during remove ... this should only happen if --purge is used, and be handled by the core...) ynh_safe_rm "/var/log/$app"
# If the user attempted to upgrade from an older MariaDB-based version, but the upgrade failed,
# the 'remove' action will automatically remove the PostgreSQL database but doesn't know
@ -41,12 +36,12 @@ ynh_secure_remove --file="/var/log/$app"
# In that case, remove the MariaDB database manually.
if mysqlshow | grep -q "^| $db_name "
then
ynh_script_progression --message="Removing MariaDB database..." --weight=1
ynh_mysql_remove_db --db_user=$db_user --db_name=$db_name
ynh_script_progression "Removing MariaDB database..."
# FIXME ynh_mysql_drop_db && ynh_mysql_drop_user --db_user=$db_user --db_name=$db_name
fi
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Removal of $app completed" --last
ynh_script_progression "Removal of $app completed"

View file

@ -1,29 +1,23 @@
#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source ../settings/scripts/_common.sh
source /usr/share/yunohost/helpers
#=================================================
# RESTORE THE APP MAIN DIR
#=================================================
ynh_script_progression --message="Restoring the app main directory..." --weight=2
ynh_script_progression "Restoring the app main directory..."
ynh_restore_file --origin_path="$install_dir"
ynh_restore "$install_dir"
chown -R $app:www-data "$install_dir"
#=================================================
# RESTORE THE DATA DIRECTORY
#=================================================
ynh_script_progression --message="Restoring the data directory..." --weight=4
ynh_script_progression "Restoring the data directory..."
ynh_restore_file --origin_path="$data_dir" --not_mandatory
ynh_restore "$data_dir"
chown -R $app:www-data "$data_dir"
@ -32,37 +26,35 @@ chown -R $app:www-data "$data_dir"
#=================================================
# RESTORE THE PHP-FPM CONFIGURATION
#=================================================
ynh_script_progression --message="Restoring system configurations related to $app..." --weight=1
ynh_script_progression "Restoring system configurations related to $app..."
ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
ynh_restore "/etc/nginx/conf.d/$domain.d/$app.conf"
ynh_psql_execute_file_as_root --file="./db.sql" --database=$db_name
ynh_psql_db_shell < "./db.sql""
logs_path="/var/log/$app"
mkdir -p $logs_path
chown -R $app: $logs_path
ynh_restore_file "/etc/systemd/system/$app.service"
ynh_restore "/etc/systemd/system/$app.service"
systemctl enable $app.service --quiet
yunohost service add $app --description="Collaboration platform built for developers" --log="/var/log/$app/$app.log"
ynh_restore_file --origin_path="/etc/logrotate.d/$app"
ynh_restore "/etc/logrotate.d/$app"
#=================================================
# GENERIC FINALIZATION
#=================================================
# RELOAD NGINX AND PHP-FPM OR THE APP SERVICE
#=================================================
ynh_script_progression --message="Reloading NGINX web server and $app's service..." --weight=1
ynh_script_progression "Reloading NGINX web server and $app's service..."
# Start a systemd service
ynh_systemd_action --service_name=$app --action=start --log_path=systemd --line_match="Started Mattermost"
ynh_systemctl --service=$app --action=start --log_path=systemd --wait_until="Started Mattermost"
ynh_systemd_action --service_name=nginx --action=reload
ynh_systemctl --service=nginx --action=reload
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Restoration completed for $app" --last
ynh_script_progression "Restoration completed for $app"

View file

@ -1,11 +1,5 @@
#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
@ -16,13 +10,13 @@ source /usr/share/yunohost/helpers
# Save the language used if not present
if [ -z "${language:-}" ]; then
language="en"
ynh_app_setting_set --app=$app --key=language --value=$language
ynh_app_setting_set --key=language --value=$language
fi
# If version setting doesn't exist
if [ -z "${version:-}" ]; then
version="Team"
ynh_app_setting_set --app=$app --key=version --value=$version
ynh_app_setting_set --key=version --value=$version
fi
#=================================================
@ -38,19 +32,17 @@ if mysqlshow | grep -q "^| $db_name "; then
mariadb-to-pg
fi
#=================================================
# STANDARD UPGRADE STEPS
#=================================================
# STOP SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Stopping a systemd service..." --weight=3
ynh_script_progression "Stopping $app's systemd service..."
ynh_systemd_action --service_name=$app --action=stop --log_path=systemd
ynh_systemctl --service=$app --action=stop --log_path=systemd
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
ynh_script_progression --message="Upgrading source files..." --weight=2
ynh_script_progression "Upgrading source files..."
# Create a temporary directory
tmpdir="$(mktemp -d)"
@ -60,7 +52,7 @@ cp -a "$install_dir/config/config.json" "$tmpdir/config.json"
cp -ar "$install_dir/plugins" "$tmpdir/plugins"
# Remove the app directory securely
ynh_secure_remove --file="$install_dir"
ynh_safe_rm "$install_dir"
if [ "$version" = "Enterprise" ]; then
ynh_setup_source --dest_dir="$install_dir" --source_id="enterprise"
@ -70,10 +62,11 @@ 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_secure_remove --file="$tmpdir"
ynh_safe_rm "$tmpdir"
chmod -R o-rwx "$install_dir"
chown -R $app:www-data "$install_dir"
@ -81,25 +74,25 @@ chown -R $app:www-data "$install_dir"
#=================================================
# REAPPLY SYSTEM CONFIGURATIONS
#=================================================
ynh_script_progression --message="Upgrading system configurations related to $app..." --weight=3
ynh_script_progression "Upgrading system configurations related to $app..."
# Create a dedicated NGINX config
ynh_add_nginx_config
ynh_config_add_nginx
# Create a dedicated systemd config
ynh_add_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_use_logrotate --non-append
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_compare_current_package_version --comparison lt --version 5.37.1~ynh1
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;
@ -114,7 +107,7 @@ UPDATE SidebarCategories set sorting = 'manual' where sorting='';
UPDATE SidebarCategories set sorting = 'manual' where sorting IS NULL;
EOM
ynh_psql_execute_as_root --sql="$fix_old_version_sql" --database=$db_name
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...
@ -123,13 +116,13 @@ fi
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting a systemd service..." --weight=2
ynh_script_progression "Starting $app's systemd service..."
# Start a systemd service
ynh_systemd_action --service_name=$app --action=start --log_path=systemd --line_match="Started Mattermost"
ynh_systemctl --service=$app --action=start --log_path=systemd --wait_until="Started Mattermost"
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Upgrade of $app completed" --last
ynh_script_progression "Upgrade of $app completed"