1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/mattermost_ynh.git synced 2024-09-03 19:36:29 +02:00
mattermost_ynh/scripts/install

97 lines
3.6 KiB
Text
Raw Normal View History

2015-10-21 13:03:49 +02:00
#!/bin/bash
2017-09-12 19:14:18 +02:00
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
2015-10-21 13:03:49 +02:00
2021-01-11 23:46:48 +01:00
source _common.sh
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
#=================================================
2021-01-11 23:46:48 +01:00
ynh_script_progression --message="Setting up source files..." --weight=3
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
if [ "$version" = "Enterprise" ]; then
# Get Enterprise binary path
2023-03-07 09:00:35 +01:00
ynh_setup_source --dest_dir="$install_dir" --source_id="enterprise_$YNH_ARCH"
elif [ "$version" = "Team" ]; then
# Get Team binary path
2023-03-07 09:00:35 +01:00
ynh_setup_source --dest_dir="$install_dir" --source_id="team_$YNH_ARCH"
fi
2016-05-23 07:41:12 +02:00
2023-02-07 22:27:23 +01:00
chown -R $app:www-data "$install_dir"
2021-09-16 11:39:20 +02:00
2017-09-12 19:14:18 +02:00
#=================================================
# EDIT MATTERMOST CONFIG
#=================================================
2021-01-11 23:46:48 +01:00
# MODIFY A CONFIG FILE
#=================================================
ynh_script_progression --message="Modifying a config file..." --weight=3
2017-09-12 19:14:18 +02:00
smtp_user_pwd=$(ynh_string_random --length=24)
2023-02-07 22:27:23 +01:00
url=https://$domain$path
2021-01-11 23:46:48 +01:00
2023-02-07 22:27:23 +01:00
ynh_add_config --template="../conf/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-03-03 19:00:59 +01:00
# SYSTEM CONFIGURATION
2017-09-12 19:14:18 +02:00
#=================================================
2023-03-03 19:00:59 +01:00
ynh_script_progression --message="Adding system configurations related to $app..." --weight=1
2017-09-12 19:14:18 +02:00
2021-01-11 23:46:48 +01:00
# Create a dedicated NGINX config
ynh_add_nginx_config
2015-10-21 13:03:49 +02:00
2021-01-11 23:46:48 +01:00
# Create a dedicated systemd config
ynh_add_systemd_config
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-03-07 09:18:55 +01:00
# Create log directory
mkdir -p /var/log/$app
chown $app -R "/var/log/$app"
# Setup logrotate
ynh_use_logrotate
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
#=================================================
2021-01-11 23:46:48 +01:00
ynh_script_progression --message="Starting a systemd service..." --weight=2
2017-09-12 19:14:18 +02:00
2021-01-11 23:46:48 +01:00
# Start a systemd service
ynh_systemd_action --service_name=$app --action=start --log_path=systemd --line_match="Started Mattermost"
2015-10-21 13:03:49 +02:00
#=================================================
# 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)
2023-02-07 22:27:23 +01:00
bin_mmctl="$install_dir/bin/mmctl"
2023-03-14 11:53:56 +01:00
email=$(ynh_user_get_info --username=$admin --key=mail)
# mmctl is not packaged with ARM versions yet
2021-11-12 22:05:35 +01:00
if [[ -f "$bin_mmctl" ]]; then
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"
fi
# Disable mmctl passwordless access
2023-02-07 22:27:23 +01:00
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"
2021-01-11 23:46:48 +01:00
#=================================================
# END OF SCRIPT
#=================================================
2021-01-11 23:46:48 +01:00
ynh_script_progression --message="Installation of $app completed" --last