diff --git a/README.md b/README.md
index a37e805..a5175fe 100644
--- a/README.md
+++ b/README.md
@@ -1,65 +1,73 @@
-Custom Webapp
--------------
+# Custom Webapp for YunoHost
-Empty application with SFTP access to the Web directory.
+[](https://dash.yunohost.org/appci/app/my_webapp)
+[](https://install-app.yunohost.org/?app=my_webapp)
+
+> *This package allow you to install Custom Webapp quickly and simply on a YunoHost server.
+If you don't have YunoHost, please see [here](https://yunohost.org/#/install) to know how to install and enjoy it.*
## Overview
This application allows you to easily install a custom Web application,
-providing files access with SFTP. It can also create a MySQL database -
+providing files access with [SFTP](https://yunohost.org/#/filezilla). It can also create a MySQL database -
which will be backed up and restored with your application. The connection
details will be stored in the file `db_accesss.txt` located in the root
directory.
-Once installed, go to the chosen URL to know the user, domain and port
-you will have to use for the SFTP access - the password is one you give
-at the installation. Under the Web directory, you will see a `www` folder
-which is the public and served one. You can put all the files of your
-custom Web application inside.
+**Once installed, go to the chosen URL to know the user, domain and port
+you will have to use for the SFTP access.** The password is one you chosen
+during the installation. Under the Web directory, you will see a `www` folder
+which contains the public files served by this app. You can put all the files
+of your custom Web application inside.
-## Upgrade
+**Shipped version:** 1.0
-Due to the SFTP access change, the upgrade can not be done from the last
-`my_webapp` application - provided with YunoHost 2.2. You will have to remove
-it first and install this new one, taking care of migrating your data.
+## Screenshots
-### Save your files and the database
+## Demo
-You will have to save the content of the `/var/www/my_webapp/files`
-directory, either from the Web admin interface provided by the old app or
-connecting to your server using SSH - or SFTP as `admin`.
+## Configuration
-If you've created a MySQL database, you can also migrate it since the new
-version allows to manage it for you. To create a dump, you could either use
-[phpMyAdmin](https://github.com/YunoHost-Apps/phpmyadmin_ynh) or connect to
-your server and execute:
-`mysqldump -u root -p$(cat /etc/yunohost/mysql --no-create-db "$dbname" > ./dump.sql`
-(do not forget to replace `$dbname` by your database name).
+## Documentation
-### Restore your custom Webapp
+ * YunoHost documentation: https://github.com/YunoHost/doc/blob/master/app_my_webapp.md
-When you've taken care of saving your files - and optionally your database,
-you can remove the app and install this new one. You can set the same
-settings as the previous installation.
+## YunoHost specific features
-To restore your files, connect to the Web directory using the SFTP account - as
-described at the installation path - and put everything into the `www` directory.
+#### Multi-users support
-If you have chosen to migrate your database too, open the file `db_access.txt`
-to know the new database, user and password you will have to set in your app
-configuration. You can restore the dump you've created earlier either using
-[phpMyAdmin](https://github.com/YunoHost-Apps/phpmyadmin_ynh) or connect to
-your server and execute:
-`mysql -u "$dbuser" -p"$dbpass" "$dbname" < ./dump.sql`
-(do not forget to replace `$dbuser`, `$dbpass` and `$dbname` with the values
-given in the file).
+#### Supported architectures
-### SFTP port ###
+* x86-64b - [](https://ci-apps.yunohost.org/ci/apps/my_webapp/)
+* ARMv8-A - [](https://ci-apps-arm.yunohost.org/ci/apps/my_webapp/)
+* Jessie x86-64b - [](https://ci-stretch.nohost.me/ci/apps/my_webapp/)
+
+## Limitations
+
+## Additional information
+
+#### SFTP port
You may have change the SSH port as described
[here (section "Modifier le port SSH"](https://yunohost.org/#/security_fr) ;
then you should use this port to update your website with SFTP.
-## Links
+## Links
-**YunoHost**: https://yunohost.org/
+ * Report a bug: https://github.com/YunoHost-Apps/my_webapp_ynh/issues
+ * YunoHost website: https://yunohost.org/
+
+---
+
+Developers info
+----------------
+
+**Only if you want to use a testing branch for coding, instead of merging directly into master.**
+Please do your pull request to the [testing branch](https://github.com/YunoHost-Apps/my_webapp_ynh/tree/testing).
+
+To try the testing branch, please proceed like that.
+```
+sudo yunohost app install https://github.com/YunoHost-Apps/my_webapp_ynh/tree/testing --debug
+or
+sudo yunohost app upgrade my_webapp -u https://github.com/YunoHost-Apps/my_webapp_ynh/tree/testing --debug
+```
diff --git a/check_process b/check_process
index a270ddb..0250537 100644
--- a/check_process
+++ b/check_process
@@ -17,7 +17,7 @@
multi_instance=1
incorrect_path=1
port_already_use=0
- change_url=0
+ change_url=1
;;; Levels
Level 1=auto
Level 2=auto
diff --git a/conf/nginx.conf b/conf/nginx.conf
index 2d343ab..dd53b38 100644
--- a/conf/nginx.conf
+++ b/conf/nginx.conf
@@ -1,6 +1,10 @@
-location __PATH__ {
+#sub_path_only rewrite ^__PATH__$ __PATH__/ permanent;
+location __PATH__/ {
+
+ # Path to source
alias __FINALPATH__/www/;
-
+
+ # Force usage of https
if ($scheme = http) {
rewrite ^ https://$server_name$request_uri? permanent;
}
@@ -28,13 +32,14 @@ location __PATH__ {
# Execute and serve PHP files
location ~ [^/]\.php(/|$) {
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
- fastcgi_pass unix:/var/run/php5-fpm-__NAME__.sock;
+ fastcgi_pass unix:/var/run/php/php7.0-fpm-__NAME__.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param REMOTE_USER $remote_user;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $request_filename;
}
+### End of PHP configuration part
# Include SSOWAT user panel.
include conf.d/yunohost_panel.conf.inc;
diff --git a/conf/php-fpm.conf b/conf/php-fpm.conf
index 0327114..4447349 100644
--- a/conf/php-fpm.conf
+++ b/conf/php-fpm.conf
@@ -1,10 +1,11 @@
; Start a new pool named 'www'.
-; the variable $pool can we used in any directive and will be replaced by the
+; the variable $pool can be used in any directive and will be replaced by the
; pool name ('www' here)
[__NAMETOCHANGE__]
; Per pool prefix
; It only applies on the following directives:
+; - 'access.log'
; - 'slowlog'
; - 'listen' (unixsocket)
; - 'chroot'
@@ -24,28 +25,35 @@ group = __USER__
; The address on which to accept FastCGI requests.
; Valid syntaxes are:
-; 'ip.add.re.ss:port' - to listen on a TCP socket to a specific address on
+; 'ip.add.re.ss:port' - to listen on a TCP socket to a specific IPv4 address on
; a specific port;
-; 'port' - to listen on a TCP socket to all addresses on a
-; specific port;
+; '[ip:6:addr:ess]:port' - to listen on a TCP socket to a specific IPv6 address on
+; a specific port;
+; 'port' - to listen on a TCP socket to all addresses
+; (IPv6 and IPv4-mapped) on a specific port;
; '/path/to/unix/socket' - to listen on a unix socket.
; Note: This value is mandatory.
-listen = /var/run/php5-fpm-__NAMETOCHANGE__.sock
+listen = /var/run/php/php7.0-fpm-__NAMETOCHANGE__.sock
-; Set listen(2) backlog. A value of '-1' means unlimited.
-; Default Value: 128 (-1 on FreeBSD and OpenBSD)
-;listen.backlog = 128
+; Set listen(2) backlog.
+; Default Value: 511 (-1 on FreeBSD and OpenBSD)
+;listen.backlog = 511
; Set permissions for unix socket, if one is used. In Linux, read/write
; permissions must be set in order to allow connections from a web server. Many
-; BSD-derived systems allow connections regardless of permissions.
+; BSD-derived systems allow connections regardless of permissions.
; Default Values: user and group are set as the running user
; mode is set to 0660
listen.owner = www-data
listen.group = www-data
;listen.mode = 0660
-
-; List of ipv4 addresses of FastCGI clients which are allowed to connect.
+; When POSIX Access Control Lists are supported you can set them using
+; these options, value is a comma separated list of user/group names.
+; When set, listen.owner and listen.group are ignored
+;listen.acl_users =
+;listen.acl_groups =
+
+; List of addresses (IPv4/IPv6) of FastCGI clients which are allowed to connect.
; Equivalent to the FCGI_WEB_SERVER_ADDRS environment variable in the original
; PHP FCGI (5.2.2+). Makes sense only with a tcp listening socket. Each address
; must be separated by a comma. If this value is left blank, connections will be
@@ -59,7 +67,13 @@ listen.group = www-data
; - The pool processes will inherit the master process priority
; unless it specified otherwise
; Default Value: no set
-; priority = -19
+; process.priority = -19
+
+; Set the process dumpable flag (PR_SET_DUMPABLE prctl) even if the process user
+; or group is differrent than the master process user. It allows to create process
+; core dump and ptrace the process for the pool user.
+; Default Value: no
+; process.dumpable = yes
; Choose how the process manager will control the number of child processes.
; Possible Values:
@@ -96,7 +110,7 @@ pm = dynamic
; forget to tweak pm.* to fit your needs.
; Note: Used when pm is set to 'static', 'dynamic' or 'ondemand'
; Note: This value is mandatory.
-pm.max_children = 10
+pm.max_children = 5
; The number of child processes created on startup.
; Note: Used only when pm is set to 'dynamic'
@@ -117,12 +131,12 @@ pm.max_spare_servers = 3
; Note: Used only when pm is set to 'ondemand'
; Default Value: 10s
;pm.process_idle_timeout = 10s;
-
+
; The number of requests each child process should execute before respawning.
; This can be useful to work around memory leaks in 3rd party libraries. For
; endless request processing specify '0'. Equivalent to PHP_FCGI_MAX_REQUESTS.
; Default Value: 0
-pm.max_requests = 500
+;pm.max_requests = 500
; The URI to view the FPM status page. If this value is not set, no URI will be
; recognized as a status page. It shows the following informations:
@@ -170,7 +184,7 @@ pm.max_requests = 500
;
; By default the status page only outputs short status. Passing 'full' in the
; query string will also return status for each pool process.
-; Example:
+; Example:
; http://www.foo.bar/status?full
; http://www.foo.bar/status?json&full
; http://www.foo.bar/status?html&full
@@ -215,7 +229,7 @@ pm.max_requests = 500
; last request memory: 0
;
; Note: There is a real-time FPM status monitoring sample web page available
-; It's available in: ${prefix}/share/fpm/status.html
+; It's available in: /usr/share/php/7.0/fpm/status.html
;
; Note: The value must start with a leading slash (/). The value can be
; anything, but it may not be a good idea to use the .php extension or it
@@ -275,7 +289,7 @@ pm.max_requests = 500
; - %{megabytes}M
; - %{mega}M
; %n: pool name
-; %o: ouput header
+; %o: output header
; it must be associated with embraces to specify the name of the header:
; - %{Content-Type}o
; - %{X-Powered-By}o
@@ -283,7 +297,7 @@ pm.max_requests = 500
; - ....
; %p: PID of the child that serviced the request
; %P: PID of the parent of the child that serviced the request
-; %q: the query string
+; %q: the query string
; %Q: the '?' character if query string exists
; %r: the request URI (without the query string, see %q and %Q)
; %R: remote IP address
@@ -291,47 +305,51 @@ pm.max_requests = 500
; %t: server time the request was received
; it can accept a strftime(3) format:
; %d/%b/%Y:%H:%M:%S %z (default)
+; The strftime(3) format must be encapsuled in a %{}t tag
+; e.g. for a ISO8601 formatted timestring, use: %{%Y-%m-%dT%H:%M:%S%z}t
; %T: time the log has been written (the request has finished)
; it can accept a strftime(3) format:
; %d/%b/%Y:%H:%M:%S %z (default)
+; The strftime(3) format must be encapsuled in a %{}t tag
+; e.g. for a ISO8601 formatted timestring, use: %{%Y-%m-%dT%H:%M:%S%z}t
; %u: remote user
;
; Default: "%R - %u %t \"%m %r\" %s"
;access.format = "%R - %u %t \"%m %r%Q%q\" %s %f %{mili}d %{kilo}M %C%%"
-
+
; The log file for slow requests
; Default Value: not set
; Note: slowlog is mandatory if request_slowlog_timeout is set
-slowlog = /var/log/nginx/__NAMETOCHANGE__.slow.log
-
+;slowlog = log/$pool.log.slow
+
; The timeout for serving a single request after which a PHP backtrace will be
; dumped to the 'slowlog' file. A value of '0s' means 'off'.
; Available units: s(econds)(default), m(inutes), h(ours), or d(ays)
; Default Value: 0
-request_slowlog_timeout = 5s
-
+;request_slowlog_timeout = 0
+
; The timeout for serving a single request after which the worker process will
; be killed. This option should be used when the 'max_execution_time' ini option
; does not stop script execution for some reason. A value of '0' means 'off'.
; Available units: s(econds)(default), m(inutes), h(ours), or d(ays)
; Default Value: 0
request_terminate_timeout = 1d
-
+
; Set open file descriptor rlimit.
; Default Value: system defined value
;rlimit_files = 1024
-
+
; Set max core size rlimit.
; Possible Values: 'unlimited' or an integer greater or equal to 0
; Default Value: system defined value
;rlimit_core = 0
-
+
; Chroot to this directory at the start. This value must be defined as an
; absolute path. When this value is not set, chroot is not used.
; Note: you can prefix with '$prefix' to chroot to the pool prefix or one
; of its subdirectories. If the pool prefix is not set, the global prefix
; will be used instead.
-; Note: chrooting is a great security feature and should be used whenever
+; Note: chrooting is a great security feature and should be used whenever
; possible. However, all PHP paths will be relative to the chroot
; (error_log, sessions.save_path, ...).
; Default Value: not set
@@ -347,16 +365,25 @@ chdir = __FINALPATH__
; Note: on highloaded environement, this can cause some delay in the page
; process time (several ms).
; Default Value: no
-catch_workers_output = yes
+;catch_workers_output = yes
+
+; Clear environment in FPM workers
+; Prevents arbitrary environment variables from reaching FPM worker processes
+; by clearing the environment in workers before env vars specified in this
+; pool configuration are added.
+; Setting to "no" will make all environment variables available to PHP code
+; via getenv(), $_ENV and $_SERVER.
+; Default Value: yes
+;clear_env = no
; Limits the extensions of the main script FPM will allow to parse. This can
; prevent configuration mistakes on the web server side. You should only limit
; FPM to .php extensions to prevent malicious users to use other extensions to
-; exectute php code.
+; execute php code.
; Note: set an empty value to allow all extensions.
; Default Value: .php
-;security.limit_extensions = .php .php3 .php4 .php5
-
+;security.limit_extensions = .php .php3 .php4 .php5 .php7
+
; Pass environment variables like LD_LIBRARY_PATH. All $VARIABLEs are taken from
; the current environment.
; Default Value: clean env
@@ -370,7 +397,7 @@ catch_workers_output = yes
; overwrite the values previously defined in the php.ini. The directives are the
; same as the PHP SAPI:
; php_value/php_flag - you can set classic ini defines which can
-; be overwritten from PHP call 'ini_set'.
+; be overwritten from PHP call 'ini_set'.
; php_admin_value/php_admin_flag - these directives won't be overwritten by
; PHP call 'ini_set'
; For php_*flag, valid values are on, off, 1, 0, true, false, yes or no.
@@ -391,6 +418,17 @@ catch_workers_output = yes
;php_admin_flag[log_errors] = on
;php_admin_value[memory_limit] = 32M
+; Common values to change to increase file upload limit
+; php_admin_value[upload_max_filesize] = 50M
+; php_admin_value[post_max_size] = 50M
+; php_admin_flag[mail.add_x_header] = Off
+
+; Other common parameters
+; php_admin_value[max_execution_time] = 600
+; php_admin_value[max_input_time] = 300
+; php_admin_value[memory_limit] = 256M
+; php_admin_flag[short_open_tag] = On
+
; Additional php.ini defines, specific to this pool of workers.
php_value[upload_max_filesize] = 1G
php_value[post_max_size] = 1G
diff --git a/manifest.json b/manifest.json
index 1152e2a..a62df13 100644
--- a/manifest.json
+++ b/manifest.json
@@ -6,20 +6,20 @@
"en": "Custom Web app with SFTP access",
"fr": "Application Web personnalisée avec accès SFTP"
},
- "version": "1.0",
+ "version": "1.0~ynh1",
"url": "https://github.com/YunoHost-Apps/my_webapp_ynh",
- "license": "GPLv3",
+ "license": "GPL-3.0-only",
"maintainer": {
"name": "YunoHost Contributors",
"email": "apps@yunohost.org"
},
"requirements": {
- "yunohost": ">= 2.7.2"
+ "yunohost": ">= 3.2.0"
},
"multi_instance": true,
"services": [
"nginx",
- "php5-fpm"
+ "php7.0-fpm"
],
"arguments": {
"install" : [
diff --git a/pull_request_template.md b/pull_request_template.md
new file mode 100644
index 0000000..07fa2bb
--- /dev/null
+++ b/pull_request_template.md
@@ -0,0 +1,24 @@
+## Problem
+- *Description of why you made this PR*
+
+## Solution
+- *And how you fix that*
+
+## PR Status
+- [ ] Code finished.
+- [ ] Tested with Package_check.
+- [ ] Fix or enhancement tested.
+- [ ] Upgrade from last version tested.
+- [ ] Can be reviewed and tested.
+
+## Validation
+---
+*Minor decision*
+- **Upgrade previous version** :
+- [ ] **Code review** :
+- [ ] **Approval (LGTM)** :
+- [ ] **Approval (LGTM)** :
+- **CI succeeded** :
+[](https://ci-apps-dev.yunohost.org/jenkins/job/my_webapp_ynh%20PR-NUM-/)
+*Please replace '-NUM-' in this link by the PR number.*
+When the PR is marked as ready to merge, you have to wait for 3 days before really merging it.
diff --git a/scripts/_common.sh b/scripts/_common.sh
new file mode 100644
index 0000000..bb04a03
--- /dev/null
+++ b/scripts/_common.sh
@@ -0,0 +1,13 @@
+#!/bin/bash
+
+# ============= FUTURE YUNOHOST HELPER =============
+# Delete a file checksum from the app settings
+#
+# $app should be defined when calling this helper
+#
+# usage: ynh_remove_file_checksum file
+# | arg: file - The file for which the checksum will be deleted
+ynh_delete_file_checksum () {
+ local checksum_setting_name=checksum_${1//[\/ ]/_} # Replace all '/' and ' ' by '_'
+ ynh_app_setting_delete $app $checksum_setting_name
+}
\ No newline at end of file
diff --git a/scripts/backup b/scripts/backup
index 13b9193..021bb79 100644
--- a/scripts/backup
+++ b/scripts/backup
@@ -2,22 +2,23 @@
#=================================================
# GENERIC START
-#=================================================
-# MANAGE SCRIPT FAILURE
-#=================================================
-
-# Exit on command errors and treat access to unset variables as an error
-set -eu
-
#=================================================
# 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
+
#=================================================
# LOAD SETTINGS
#=================================================
+ynh_print_info "Loading installation settings..."
app=$YNH_APP_INSTANCE_NAME
@@ -31,25 +32,35 @@ with_mysql=$(ynh_app_setting_get $app with_mysql)
#=================================================
# BACKUP THE APP MAIN DIR
#=================================================
+ynh_print_info "Backing up the main app directory..."
ynh_backup "$final_path"
#=================================================
# BACKUP THE NGINX CONFIGURATION
#=================================================
+ynh_print_info "Backing up nginx web server configuration..."
ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf"
#=================================================
# BACKUP THE PHP-FPM CONFIGURATION
#=================================================
+ynh_print_info "Backing up php-fpm configuration..."
-ynh_backup "/etc/php5/fpm/pool.d/$app.conf"
+ynh_backup "/etc/php/7.0/fpm/pool.d/$app.conf"
#=================================================
# BACKUP THE MYSQL DATABASE
#=================================================
if [ $with_mysql -eq 1 ]; then
+ ynh_print_info "Backing up the MySQL database..."
ynh_mysql_dump_db "$db_name" > db.sql
fi
+
+#=================================================
+# END OF SCRIPT
+#=================================================
+
+ynh_print_info "Backup script completed for $app. (YunoHost will then actually copy those files to the archive)."
diff --git a/scripts/change_url b/scripts/change_url
new file mode 100644
index 0000000..a4eed15
--- /dev/null
+++ b/scripts/change_url
@@ -0,0 +1,92 @@
+#!/bin/bash
+
+#=================================================
+# GENERIC STARTING
+#=================================================
+# IMPORT GENERIC HELPERS
+#=================================================
+
+source _common.sh
+source /usr/share/yunohost/helpers
+
+#=================================================
+# RETRIEVE ARGUMENTS
+#=================================================
+
+old_domain=$YNH_APP_OLD_DOMAIN
+old_path=$YNH_APP_OLD_PATH
+
+new_domain=$YNH_APP_NEW_DOMAIN
+new_path=$YNH_APP_NEW_PATH
+
+app=$YNH_APP_INSTANCE_NAME
+
+#=================================================
+# LOAD SETTINGS
+#=================================================
+
+# Needed for helper "ynh_add_nginx_config"
+final_path=$(ynh_app_setting_get $app final_path)
+
+#=================================================
+# 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)
+
+#=================================================
+# CHECK WHICH PARTS SHOULD BE CHANGED
+#=================================================
+
+change_domain=0
+if [ "$old_domain" != "$new_domain" ]
+then
+ change_domain=1
+fi
+
+change_path=0
+if [ "$old_path" != "$new_path" ]
+then
+ change_path=1
+fi
+
+#=================================================
+# STANDARD MODIFICATIONS
+#=================================================
+# MODIFY URL IN NGINX CONF
+#=================================================
+
+nginx_conf_path=/etc/nginx/conf.d/$old_domain.d/$app.conf
+
+# Change the path in the nginx config file
+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"
+ # Set global variables for nginx helper
+ domain="$old_domain"
+ path_url="$new_path"
+ # Create a dedicated nginx config
+ ynh_add_nginx_config
+fi
+
+# Change the domain for nginx
+if [ $change_domain -eq 1 ]
+then
+ # Delete file checksum for the old conf file location
+ ynh_delete_file_checksum "$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"
+fi
+
+#=================================================
+# GENERIC FINALISATION
+#=================================================
+# RELOAD NGINX
+#=================================================
+
+systemctl reload nginx
diff --git a/scripts/install b/scripts/install
index 9b32084..5514728 100644
--- a/scripts/install
+++ b/scripts/install
@@ -6,6 +6,7 @@
# IMPORT GENERIC HELPERS
#=================================================
+source _common.sh
source /usr/share/yunohost/helpers
#=================================================
@@ -23,6 +24,7 @@ domain=$YNH_APP_ARG_DOMAIN
path_url=$YNH_APP_ARG_PATH
password=$YNH_APP_ARG_PASSWORD
is_public=$YNH_APP_ARG_IS_PUBLIC
+
with_mysql=$YNH_APP_ARG_WITH_MYSQL
app=$YNH_APP_INSTANCE_NAME
@@ -31,6 +33,7 @@ app_nb=$YNH_APP_INSTANCE_NUMBER
#=================================================
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
#=================================================
+ynh_print_info "Validating installation parameters..."
final_path=/var/www/$app
test ! -e "$final_path" || ynh_die "This path already contains a folder"
@@ -42,14 +45,13 @@ test ! -e "$final_path" || ynh_die "This path already contains a folder"
# 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 SETTINGS FROM MANIFEST
#=================================================
+ynh_print_info "Storing installation settings..."
user=webapp${app_nb}
ynh_app_setting_set $app domain $domain
@@ -67,6 +69,7 @@ ynh_app_setting_set $app final_path $final_path
#=================================================
if [ $with_mysql -eq 1 ]; then
+ ynh_print_info "Creating a MySQL database..."
db_name=$(ynh_sanitize_dbid $app)
ynh_app_setting_set $app db_name $db_name
ynh_mysql_setup_db $db_name $db_name
@@ -75,6 +78,7 @@ fi
#=================================================
# NGINX CONFIGURATION
#=================================================
+ynh_print_info "Configuring nginx web server..."
# Create a dedicated nginx config
ynh_add_nginx_config
@@ -82,6 +86,7 @@ ynh_add_nginx_config
#=================================================
# CREATE DEDICATED USER
#=================================================
+ynh_print_info "Configuring system user..."
# Create a standard user (not a system user for sftp)
ynh_system_user_exists "$user" || \
@@ -89,19 +94,12 @@ ynh_system_user_exists "$user" || \
# Add the password to this user
chpasswd <<< "${user}:${password}"
-#=================================================
-# PHP-FPM CONFIGURATION
-#=================================================
-
-# Create a dedicated php-fpm config
-ynh_replace_string "__USER__" "$user" "../conf/php-fpm.conf"
-ynh_add_fpm_config
-
#=================================================
# SPECIFIC SETUP
#=================================================
# CONFIGURE SSH
#=================================================
+ynh_print_info "Configuring ssh..."
# Harden SSH connection for the user
echo "##-> ${app}
@@ -117,11 +115,11 @@ Match User ${user}
systemctl reload ssh
#=================================================
-# FILL AND COPY SOURCE FILES
+# MODIFY A CONFIG FILE
#=================================================
-ynh_replace_string "{DOMAIN}" "$domain" ../sources/www/index.html
-ynh_replace_string "{USER}" "$user" ../sources/www/index.html
+ynh_replace_string "__DOMAIN__" "$domain" ../sources/www/index.html
+ynh_replace_string "__USER__" "$user" ../sources/www/index.html
if [ $with_mysql -eq 1 ]; then
# Store the database access
@@ -132,13 +130,21 @@ fi
# Copy files to the right place
cp -r ../sources "$final_path"
+#=================================================
+# PHP-FPM CONFIGURATION
+#=================================================
+ynh_print_info "Configuring php-fpm..."
+
+# Create a dedicated php-fpm config
+ynh_replace_string "__USER__" "$user" "../conf/php-fpm.conf"
+ynh_add_fpm_config
+
#=================================================
# GENERIC FINALIZATION
#=================================================
# SECURE FILES AND DIRECTORIES
#=================================================
-# Set permissions to app files
chown -R $user: "$final_path"
# Home directory of the user needs to be owned by root to allow
# SFTP connections
@@ -147,6 +153,7 @@ chown root: "$final_path"
#=================================================
# SETUP SSOWAT
#=================================================
+ynh_print_info "Configuring SSOwat..."
# Make app public if necessary
if [ $is_public -eq 1 ]
@@ -157,5 +164,12 @@ fi
#=================================================
# RELOAD NGINX
#=================================================
+ynh_print_info "Reloading nginx web server..."
systemctl reload nginx
+
+#=================================================
+# END OF SCRIPT
+#=================================================
+
+ynh_print_info "Installation of $app completed"
diff --git a/scripts/remove b/scripts/remove
index 83e2ef3..384d60f 100644
--- a/scripts/remove
+++ b/scripts/remove
@@ -6,18 +6,22 @@
# IMPORT GENERIC HELPERS
#=================================================
+source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# LOAD SETTINGS
#=================================================
+ynh_print_info "Loading installation settings..."
app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get $app domain)
with_mysql=$(ynh_app_setting_get $app with_mysql)
user=$(ynh_app_setting_get $app user)
+
db_name=$(ynh_app_setting_get $app db_name)
+db_user=$db_name
final_path=$(ynh_app_setting_get $app final_path)
#=================================================
@@ -27,13 +31,15 @@ final_path=$(ynh_app_setting_get $app final_path)
#=================================================
if [ $with_mysql -eq 1 ]; then
+ ynh_print_info "Removing the MySQL database"
# Remove a database if it exists, along with the associated user
- ynh_mysql_remove_db $db_name $db_name
+ ynh_mysql_remove_db $db_user $db_name
fi
#=================================================
# REMOVE APP MAIN DIR
#=================================================
+ynh_print_info "Removing app main directory"
# Remove the app directory securely
ynh_secure_remove "$final_path"
@@ -41,6 +47,8 @@ ynh_secure_remove "$final_path"
#=================================================
# REMOVE NGINX CONFIGURATION
#=================================================
+ynh_print_info "Removing nginx web server configuration"
+
# Remove the dedicated nginx config
ynh_remove_nginx_config
@@ -48,6 +56,7 @@ ynh_remove_nginx_config
#=================================================
# REMOVE PHP-FPM CONFIGURATION
#=================================================
+ynh_print_info "Removing php-fpm configuration"
# Remove the dedicated php-fpm config
ynh_remove_fpm_config
@@ -57,6 +66,7 @@ ynh_remove_fpm_config
#=================================================
# REMOVE THE CUSTOM SSH CONFIG
#=================================================
+ynh_print_info "Removing the custom ssh config"
sed -i "/##-> ${app}/,/##<- ${app}/d" /etc/ssh/sshd_config
systemctl reload ssh
@@ -66,6 +76,13 @@ systemctl reload ssh
#=================================================
# REMOVE DEDICATED USER
#=================================================
+ynh_print_info "Removing the dedicated system user"
# Delete an user
ynh_system_user_delete $user
+
+#=================================================
+# END OF SCRIPT
+#=================================================
+
+ynh_print_info "Removal of $app completed"
diff --git a/scripts/restore b/scripts/restore
index 6c5a219..efb77e8 100644
--- a/scripts/restore
+++ b/scripts/restore
@@ -2,22 +2,23 @@
#=================================================
# GENERIC START
-#=================================================
-# MANAGE SCRIPT FAILURE
-#=================================================
-
-# Exit on command errors and treat access to unset variables as an error
-set -eu
-
#=================================================
# 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
+
#=================================================
# LOAD SETTINGS
#=================================================
+ynh_print_info "Loading settings..."
app=$YNH_APP_INSTANCE_NAME
@@ -32,6 +33,7 @@ user=$(ynh_app_setting_get $app user)
#=================================================
# CHECK IF THE APP CAN BE RESTORED
#=================================================
+ynh_print_info "Validating restoration parameters..."
ynh_webpath_available $domain $path_url \
|| ynh_die "Path not available: ${domain}${path_url}"
@@ -49,6 +51,7 @@ ynh_restore_file "/etc/nginx/conf.d/$domain.d/$app.conf"
#=================================================
# RESTORE THE APP MAIN DIR
#=================================================
+ynh_print_info "Restoring the app main directory..."
ynh_restore_file "$final_path"
@@ -57,6 +60,7 @@ ynh_restore_file "$final_path"
#=================================================
if [ $with_mysql -eq 1 ]; then
+ ynh_print_info "Restoring the mysql database..."
db_pwd=$(ynh_app_setting_get $app mysqlpwd)
ynh_mysql_setup_db $db_name $db_name $db_pwd
ynh_mysql_connect_as $db_name $db_pwd $db_name < ./db.sql
@@ -65,6 +69,7 @@ fi
#=================================================
# RECREATE THE DEDICATED USER
#=================================================
+ynh_print_info "Recreating the dedicated system user..."
# Create a standard user (not a system user for sftp)
ynh_system_user_exists "$user" || \
@@ -86,13 +91,14 @@ chown root: "$final_path"
# RESTORE THE PHP-FPM CONFIGURATION
#=================================================
-ynh_restore_file "/etc/php5/fpm/pool.d/$app.conf"
+ynh_restore_file "/etc/php/7.0/fpm/pool.d/$app.conf"
#=================================================
# SPECIFIC RESTORATION
#=================================================
# CONFIGURE SSH
#=================================================
+ynh_print_info "Configuring ssh..."
# Harden SSH connection for the user
echo "##-> ${app}
@@ -112,6 +118,13 @@ systemctl reload ssh
#=================================================
# RELOAD NGINX AND PHP-FPM
#=================================================
+ynh_print_info "Reloading nginx web server and php-fpm..."
-systemctl reload php5-fpm
+systemctl reload php7.0-fpm
systemctl reload nginx
+
+#=================================================
+# END OF SCRIPT
+#=================================================
+
+ynh_print_info "Restoration completed for $app"
diff --git a/scripts/upgrade b/scripts/upgrade
index abacad4..9a16c35 100644
--- a/scripts/upgrade
+++ b/scripts/upgrade
@@ -6,11 +6,13 @@
# IMPORT GENERIC HELPERS
#=================================================
+source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# LOAD SETTINGS
#=================================================
+ynh_print_info "Loading installation settings..."
app=$YNH_APP_INSTANCE_NAME
@@ -23,18 +25,28 @@ with_mysql=$(ynh_app_setting_get $app with_mysql)
password=$(ynh_app_setting_get $app password)
user=$(ynh_app_setting_get $app user)
-#=================================================
-# CHECK IF THE UPGRADE CAN BE AUTOMATED
-#=================================================
-
-([[ -n "$with_mysql" ]] && [[ -n "$password" ]] && [[ -n "$user" ]]) \
- || ynh_die "The app changed and can not be automatically upgraded. \
-You will have to manually upgrade it following these instructions: \
-https://github.com/YunoHost-Apps/my_webapp_ynh#upgrade"
-
#=================================================
# ENSURE DOWNWARD COMPATIBILITY
#=================================================
+ynh_print_info "Ensuring downward compatibility..."
+
+# Fix is_public as a boolean value
+if [ "$is_public" = "Yes" ]; then
+ ynh_app_setting_set $app is_public 1
+ is_public=1
+elif [ "$is_public" = "No" ]; then
+ ynh_app_setting_set $app is_public 0
+ is_public=0
+fi
+
+# Fix is_public as a boolean value
+if [ "$is_public" = "Yes" ]; then
+ ynh_app_setting_set $app is_public 1
+ is_public=1
+elif [ "$is_public" = "No" ]; then
+ ynh_app_setting_set $app is_public 0
+ is_public=0
+fi
# If db_name doesn't exist, create it
if [ -z $db_name ]; then
@@ -51,12 +63,16 @@ fi
#=================================================
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
#=================================================
+ynh_print_info "Backing up the app before upgrading (may take a while)..."
-ynh_backup_before_upgrade # Backup the current version of the app
+# Backup the current version of the app
+ynh_backup_before_upgrade
ynh_clean_setup () {
- ynh_restore_upgradebackup # restore it if the upgrade fails
+ # restore it if the upgrade fails
+ ynh_restore_upgradebackup
}
-ynh_abort_if_errors # Exit if an error occurs during the execution of the script
+# Exit if an error occurs during the execution of the script
+ynh_abort_if_errors
#=================================================
# CHECK THE PATH
@@ -67,33 +83,15 @@ path_url=$(ynh_normalize_url_path $path_url)
#=================================================
# STANDARD UPGRADE STEPS
-#=================================================
-
-# Check if a config file was modified
-is_checksum_different () {
- local file=$1
- local checksum_setting_name=checksum_${file//[\/ ]/_} # Replace all '/' and ' ' by '_'
- local checksum_value=$(ynh_app_setting_get $app $checksum_setting_name)
- if [ -n "$checksum_value" ]
- then # Proceed only if a value was stored into the app settings
- if ! echo "$checksum_value $file" | sudo md5sum -c --status
- then # If the checksum is now different
- echo "File $file has been manually modified since the installation or last upgrade. So it will not be replaced." >&2
- echo "1"
- else
- echo "0"
- fi
- else
- echo "0"
- fi
-}
-
#=================================================
# NGINX CONFIGURATION
#=================================================
-if [ $(is_checksum_different "/etc/nginx/conf.d/$domain.d/$app.conf") -eq 0 ]
+modified_config=$(ynh_backup_if_checksum_is_different "/etc/nginx/conf.d/$domain.d/$app.conf")
+# Replace nginx config only if it wasn't modified.
+if [ -z "$modified_config" ]
then
+ ynh_print_info "Upgrading nginx web server configuration..."
# Create a dedicated nginx config
ynh_add_nginx_config
fi
@@ -101,6 +99,7 @@ fi
#=================================================
# CREATE DEDICATED USER
#=================================================
+ynh_print_info "Making sure dedicated system user exists..."
# Create a standard user (not a system user for sftp)
ynh_system_user_exists "$user" || \
@@ -116,8 +115,11 @@ usermod -g "$user" "$user"
# PHP-FPM CONFIGURATION
#=================================================
-if [ $(is_checksum_different "/etc/php5/fpm/pool.d/$app.conf") -eq 0 ]
+modified_config=$(ynh_backup_if_checksum_is_different "/etc/php5/fpm/pool.d/$app.conf")
+# Replace nginx config only if it wasn't modified.
+if [ -z "$modified_config" ]
then
+ ynh_print_info "Upgrading php-fpm configuration..."
# Create a dedicated php-fpm config
ynh_replace_string "__USER__" "$user" "../conf/php-fpm.conf"
ynh_add_fpm_config
@@ -128,9 +130,10 @@ fi
#=================================================
# CONFIGURE SSH
#=================================================
+ynh_print_info "Configuring ssh..."
# Remove the previous config for upgrading it
-sudo sed -i "/##-> ${app}/,/##<- ${app}/d" /etc/ssh/sshd_config
+sed -i "/##-> ${app}/,/##<- ${app}/d" /etc/ssh/sshd_config
# Harden SSH connection for the user
echo "##-> ${app}
# Hardening user connection
@@ -157,6 +160,7 @@ chown root: "$final_path"
#=================================================
# SETUP SSOWAT
#=================================================
+ynh_print_info "Upgrading SSOwat configuration..."
# Make app public if necessary
if [ $is_public -eq 1 ]
@@ -167,5 +171,12 @@ fi
#=================================================
# RELOAD NGINX
#=================================================
+ynh_print_info "Reloading nginx web server..."
systemctl reload nginx
+
+#=================================================
+# END OF SCRIPT
+#=================================================
+
+ynh_print_info "Upgrade of $app completed"
diff --git a/sources/www/index.html b/sources/www/index.html
index cb0cf2f..051a429 100644
--- a/sources/www/index.html
+++ b/sources/www/index.html
@@ -16,11 +16,11 @@
- Domain
- - {DOMAIN}
+ - __DOMAIN__
- Port
- 22 (or the port you defined if you change the ssh port)
- User
- - {USER}
+ - __USER__
- Password
- the one you set at installation