From ee502444c64f00ab6866c8a218c32c52d3170b51 Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Tue, 12 Sep 2017 17:31:22 +0530 Subject: [PATCH 01/19] install: modernize checking for domain availability --- scripts/install | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/scripts/install b/scripts/install index 106e8ca..4d7d5d7 100644 --- a/scripts/install +++ b/scripts/install @@ -4,7 +4,7 @@ domain=$YNH_APP_ARG_DOMAIN is_public=$YNH_APP_ARG_PUBLIC_SITE analytics=$YNH_APP_ARG_ANALYTICS -path="" +path_url="/" # Source app helpers source /usr/share/yunohost/helpers @@ -45,11 +45,13 @@ 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 +# 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 mattermost domain "$domain" # Install dependencies From 51b88801571bab385579b7d243a4a4ef9e15afd4 Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Tue, 12 Sep 2017 17:31:45 +0530 Subject: [PATCH 02/19] install: use the $YNH_APP_INSTANCE_NAME variable --- scripts/install | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/scripts/install b/scripts/install index 4d7d5d7..37c6b72 100644 --- a/scripts/install +++ b/scripts/install @@ -1,6 +1,7 @@ #!/bin/bash # Retrieve arguments +app=$YNH_APP_INSTANCE_NAME domain=$YNH_APP_ARG_DOMAIN is_public=$YNH_APP_ARG_PUBLIC_SITE analytics=$YNH_APP_ARG_ANALYTICS @@ -14,8 +15,8 @@ ynh_abort_if_errors # Set up common variables root_path="$(pwd)/.." -final_path=/var/www/mattermost -data_path=/home/yunohost.app/mattermost +final_path=/var/www/$app +data_path=/home/yunohost.app/$app version=$(cat "$root_path/VERSION") archive_filename="mattermost-$version.tar.gz" From 9286fe5e85b8bdf0fbd9e5a80657cf384a279d5d Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Tue, 12 Sep 2017 17:32:49 +0530 Subject: [PATCH 03/19] install: install error handler before creating the database --- scripts/install | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/scripts/install b/scripts/install index 37c6b72..64cf226 100644 --- a/scripts/install +++ b/scripts/install @@ -55,15 +55,6 @@ ynh_webpath_register $app $domain $path_url # Store setting ynh_app_setting_set mattermost domain "$domain" -# Install dependencies -command -v supervisorctl >/dev/null 2>&1 || sudo apt-get install -y supervisor - -# Initialize database and store mysql password for upgrade -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 @@ -80,6 +71,15 @@ function fail_properly } trap fail_properly ERR +command -v supervisorctl >/dev/null 2>&1 || sudo apt-get install -y supervisor + +# Initialize database and store mysql password for upgrade +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" + # 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" From 533f10d93b4d38976d400ade0265d5aaee32d952 Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Tue, 12 Sep 2017 17:33:09 +0530 Subject: [PATCH 04/19] =?UTF-8?q?install:=20don=E2=80=99t=20print=20an=20e?= =?UTF-8?q?rror=20if=20archive=20doesn=E2=80=99t=20exist?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/install | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/install b/scripts/install index 64cf226..151518b 100644 --- a/scripts/install +++ b/scripts/install @@ -64,7 +64,7 @@ function fail_properly sudo userdel mattermost sudo rm -Rf "$final_path" - sudo rm "$archive_filename" + sudo rm -f "$archive_filename" # Exit (without triggering a package_linter warning) script_die "An error occurred during the installation." From c51127e1eb27c31ea29f5879f0a6cb9f09618113 Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Tue, 12 Sep 2017 17:33:48 +0530 Subject: [PATCH 05/19] =?UTF-8?q?install:=20don=E2=80=99t=20fail=20to=20re?= =?UTF-8?q?move=20database=20if=20not=20exist?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/install | 5 +++-- scripts/remove | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/scripts/install b/scripts/install index 151518b..db0153f 100644 --- a/scripts/install +++ b/scripts/install @@ -60,13 +60,14 @@ ynh_app_setting_set mattermost domain "$domain" function fail_properly { set +e - ynh_mysql_execute_as_root "DROP DATABASE $db_name ; DROP USER $db_user@localhost ;" + # Remove database + # (DROP USER IF EXISTS is only available on MySQL >= 5.7, so we don't use it for now) + ynh_mysql_execute_as_root "DROP DATABASE IF EXISTS $db_name ; DROP USER $db_user@localhost ;" sudo userdel mattermost sudo rm -Rf "$final_path" sudo rm -f "$archive_filename" - # Exit (without triggering a package_linter warning) script_die "An error occurred during the installation." } trap fail_properly ERR diff --git a/scripts/remove b/scripts/remove index 61c927b..8a2f166 100755 --- a/scripts/remove +++ b/scripts/remove @@ -17,7 +17,8 @@ sudo rm -rf /var/www/mattermost sudo rm -rf /home/yunohost.app/mattermost # Remove database -ynh_mysql_execute_as_root "DROP DATABASE $db_name ; DROP USER $db_user@localhost ;" +# (DROP USER IF EXISTS is only available on MySQL >= 5.7, so we don't use it for now) +ynh_mysql_execute_as_root "DROP DATABASE IF EXISTS $db_name ; DROP USER $db_user@localhost ;" # Remove uploaded files From f524bd7940592b771fd461385822bed020665043 Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Tue, 12 Sep 2017 22:44:18 +0530 Subject: [PATCH 06/19] install: improve comments --- scripts/install | 102 +++++++++++++++++++++++++++++++++++++----------- 1 file changed, 79 insertions(+), 23 deletions(-) diff --git a/scripts/install b/scripts/install index db0153f..4057f2b 100644 --- a/scripts/install +++ b/scripts/install @@ -1,24 +1,33 @@ #!/bin/bash -# Retrieve arguments +#================================================= +# 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 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="/" -# Source app helpers -source /usr/share/yunohost/helpers - -# 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/$app -data_path=/home/yunohost.app/$app -version=$(cat "$root_path/VERSION") -archive_filename="mattermost-$version.tar.gz" +#================================================= +# CHECK IF THE APP CAN BE INSTALLED +#================================================= # Allow using the `ynh_die` command without triggering linter warnings function script_die () { @@ -55,8 +64,12 @@ ynh_webpath_register $app $domain $path_url # Store setting ynh_app_setting_set mattermost domain "$domain" +#================================================= +# REGISTER ERROR HANDLER +#================================================= # Delete db and user if exit with an error +# (N.B. this section doesn't seem executed on Yunohost >= 2.7 ; the `remove` script is executed instead.) function fail_properly { set +e @@ -72,21 +85,44 @@ function fail_properly } trap fail_properly ERR +#================================================= +# 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 +#================================================= + 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" -# Create user for email notifications +#================================================= +# 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" @@ -96,7 +132,10 @@ 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 +#================================================= + 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 @@ -117,26 +156,43 @@ if [ $analytics -eq 0 ]; then fi ynh_app_setting_set mattermost analytics "$analytics" -# Set permissions to app directories +#================================================= +# SECURE FILES AND 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 +#================================================= +# NGINX CONFIGURATION +#================================================= + sudo cp $root_path/conf/nginx.conf-nosub /etc/nginx/conf.d/$domain.d/mattermost.conf -# Copy supervisor script +#================================================= +# SETUP SUPERVISOR +#================================================= + sudo cp $root_path/conf/supervisor.conf /etc/supervisor/conf.d/mattermost.conf -# Enable public access if needed +#================================================= +# SETUP SSOWAT +#================================================= + ynh_app_setting_set mattermost is_public "$is_public" if [ "$is_public" = "Yes" ]; then ynh_app_setting_set mattermost 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 From e37638f2f859d83ac99d8267e538f728f03e4613 Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Tue, 12 Sep 2017 22:52:16 +0530 Subject: [PATCH 07/19] install: modernize script with Yunohost 2.6.4 helpers --- scripts/install | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/scripts/install b/scripts/install index 4057f2b..b213ab3 100644 --- a/scripts/install +++ b/scripts/install @@ -62,7 +62,7 @@ ynh_webpath_available $domain $path_url # Register (book) web path ynh_webpath_register $app $domain $path_url # Store setting -ynh_app_setting_set mattermost domain "$domain" +ynh_app_setting_set "$app" domain "$domain" #================================================= # REGISTER ERROR HANDLER @@ -136,11 +136,12 @@ sudo rm -f "$archive_filename" # 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 @@ -148,13 +149,15 @@ 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 @@ -179,10 +182,10 @@ sudo cp $root_path/conf/supervisor.conf /etc/supervisor/conf.d/mattermost.conf # SETUP SSOWAT #================================================= -ynh_app_setting_set mattermost is_public "$is_public" +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 #================================================= From f1b741980f58e93fdc1514eb154a284f6f5df041 Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Tue, 10 Oct 2017 17:31:48 +0530 Subject: [PATCH 08/19] install: remove the custom error handler Yunohost will automatically execute the `remove` script anyway after a failed install. --- scripts/install | 21 --------------------- 1 file changed, 21 deletions(-) diff --git a/scripts/install b/scripts/install index b213ab3..0c1a6d0 100644 --- a/scripts/install +++ b/scripts/install @@ -64,27 +64,6 @@ ynh_webpath_register $app $domain $path_url # Store setting ynh_app_setting_set "$app" domain "$domain" -#================================================= -# REGISTER ERROR HANDLER -#================================================= - -# Delete db and user if exit with an error -# (N.B. this section doesn't seem executed on Yunohost >= 2.7 ; the `remove` script is executed instead.) -function fail_properly -{ - set +e - # Remove database - # (DROP USER IF EXISTS is only available on MySQL >= 5.7, so we don't use it for now) - ynh_mysql_execute_as_root "DROP DATABASE IF EXISTS $db_name ; DROP USER $db_user@localhost ;" - - sudo userdel mattermost - sudo rm -Rf "$final_path" - sudo rm -f "$archive_filename" - - script_die "An error occurred during the installation." -} -trap fail_properly ERR - #================================================= # SET UP INSTALLATION VARIABLES #================================================= From c2e27b976453ca52bf52de270b4f8c92d663e8b4 Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Tue, 10 Oct 2017 17:39:26 +0530 Subject: [PATCH 09/19] remove: improve comments --- scripts/remove | 54 +++++++++++++++++++++++++++++++++++++------------- 1 file changed, 40 insertions(+), 14 deletions(-) diff --git a/scripts/remove b/scripts/remove index 8a2f166..637d490 100755 --- a/scripts/remove +++ b/scripts/remove @@ -1,33 +1,59 @@ #!/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 +#================================================= + domain=$(ynh_app_setting_get mattermost domain) db_name="mattermost" db_user="mmuser" -# Stop service +#================================================= +# STANDARD REMOVE +#================================================= +# STOP AND REMOVE SERVICE +#================================================= + sudo supervisorctl stop mattermost +sudo rm -f /etc/supervisor/conf.d/mattermost.conf -# Remove sources and data -sudo rm -rf /var/www/mattermost -sudo rm -rf /home/yunohost.app/mattermost +#================================================= +# REMOVE THE MYSQL DATABASE +#================================================= -# Remove database # (DROP USER IF EXISTS is only available on MySQL >= 5.7, so we don't use it for now) ynh_mysql_execute_as_root "DROP DATABASE IF EXISTS $db_name ; DROP USER $db_user@localhost ;" -# Remove uploaded files +#================================================= +# REMOVE APP MAIN DIR +#================================================= -# Delete SMTP user -sudo userdel mattermost +sudo rm -rf /var/www/mattermost +sudo rm -rf /home/yunohost.app/mattermost + +#================================================= +# REMOVE NGINX CONFIGURATION +#================================================= -# Remove configuration files sudo rm -f /etc/nginx/conf.d/$domain.d/mattermost.conf -sudo rm -f /etc/supervisor/conf.d/mattermost.conf -# Remove log files -sudo rm -f /var/log/mattermost.log +#================================================= +# REMOVE LOG FILE +#================================================= + +sudo rm -f "/var/log/mattermost.log" + +#================================================= +# REMOVE DEDICATED USER +#================================================= + +sudo userdel mattermost From 1a40ff1eed837f2e777e79d62efd3fb01f6eb7df Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Tue, 10 Oct 2017 17:42:41 +0530 Subject: [PATCH 10/19] remove: use more variables instead of hardcoded values --- scripts/remove | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/scripts/remove b/scripts/remove index 637d490..a1055e5 100755 --- a/scripts/remove +++ b/scripts/remove @@ -13,9 +13,12 @@ source /usr/share/yunohost/helpers # 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" #================================================= # STANDARD REMOVE @@ -23,8 +26,8 @@ db_user="mmuser" # STOP AND REMOVE SERVICE #================================================= -sudo supervisorctl stop mattermost -sudo rm -f /etc/supervisor/conf.d/mattermost.conf +sudo supervisorctl stop "$app" +sudo rm -f "/etc/supervisor/conf.d/${app}.conf" #================================================= # REMOVE THE MYSQL DATABASE @@ -37,23 +40,23 @@ ynh_mysql_execute_as_root "DROP DATABASE IF EXISTS $db_name ; DROP USER $db_user # REMOVE APP MAIN DIR #================================================= -sudo rm -rf /var/www/mattermost -sudo rm -rf /home/yunohost.app/mattermost +sudo rm -rf "$final_path" +sudo rm -rf "$data_path" #================================================= # REMOVE NGINX CONFIGURATION #================================================= -sudo rm -f /etc/nginx/conf.d/$domain.d/mattermost.conf +sudo rm -f "/etc/nginx/conf.d/${domain}.d/${app}.conf" #================================================= # REMOVE LOG FILE #================================================= -sudo rm -f "/var/log/mattermost.log" +sudo rm -f "/var/log/${app}.log" #================================================= # REMOVE DEDICATED USER #================================================= -sudo userdel mattermost +sudo userdel "$app" From f2013abebc86444ed8ab79bc8fe2d3f676260542 Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Tue, 10 Oct 2017 17:44:32 +0530 Subject: [PATCH 11/19] remove: use `ynh_mysql_remove_db` helper --- scripts/remove | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/scripts/remove b/scripts/remove index a1055e5..1ece7fd 100755 --- a/scripts/remove +++ b/scripts/remove @@ -33,8 +33,7 @@ sudo rm -f "/etc/supervisor/conf.d/${app}.conf" # REMOVE THE MYSQL DATABASE #================================================= -# (DROP USER IF EXISTS is only available on MySQL >= 5.7, so we don't use it for now) -ynh_mysql_execute_as_root "DROP DATABASE IF EXISTS $db_name ; DROP USER $db_user@localhost ;" +ynh_mysql_remove_db "$db_user" "$db_name" #================================================= # REMOVE APP MAIN DIR From a0a9fe6ab7002058faca904e53d77d93b55cd1a6 Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Wed, 11 Oct 2017 15:34:01 +0530 Subject: [PATCH 12/19] remove: use ynh_system_user_delete helper --- scripts/remove | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/remove b/scripts/remove index 1ece7fd..68399f6 100755 --- a/scripts/remove +++ b/scripts/remove @@ -58,4 +58,4 @@ sudo rm -f "/var/log/${app}.log" # REMOVE DEDICATED USER #================================================= -sudo userdel "$app" +ynh_system_user_delete "$app" From f781efb160eb43fe1f8e75e8e023aebdf44b5a0a Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Tue, 10 Oct 2017 17:56:45 +0530 Subject: [PATCH 13/19] scripts: use `ynh_add_nginx_config` helper --- conf/{nginx.conf-nosub => nginx.conf} | 0 scripts/install | 4 +++- scripts/remove | 6 +++--- scripts/upgrade | 5 +++-- 4 files changed, 9 insertions(+), 6 deletions(-) rename conf/{nginx.conf-nosub => nginx.conf} (100%) diff --git a/conf/nginx.conf-nosub b/conf/nginx.conf similarity index 100% rename from conf/nginx.conf-nosub rename to conf/nginx.conf diff --git a/scripts/install b/scripts/install index 0c1a6d0..694415b 100644 --- a/scripts/install +++ b/scripts/install @@ -149,7 +149,8 @@ sudo chown -R www-data: $data_path # NGINX CONFIGURATION #================================================= -sudo cp $root_path/conf/nginx.conf-nosub /etc/nginx/conf.d/$domain.d/mattermost.conf +# Copy conf/nginx.conf to the correct location +ynh_add_nginx_config #================================================= # SETUP SUPERVISOR @@ -177,4 +178,5 @@ sudo yunohost app ssowatconf #================================================= # START APP #================================================= + sudo supervisorctl reload diff --git a/scripts/remove b/scripts/remove index 68399f6..c469a30 100755 --- a/scripts/remove +++ b/scripts/remove @@ -39,14 +39,14 @@ ynh_mysql_remove_db "$db_user" "$db_name" # REMOVE APP MAIN DIR #================================================= -sudo rm -rf "$final_path" -sudo rm -rf "$data_path" +ynh_secure_remove "$final_path" +ynh_secure_remove "$data_path" #================================================= # REMOVE NGINX CONFIGURATION #================================================= -sudo rm -f "/etc/nginx/conf.d/${domain}.d/${app}.conf" +ynh_remove_nginx_config #================================================= # REMOVE LOG FILE diff --git a/scripts/upgrade b/scripts/upgrade index 7345187..b46b432 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -7,6 +7,7 @@ source /usr/share/yunohost/helpers ynh_abort_if_errors # Retrieve arguments +app=$YNH_APP_INSTANCE_NAME domain=$(ynh_app_setting_get mattermost domain) is_public=$(ynh_app_setting_get mattermost is_public) @@ -58,8 +59,8 @@ sudo sed -i "s|\"FileLocation\": \"/var/log/mattermost.log\"|\"FileLocation\": \ # 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 +# Update Nginx configuration +ynh_add_nginx_config # Start server sudo supervisorctl start mattermost From ee7b6a152246bc142cc10f0189208e9ef3892f53 Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Wed, 11 Oct 2017 15:43:37 +0530 Subject: [PATCH 14/19] upgrade: improve comments --- scripts/upgrade | 70 ++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 57 insertions(+), 13 deletions(-) diff --git a/scripts/upgrade b/scripts/upgrade index b46b432..fe0f513 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -1,23 +1,37 @@ #!/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 +#================================================= +# ACTIVE TRAP +#================================================= + function cleanup_and_restart { set +e @@ -30,37 +44,67 @@ function cleanup_and_restart } trap cleanup_and_restart ERR -# Download code +#================================================= +# STANDARD UPGRADE STEPS +#================================================= +# DOWNLOAD, CHECK AND UNPACK 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 -ynh_add_nginx_config +#================================================= +# RELOAD NGINX +#================================================= + +sudo service nginx reload + +#================================================= +# START SERVER +#================================================= -# Start server sudo supervisorctl start mattermost From faa51975afd1952f37f9cc384553d59e6470c8c8 Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Wed, 11 Oct 2017 15:50:00 +0530 Subject: [PATCH 15/19] upgrade: backup before upgrading, and restore backup on failure --- scripts/upgrade | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/scripts/upgrade b/scripts/upgrade index fe0f513..f9fd8c5 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -29,25 +29,25 @@ version=$(cat "$root_path/VERSION") archive_filename="mattermost-$version.tar.gz" #================================================= -# ACTIVE TRAP +# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP #================================================= -function cleanup_and_restart -{ - set +e - sudo rm -f "$archive_filename" - sudo supervisorctl start mattermost - - # 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 + +# Exit if an error occurs during the execution of the script +ynh_abort_if_errors #================================================= -# STANDARD UPGRADE STEPS -#================================================= -# DOWNLOAD, CHECK AND UNPACK SOURCE +# DOWNLOAD SOURCE #================================================= archive_url="https://releases.mattermost.com/${version}/mattermost-team-${version}-linux-amd64.tar.gz" From f6bef01487bf815e746af0f269b4c3d6726fa308 Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Thu, 12 Oct 2017 11:38:53 +0530 Subject: [PATCH 16/19] restore: improve comments --- scripts/restore | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/scripts/restore b/scripts/restore index 870d6f7..fc9c88b 100644 --- a/scripts/restore +++ b/scripts/restore @@ -105,8 +105,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 From 6e15ed6634121bbde1fa5428d310e869081f8699 Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Thu, 12 Oct 2017 11:39:21 +0530 Subject: [PATCH 17/19] restore: replace deprecated `yunohost app checkurl` --- scripts/restore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/restore b/scripts/restore index fc9c88b..e4851d0 100644 --- a/scripts/restore +++ b/scripts/restore @@ -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 " From caf342f4fd1faf63b4269a7e2dcc24d8ef0ce432 Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Thu, 12 Oct 2017 11:47:36 +0530 Subject: [PATCH 18/19] Require Yunohost >= 2.6.4 New helpers used in modernized scripts require this. --- README.md | 1 + manifest.json | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 39250f8..1c0bb80 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/manifest.json b/manifest.json index 1b5d206..3d99720 100644 --- a/manifest.json +++ b/manifest.json @@ -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 ?" From 7fc00fe0dfe720c394faba430bd5f0588e6ec220 Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Thu, 12 Oct 2017 11:57:13 +0530 Subject: [PATCH 19/19] =?UTF-8?q?test:=20don=E2=80=99t=20mix=20`--verbose`?= =?UTF-8?q?=20option=20with=20app=20names?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test.sh b/test.sh index 9af51a3..b8fa766 100755 --- a/test.sh +++ b/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" }