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
Éric Gaspar 965d45f287 v2
2023-02-07 22:27:23 +01:00

230 lines
8.7 KiB
Bash

#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
#REMOVEME? ynh_clean_setup () {
ynh_clean_check_starting
}
# Exit if an error occurs during the execution of the script
#REMOVEME? ynh_abort_if_errors
#=================================================
# RETRIEVE ARGUMENTS FROM THE MANIFEST
#=================================================
#REMOVEME? domain=$YNH_APP_ARG_DOMAIN
#REMOVEME? path=$YNH_APP_ARG_PATH
#REMOVEME? is_public=$YNH_APP_ARG_IS_PUBLIC
#REMOVEME? admin=$YNH_APP_ARG_ADMIN
email=$(ynh_user_get_info --username=$admin --key=mail)
#REMOVEME? password=$YNH_APP_ARG_PASSWORD
#REMOVEME? language=$YNH_APP_ARG_LANGUAGE
#REMOVEME? team_display_name=$YNH_APP_ARG_TEAM_DISPLAY_NAME
#REMOVEME? version=$YNH_APP_ARG_VERSION
#REMOVEME? app=$YNH_APP_INSTANCE_NAME
#=================================================
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
#=================================================
#REMOVEME? ynh_script_progression --message="Validating installation parameters..." --weight=1
#REMOVEME? install_dir=/var/www/$app
#REMOVEME? test ! -e "$install_dir" || ynh_die --message="This path already contains a folder"
# Register (book) web path
#REMOVEME? ynh_webpath_register --app=$app --domain=$domain --path=$path
#=================================================
# STORE SETTINGS FROM MANIFEST
#=================================================
#REMOVEME? ynh_script_progression --message="Storing installation settings..." --weight=6
#REMOVEME? ynh_app_setting_set --app=$app --key=domain --value=$domain
#REMOVEME? ynh_app_setting_set --app=$app --key=path --value=$path
#REMOVEME? ynh_app_setting_set --app=$app --key=admin --value=$admin
#REMOVEME? 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
#=================================================
#REMOVEME? ynh_script_progression --message="Finding an available port..." --weight=3
# Find an available port
#REMOVEME? port=$(ynh_find_port --port=8065)
#REMOVEME? ynh_app_setting_set --app=$app --key=port --value=$port
#=================================================
# INSTALL DEPENDENCIES
#=================================================
#REMOVEME? ynh_script_progression --message="Installing dependencies..." --weight=10
#REMOVEME? ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies
#=================================================
# CREATE DEDICATED USER
#=================================================
#REMOVEME? ynh_script_progression --message="Configuring system user..." --weight=3
# Create a system user
#REMOVEME? ynh_system_user_create --username=$app --home_dir="$install_dir"
#=================================================
# CREATE A DATABASE
#=================================================
ynh_script_progression --message="Creating a database..." --weight=10
#REMOVEME? db_name=$(ynh_sanitize_dbid --db_name=$app)
#REMOVEME? db_user=$db_name
#REMOVEME? ynh_app_setting_set --app=$app --key=db_name --value=$db_name
#REMOVEME? ynh_psql_test_if_first_run
#REMOVEME? ynh_psql_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
#REMOVEME? ynh_app_setting_set --app=$app --key=install_dir --value=$install_dir
# Download, check integrity, uncompress and patch the source from app.src
if [ "$version" = "Enterprise" ]; then
# Get Enterprise binary path
ynh_setup_source --dest_dir="$install_dir" --source_id="enterprise"
elif [ "$version" = "Team" ]; then
# Get Team binary path
ynh_setup_source --dest_dir="$install_dir" --source_id="$YNH_ARCH"
fi
chmod 750 "$install_dir"
chmod -R o-rwx "$install_dir"
chown -R $app:www-data "$install_dir"
#=================================================
# CREATE DIRECTORY FOR DATA
#=================================================
ynh_script_progression --message="Creating the data directory..." --weight=1
data_path=/home/yunohost.app/$app
#REMOVEME? 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
chown $app -R "/var/log/$app"
# 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
#REMOVEME? db_pwd=$(ynh_app_setting_get --app=$app --key=psqlpwd)
ynh_add_config --template="../conf/config.json" --destination="$install_dir/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)
bin_mmctl="$install_dir/bin/mmctl"
# mmctl is not packaged with ARM versions yet
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
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"
#=================================================
# SETUP SSOWAT
#=================================================
#REMOVEME? ynh_script_progression --message="Configuring permissions..." --weight=1
#REMOVEME? if [ $is_public -eq 1 ]
then
#REMOVEME? ynh_permission_update --permission="main" --add="visitors"
fi
#=================================================
# RELOAD NGINX
#=================================================
#REMOVEME? ynh_script_progression --message="Reloading NGINX web server..." --weight=2
#REMOVEME? ynh_systemd_action --service_name=nginx --action=reload
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Installation of $app completed" --last