diff --git a/README.md b/README.md
index f280861..3c23531 100644
--- a/README.md
+++ b/README.md
@@ -1,8 +1,8 @@
# Flarum for YunoHost
-[](https://install-app.yunohost.org/?app=flarum)
+[](https://install-app.yunohost.org/?app=flarum)
-[.svg)](https://dash.yunohost.org/appci/app/flarum) [](https://github.com/flarum/core/releases/tag/v0.1.0-beta.7.2)
+[.svg)](https://dash.yunohost.org/appci/app/flarum) [](https://github.com/flarum/flarum/releases/tag/v0.1.0-beta.9) 
[Flarum](http://flarum.org/), an open-source forum software, packaged for [YunoHost](https://yunohost.org/), a self-hosting server operating server.
@@ -14,6 +14,8 @@
- SSOwat integration through a [dedicated extension](https://github.com/tituspijean/flarum-ext-auth-ssowat).
## Installation
+::warning: Flarum requires PHP 7.1+. PHP versions above 7.0 are currently not officially supported by YunoHost. This package's `install` script directly calls `apt install php7.3 ...`. Proceed with caution.
+
This Flarum package can be installed through:
- YunoHost's webadmin, in the Community listing
- YunoHost's CLI: `yunohost app install https://github.com/YunoHost-Apps/flarum_ynh`.
@@ -24,7 +26,7 @@ Required parameters are:
- `admin`, among the YunoHosts users
- `public`, *true* by default, for guests to read the forum
- `title` of the forum
-- `language` can be English (by default), French, and German. Other languages installable after installation as any other extensions
+- `language` can be English `en` (by default), French `fr`, and German `de`. Other languages are installable after installation like any other extensions
- `bazaar_extension` to install the extension marketplace (*false* by default), to avoid using the command line to add new extensions.
After installation, simply open your browser to Flarum's page. First loading may be a bit longer as assets are generated.
@@ -50,13 +52,13 @@ Reboot the system and try the installation again.
### `Timeout` errors
Some users have reported a successful installation, but get a blank page due to a `timeout` on a PHP script that prepares the forum assests (`Minify.php`, notably).
-In `/etc/php/7.0/fpm/conf.d/20-{APPID}.ini`, you can increase the `max_execution_time` and `max_input_time` limits (both values are in seconds if nothing is specified).
+In `/etc/php/*php_version*/fpm/pool.d/*app_id*.conf`, you can increase the `max_execution_time` and `max_input_time` limits (both values are in seconds if nothing is specified).
-Reload PHP-FPM with `sudo service php7.0-fpm reload`.
+Reload PHP-FPM with `sudo service php*php_version*-fpm reload`.
### Upload limit
If you are facing an error while uploading large files into the forum, PHP may be limiting file upload.
-In `/etc/php/7.0/fpm/conf.d/20-{APPID}.ini`, you can uncomment (remove `;` at the beginning of the line) and increase the values of `upload_max_filesize` and `post_max_size` (both values are in bytes).
+In `/etc/php/*php_version*/fpm/pool.d/*app_id*.conf`, you can uncomment (remove `;` at the beginning of the line) and increase the values of `upload_max_filesize` and `post_max_size` (both values are in bytes).
-Reload PHP-FPM with `sudo service php7.0-fpm reload`.
+Reload PHP-FPM with `sudo service php*php_version*-fpm reload`.
diff --git a/check_process b/check_process
index a4d9152..af32cc5 100644
--- a/check_process
+++ b/check_process
@@ -17,7 +17,7 @@
setup_private=1
setup_public=1
upgrade=1
- upgrade=1 from_commit=46ca549825e311f4095b173e79d58a349d70d9a2
+ upgrade=1 from_commit=e9d524d3ede85572e72bf9ac05b224c18b2f1765
backup_restore=1
multi_instance=1
incorrect_path=1
diff --git a/conf/nginx.conf b/conf/nginx.conf
index 4eaa8b2..7843482 100644
--- a/conf/nginx.conf
+++ b/conf/nginx.conf
@@ -4,23 +4,16 @@ location ^~ __PATH__ {
rewrite ^ https://$server_name$request_uri? permanent;
}
- alias __FINALPATH__/;
- try_files $uri $uri/ /index.php?$query_string;
- index __LOCATION_HACK__/index.php;
+ alias __FINALPATH__/public/;
+ index index.php;
# Bug in Nginx with locations and aliases (see http://stackoverflow.com/a/35102259 )
- location __LOCATION_HACK__/ { try_files $uri $uri/ __PATH_HACK__/index.php?$query_string; }
- location __LOCATION_HACK__/api { try_files $uri $uri/ __PATH_HACK__/api.php?$query_string; }
- location __LOCATION_HACK__/admin { try_files $uri $uri/ __PATH_HACK__/admin.php?$query_string; }
-
- location __LOCATION_HACK__/flarum/ {
- deny all;
- return 404;
- }
+ # try_files $uri $uri/ /index.php?$query_string; # will not work for /admin and /api
+ if (!-e $request_filename) { rewrite ^ __PATH_HACK__/index.php last; }
location ~* \.php$ {
fastcgi_split_path_info ^(.+.php)(/.+)$;
- fastcgi_pass unix:/var/run/php5-fpm-__NAME__.sock;
+ fastcgi_pass unix:/var/run/php-fpm-__NAME__.sock;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $request_filename;
fastcgi_param HTTP_PROXY ""; # Fix for https://httpoxy.org/ vulnerability
@@ -28,38 +21,61 @@ location ^~ __PATH__ {
fastcgi_read_timeout 600;
}
- location ~* \.html$ {
- expires -1;
+ # Expire rules for static content
+ location ~* \.(?:manifest|appcache|html?|xml|json)$ {
+ add_header Cache-Control "max-age=0";
}
- location ~* \.(css|js|gif|jpe?g|png)$ {
- expires 1M;
- add_header Pragma public;
- add_header Cache-Control "public, must-revalidate, proxy-revalidate";
+ location ~* \.(?:rss|atom)$ {
+ add_header Cache-Control "max-age=3600";
}
+ location ~* \.(?:jpg|jpeg|gif|png|ico|cur|gz|svg|mp4|ogg|ogv|webm|htc)$ {
+ add_header Cache-Control "max-age=2592000";
+ access_log off;
+ }
+
+ location ~* \.(?:css|js)$ {
+ add_header Cache-Control "max-age=31536000";
+ access_log off;
+ }
+
+ location ~* \.(?:ttf|ttc|otf|eot|woff|woff2)$ {
+ add_header Cache-Control "max-age=2592000";
+ access_log off;
+ }
+
+ # Gzip compression
gzip on;
- gzip_http_version 1.1;
- gzip_vary on;
- gzip_comp_level 6;
+ gzip_comp_level 5;
+ gzip_min_length 256;
gzip_proxied any;
- gzip_types application/atom+xml
- application/javascript
- application/json
- application/vnd.ms-fontobject
- application/x-font-ttf
- application/x-web-app-manifest+json
- application/xhtml+xml
- application/xml
- font/opentype
- image/svg+xml
- image/x-icon
- text/css
- text/plain
- text/xml;
- gzip_buffers 16 8k;
- gzip_disable "MSIE [1-6]\.(?!.*SV1)";
-
+ gzip_vary on;
+ gzip_types
+ application/atom+xml
+ application/javascript
+ application/json
+ application/ld+json
+ application/manifest+json
+ application/rss+xml
+ application/vnd.geo+json
+ application/vnd.ms-fontobject
+ application/x-font-ttf
+ application/x-web-app-manifest+json
+ application/xhtml+xml
+ application/xml
+ font/opentype
+ image/bmp
+ image/svg+xml
+ image/x-icon
+ text/cache-manifest
+ text/css
+ text/plain
+ text/vcard
+ text/vnd.rim.location.xloc
+ text/vtt
+ text/x-component
+ text/x-cross-domain-policy;
# Include SSOWAT user panel.
# include conf.d/yunohost_panel.conf.inc;
diff --git a/conf/php-fpm.conf b/conf/php-fpm.conf
index 74fcc4c..7646d26 100644
--- a/conf/php-fpm.conf
+++ b/conf/php-fpm.conf
@@ -24,7 +24,7 @@
; specific port;
; '/path/to/unix/socket' - to listen on a unix socket.
; Note: This value is mandatory.
-listen = /var/run/php5-fpm-__USER__.sock
+listen = /var/run/php-fpm-__USER__.sock
; Set listen(2) backlog. A value of '-1' means unlimited.
; Default Value: 128 (-1 on FreeBSD and OpenBSD)
@@ -246,7 +246,7 @@ catch_workers_output = yes
; Other common parameters
php_value[max_execution_time] = 600
php_value[max_input_time] = 600
-;php_value[memory_limit] = 256M
+php_value[memory_limit] = 256M
;php_value[short_open_tag] = On
env[COMPOSER_HOME] = __FINALPATH__/.composer
diff --git a/conf/php-fpm.ini b/conf/php-fpm.ini
deleted file mode 100644
index 70d2334..0000000
--- a/conf/php-fpm.ini
+++ /dev/null
@@ -1,10 +0,0 @@
-; Common values to change to increase file upload limit
-; upload_max_filesize = 50M
-; post_max_size = 50M
-; mail.add_x_header = Off
-
-; Other common parameters
-max_execution_time = 600
-max_input_time = 300
-memory_limit = 256M
-; short_open_tag = On
diff --git a/manifest.json b/manifest.json
index 7fb7d2f..04358a5 100644
--- a/manifest.json
+++ b/manifest.json
@@ -9,9 +9,9 @@
},
"url": "http://flarum.org/",
"license": "MIT",
- "version": "0.1.0-beta.7",
+ "version": "0.1.0-beta.9~ynh1",
"maintainer": {
- "name": "Titus PiJean",
+ "name": "tituspijean",
"email": "tituspijean@outlook.com"
},
"requirements": {
@@ -20,7 +20,7 @@
"multi_instance": true,
"services": [
"nginx",
- "php5-fpm",
+ "php7.3-fpm",
"mysql"
],
"arguments": {
diff --git a/scripts/_common.sh b/scripts/_common.sh
index 9f06b3d..6dc6003 100644
--- a/scripts/_common.sh
+++ b/scripts/_common.sh
@@ -1,77 +1,38 @@
+#=================================================
+# COMMON VARIABLES
+#=================================================
+
+# dependencies used by the app
+pkg_dependencies="php7.3 php7.3-curl php7.3-dom php7.3-gd php7.3-json php7.3-mbstring php7.3-pdo-mysql php7.3-tokenizer php7.3-zip"
+
# Version numbers
-project_version="0.1.0-beta.7"
-flarum_version="0.1.0-beta.7.2"
-ssowat_ext_ver="0.6"
+php_version="7.3"
+project_version="0.1.0-beta.9"
+core_version="0.1.0-beta.9"
+ssowat_version="0.1.0-beta.9-1"
-# Execute a command as another user
-# usage: exec_as USER COMMAND [ARG ...]
-exec_as() {
- local USER=$1
- shift 1
-
- if [[ $USER = $(whoami) ]]
- then
- eval $@
- else
- sudo -u "$USER" $@
- fi
-}
-
-# Execute a composer command from a given directory
-# usage: composer_exec AS_USER WORKDIR COMMAND [ARG ...]
-exec_composer() {
- local AS_USER=$1
- local WORKDIR=$2
- shift 2
-
- # Do not run composer as root
- if [ $AS_USER = "root" ] ; then ynh_die "Do not run composer as root" ; fi
- pushd "${WORKDIR}"
- ynh_exec_warn_less \
- "exec_as "$AS_USER" COMPOSER_HOME="${WORKDIR}/.composer" \
- php -d memory_limit=-1 \
- "${WORKDIR}/composer.phar" $@ \
- --no-interaction"
- popd
-}
-
-# Install and initialize Composer in the given directory
-# usage: init_composer destdir
-init_composer() {
- local AS_USER=$1
- local WORKDIR=$2
-
- # Do not install composer as root
- if [ $AS_USER = "root" ] ; then ynh_die "Do not install composer as root" ; fi
-
- # install composer
- curl -sS https://getcomposer.org/installer \
- | ynh_exec_warn_less \
- "COMPOSER_HOME="${WORKDIR}/.composer" php -- --install-dir="$WORKDIR"" \
- || ynh_die "Unable to install Composer"
- chmod +x "${WORKDIR}/composer.phar"
- # update dependencies to create composer.lock
- #exec_composer "$AS_USER" "$WORKDIR" install --no-dev \
- # || ynh_die "Unable to update core dependencies with Composer"
-}
+#=================================================
+# PERSONAL HELPERS
+#=================================================
# Install extension, and activate it in database
-# usage: install_and_activate_extension $user $final_path $db_name $extension $short_extension
+# usage: install_and_activate_extension $user $php_version $final_path $db_name $extension $short_extension
# $extension is the "vendor/extension-name" string from packagist
# $short_extension is the extension name written in database, how it is shortened is still a mystery
install_and_activate_extension() {
local AS_USER=$1
- local WORKDIR=$2
- local DB_NAME=$3
- local EXTENSION=$4
- local SHORT_EXTENSION=$5
+ local PHP_VERSION=$2
+ local WORKDIR=$3
+ local DB_NAME=$4
+ local EXTENSION=$5
+ local SHORT_EXTENSION=$6
local sql_command
local old_extensions_enabled
local addition
local new_extensions_enabled
# Install extension
- exec_composer $AS_USER $WORKDIR "require $EXTENSION -n --ansi -d $WORKDIR"
+ ynh_composer_exec $AS_USER $PHP_VERSION $WORKDIR "require $EXTENSION -n --ansi -d $WORKDIR"
# Retrieve current extensions
sql_command="SELECT \`value\` FROM settings WHERE \`key\` = 'extensions_enabled'"
@@ -86,63 +47,8 @@ install_and_activate_extension() {
}
-# Send an email to inform the administrator
-#
-# usage: ynh_send_readme_to_admin app_message [recipients]
-# | arg: app_message - The message to send to the administrator.
-# | arg: recipients - The recipients of this email. Use spaces to separate multiples recipients. - default: root
-# example: "root admin@domain"
-# If you give the name of a YunoHost user, ynh_send_readme_to_admin will find its email adress for you
-# example: "root admin@domain user1 user2"
-ynh_send_readme_to_admin() {
- local app_message="${1:-...No specific information...}"
- local recipients="${2:-root}"
+#=================================================
+# EXPERIMENTAL HELPERS
+#=================================================
- # Retrieve the email of users
- find_mails () {
- local list_mails="$1"
- local mail
- local recipients=" "
- # Read each mail in argument
- for mail in $list_mails
- do
- # Keep root or a real email address as it is
- if [ "$mail" = "root" ] || echo "$mail" | grep --quiet "@"
- then
- recipients="$recipients $mail"
- else
- # But replace an user name without a domain after by its email
- if mail=$(ynh_user_get_info "$mail" "mail" 2> /dev/null)
- then
- recipients="$recipients $mail"
- fi
- fi
- done
- echo "$recipients"
- }
- recipients=$(find_mails "$recipients")
-
- local mail_subject="☁️🆈🅽🅷☁️: \`$app\` was just installed!"
-
- local mail_message="This is an automated message from your beloved YunoHost server.
-
-Specific information for the application $app.
-
-$app_message
-
----
-Automatic diagnosis data from YunoHost
-
-$(yunohost tools diagnosis | grep -B 100 "services:" | sed '/services:/d')"
-
- # Define binary to use for mail command
- if [ -e /usr/bin/bsd-mailx ]
- then
- local mail_bin=/usr/bin/bsd-mailx
- else
- local mail_bin=/usr/bin/mail.mailutils
- fi
-
- # Send the email to the recipients
- echo "$mail_message" | $mail_bin -a "Content-Type: text/plain; charset=UTF-8" -s "$mail_subject" "$recipients"
-}
+# See ynh_* scripts
diff --git a/scripts/backup b/scripts/backup
index 1d863fd..9bbdafc 100644
--- a/scripts/backup
+++ b/scripts/backup
@@ -6,62 +6,73 @@
# IMPORT GENERIC HELPERS
#=================================================
-if [ ! -e _common.sh ]; then
- # Get the _common.sh file if it's not in the current directory
- cp ../settings/scripts/_common.sh ./_common.sh
- chmod a+rx _common.sh
-fi
-source _common.sh
+#Keep this path for calling _common.sh inside the execution's context of backup and restore scripts
+source ../settings/scripts/_common.sh
source /usr/share/yunohost/helpers
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
+ynh_clean_setup () {
+ ### Remove this function if there's nothing to clean before calling the remove script.
+ true
+}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#=================================================
# LOAD SETTINGS
#=================================================
+ynh_script_progression --message="Loading installation settings..." --time --weight=1
app=$YNH_APP_INSTANCE_NAME
-final_path=$(ynh_app_setting_get $app final_path)
-domain=$(ynh_app_setting_get $app domain)
-db_name=$(ynh_app_setting_get $app db_name)
+final_path=$(ynh_app_setting_get --app=$app --key=final_path)
+domain=$(ynh_app_setting_get --app=$app --key=domain)
+db_name=$(ynh_app_setting_get --app=$app --key=db_name)
#=================================================
# STANDARD BACKUP STEPS
#=================================================
# BACKUP THE APP MAIN DIR
#=================================================
+ynh_script_progression --message="Backing up the main app directory..." --time --weight=1
-ynh_backup "$final_path"
+ynh_backup --src_path="$final_path"
#=================================================
# BACKUP THE NGINX CONFIGURATION
#=================================================
+ynh_script_progression --message="Backing up nginx web server configuration..." --time --weight=1
-ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf"
+ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf"
#=================================================
# BACKUP THE PHP-FPM CONFIGURATION
#=================================================
+ynh_script_progression --message="Backing up php-fpm configuration..." --time --weight=1
-ynh_backup "/etc/php5/fpm/pool.d/$app.conf"
-ynh_backup "/etc/php5/fpm/conf.d/20-$app.ini"
+ynh_backup --src_path="/etc/php/7.0/fpm/pool.d/$app.conf"
#=================================================
# BACKUP THE MYSQL DATABASE
#=================================================
+ynh_script_progression --message="Backing up the MySQL database..." --time --weight=1
-ynh_mysql_dump_db "$db_name" > db.sql
+ynh_mysql_dump_db --database="$db_name" > db.sql
#=================================================
# SPECIFIC BACKUP
#=================================================
# BACKUP LOGROTATE
#=================================================
+ynh_script_progression --message="Backing up logrotate configuration..." --time --weight=1
-ynh_backup "/etc/logrotate.d/$app"
+ynh_backup --src_path="/etc/logrotate.d/$app"
+
+#=================================================
+# END OF SCRIPT
+#=================================================
+
+ynh_script_progression --message="Backup script completed for $app. (YunoHost will then actually copy those files to the archive)." --time --last
diff --git a/scripts/change_url b/scripts/change_url
index a0e53ea..ef3dd3d 100644
--- a/scripts/change_url
+++ b/scripts/change_url
@@ -24,22 +24,15 @@ app=$YNH_APP_INSTANCE_NAME
#=================================================
# LOAD SETTINGS
#=================================================
+ynh_script_progression --message="Loading installation settings..." --time --weight=1
# Needed for helper "ynh_add_nginx_config"
-final_path=$(ynh_app_setting_get $app final_path)
+final_path=$(ynh_app_setting_get --app=$app --key=final_path)
# Add settings here as needed by your application
-#db_name=$(ynh_app_setting_get "$app" db_name)
-#db_pwd=$(ynh_app_setting_get $app db_pwd)
-
-#=================================================
-# CHECK THE SYNTAX OF THE PATHS
-#=================================================
-
-test -n "$old_path" || old_path="/"
-test -n "$new_path" || new_path="/"
-new_path=$(ynh_normalize_url_path $new_path)
-old_path=$(ynh_normalize_url_path $old_path)
+#db_name=$(ynh_app_setting_get --app=$app --key=db_name)
+#db_user=$db_name
+#db_pwd=$(ynh_app_setting_get --app=$app --key=db_pwd)
#=================================================
# CHECK WHICH PARTS SHOULD BE CHANGED
@@ -59,9 +52,17 @@ fi
#=================================================
# STANDARD MODIFICATIONS
+#=================================================
+# STOP SYSTEMD SERVICE
+#=================================================
+ynh_script_progression --message="Stopping a systemd service..." --time --weight=1
+
+ynh_systemd_action --service_name=$app --action="stop" --log_path="/var/log/$app/$app.log"
+
#=================================================
# MODIFY URL IN NGINX CONF
#=================================================
+ynh_script_progression --message="Updating nginx web server configuration..." --time --weight=1
nginx_conf_path=/etc/nginx/conf.d/$old_domain.d/$app.conf
@@ -69,17 +70,15 @@ nginx_conf_path=/etc/nginx/conf.d/$old_domain.d/$app.conf
if [ $change_path -eq 1 ]
then
# Make a backup of the original nginx config file if modified
- ynh_backup_if_checksum_is_different "$nginx_conf_path"
+ ynh_backup_if_checksum_is_different --file="$nginx_conf_path"
# Set global variables for nginx helper
domain="$old_domain"
path_url="$new_path"
# Bug in Nginx with locations and aliases (see http://stackoverflow.com/a/35102259 )
if [ $path_url = "/" ]; then
- sed -i "s@__LOCATION_HACK__@@g" ../conf/nginx.conf
- sed -i "s@__PATH_HACK__@/@g" ../conf/nginx.conf
+ ynh_replace_string "__PATH_HACK__" "" "../conf/nginx.conf"
else
- sed -i "s@__LOCATION_HACK__@$path_url@g" ../conf/nginx.conf
- sed -i "s@__PATH_HACK__@$path_url$path_url@g" ../conf/nginx.conf
+ ynh_replace_string "__PATH_HACK__" "$path_url" "../conf/nginx.conf"
fi
# Create a dedicated nginx config
ynh_add_nginx_config
@@ -89,32 +88,36 @@ fi
if [ $change_domain -eq 1 ]
then
# Delete file checksum for the old conf file location
- ynh_delete_file_checksum "$nginx_conf_path"
+ ynh_delete_file_checksum --file="$nginx_conf_path"
mv $nginx_conf_path /etc/nginx/conf.d/$new_domain.d/$app.conf
# Store file checksum for the new config file location
- ynh_store_file_checksum "/etc/nginx/conf.d/$new_domain.d/$app.conf"
+ ynh_store_file_checksum --file="/etc/nginx/conf.d/$new_domain.d/$app.conf"
fi
#=================================================
# SPECIFIC MODIFICATIONS
#=================================================
-# MODIFY URL IN CONFIG.PHP
+# ...
#=================================================
-if [ $change_domain -eq 1 ]
-then
- ynh_replace_string $old_domain $new_domain $final_path/config.php
-fi
-
-if [ $change_path -eq 1 ]
-then
- ynh_replace_string $old_path $new_path $final_path/config.php
-fi
-
#=================================================
# GENERIC FINALISATION
+#=================================================
+# START SYSTEMD SERVICE
+#=================================================
+ynh_script_progression --message="Starting a systemd service..." --time --weight=1
+
+ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log"
+
#=================================================
# RELOAD NGINX
#=================================================
+ynh_script_progression --message="Reloading nginx web server..." --time --weight=1
-systemctl reload nginx
+ynh_systemd_action --service_name=nginx --action=reload
+
+#=================================================
+# END OF SCRIPT
+#=================================================
+
+ynh_script_progression --message="Change of URL completed for $app" --time --last
diff --git a/scripts/install b/scripts/install
index 1d2da37..c72d0d4 100644
--- a/scripts/install
+++ b/scripts/install
@@ -7,6 +7,9 @@
#=================================================
source _common.sh
+source ynh_exec_as
+source ynh_composer__2
+source ynh_send_readme_to_admin__2
source /usr/share/yunohost/helpers
#=================================================
@@ -69,16 +72,35 @@ ynh_app_setting_set $app admin $admin
ynh_app_setting_set $app is_public $is_public
ynh_app_setting_set $app language $language
ynh_app_setting_set $app final_path $final_path
+ynh_app_setting_set $app php_version $php_version
ynh_app_setting_set $app project_version $project_version
-ynh_app_setting_set $app flarum_version $flarum_version
-ynh_app_setting_set $app ssowat_ext_ver $ssowat_ext_ver
+ynh_app_setting_set $app core_version $core_version
+ynh_app_setting_set $app ssowat_version $ssowat_version
ynh_app_setting_set $app bazaar_extension $bazaar_extension
+#=================================================
+# STANDARD MODIFICATIONS
+#=================================================
+# INSTALL DEPENDENCIES
+#=================================================
+ynh_script_progression --message="Installing dependencies..." --time --weight=1
+
+### `ynh_install_app_dependencies` allows you to add any "apt" dependencies to the package.
+### Those deb packages will be installed as dependencies of this package.
+### If you're not using this helper:
+### - Remove the section "REMOVE DEPENDENCIES" in the remove script
+### - Remove the variable "pkg_dependencies" in _common.sh
+### - As well as the section "REINSTALL DEPENDENCIES" in the restore script
+### - And the section "UPGRADE DEPENDENCIES" in the upgrade script
+
+#ynh_install_app_dependencies $pkg_dependencies
+apt install $pkg_dependencies
+
#===================================================
# CREATE DEDICATED USER
#===================================================
-ynh_system_user_create $app $final_path
+ynh_system_user_create $app $final_path 1
sudo usermod -a -G www-data $app
# Create working directory
sudo mkdir -p "$final_path/.composer"
@@ -89,7 +111,8 @@ sudo chmod -R 0775 $final_path
# COMPOSER INSTALLATION
#=================================================
-init_composer $app $final_path
+ynh_script_progression --message="Installing Composer..." --time --weight=1
+ynh_install_composer $php_version $final_path
#=================================================
# FLARUM INSTALLATION
@@ -102,18 +125,21 @@ sudo chown -R $app:www-data $tmp
sudo chmod -R 0775 $tmp
# Install Flarum
-ynh_print_info "Composer is installing Flarum and its dependencies. It may take a while..."
+ynh_script_progression --message="Composer is installing Flarum and its dependencies (may take a while)..." --time --weight=3
+
# First, create the project with core and all basic extensions
-exec_composer $app $final_path "create-project flarum/flarum=$project_version $tmp --stability=beta --ansi -d $tmp"
+ynh_composer_exec $app $php_version $final_path "create-project flarum/flarum=$project_version $tmp --stability=beta --ansi -d $tmp"
# Let's fix the core version by explicitely requiring it
-exec_composer $app $final_path "require flarum/core:$flarum_version -n --ansi -d $tmp"
+ynh_composer_exec $app $php_version $final_path "require flarum/core:$core_version -n --ansi -d $tmp"
# Copy Flarum to working directory and clean temp directory
sudo cp -Rf $tmp/* $final_path
-sudo chown -R $app:www-data $final_path
-sudo chmod -R 0775 $final_path
ynh_secure_remove $tmp
-ynh_print_info " ... done!"
+
+# Set right permissions for the post-installation
+chown -R $app: $final_path
+chown -R $app:www-data $final_path/storage
+sudo chmod -R 0775 $final_path
#=================================================
# CREATE A MYSQL DATABASE
@@ -130,12 +156,11 @@ ynh_app_setting_set "$app" db_pwd "$db_pwd"
# Bug in Nginx with locations and aliases (see http://stackoverflow.com/a/35102259 )
if [ $path_url = "/" ]; then
- ynh_replace_string "__LOCATION_HACK__" "" "../conf/nginx.conf"
- ynh_replace_string "__PATH_HACK__" "/" "../conf/nginx.conf"
+ ynh_replace_string "__PATH_HACK__" "" "../conf/nginx.conf"
else
- ynh_replace_string "__LOCATION_HACK__" "$path_url" "../conf/nginx.conf"
- ynh_replace_string "__PATH_HACK__" "$path_url$path_url" "../conf/nginx.conf"
+ ynh_replace_string "__PATH_HACK__" "$path_url" "../conf/nginx.conf"
fi
+
# Create a dedicated nginx config
ynh_add_nginx_config
@@ -144,7 +169,7 @@ ynh_add_nginx_config
#=================================================
# Create a dedicated php-fpm config
-ynh_add_fpm_config
+ynh_add_fpm_config $php_version
#=================================================
# SETUP LOGROTATE
@@ -177,8 +202,8 @@ systemctl reload nginx
#=================================================
# FLARUM POST-INSTALL
#=================================================
+ynh_script_progression --message="Configuring Flarum..." --time --weight=2
-ynh_print_info "Configuring Flarum..."
# Copy the configuration.yml to working directory
finalflarumconf="$final_path/configuration.yml"
cp ../conf/configuration.yml $finalflarumconf
@@ -197,9 +222,9 @@ ynh_replace_string "__ADMIN_EML__" "$admin_mail" "$finalflarumconf"
ynh_replace_string "__FORUM_TITLE__" "$title" "$finalflarumconf"
# Execute post-installation
pushd $final_path
-exec_as $app "php -d $final_path -d memory_limit=-1 flarum install -f configuration.yml"
-# Delete configuration.yml as it sensitive data
-ynh_secure_remove $finalflarumconf
+ exec_as $app php$php_version -d $final_path -d memory_limit=-1 flarum install -f configuration.yml
+ # Delete configuration.yml as it contains sensitive data
+ ynh_secure_remove $finalflarumconf
popd
# Email setup
@@ -210,10 +235,11 @@ sql_command="REPLACE INTO \`settings\` (\`key\`, \`value\`) VALUES
('mail_host', 'localhost'),
('mail_port', '587');"
ynh_mysql_execute_as_root "$sql_command" $db_name
-ynh_print_info " ... done!"
+
# Install and activate the SSOwat auth extension
-install_and_activate_extension $app $final_path $db_name "tituspijean/flarum-ext-auth-ssowat:$ssowat_ext_ver" "tituspijean-auth-ssowat"
+ynh_script_progression --message="Installing SSOwat extension..." --time --weight=2
+install_and_activate_extension $app $php_version $final_path $db_name "tituspijean/flarum-ext-auth-ssowat:$ssowat_version" "tituspijean-auth-ssowat"
# Configure SSOwat auth extension
ssowatdomain=$( /dev/null; then
+ ynh_install_composer $php_version $final_path
+fi
+
+#=================================================
+# FLARUM UPGRADE
+#=================================================
+
+# Downward compatibility: remove the v before version number
+if [[ $old_project_version == "v*" ]]; then $old_project_version = ${old_project_version:1}; fi
+# Check if upgrade of Flarum core is needed
+if [[ $(dpkg --compare-versions $old_project_version lt $project_version && echo true) ]]; then
+ # Upgrade Flarum
+ ynh_composer_exec $app $php_version $final_path "require -n flarum/core:$project_version"
+ # Database password has to be input on admin page after upgrade to 0.1.0-beta.7.2
+ if [[ $project_version == "0.1.0-beta.7.2" ]]; then
+ curl "https://$domain$path_url/admin" -H "Accept: */*" --compressed -H "Content-Type: application/x-www-form-urlencoded; charset=UTF-8" --data "databasePassword=$db_pwd" -k
+ fi
+ pushd $final_path
+ exec_as $app php flarum cache:clear
+ popd
+ ynh_print_info "Flarum has been updated to version $project_version."
+ upgraded_flarum=true
+else
+ ynh_print_info "Flarum does not need updating."
+ upgraded_flarum=false
+fi
+
+# Check if upgrade of SSOwat extension is needed
+if [[ $(dpkg --compare-versions $old_ssowat_version lt $ssowat_version && echo true) || -z $old_ssowat_version ]]; then
+ # Install and activate the SSOwat auth extension
+ install_and_activate_extension $app $final_path $db_name "tituspijean/flarum-ext-auth-ssowat:$ssowat_version" "tituspijean-auth-ssowat"
+ # Configure SSOwat auth extension
+ ssowatdomain=$( /dev/null; then
- init_composer $app $final_path
-fi
-
-#=================================================
-# FLARUM UPGRADE
-#=================================================
-
-# Downward compatibility: remove the v before version number
-if [[ $old_flarum_version == "v*" ]]; then $old_flarum_version = ${old_flarum_version:1}; fi
-# Check if upgrade of Flarum core is needed
-if [[ $(dpkg --compare-versions $old_flarum_version lt $flarum_version && echo true) ]]; then
- # Upgrade Flarum
- exec_composer $app $final_path "require -n flarum/core:$flarum_version"
- # Database password has to be input on admin page after upgrade to 0.1.0-beta.7.2
- if [[ $flarum_version == "0.1.0-beta.7.2" ]]; then
- curl "https://$domain$path_url/admin" -H "Accept: */*" --compressed -H "Content-Type: application/x-www-form-urlencoded; charset=UTF-8" --data "databasePassword=$db_pwd" -k
- fi
- pushd $final_path
- exec_as $app php flarum cache:clear
- popd
- ynh_print_info "Flarum has been updated to version $flarum_version."
- upgraded_flarum=true
-else
- ynh_print_info "Flarum does not need updating."
- upgraded_flarum=false
-fi
-
-# Check if upgrade of SSOwat extension is needed
-if [[ $(dpkg --compare-versions $old_ssowat_ext_ver lt $ssowat_ext_ver && echo true) || -z $old_ssowat_ext_ver ]]; then
- # Install and activate the SSOwat auth extension
- install_and_activate_extension $app $final_path $db_name "tituspijean/flarum-ext-auth-ssowat:$ssowat_ext_ver" "tituspijean-auth-ssowat"
- # Configure SSOwat auth extension
- ssowatdomain=$( /dev/null)
+ then
+ recipients="$recipients $mail"
+ fi
+ fi
+ done
+ echo "$recipients"
+ }
+ recipients=$(find_mails "$recipients")
+
+ # Subject base
+ local mail_subject="☁️🆈🅽🅷☁️: \`$app\`"
+
+ # Adapt the subject according to the type of mail required.
+ if [ "$type" = "backup" ]; then
+ mail_subject="$mail_subject has just been backup."
+ elif [ "$type" = "change_url" ]; then
+ mail_subject="$mail_subject has just been moved to a new URL!"
+ elif [ "$type" = "remove" ]; then
+ mail_subject="$mail_subject has just been removed!"
+ elif [ "$type" = "restore" ]; then
+ mail_subject="$mail_subject has just been restored!"
+ elif [ "$type" = "upgrade" ]; then
+ mail_subject="$mail_subject has just been upgraded!"
+ else # install
+ mail_subject="$mail_subject has just been installed!"
+ fi
+
+ local mail_message="This is an automated message from your beloved YunoHost server.
+
+Specific information for the application $app.
+
+$(if [ -n "$app_message" ]
+then
+ cat "$app_message"
+else
+ echo "...No specific information..."
+fi)
+
+---
+Automatic diagnosis data from YunoHost
+
+__PRE_TAG1__$(yunohost tools diagnosis | grep -B 100 "services:" | sed '/services:/d')__PRE_TAG2__"
+
+ # Store the message into a file for further modifications.
+ echo "$mail_message" > mail_to_send
+
+ # If a html email is required. Apply html tags to the message.
+ if [ "$admin_mail_html" -eq 1 ]
+ then
+ # Insert 'br' tags at each ending of lines.
+ ynh_replace_string "$" "
" mail_to_send
+
+ # Insert starting HTML tags
+ sed --in-place '1s@^@\n\n
" mail_to_send + ynh_replace_string "__PRE_TAG2__" "<\pre>" mail_to_send + + # Insert finishing HTML tags + echo -e "\n\n" >> mail_to_send + + # Otherwise, remove tags to keep a plain text. + else + # Remove URL tags + ynh_replace_string "__URL_TAG[1,3]__" "" mail_to_send + ynh_replace_string "__URL_TAG2__" ": " mail_to_send + + # Remove PRE tags + ynh_replace_string "__PRE_TAG[1-2]__" "" mail_to_send + fi + + # Define binary to use for mail command + if [ -e /usr/bin/bsd-mailx ] + then + local mail_bin=/usr/bin/bsd-mailx + else + local mail_bin=/usr/bin/mail.mailutils + fi + + if [ "$admin_mail_html" -eq 1 ] + then + content_type="text/html" + else + content_type="text/plain" + fi + + # Send the email to the recipients + cat mail_to_send | $mail_bin -a "Content-Type: $content_type; charset=UTF-8" -s "$mail_subject" "$recipients" +}