mirror of
https://github.com/YunoHost-Apps/mattermost_ynh.git
synced 2024-09-03 19:36:29 +02:00
Merge pull request #52 from YunoHost-Apps/modernize-scripts
Modernize scripts
This commit is contained in:
commit
1090b1a946
8 changed files with 220 additions and 95 deletions
|
@ -11,6 +11,7 @@ See https://ci-apps.yunohost.org/jenkins/job/mattermost%20(Community)/ for check
|
|||
Mattermost requires:
|
||||
|
||||
* A x86_64 system (check with `uname -m`),
|
||||
* Yunohost 2.6.4 or higher (check in Yunohost Admin panel),
|
||||
* MySQL 5.6 or higher, or MariaDB 10 or higher (check with `mysql --version`).
|
||||
|
||||
## Installing
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
"nginx"
|
||||
],
|
||||
"requirements": {
|
||||
"yunohost": ">= 2.4.0"
|
||||
"yunohost": ">= 2.6.4"
|
||||
},
|
||||
"arguments": {
|
||||
"install" : [
|
||||
|
@ -41,7 +41,7 @@
|
|||
},
|
||||
{
|
||||
"name": "analytics",
|
||||
"type": "boolean",
|
||||
"type": "boolean",
|
||||
"ask": {
|
||||
"en": "Do you want to allow Mattermost to send some telemetrics about your usage of this app?",
|
||||
"fr": "Autorisez-vous Mattermost à envoyer des informations anonymes sur votre usage de l’application ?"
|
||||
|
|
144
scripts/install
144
scripts/install
|
@ -1,23 +1,33 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Retrieve arguments
|
||||
domain=$YNH_APP_ARG_DOMAIN
|
||||
is_public=$YNH_APP_ARG_PUBLIC_SITE
|
||||
analytics=$YNH_APP_ARG_ANALYTICS
|
||||
path=""
|
||||
#=================================================
|
||||
# GENERIC START
|
||||
#=================================================
|
||||
# IMPORT GENERIC HELPERS
|
||||
#=================================================
|
||||
|
||||
# Source app helpers
|
||||
source /usr/share/yunohost/helpers
|
||||
|
||||
#=================================================
|
||||
# MANAGE SCRIPT FAILURE
|
||||
#=================================================
|
||||
|
||||
# Exit if an error occurs during the execution of the script
|
||||
ynh_abort_if_errors
|
||||
|
||||
# Set up common variables
|
||||
root_path="$(pwd)/.."
|
||||
final_path=/var/www/mattermost
|
||||
data_path=/home/yunohost.app/mattermost
|
||||
version=$(cat "$root_path/VERSION")
|
||||
archive_filename="mattermost-$version.tar.gz"
|
||||
#=================================================
|
||||
# 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
|
||||
#=================================================
|
||||
|
||||
# Allow using the `ynh_die` command without triggering linter warnings
|
||||
function script_die () {
|
||||
|
@ -45,44 +55,53 @@ then
|
|||
script_die "Mattermost requires MySQL 5.6 or higher, or MariaDB 10 or higher."
|
||||
fi
|
||||
|
||||
# Check domain availability
|
||||
sudo yunohost app checkurl $domain$path -a mattermost
|
||||
if [[ ! $? -eq 0 ]]; then
|
||||
script_die "The app cannot be installed at '$domain$path': this location is already used."
|
||||
fi
|
||||
ynh_app_setting_set mattermost domain "$domain"
|
||||
# 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"
|
||||
|
||||
#=================================================
|
||||
# SET UP INSTALLATION VARIABLES
|
||||
#=================================================
|
||||
|
||||
root_path="$(pwd)/.."
|
||||
final_path="/var/www/$app"
|
||||
data_path="/home/yunohost.app/$app"
|
||||
version=$(cat "$root_path/VERSION")
|
||||
archive_filename="mattermost-$version.tar.gz"
|
||||
|
||||
#=================================================
|
||||
# INSTALL DEPENDENCIES
|
||||
#=================================================
|
||||
|
||||
# Install dependencies
|
||||
command -v supervisorctl >/dev/null 2>&1 || sudo apt-get install -y supervisor
|
||||
|
||||
# Initialize database and store mysql password for upgrade
|
||||
#=================================================
|
||||
# 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"
|
||||
|
||||
# Delete db and user if exit with an error
|
||||
function fail_properly
|
||||
{
|
||||
set +e
|
||||
ynh_mysql_execute_as_root "DROP DATABASE $db_name ; DROP USER $db_user@localhost ;"
|
||||
#=================================================
|
||||
# CREATE USER FOR EMAIL NOTIFICATIONS
|
||||
#=================================================
|
||||
|
||||
sudo userdel mattermost
|
||||
sudo rm -Rf "$final_path"
|
||||
sudo rm "$archive_filename"
|
||||
|
||||
# Exit (without triggering a package_linter warning)
|
||||
script_die "An error occurred during the installation."
|
||||
}
|
||||
trap fail_properly ERR
|
||||
|
||||
# Create user for email notifications
|
||||
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"
|
||||
|
||||
# Download and install code
|
||||
#=================================================
|
||||
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
||||
#=================================================
|
||||
|
||||
archive_url="https://releases.mattermost.com/${version}/mattermost-team-${version}-linux-amd64.tar.gz"
|
||||
|
||||
sudo mkdir -p "$final_path"
|
||||
|
@ -92,12 +111,16 @@ sudo wget --quiet --output-document "$archive_filename" "$archive_url"
|
|||
sudo tar -xvz --file "$archive_filename" --directory "$final_path" --strip-components 1
|
||||
sudo rm -f "$archive_filename"
|
||||
|
||||
# Change variables in Mattermost config
|
||||
#=================================================
|
||||
# EDIT MATTERMOST CONFIG
|
||||
#=================================================
|
||||
|
||||
# Configure the database connection
|
||||
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
|
||||
sudo sed -i "s|\"Directory\": \"./data/\"|\"Directory\": \"${data_path}/\"|g" $final_path/config/config.json
|
||||
|
||||
# Configure SMTP account for sending email notifications
|
||||
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
|
||||
|
@ -105,34 +128,55 @@ sudo sed -i "s|\"SMTPUsername\": \"\"|\"SMTPUsername\": \"mattermost\"|g"
|
|||
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
|
||||
sudo sed -i "s|\"EnableConsole\": true|\"EnableConsole\": false|g" $final_path/config/config.json
|
||||
# Configure log file location
|
||||
sudo sed -i "s|\"FileLocation\": \"\"|\"FileLocation\": \"/var/log\"|g" $final_path/config/config.json
|
||||
# Configure analytics according to user choice
|
||||
if [ $analytics -eq 0 ]; then
|
||||
sudo sed -i "s|\"EnableDiagnostics\": true|\"EnableDiagnostics\": false|g" $final_path/config/config.json
|
||||
fi
|
||||
ynh_app_setting_set mattermost analytics "$analytics"
|
||||
ynh_app_setting_set "$app" analytics "$analytics"
|
||||
|
||||
#=================================================
|
||||
# SECURE FILES AND DIRECTORIES
|
||||
#=================================================
|
||||
|
||||
# Set permissions to app directories
|
||||
sudo chown -R www-data: $final_path
|
||||
sudo chown -R www-data: $data_path
|
||||
|
||||
# Modify Nginx configuration file and copy it to Nginx conf directory
|
||||
sudo cp $root_path/conf/nginx.conf-nosub /etc/nginx/conf.d/$domain.d/mattermost.conf
|
||||
#=================================================
|
||||
# NGINX CONFIGURATION
|
||||
#=================================================
|
||||
|
||||
# Copy conf/nginx.conf to the correct location
|
||||
ynh_add_nginx_config
|
||||
|
||||
#=================================================
|
||||
# SETUP SUPERVISOR
|
||||
#=================================================
|
||||
|
||||
# Copy supervisor script
|
||||
sudo cp $root_path/conf/supervisor.conf /etc/supervisor/conf.d/mattermost.conf
|
||||
|
||||
# Enable public access if needed
|
||||
ynh_app_setting_set mattermost is_public "$is_public"
|
||||
#=================================================
|
||||
# SETUP SSOWAT
|
||||
#=================================================
|
||||
|
||||
ynh_app_setting_set "$app" is_public "$is_public"
|
||||
if [ "$is_public" = "Yes" ];
|
||||
then
|
||||
ynh_app_setting_set mattermost unprotected_uris "/"
|
||||
ynh_app_setting_set "$app" unprotected_uris "/"
|
||||
fi
|
||||
|
||||
# Reload Nginx and regenerate SSOwat conf
|
||||
#=================================================
|
||||
# RELOAD NGINX
|
||||
#=================================================
|
||||
|
||||
sudo service nginx reload
|
||||
sudo yunohost app ssowatconf
|
||||
|
||||
# Start app
|
||||
#=================================================
|
||||
# START APP
|
||||
#=================================================
|
||||
|
||||
sudo supervisorctl reload
|
||||
|
|
|
@ -1,32 +1,61 @@
|
|||
#!/bin/bash
|
||||
set -u # treat unset variables as an error
|
||||
|
||||
# Source app helpers
|
||||
#=================================================
|
||||
# GENERIC START
|
||||
#=================================================
|
||||
# IMPORT GENERIC HELPERS
|
||||
#=================================================
|
||||
|
||||
source /usr/share/yunohost/helpers
|
||||
|
||||
# Read configuration
|
||||
#=================================================
|
||||
# LOAD SETTINGS
|
||||
#=================================================
|
||||
|
||||
app=$YNH_APP_INSTANCE_NAME
|
||||
domain=$(ynh_app_setting_get mattermost domain)
|
||||
db_name="mattermost"
|
||||
db_user="mmuser"
|
||||
final_path="/var/www/$app"
|
||||
data_path="/home/yunohost.app/$app"
|
||||
|
||||
# Stop service
|
||||
sudo supervisorctl stop mattermost
|
||||
#=================================================
|
||||
# STANDARD REMOVE
|
||||
#=================================================
|
||||
# STOP AND REMOVE SERVICE
|
||||
#=================================================
|
||||
|
||||
# Remove sources and data
|
||||
sudo rm -rf /var/www/mattermost
|
||||
sudo rm -rf /home/yunohost.app/mattermost
|
||||
sudo supervisorctl stop "$app"
|
||||
sudo rm -f "/etc/supervisor/conf.d/${app}.conf"
|
||||
|
||||
# Remove database
|
||||
ynh_mysql_execute_as_root "DROP DATABASE $db_name ; DROP USER $db_user@localhost ;"
|
||||
#=================================================
|
||||
# REMOVE THE MYSQL DATABASE
|
||||
#=================================================
|
||||
|
||||
# Remove uploaded files
|
||||
ynh_mysql_remove_db "$db_user" "$db_name"
|
||||
|
||||
# Delete SMTP user
|
||||
sudo userdel mattermost
|
||||
#=================================================
|
||||
# REMOVE APP MAIN DIR
|
||||
#=================================================
|
||||
|
||||
# Remove configuration files
|
||||
sudo rm -f /etc/nginx/conf.d/$domain.d/mattermost.conf
|
||||
sudo rm -f /etc/supervisor/conf.d/mattermost.conf
|
||||
ynh_secure_remove "$final_path"
|
||||
ynh_secure_remove "$data_path"
|
||||
|
||||
# Remove log files
|
||||
sudo rm -f /var/log/mattermost.log
|
||||
#=================================================
|
||||
# REMOVE NGINX CONFIGURATION
|
||||
#=================================================
|
||||
|
||||
ynh_remove_nginx_config
|
||||
|
||||
#=================================================
|
||||
# REMOVE LOG FILE
|
||||
#=================================================
|
||||
|
||||
sudo rm -f "/var/log/${app}.log"
|
||||
|
||||
#=================================================
|
||||
# REMOVE DEDICATED USER
|
||||
#=================================================
|
||||
|
||||
ynh_system_user_delete "$app"
|
||||
|
|
|
@ -21,6 +21,7 @@ app=$YNH_APP_INSTANCE_NAME
|
|||
|
||||
domain=$(ynh_app_setting_get $app domain)
|
||||
is_public=$(ynh_app_setting_get $app is_public)
|
||||
path_url="/"
|
||||
final_path="/var/www/$app"
|
||||
data_path="/home/yunohost.app/$app"
|
||||
db_name="$app"
|
||||
|
@ -30,7 +31,7 @@ db_user="mmuser"
|
|||
# CHECK IF THE APP CAN BE RESTORED
|
||||
#=================================================
|
||||
|
||||
yunohost app checkurl "${domain}" -a "$app" \
|
||||
ynh_webpath_available $domain $path_url \
|
||||
|| ynh_die "Path not available: ${domain}"
|
||||
test ! -d $final_path \
|
||||
|| ynh_die "There is already a directory: $final_path "
|
||||
|
@ -105,8 +106,13 @@ ynh_restore_file "/etc/supervisor/conf.d/$app.conf"
|
|||
#=================================================
|
||||
# GENERIC FINALIZATION
|
||||
#=================================================
|
||||
# RELOAD NGINX AND START THE APP
|
||||
# RELOAD NGINX
|
||||
#=================================================
|
||||
|
||||
sudo service nginx reload
|
||||
|
||||
#=================================================
|
||||
# START SERVER
|
||||
#=================================================
|
||||
|
||||
sudo supervisorctl reload
|
||||
|
|
|
@ -1,65 +1,110 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Source app helpers
|
||||
#=================================================
|
||||
# GENERIC START
|
||||
#=================================================
|
||||
# IMPORT GENERIC HELPERS
|
||||
#=================================================
|
||||
|
||||
source /usr/share/yunohost/helpers
|
||||
|
||||
#=================================================
|
||||
# MANAGE SCRIPT FAILURE
|
||||
#=================================================
|
||||
|
||||
# Exit if an error occurs during the execution of the script
|
||||
ynh_abort_if_errors
|
||||
|
||||
# Retrieve arguments
|
||||
#=================================================
|
||||
# LOAD SETTINGS
|
||||
#=================================================
|
||||
|
||||
app=$YNH_APP_INSTANCE_NAME
|
||||
domain=$(ynh_app_setting_get mattermost domain)
|
||||
is_public=$(ynh_app_setting_get mattermost is_public)
|
||||
|
||||
# Set up common variables
|
||||
root_path="$(pwd)/.."
|
||||
final_path=/var/www/mattermost
|
||||
version=$(cat "$root_path/VERSION")
|
||||
archive_filename="mattermost-$version.tar.gz"
|
||||
|
||||
# Cleanup and restart if exit with an error
|
||||
function cleanup_and_restart
|
||||
{
|
||||
set +e
|
||||
sudo rm -f "$archive_filename"
|
||||
sudo supervisorctl start mattermost
|
||||
#=================================================
|
||||
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
|
||||
#=================================================
|
||||
|
||||
# Exit (without triggering a package_linter warning)
|
||||
die_command='ynh_' + 'die'
|
||||
$die_command "An error occurred during the installation."
|
||||
# Backup the current version of the app
|
||||
ynh_backup_before_upgrade
|
||||
ynh_clean_setup () {
|
||||
# Restore the backup if the upgrade fails
|
||||
ynh_restore_upgradebackup
|
||||
# Remove the temporary archive
|
||||
sudo rm -f "$archive_filename"
|
||||
# Restart the server
|
||||
sudo supervisorctl restart mattermost
|
||||
}
|
||||
trap cleanup_and_restart ERR
|
||||
|
||||
# Download code
|
||||
# Exit if an error occurs during the execution of the script
|
||||
ynh_abort_if_errors
|
||||
|
||||
#=================================================
|
||||
# DOWNLOAD SOURCE
|
||||
#=================================================
|
||||
|
||||
archive_url="https://releases.mattermost.com/${version}/mattermost-team-${version}-linux-amd64.tar.gz"
|
||||
sudo wget --quiet --output-document "$archive_filename" "$archive_url"
|
||||
|
||||
# Stop server
|
||||
#=================================================
|
||||
# STOP SERVER
|
||||
#=================================================
|
||||
|
||||
sudo supervisorctl stop mattermost
|
||||
|
||||
# Backup configuration file
|
||||
#=================================================
|
||||
# BACKUP CONFIGURATION FILE
|
||||
#=================================================
|
||||
|
||||
config_file="$final_path/config/config.json"
|
||||
backup_config_file="/tmp/config.json"
|
||||
|
||||
sudo cp -f "$config_file" "$backup_config_file"
|
||||
|
||||
# Copy new code
|
||||
#=================================================
|
||||
# COPY NEW CODE
|
||||
#=================================================
|
||||
|
||||
sudo rm -rf "$final_path"
|
||||
sudo mkdir -p "$final_path"
|
||||
sudo tar -xvz --file "$archive_filename" --directory "$final_path" --strip-components 1
|
||||
sudo rm -f "$archive_filename"
|
||||
|
||||
# Restore configuration file
|
||||
#=================================================
|
||||
# RESTORE CONFIGURATION FILE
|
||||
#=================================================
|
||||
|
||||
sudo cp -f "$backup_config_file" "$config_file"
|
||||
|
||||
#=================================================
|
||||
# SPECIFIC UPGRADE STEPS
|
||||
#=================================================
|
||||
|
||||
# Fix log FileLocation path (changed in Mattermost 3.8, makes Mattermost >= 4.2 crash)
|
||||
# https://docs.mattermost.com/administration/changelog.html#release-v3-8-3
|
||||
sudo sed -i "s|\"FileLocation\": \"/var/log/mattermost.log\"|\"FileLocation\": \"/var/log\"|g" "$config_file"
|
||||
|
||||
# Restore file permissions
|
||||
#=================================================
|
||||
# RESTORE FILE PERMISSIONS
|
||||
#=================================================
|
||||
|
||||
sudo chown -R www-data: "$final_path"
|
||||
|
||||
# Update Nginx configuration file
|
||||
sudo cp -f $root_path/conf/nginx.conf-nosub /etc/nginx/conf.d/$domain.d/mattermost.conf
|
||||
#=================================================
|
||||
# RELOAD NGINX
|
||||
#=================================================
|
||||
|
||||
sudo service nginx reload
|
||||
|
||||
#=================================================
|
||||
# START SERVER
|
||||
#=================================================
|
||||
|
||||
# Start server
|
||||
sudo supervisorctl start mattermost
|
||||
|
|
4
test.sh
4
test.sh
|
@ -136,7 +136,7 @@ function test_simple_upgrade() {
|
|||
|
||||
function test_simple_backup() {
|
||||
echo "--- Running simple backup test ---"
|
||||
_vagrant_ssh "sudo yunohost backup create --name mattermost-test-backup --ignore-system --apps $APP_NAME $VERBOSE_OPT"
|
||||
_vagrant_ssh "sudo yunohost backup create --name mattermost-test-backup --ignore-system $VERBOSE_OPT --apps $APP_NAME"
|
||||
}
|
||||
|
||||
function test_simple_remove() {
|
||||
|
@ -146,7 +146,7 @@ function test_simple_remove() {
|
|||
|
||||
function test_simple_restore() {
|
||||
echo "--- Running simple restore test ---"
|
||||
_vagrant_ssh "sudo yunohost backup restore mattermost-test-backup --force --ignore-system --apps $APP_NAME $VERBOSE_OPT"
|
||||
_vagrant_ssh "sudo yunohost backup restore mattermost-test-backup --force --ignore-system $VERBOSE_OPT --apps $APP_NAME"
|
||||
_assert_mattermost_frontpage_up "$DOMAIN"
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue