mirror of
https://github.com/YunoHost-Apps/mattermost_ynh.git
synced 2024-09-03 19:36:29 +02:00
940589206b
`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".
220 lines
8 KiB
Bash
220 lines
8 KiB
Bash
#!/bin/bash
|
|
|
|
#=================================================
|
|
# GENERIC START
|
|
#=================================================
|
|
# IMPORT GENERIC HELPERS
|
|
#=================================================
|
|
|
|
source _common.sh
|
|
source /usr/share/yunohost/helpers
|
|
|
|
#=================================================
|
|
# MANAGE SCRIPT FAILURE
|
|
#=================================================
|
|
|
|
ynh_clean_setup () {
|
|
ynh_clean_check_starting
|
|
}
|
|
# Exit if an error occurs during the execution of the script
|
|
ynh_abort_if_errors
|
|
|
|
#=================================================
|
|
# RETRIEVE ARGUMENTS FROM THE MANIFEST
|
|
#=================================================
|
|
|
|
domain=$YNH_APP_ARG_DOMAIN
|
|
path_url=$YNH_APP_ARG_PATH
|
|
is_public=$YNH_APP_ARG_IS_PUBLIC
|
|
admin=$YNH_APP_ARG_ADMIN
|
|
email=$(ynh_user_get_info --username=$admin --key=mail)
|
|
password=$YNH_APP_ARG_PASSWORD
|
|
language=$YNH_APP_ARG_LANGUAGE
|
|
team_display_name=$YNH_APP_ARG_TEAM_DISPLAY_NAME
|
|
architecture=$(ynh_detect_arch)
|
|
version=$YNH_APP_ARG_VERSION
|
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
|
|
|
#=================================================
|
|
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
|
|
#=================================================
|
|
ynh_script_progression --message="Validating installation parameters..." --weight=1
|
|
|
|
final_path=/var/www/$app
|
|
test ! -e "$final_path" || ynh_die --message="This path already contains a folder"
|
|
|
|
# Register (book) web path
|
|
ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url
|
|
|
|
#=================================================
|
|
# STORE SETTINGS FROM MANIFEST
|
|
#=================================================
|
|
ynh_script_progression --message="Storing installation settings..." --weight=6
|
|
|
|
ynh_app_setting_set --app=$app --key=domain --value=$domain
|
|
ynh_app_setting_set --app=$app --key=path --value=$path_url
|
|
ynh_app_setting_set --app=$app --key=admin --value=$admin
|
|
ynh_app_setting_set --app=$app --key=password --value=$password
|
|
ynh_app_setting_set --app=$app --key=language --value=$language
|
|
ynh_app_setting_set --app=$app --key=version --value=$version
|
|
ynh_app_setting_set --app=$app --key=team_display_name --value=$team_display_name
|
|
|
|
#=================================================
|
|
# FIND AN AVAILABLE PORT
|
|
#=================================================
|
|
ynh_script_progression --message="Finding an available port..." --weight=3
|
|
|
|
# Find an available port
|
|
port=$(ynh_find_port --port=8065)
|
|
ynh_app_setting_set --app=$app --key=port --value=$port
|
|
|
|
#=================================================
|
|
# CREATE DEDICATED USER
|
|
#=================================================
|
|
ynh_script_progression --message="Configuring system user..." --weight=3
|
|
|
|
# Create a system user
|
|
ynh_system_user_create --username=$app --home_dir="$final_path"
|
|
|
|
#=================================================
|
|
# CREATE A MYSQL DATABASE
|
|
#=================================================
|
|
ynh_script_progression --message="Creating a MySQL database..." --weight=10
|
|
|
|
db_name=$(ynh_sanitize_dbid --db_name=$app)
|
|
db_user=$db_name
|
|
ynh_app_setting_set --app=$app --key=db_name --value=$db_name
|
|
ynh_mysql_setup_db --db_user=$db_user --db_name=$db_name
|
|
|
|
#=================================================
|
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
|
#=================================================
|
|
ynh_script_progression --message="Setting up source files..." --weight=3
|
|
|
|
ynh_app_setting_set --app=$app --key=final_path --value=$final_path
|
|
# Download, check integrity, uncompress and patch the source from app.src
|
|
|
|
if [ "$version" = "Enterprise" ]; then
|
|
# Get Enterprise binary path
|
|
ynh_setup_source --dest_dir="$final_path" --source_id="enterprise"
|
|
elif [ "$version" = "Team" ]; then
|
|
# Get Team binary path
|
|
ynh_setup_source --dest_dir="$final_path" --source_id="$architecture"
|
|
fi
|
|
|
|
chmod 750 "$final_path"
|
|
chmod -R o-rwx "$final_path"
|
|
chown -R $app:www-data "$final_path"
|
|
|
|
#=================================================
|
|
# CREATE DIRECTORY FOR DATA
|
|
#=================================================
|
|
ynh_script_progression --message="Creating the data directory..." --weight=1
|
|
|
|
data_path=/home/yunohost.app/$app
|
|
ynh_app_setting_set --app=$app --key=data_path --value=$data_path
|
|
|
|
mkdir -p $data_path
|
|
|
|
chmod 750 "$data_path"
|
|
chmod -R o-rwx "$data_path"
|
|
chown -R $app:www-data "$data_path"
|
|
|
|
#=================================================
|
|
# HANDLE LOG FILES AND LOGROTATE
|
|
#=================================================
|
|
ynh_script_progression --message="Configuring log rotation..." --weight=1
|
|
|
|
# Create log directory
|
|
mkdir -p /var/log/$app
|
|
#touch /var/log/$app/$app.log
|
|
logs_path="/var/log/$app"
|
|
chown $app -R $logs_path
|
|
|
|
# Setup logrotate
|
|
ynh_use_logrotate
|
|
|
|
#=================================================
|
|
# EDIT MATTERMOST CONFIG
|
|
#=================================================
|
|
# MODIFY A CONFIG FILE
|
|
#=================================================
|
|
ynh_script_progression --message="Modifying a config file..." --weight=3
|
|
|
|
smtp_user_pwd=$(ynh_string_random --length=24)
|
|
url=https://$domain$path_url
|
|
|
|
ynh_add_config --template="../conf/config.json" --destination="$final_path/config/config.json"
|
|
|
|
#=================================================
|
|
# NGINX CONFIGURATION
|
|
#=================================================
|
|
ynh_script_progression --message="Configuring NGINX web server..." --weight=2
|
|
|
|
# Create a dedicated NGINX config
|
|
ynh_add_nginx_config
|
|
|
|
#=================================================
|
|
# SETUP SYSTEMD
|
|
#=================================================
|
|
ynh_script_progression --message="Configuring a systemd service..." --weight=2
|
|
|
|
# Create a dedicated systemd config
|
|
ynh_add_systemd_config
|
|
|
|
#=================================================
|
|
# INTEGRATE SERVICE IN YUNOHOST
|
|
#=================================================
|
|
ynh_script_progression --message="Integrating service in YunoHost..." --weight=1
|
|
|
|
yunohost service add $app --description="Collaboration platform built for developers" --log="/var/log/$app/$app.log"
|
|
|
|
#=================================================
|
|
# START SYSTEMD SERVICE
|
|
#=================================================
|
|
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
|
|
#=================================================
|
|
ynh_script_progression --message="Configuring permissions..." --weight=1
|
|
|
|
if [ $is_public -eq 1 ]
|
|
then
|
|
ynh_permission_update --permission="main" --add="visitors"
|
|
fi
|
|
|
|
#=================================================
|
|
# RELOAD NGINX
|
|
#=================================================
|
|
ynh_script_progression --message="Reloading NGINX web server..." --weight=2
|
|
|
|
ynh_systemd_action --service_name=nginx --action=reload
|
|
|
|
#=================================================
|
|
# END OF SCRIPT
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Installation of $app completed" --last
|