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

189 lines
7.1 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
source /usr/share/yunohost/helpers
2017-09-12 19:14:18 +02:00
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
# 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
is_public=$YNH_APP_ARG_PUBLIC_SITE
analytics=$YNH_APP_ARG_ANALYTICS
path_url="/"
#=================================================
# CHECK IF THE APP CAN BE INSTALLED
#=================================================
2016-04-17 18:35: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
script_die "Mattermost requires an x86_64 machine, but this one is '${arch}'."
2015-10-21 16:24:51 +02:00
fi
# 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
script_die "Mattermost requires MySQL 5.6 or higher, or MariaDB 10 or higher."
2015-10-21 16:24:51 +02:00
fi
# Normalize the url path syntax
path_url=$(ynh_normalize_url_path $path_url)
# Check web path availability
ynh_webpath_available $domain $path_url
# Register (book) web path
ynh_webpath_register $app $domain $path_url
# Store setting
ynh_app_setting_set "$app" domain "$domain"
2015-10-21 13:03:49 +02:00
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"
logs_path="/var/log/$app"
2017-09-12 19:14:18 +02:00
version=$(cat "$root_path/VERSION")
archive_filename="mattermost-$version.tar.gz"
#=================================================
# CREATE A MYSQL DATABASE
#=================================================
db_name="mattermost"
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')
ynh_mysql_create_db $db_name $db_user $db_password
ynh_app_setting_set mattermost mysqlpwd "$db_password"
2017-09-12 19:14:18 +02:00
#=================================================
# CREATE USER FOR EMAIL NOTIFICATIONS
#=================================================
2015-10-21 14:33:49 +02:00
smtp_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 "$smtp_password") "mattermost"
ynh_app_setting_set mattermost smtppwd "$smtp_password"
2016-05-23 07:41:12 +02:00
2017-09-12 19:14:18 +02:00
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
2016-04-17 18:35:42 +02:00
archive_url="https://releases.mattermost.com/${version}/mattermost-team-${version}-linux-amd64.tar.gz"
sudo mkdir -p "$final_path"
sudo mkdir -p "$data_path"
sudo mkdir -p "$logs_path"
sudo wget --quiet --output-document "$archive_filename" "$archive_url"
2016-04-17 18:35:42 +02:00
sudo tar -xvz --file "$archive_filename" --directory "$final_path" --strip-components 1
sudo rm -f "$archive_filename"
2015-10-21 14:33:49 +02:00
2017-09-12 19:14:18 +02:00
#=================================================
# EDIT MATTERMOST CONFIG
#=================================================
# Configure Service Settings
sudo sed -i "s|\"SiteURL\": \"\"|\"SiteURL\": \"https://${domain}${path_url}\"|g" $final_path/config/config.json
# 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"
sudo sed -i "s|\"DataSource\": \".*\"|\"DataSource\": \"${db_connection_url}\"|g" $final_path/config/config.json
# Configure uploaded files directory
2016-04-17 18:35:42 +02:00
sudo sed -i "s|\"Directory\": \"./data/\"|\"Directory\": \"${data_path}/\"|g" $final_path/config/config.json
# Configure SMTP account for sending email notifications
2015-10-21 14:33:49 +02: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\"|g" $final_path/config/config.json
sudo sed -i "s|\"SMTPPassword\": \"\"|\"SMTPPassword\": \"${smtp_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
# Disable Mattermost debug console by default
2015-10-21 14:46:47 +02:00
sudo sed -i "s|\"EnableConsole\": true|\"EnableConsole\": false|g" $final_path/config/config.json
# Configure log file location
sudo sed -i "s|\"FileLocation\": \"\"|\"FileLocation\": \"$logs_path\"|g" $final_path/config/config.json
# 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
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
#=================================================
sudo chown -R mattermost:www-data "$final_path"
sudo chown -R mattermost:www-data "$data_path"
sudo chown -R mattermost:adm "$logs_path"
2015-10-21 13:03:49 +02:00
2017-09-12 19:14:18 +02:00
#=================================================
# NGINX CONFIGURATION
#=================================================
# Copy conf/nginx.conf to the correct location
ynh_add_nginx_config
2015-10-21 13:03:49 +02:00
2017-09-12 19:14:18 +02:00
#=================================================
# SYSTEMD CONFIGURATION
2017-09-12 19:14:18 +02:00
#=================================================
# Create a dedicated systemd config
ynh_add_systemd_config
2015-10-21 13:03:49 +02:00
#=================================================
# ADVERTISE SERVICE IN ADMIN PANEL
#=================================================
sudo yunohost service add "$app" --log "$logs_path/mattermost.log"
2017-09-12 19:14:18 +02:00
#=================================================
# SETUP SSOWAT
#=================================================
ynh_app_setting_set "$app" is_public "$is_public"
2015-10-21 14:33:49 +02:00
if [ "$is_public" = "Yes" ];
then
ynh_app_setting_set "$app" unprotected_uris "/"
2015-10-21 14:33:49 +02:00
fi
sudo yunohost app ssowatconf
2015-10-21 14:33:49 +02:00
2017-09-12 19:14:18 +02:00
#=================================================
# RELOAD NGINX
#=================================================
sudo systemctl reload nginx
2015-10-21 13:03:49 +02:00
2017-09-12 19:14:18 +02:00
#=================================================
# START SERVER
2017-09-12 19:14:18 +02:00
#=================================================
sudo systemctl start mattermost