From 0ffc0bcc3ab1ecded87bff2f217fa7e4e1de21ae Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Sat, 30 Oct 2021 14:32:53 +0200 Subject: [PATCH] install: replace bin/mattermost by bin/mmctl `mmctl` is supposed to authenticate as one of the admin users. But since this is the first user we're creating, there are no admin yet. So in order to create the first user, we: 1. enable mmctl's "local mode", which connects to the Mattermost server through a socket (rather than through the authenticated API), 2. create the first user and team, 3. disable the "local mode". --- conf/config.json | 2 +- scripts/install | 31 ++++++++++++++++++------------- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/conf/config.json b/conf/config.json index c5a1403..7cd2878 100644 --- a/conf/config.json +++ b/conf/config.json @@ -83,7 +83,7 @@ "EnableSVGs": false, "EnableLatex": false, "EnableAPIChannelDeletion": false, - "EnableLocalMode": false, + "EnableLocalMode": true, "LocalModeSocketLocation": "/var/tmp/mattermost_local.socket", "EnableAWSMetering": false, "SplitKey": "", diff --git a/scripts/install b/scripts/install index 2ef3c9b..e7e7d29 100644 --- a/scripts/install +++ b/scripts/install @@ -163,19 +163,6 @@ ynh_script_progression --message="Configuring a systemd service..." --weight=2 # Create a dedicated systemd config ynh_add_systemd_config -#================================================= -# CREATE ADMIN AND FIRST 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) - -pushd "$final_path" - ynh_exec_warn_less ynh_exec_as $app bin/mattermost user create --username "$admin" --email "$email" --password "$password" --locale "$language" --system_admin - ynh_exec_warn_less ynh_exec_as $app bin/mattermost user verify "$admin" - ynh_exec_warn_less ynh_exec_as $app bin/mattermost team create --name "$team_name" --display_name "$team_display_name" --email "$email" - ynh_exec_warn_less ynh_exec_as $app bin/mattermost team add "$team_name" "$admin" -popd - #================================================= # INTEGRATE SERVICE IN YUNOHOST #================================================= @@ -191,6 +178,24 @@ ynh_script_progression --message="Starting a systemd service..." --weight=2 # Start a systemd service ynh_systemd_action --service_name=$app --action=start --log_path=systemd --line_match="Started Mattermost" +#================================================= +# CREATE ADMIN AND FIRST TEAM +#================================================= +ynh_script_progression --message="Create the first administrator and team..." --weight=1 + +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) + +pushd "$final_path" + ynh_exec_warn_less ynh_exec_as $app bin/mmctl user create --local --username "$admin" --email "$email" --password "$password" --locale "$language" --system_admin + ynh_exec_warn_less ynh_exec_as $app bin/mmctl user verify --local "$admin" + ynh_exec_warn_less ynh_exec_as $app bin/mmctl team create --local --name "$team_name" --display_name "$team_display_name" --email "$email" + ynh_exec_warn_less ynh_exec_as $app bin/mmctl team add --local "$team_name" "$admin" +popd + +# Now that the first user is created, disable mmctl passwordless access +ynh_replace_string 'EnableLocalMode": true' '"EnableLocalMode": false' "$final_path/config/config.json" +ynh_systemd_action --service_name=$app --action=restart --log_path=systemd --line_match="Started Mattermost" + #================================================= # SETUP SSOWAT #=================================================