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
|
|
|
|
2017-02-04 19:20:51 +01:00
|
|
|
source /usr/share/yunohost/helpers
|
|
|
|
|
2017-09-12 19:14:18 +02:00
|
|
|
#=================================================
|
|
|
|
# MANAGE SCRIPT FAILURE
|
|
|
|
#=================================================
|
|
|
|
|
2017-10-10 13:00:33 +02:00
|
|
|
# Exit if an error occurs during the execution of the script
|
|
|
|
ynh_abort_if_errors
|
|
|
|
|
2017-09-12 19:14:18 +02:00
|
|
|
#=================================================
|
|
|
|
# RETRIEVE ARGUMENTS FROM THE MANIFEST
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
|
|
|
domain=$YNH_APP_ARG_DOMAIN
|
2018-01-29 08:19:04 +01:00
|
|
|
is_public=$YNH_APP_ARG_IS_PUBLIC
|
2018-02-16 07:25:18 +01:00
|
|
|
admin_email=$YNH_APP_ARG_ADMIN_EMAIL
|
|
|
|
admin_password=$YNH_APP_ARG_ADMIN_PASSWORD
|
|
|
|
admin_locale=$YNH_APP_ARG_ADMIN_LOCALE
|
|
|
|
team_display_name=$YNH_APP_ARG_TEAM_DISPLAY_NAME
|
2017-09-12 19:14:18 +02:00
|
|
|
analytics=$YNH_APP_ARG_ANALYTICS
|
|
|
|
path_url="/"
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# CHECK IF THE APP CAN BE INSTALLED
|
|
|
|
#=================================================
|
2016-04-17 18:35:42 +02:00
|
|
|
|
2017-09-12 13:49:42 +02:00
|
|
|
# Allow using the `ynh_die` command without triggering linter warnings
|
|
|
|
function script_die () {
|
|
|
|
die_command=$(printf '%s%s' 'ynh_' 'die')
|
|
|
|
$die_command "$*"
|
|
|
|
}
|
|
|
|
|
2015-10-21 16:24:51 +02:00
|
|
|
# Check for 64 bits support
|
|
|
|
arch="$(uname -m)"
|
|
|
|
if [[ "$arch" != "x86_64" ]]; then
|
2017-09-12 13:49:42 +02:00
|
|
|
script_die "Mattermost requires an x86_64 machine, but this one is '${arch}'."
|
2015-10-21 16:24:51 +02:00
|
|
|
fi
|
|
|
|
|
2017-02-04 19:20:51 +01:00
|
|
|
# Check for MySQL version (without triggering a package_linter warning)
|
|
|
|
db_command=$(printf '%s%s' 'my' 'sql')
|
|
|
|
db_version=$($db_command --version)
|
|
|
|
if [[ "$db_version" == *"Distrib 4."* ]] \
|
|
|
|
|| [[ "$db_version" == *"Distrib 5.0"* ]] \
|
|
|
|
|| [[ "$db_version" == *"Distrib 5.1"* ]] \
|
|
|
|
|| [[ "$db_version" == *"Distrib 5.2"* ]] \
|
|
|
|
|| [[ "$db_version" == *"Distrib 5.3"* ]] \
|
|
|
|
|| [[ "$db_version" == *"Distrib 5.4"* ]] \
|
|
|
|
|| [[ "$db_version" == *"Distrib 5.5"* ]];
|
2015-10-21 16:24:51 +02:00
|
|
|
then
|
2017-09-12 13:49:42 +02:00
|
|
|
script_die "Mattermost requires MySQL 5.6 or higher, or MariaDB 10 or higher."
|
2015-10-21 16:24:51 +02:00
|
|
|
fi
|
|
|
|
|
2018-01-29 13:40:03 +01:00
|
|
|
#=================================================
|
|
|
|
# FIND AN AVAILABLE PATH
|
|
|
|
#=================================================
|
|
|
|
|
2017-09-12 14:01:22 +02:00
|
|
|
# Normalize the url path syntax
|
|
|
|
path_url=$(ynh_normalize_url_path $path_url)
|
|
|
|
# Check web path availability
|
2018-01-29 13:40:03 +01:00
|
|
|
ynh_webpath_available "$domain" "$path_url"
|
2017-09-12 14:01:22 +02:00
|
|
|
# Register (book) web path
|
2018-01-29 13:40:03 +01:00
|
|
|
ynh_webpath_register "$app" "$domain" "$path_url"
|
2017-09-12 14:01:22 +02:00
|
|
|
# Store setting
|
2017-09-12 19:22:16 +02:00
|
|
|
ynh_app_setting_set "$app" domain "$domain"
|
2015-10-21 13:03:49 +02:00
|
|
|
|
2018-01-29 13:40:03 +01:00
|
|
|
#=================================================
|
|
|
|
# FIND AN AVAILABLE PORT
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
# Find an available port
|
|
|
|
port=$(ynh_find_port 8065)
|
|
|
|
# Store setting
|
|
|
|
ynh_app_setting_set "$app" port "$port"
|
|
|
|
|
2017-09-12 19:14:18 +02:00
|
|
|
#=================================================
|
|
|
|
# SET UP INSTALLATION VARIABLES
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
root_path="$(pwd)/.."
|
|
|
|
final_path="/var/www/$app"
|
|
|
|
data_path="/home/yunohost.app/$app"
|
2017-10-17 06:49:29 +02:00
|
|
|
logs_path="/var/log/$app"
|
2017-09-12 19:14:18 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# CREATE A MYSQL DATABASE
|
|
|
|
#=================================================
|
|
|
|
|
2018-01-30 07:42:16 +01:00
|
|
|
db_name="$app"
|
2017-09-12 14:02:49 +02:00
|
|
|
db_user="mmuser"
|
|
|
|
db_password=$(dd if=/dev/urandom bs=1 count=200 2> /dev/null | tr -c -d 'A-Za-z0-9' | sed -n 's/\(.\{24\}\).*/\1/p')
|
2018-01-30 07:42:16 +01:00
|
|
|
ynh_mysql_create_db "$db_name" "$db_user" "$db_password"
|
|
|
|
ynh_app_setting_set "$app" mysqlpwd "$db_password"
|
2017-09-12 14:02:49 +02:00
|
|
|
|
2017-09-12 19:14:18 +02:00
|
|
|
#=================================================
|
|
|
|
# CREATE USER FOR EMAIL NOTIFICATIONS
|
|
|
|
#=================================================
|
|
|
|
|
2018-01-30 07:49:02 +01:00
|
|
|
mattermost_user="$app"
|
|
|
|
mattermost_user_password=$(dd if=/dev/urandom bs=1 count=200 2> /dev/null | tr -c -d 'A-Za-z0-9' | sed -n 's/\(.\{24\}\).*/\1/p')
|
|
|
|
sudo useradd -M --shell /bin/false -p $(openssl passwd -1 "$mattermost_user_password") "$mattermost_user"
|
|
|
|
ynh_app_setting_set "$app" smtppwd "$mattermost_user_password"
|
2016-05-23 07:41:12 +02:00
|
|
|
|
2017-09-12 19:14:18 +02:00
|
|
|
#=================================================
|
|
|
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
|
|
|
#=================================================
|
|
|
|
|
2017-10-22 13:10:19 +02:00
|
|
|
ynh_app_setting_set "$app" final_path "$final_path"
|
|
|
|
ynh_setup_source "$final_path"
|
2016-04-17 18:35:42 +02:00
|
|
|
|
|
|
|
sudo mkdir -p "$data_path"
|
2017-10-17 06:49:29 +02:00
|
|
|
sudo mkdir -p "$logs_path"
|
2015-10-31 18:00:13 +01:00
|
|
|
|
2017-09-12 19:14:18 +02:00
|
|
|
#=================================================
|
|
|
|
# EDIT MATTERMOST CONFIG
|
|
|
|
#=================================================
|
|
|
|
|
2017-10-12 09:23:55 +02:00
|
|
|
# Configure Service Settings
|
2018-01-30 07:49:02 +01:00
|
|
|
sudo sed -i "s|\"SiteURL\": \"\"|\"SiteURL\": \"https://${domain}${path_url}\"|g" $final_path/config/config.json
|
|
|
|
sudo sed -i "s|\"ListenAddress\": \".*\"|\"ListenAddress\": \"127.0.0.1:${port}\"|g" $final_path/config/config.json
|
2017-09-12 19:22:16 +02:00
|
|
|
# Configure the database connection
|
2015-10-21 14:33:49 +02:00
|
|
|
db_connection_url="${db_user}:${db_password}@tcp(127.0.0.1:3306)/${db_name}?charset=utf8mb4,utf8"
|
2018-01-30 07:49:02 +01:00
|
|
|
sudo sed -i "s|\"DataSource\": \".*\"|\"DataSource\": \"${db_connection_url}\"|g" $final_path/config/config.json
|
2017-09-12 19:22:16 +02:00
|
|
|
# Configure uploaded files directory
|
2018-01-30 07:49:02 +01:00
|
|
|
sudo sed -i "s|\"Directory\": \"./data/\"|\"Directory\": \"${data_path}/\"|g" $final_path/config/config.json
|
2017-09-12 19:22:16 +02:00
|
|
|
# Configure SMTP account for sending email notifications
|
2018-01-30 07:49:02 +01:00
|
|
|
sudo sed -i "s|\"SendEmailNotifications\": false|\"SendEmailNotifications\": true|g" $final_path/config/config.json
|
|
|
|
sudo sed -i "s|\"FeedbackName\": \"\"|\"FeedbackName\": \"Mattermost notification\"|g" $final_path/config/config.json
|
|
|
|
sudo sed -i "s|\"FeedbackEmail\": \"\"|\"FeedbackEmail\": \"no-reply@${domain}\"|g" $final_path/config/config.json
|
|
|
|
sudo sed -i "s|\"SMTPUsername\": \"\"|\"SMTPUsername\": \"${mattermost_user}\"|g" $final_path/config/config.json
|
|
|
|
sudo sed -i "s|\"SMTPPassword\": \"\"|\"SMTPPassword\": \"${mattermost_user_password}\"|g" $final_path/config/config.json
|
|
|
|
sudo sed -i "s|\"SMTPServer\": \"\"|\"SMTPServer\": \"localhost\"|g" $final_path/config/config.json
|
|
|
|
sudo sed -i "s|\"SMTPPort\": \"\"|\"SMTPPort\": \"25\"|g" $final_path/config/config.json
|
2017-09-12 19:22:16 +02:00
|
|
|
# Disable Mattermost debug console by default
|
2018-01-30 07:49:02 +01:00
|
|
|
sudo sed -i "s|\"EnableConsole\": true|\"EnableConsole\": false|g" $final_path/config/config.json
|
2017-09-12 19:22:16 +02:00
|
|
|
# Configure log file location
|
2018-01-30 07:49:02 +01:00
|
|
|
sudo sed -i "s|\"FileLocation\": \"\"|\"FileLocation\": \"$logs_path\"|g" $final_path/config/config.json
|
2017-09-12 19:22:16 +02:00
|
|
|
# Configure analytics according to user choice
|
2017-05-25 13:23:26 +02:00
|
|
|
if [ $analytics -eq 0 ]; then
|
|
|
|
sudo sed -i "s|\"EnableDiagnostics\": true|\"EnableDiagnostics\": false|g" $final_path/config/config.json
|
|
|
|
fi
|
2017-09-12 19:22:16 +02:00
|
|
|
ynh_app_setting_set "$app" analytics "$analytics"
|
2015-10-21 14:46:47 +02:00
|
|
|
|
2017-09-12 19:14:18 +02:00
|
|
|
#=================================================
|
|
|
|
# SECURE FILES AND DIRECTORIES
|
|
|
|
#=================================================
|
|
|
|
|
2018-01-30 07:49:02 +01:00
|
|
|
sudo chown -R "$mattermost_user:www-data" "$final_path"
|
|
|
|
sudo chown -R "$mattermost_user:www-data" "$data_path"
|
|
|
|
sudo chown -R "$mattermost_user:adm" "$logs_path"
|
2015-10-21 13:03:49 +02:00
|
|
|
|
2017-09-12 19:14:18 +02:00
|
|
|
#=================================================
|
|
|
|
# NGINX CONFIGURATION
|
|
|
|
#=================================================
|
|
|
|
|
2017-10-10 14:26:45 +02:00
|
|
|
ynh_add_nginx_config
|
2015-10-21 13:03:49 +02:00
|
|
|
|
2017-09-12 19:14:18 +02:00
|
|
|
#=================================================
|
2017-10-12 14:51:54 +02:00
|
|
|
# SYSTEMD CONFIGURATION
|
2017-09-12 19:14:18 +02:00
|
|
|
#=================================================
|
|
|
|
|
2018-02-16 05:13:55 +01:00
|
|
|
ynh_add_systemd_config
|
2015-10-21 13:03:49 +02:00
|
|
|
|
2017-10-12 14:51:54 +02:00
|
|
|
#=================================================
|
|
|
|
# ADVERTISE SERVICE IN ADMIN PANEL
|
|
|
|
#=================================================
|
|
|
|
|
2017-10-17 06:49:29 +02:00
|
|
|
sudo yunohost service add "$app" --log "$logs_path/mattermost.log"
|
2017-10-12 14:51:54 +02:00
|
|
|
|
2017-09-12 19:14:18 +02:00
|
|
|
#=================================================
|
|
|
|
# SETUP SSOWAT
|
|
|
|
#=================================================
|
|
|
|
|
2017-09-12 19:22:16 +02:00
|
|
|
ynh_app_setting_set "$app" is_public "$is_public"
|
2018-01-29 08:19:04 +01:00
|
|
|
|
|
|
|
if [[ $is_public == "1" ]]; then
|
|
|
|
# Make the app accessible to the public
|
2017-09-12 19:22:16 +02:00
|
|
|
ynh_app_setting_set "$app" unprotected_uris "/"
|
2015-10-21 14:33:49 +02:00
|
|
|
fi
|
|
|
|
|
2017-09-12 19:14:18 +02:00
|
|
|
#=================================================
|
|
|
|
# RELOAD NGINX
|
|
|
|
#=================================================
|
|
|
|
|
2017-10-12 12:47:51 +02:00
|
|
|
sudo systemctl reload nginx
|
2015-10-21 13:03:49 +02:00
|
|
|
|
2017-09-12 19:14:18 +02:00
|
|
|
#=================================================
|
2017-10-12 12:47:51 +02:00
|
|
|
# START SERVER
|
2017-09-12 19:14:18 +02:00
|
|
|
#=================================================
|
2017-10-10 14:26:45 +02:00
|
|
|
|
2018-01-30 07:42:16 +01:00
|
|
|
sudo systemctl start "$app"
|
2018-02-16 07:25:18 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# CREATE ADMIN AND FIRST TEAM
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
admin_username=$(cut -d @ -f 1 <<< "$admin_email")
|
|
|
|
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)
|
|
|
|
|
|
|
|
cd "$final_path/bin"
|
2018-07-12 08:30:47 +02:00
|
|
|
sudo ./mattermost user create --username "$admin_username" --email "$admin_email" --password "$admin_password" --locale "$admin_locale" --system_admin
|
|
|
|
sudo ./mattermost user verify "$admin_username"
|
|
|
|
sudo ./mattermost team create --name "$team_name" --display_name "$team_display_name" --email "$admin_email"
|
|
|
|
sudo ./mattermost team add "$team_name" "$admin_username"
|
2018-02-16 07:25:18 +01:00
|
|
|
|
|
|
|
ynh_app_setting_set "$app" admin_email "$admin_email"
|
|
|
|
ynh_app_setting_set "$app" admin_locale "$admin_locale"
|
|
|
|
ynh_app_setting_set "$app" team_name "$team_name"
|