2015-10-21 13:03:49 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
2021-01-11 23:46:48 +01:00
|
|
|
source _common.sh
|
2017-02-04 19:20:51 +01:00
|
|
|
source /usr/share/yunohost/helpers
|
|
|
|
|
2017-09-12 19:14:18 +02:00
|
|
|
#=================================================
|
2021-01-11 23:46:48 +01:00
|
|
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
2017-09-12 19:14:18 +02:00
|
|
|
#=================================================
|
2024-06-22 21:41:44 +02:00
|
|
|
ynh_script_progression "Setting up source files..."
|
2017-09-12 19:14:18 +02:00
|
|
|
|
2021-01-11 23:46:48 +01:00
|
|
|
# Download, check integrity, uncompress and patch the source from app.src
|
2021-01-13 11:31:12 +01:00
|
|
|
|
|
|
|
if [ "$version" = "Enterprise" ]; then
|
|
|
|
# Get Enterprise binary path
|
2023-09-11 21:36:20 +02:00
|
|
|
ynh_setup_source --dest_dir="$install_dir" --source_id="enterprise"
|
2021-01-13 11:31:12 +01:00
|
|
|
elif [ "$version" = "Team" ]; then
|
|
|
|
# Get Team binary path
|
2023-09-11 21:36:20 +02:00
|
|
|
ynh_setup_source --dest_dir="$install_dir" --source_id="main"
|
2021-01-13 11:31:12 +01:00
|
|
|
fi
|
2016-05-23 07:41:12 +02:00
|
|
|
|
2023-09-11 21:36:20 +02:00
|
|
|
chown -R $app:www-data "$install_dir"
|
2015-10-31 18:00:13 +01:00
|
|
|
|
2017-09-12 19:14:18 +02:00
|
|
|
#=================================================
|
|
|
|
# EDIT MATTERMOST CONFIG
|
|
|
|
#=================================================
|
2021-01-11 23:46:48 +01:00
|
|
|
# MODIFY A CONFIG FILE
|
|
|
|
#=================================================
|
2024-06-22 21:41:44 +02:00
|
|
|
ynh_script_progression "Updating configuration..."
|
2017-09-12 19:14:18 +02:00
|
|
|
|
2021-03-17 20:59:57 +01:00
|
|
|
smtp_user_pwd=$(ynh_string_random --length=24)
|
2023-09-11 21:36:20 +02:00
|
|
|
url=https://$domain$path
|
2021-01-11 23:46:48 +01:00
|
|
|
|
2024-06-22 21:41:44 +02:00
|
|
|
ynh_config_add --template="config.json" --destination="$install_dir/config/config.json"
|
2015-10-21 14:46:47 +02:00
|
|
|
|
2017-09-12 19:14:18 +02:00
|
|
|
#=================================================
|
2023-09-11 21:36:20 +02:00
|
|
|
# SYSTEM CONFIGURATION
|
2017-09-12 19:14:18 +02:00
|
|
|
#=================================================
|
2024-06-22 21:41:44 +02:00
|
|
|
ynh_script_progression "Adding system configurations related to $app..."
|
2017-09-12 19:14:18 +02:00
|
|
|
|
2021-01-11 23:46:48 +01:00
|
|
|
# Create a dedicated NGINX config
|
2024-06-22 21:41:44 +02:00
|
|
|
ynh_config_add_nginx
|
2015-10-21 13:03:49 +02:00
|
|
|
|
2021-01-11 23:46:48 +01:00
|
|
|
# Create a dedicated systemd config
|
2024-06-22 21:41:44 +02:00
|
|
|
ynh_config_add_systemd
|
2015-10-21 13:03:49 +02:00
|
|
|
|
2021-01-11 23:46:48 +01:00
|
|
|
yunohost service add $app --description="Collaboration platform built for developers" --log="/var/log/$app/$app.log"
|
2015-10-21 14:33:49 +02:00
|
|
|
|
2023-09-11 21:36:20 +02:00
|
|
|
# Create log directory
|
|
|
|
mkdir -p /var/log/$app
|
|
|
|
chown $app -R "/var/log/$app"
|
|
|
|
|
|
|
|
# Setup logrotate
|
2024-06-22 21:41:44 +02:00
|
|
|
ynh_config_add_logrotate
|
2023-09-11 21:36:20 +02:00
|
|
|
|
2017-09-12 19:14:18 +02:00
|
|
|
#=================================================
|
2021-01-11 23:46:48 +01:00
|
|
|
# START SYSTEMD SERVICE
|
2017-09-12 19:14:18 +02:00
|
|
|
#=================================================
|
2024-06-22 21:41:44 +02:00
|
|
|
ynh_script_progression "Starting $app's systemd service..."
|
2017-09-12 19:14:18 +02:00
|
|
|
|
2021-01-11 23:46:48 +01:00
|
|
|
# Start a systemd service
|
2024-06-22 21:41:44 +02:00
|
|
|
ynh_systemctl --service=$app --action=start --log_path=systemd --wait_until="Started Mattermost"
|
2015-10-21 13:03:49 +02:00
|
|
|
|
2021-10-30 14:32:53 +02:00
|
|
|
#=================================================
|
|
|
|
# CREATE ADMIN AND FIRST TEAM
|
|
|
|
#=================================================
|
2024-06-22 21:41:44 +02:00
|
|
|
ynh_script_progression "Create the first administrator and team..."
|
2021-10-30 14:32:53 +02:00
|
|
|
|
|
|
|
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)
|
2023-09-11 21:36:20 +02:00
|
|
|
bin_mmctl="$install_dir/bin/mmctl"
|
|
|
|
email=$(ynh_user_get_info --username=$admin --key=mail)
|
2021-10-30 14:32:53 +02:00
|
|
|
|
2023-09-11 21:36:20 +02:00
|
|
|
export MMCTL_LOCAL=true
|
|
|
|
export MMCTL_LOCAL_SOCKET_PATH="/var/run/${app}/mattermost_local.socket"
|
2021-11-05 16:43:05 +01:00
|
|
|
|
2024-06-22 21:41:44 +02:00
|
|
|
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"
|
2021-10-30 14:32:53 +02:00
|
|
|
|
2021-11-05 16:43:05 +01:00
|
|
|
# Disable mmctl passwordless access
|
2024-06-22 21:41:44 +02:00
|
|
|
ynh_replace '"EnableLocalMode": true' '"EnableLocalMode": false' "$install_dir/config/config.json"
|
|
|
|
ynh_systemctl --service=$app --action=restart --log_path=systemd --wait_until="Started Mattermost"
|
2021-10-30 14:32:53 +02:00
|
|
|
|
2021-01-11 23:46:48 +01:00
|
|
|
#=================================================
|
|
|
|
# END OF SCRIPT
|
|
|
|
#=================================================
|
2018-02-16 07:25:18 +01:00
|
|
|
|
2024-06-22 21:41:44 +02:00
|
|
|
ynh_script_progression "Installation of $app completed"
|