From eef0303278cb6e525642d46c83b065253b76998e Mon Sep 17 00:00:00 2001 From: anmol26s <5068843+anmol26s@users.noreply.github.com> Date: Wed, 29 Apr 2020 23:28:50 +0530 Subject: [PATCH] Updated to version 2.17.0 --- README.md | 4 +- check_process | 15 +- conf/.env | 21 +- conf/app.src | 6 +- conf/php-fpm.conf | 328 ++++++++++++++++++++++++-------- manifest.json | 4 +- scripts/_common.sh | 79 ++++---- scripts/backup | 39 ++-- scripts/helpers/ynh_composer__2 | 15 +- scripts/install | 172 +++++++++++------ scripts/remove | 26 ++- scripts/restore | 63 +++--- scripts/upgrade | 126 +++++++----- 13 files changed, 595 insertions(+), 303 deletions(-) diff --git a/README.md b/README.md index a8e46cb..b2d9692 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,10 @@ # Monica app for YunoHost -[![Integration level](https://dash.yunohost.org/integration/monica.svg)](https://ci-apps.yunohost.org/jenkins/job/monica%20%28Community%29/lastBuild/consoleFull) +[![Integration level](https://dash.yunohost.org/integration/monica.svg)](https://dash.yunohost.org/appci/app/monica) [![Installer Monica with YunoHost](https://install-app.yunohost.org/install-with-yunohost.png)](https://install-app.yunohost.org/?app=monica) -Shipped version: **2.14.0** +Shipped version: **2.17.0.**

Personal Relationship Manager

diff --git a/check_process b/check_process index 6b1b6f2..16ebc64 100644 --- a/check_process +++ b/check_process @@ -20,22 +20,13 @@ upgrade=1 backup_restore=1 multi_instance=1 - incorrect_path=0 + # This test is no longer necessary since the version 2.7 (PR: https://github.com/YunoHost/yunohost/pull/304), you can still do it if your app could be installed with this version. + # incorrect_path=1 port_already_use=0 change_url=0 ;;; Levels - Level 1=auto - Level 2=auto - Level 3=auto -# Level 4: - Level 4=0 -# Level 5: + # If the level 5 (Package linter) is forced to 1. Please add justifications here. Level 5=auto - Level 6=auto - Level 7=auto - Level 8=0 - Level 9=0 - Level 10=0 ;;; Options Email=anmol@datamol.org Notification=change diff --git a/conf/.env b/conf/.env index 660bb8d..b7bde89 100644 --- a/conf/.env +++ b/conf/.env @@ -69,7 +69,8 @@ APP_SIGNUP_DOUBLE_OPTIN=false # Set trusted proxy IP addresses. # To trust all proxies that connect directly to your server, use a "*". -# To trust one or more specific proxies that connect directly to your server, use a comma separated list of IP addresses. +# To trust one or more specific proxies that connect directly to your server, +# use a comma separated list of IP addresses. APP_TRUSTED_PROXIES= # Enable automatic cloudflare trusted proxy discover @@ -90,11 +91,20 @@ SENTRY_LARAVEL_DSN= # Default to true. CHECK_VERSION=true -# Change this only if you know what you are doing +# Cache, session, and queue parameters +# ⚠ Change this only if you know what you are doing +#. Cache: database, file, memcached, redis, dynamodb +#. Session: file, cookie, database, apc, memcached, redis, array +#. Queue: sync, database, beanstalkd, sqs, redis +# If Queue is not set to 'sync', you'll have to set a queue worker +# See https://laravel.com/docs/5.7/queues#running-the-queue-worker CACHE_DRIVER=database SESSION_DRIVER=file SESSION_LIFETIME=120 -QUEUE_DRIVER=sync +QUEUE_CONNECTION=sync + +# If you use redis, set the redis host or ip, like: +#REDIS_HOST=redis # Maximum allowed size for uploaded files, in kilobytes. # Make sure this is an integer, without commas or spaces. @@ -118,12 +128,13 @@ AWS_SERVER= # Allow Two Factor Authentication feature on your instance MFA_ENABLED=false -# Enable CardDAV support (beta feature) -CARDDAV_ENABLED=false +# Enable DAV support +DAV_ENABLED=true # CLIENT ID and SECRET used for the official mobile application # This is to make sure that only the mobile application that you approve can # access the route to let your users sign in with their credentials +# Note: the official mobile application is not currently available on the stores. MOBILE_CLIENT_ID=__IDENTITY__ MOBILE_CLIENT_SECRET=__KEY__ diff --git a/conf/app.src b/conf/app.src index 28bd4cf..0750fdb 100644 --- a/conf/app.src +++ b/conf/app.src @@ -1,6 +1,6 @@ -SOURCE_URL=https://github.com/monicahq/monica/archive/v2.14.0.zip -SOURCE_SUM=796ff50a2b7778c58835da1aa07fd8b5626faee50471cfd9b475325821aea725 +SOURCE_URL=https://github.com/monicahq/monica/archive/v2.17.0.zip +SOURCE_SUM=834c91b901f84e4a14a7e4697c0b6226b9b0768ff0b0ed761029c4e9d765262c SOURCE_SUM_PRG=sha256sum SOURCE_FORMAT=zip SOURCE_IN_SUBDIR=true -SOURCE_FILENAME=v2.14.0.zip +SOURCE_FILENAME=v2.17.0.zip diff --git a/conf/php-fpm.conf b/conf/php-fpm.conf index fa27d3d..49f1a37 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' @@ -16,21 +17,43 @@ ; Default Value: none ;prefix = /path/to/pools/$pool +; Unix user/group of processes +; Note: The user is mandatory. If the group is not set, the default user's group +; will be used. +user = __USER__ +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/php/php7.2-fpm-__NAMETOCHANGE__.sock -; Set listen(2) backlog. A value of '-1' means unlimited. -; Default Value: 128 (-1 on FreeBSD and OpenBSD) -;listen.backlog = -1 +; Set listen(2) backlog. +; Default Value: 511 (-1 on FreeBSD and OpenBSD) +;listen.backlog = 511 -; List of ipv4 addresses of FastCGI clients which are allowed to connect. +; 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. +; 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 +; 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 @@ -38,26 +61,26 @@ listen = /var/run/php/php7.2-fpm-__NAMETOCHANGE__.sock ; Default Value: any ;listen.allowed_clients = 127.0.0.1 -; 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. -; Default Values: user and group are set as the running user -; mode is set to 0666 -listen.owner = www-data -listen.group = www-data -listen.mode = 0600 +; Specify the nice(2) priority to apply to the pool processes (only if set) +; The value can vary from -19 (highest priority) to 20 (lower priority) +; Note: - It will only work if the FPM master process is launched as root +; - The pool processes will inherit the master process priority +; unless it specified otherwise +; Default Value: no set +; process.priority = -19 -; Unix user/group of processes -; Note: The user is mandatory. If the group is not set, the default user's group -; will be used. -user = __USER__ -group = __USER__ +; 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: ; static - a fixed number (pm.max_children) of child processes; ; dynamic - the number of child processes are set dynamically based on the -; following directives: +; following directives. With this process management, there will be +; always at least 1 children. ; pm.max_children - the maximum number of children that can ; be alive at the same time. ; pm.start_servers - the number of children created on startup. @@ -69,73 +92,150 @@ group = __USER__ ; state (waiting to process). If the number ; of 'idle' processes is greater than this ; number then some children will be killed. +; ondemand - no children are created at startup. Children will be forked when +; new requests will connect. The following parameter are used: +; pm.max_children - the maximum number of children that +; can be alive at the same time. +; pm.process_idle_timeout - The number of seconds after which +; an idle process will be killed. ; Note: This value is mandatory. pm = dynamic ; The number of child processes to be created when pm is set to 'static' and the -; maximum number of child processes to be created when pm is set to 'dynamic'. +; maximum number of child processes when pm is set to 'dynamic' or 'ondemand'. ; This value sets the limit on the number of simultaneous requests that will be ; served. Equivalent to the ApacheMaxClients directive with mpm_prefork. ; Equivalent to the PHP_FCGI_CHILDREN environment variable in the original PHP -; CGI. -; Note: Used when pm is set to either 'static' or 'dynamic' +; CGI. The below defaults are based on a server without much resources. Don't +; 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 = 6 +pm.max_children = 5 ; The number of child processes created on startup. ; Note: Used only when pm is set to 'dynamic' ; Default Value: min_spare_servers + (max_spare_servers - min_spare_servers) / 2 -pm.start_servers = 3 +pm.start_servers = 2 ; The desired minimum number of idle server processes. ; Note: Used only when pm is set to 'dynamic' ; Note: Mandatory when pm is set to 'dynamic' -pm.min_spare_servers = 3 +pm.min_spare_servers = 1 ; The desired maximum number of idle server processes. ; Note: Used only when pm is set to 'dynamic' ; Note: Mandatory when pm is set to 'dynamic' -pm.max_spare_servers = 5 +pm.max_spare_servers = 3 + +; The number of seconds after which an idle process will be killed. +; 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. By default, the status page shows the following -; information: -; accepted conn - the number of request accepted by the pool; +; recognized as a status page. It shows the following informations: ; pool - the name of the pool; -; process manager - static or dynamic; +; process manager - static, dynamic or ondemand; +; start time - the date and time FPM has started; +; start since - number of seconds since FPM has started; +; accepted conn - the number of request accepted by the pool; +; listen queue - the number of request in the queue of pending +; connections (see backlog in listen(2)); +; max listen queue - the maximum number of requests in the queue +; of pending connections since FPM has started; +; listen queue len - the size of the socket queue of pending connections; ; idle processes - the number of idle processes; ; active processes - the number of active processes; -; total processes - the number of idle + active processes. +; total processes - the number of idle + active processes; +; max active processes - the maximum number of active processes since FPM +; has started; ; max children reached - number of times, the process limit has been reached, ; when pm tries to start more children (works only for -; pm 'dynamic') -; The values of 'idle processes', 'active processes' and 'total processes' are -; updated each second. The value of 'accepted conn' is updated in real time. +; pm 'dynamic' and 'ondemand'); +; Value are updated in real time. ; Example output: -; accepted conn: 12073 ; pool: www ; process manager: static -; idle processes: 35 -; active processes: 65 -; total processes: 100 -; max children reached: 1 +; start time: 01/Jul/2011:17:53:49 +0200 +; start since: 62636 +; accepted conn: 190460 +; listen queue: 0 +; max listen queue: 1 +; listen queue len: 42 +; idle processes: 4 +; active processes: 11 +; total processes: 15 +; max active processes: 12 +; max children reached: 0 +; ; By default the status page output is formatted as text/plain. Passing either -; 'html' or 'json' as a query string will return the corresponding output -; syntax. Example: +; 'html', 'xml' or 'json' in the query string will return the corresponding +; output syntax. Example: ; http://www.foo.bar/status ; http://www.foo.bar/status?json ; http://www.foo.bar/status?html +; http://www.foo.bar/status?xml +; +; By default the status page only outputs short status. Passing 'full' in the +; query string will also return status for each pool process. +; Example: +; http://www.foo.bar/status?full +; http://www.foo.bar/status?json&full +; http://www.foo.bar/status?html&full +; http://www.foo.bar/status?xml&full +; The Full status returns for each process: +; pid - the PID of the process; +; state - the state of the process (Idle, Running, ...); +; start time - the date and time the process has started; +; start since - the number of seconds since the process has started; +; requests - the number of requests the process has served; +; request duration - the duration in µs of the requests; +; request method - the request method (GET, POST, ...); +; request URI - the request URI with the query string; +; content length - the content length of the request (only with POST); +; user - the user (PHP_AUTH_USER) (or '-' if not set); +; script - the main script called (or '-' if not set); +; last request cpu - the %cpu the last request consumed +; it's always 0 if the process is not in Idle state +; because CPU calculation is done when the request +; processing has terminated; +; last request memory - the max amount of memory the last request consumed +; it's always 0 if the process is not in Idle state +; because memory calculation is done when the request +; processing has terminated; +; If the process is in Idle state, then informations are related to the +; last request the process has served. Otherwise informations are related to +; the current request being served. +; Example output: +; ************************ +; pid: 31330 +; state: Running +; start time: 01/Jul/2011:17:53:49 +0200 +; start since: 63087 +; requests: 12808 +; request duration: 1250261 +; request method: GET +; request URI: /test_mem.php?N=10000 +; content length: 0 +; user: - +; script: /home/fat/web/docs/php/test_mem.php +; last request cpu: 0.00 +; last request memory: 0 +; +; Note: There is a real-time FPM status monitoring sample web page available +; 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 ; may conflict with a real PHP file. ; Default Value: not set -pm.status_path = /fpm-status +;pm.status_path = /status ; The ping URI to call the monitoring page of FPM. If this value is not set, no ; URI will be recognized as a ping page. This could be used to test from outside @@ -147,39 +247,102 @@ pm.status_path = /fpm-status ; anything, but it may not be a good idea to use the .php extension or it ; may conflict with a real PHP file. ; Default Value: not set -ping.path = /ping +;ping.path = /ping ; This directive may be used to customize the response of a ping request. The ; response is formatted as text/plain with a 200 response code. ; Default Value: pong ;ping.response = pong -; 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 = 120s +; The access log file +; Default: not set +;access.log = log/$pool.access.log + +; The access log format. +; The following syntax is allowed +; %%: the '%' character +; %C: %CPU used by the request +; it can accept the following format: +; - %{user}C for user CPU only +; - %{system}C for system CPU only +; - %{total}C for user + system CPU (default) +; %d: time taken to serve the request +; it can accept the following format: +; - %{seconds}d (default) +; - %{miliseconds}d +; - %{mili}d +; - %{microseconds}d +; - %{micro}d +; %e: an environment variable (same as $_ENV or $_SERVER) +; it must be associated with embraces to specify the name of the env +; variable. Some exemples: +; - server specifics like: %{REQUEST_METHOD}e or %{SERVER_PROTOCOL}e +; - HTTP headers like: %{HTTP_HOST}e or %{HTTP_USER_AGENT}e +; %f: script filename +; %l: content-length of the request (for POST request only) +; %m: request method +; %M: peak of memory allocated by PHP +; it can accept the following format: +; - %{bytes}M (default) +; - %{kilobytes}M +; - %{kilo}M +; - %{megabytes}M +; - %{mega}M +; %n: pool name +; %o: output header +; it must be associated with embraces to specify the name of the header: +; - %{Content-Type}o +; - %{X-Powered-By}o +; - %{Transfert-Encoding}o +; - .... +; %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 '?' character if query string exists +; %r: the request URI (without the query string, see %q and %Q) +; %R: remote IP address +; %s: status (response code) +; %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 = 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 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 +; 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 = 4096 +;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 +;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. @@ -202,7 +365,24 @@ 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 +; execute php code. +; Note: set an empty value to allow all extensions. +; Default Value: .php +;security.limit_extensions = .php .php3 .php4 .php5 .php7 ; Pass environment variables like LD_LIBRARY_PATH. All $VARIABLEs are taken from ; the current environment. @@ -239,24 +419,12 @@ catch_workers_output = yes ;php_admin_value[memory_limit] = 32M ; Common values to change to increase file upload limit -;php_value[upload_max_filesize] = 50M -;php_value[post_max_size] = 50M -;php_value[mail.add_x_header] = Off +; 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_value[max_execution_time] = 600 -;php_value[max_input_time] = 300 -;php_value[memory_limit] = 256M -;php_value[short_open_tag] = On - -; 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 - +; 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 diff --git a/manifest.json b/manifest.json index 1f71625..b966a66 100644 --- a/manifest.json +++ b/manifest.json @@ -7,14 +7,14 @@ }, "url": "https://monicahq.com", "license": "GPL-3.0", - "version": "2.14.0", + "version": "2.17.0~ynh1", "maintainer": { "name": "Sebastian Gumprich", "email": "yunohost@gumpri.ch", "url": "http://github.com/rndmh3ro/monica_ynh" }, "requirements": { - "yunohost": ">> 2.4.2" + "yunohost": ">= 3.5" }, "multi_instance": true, "services": [ diff --git a/scripts/_common.sh b/scripts/_common.sh index 6be0344..82c4ddc 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -1,39 +1,52 @@ #!/bin/bash -source helpers/ynh_add_extra_apt_repos__3 -source helpers/ynh_install_php__3 -source helpers/ynh_composer__2 -# ============================================================================= -# YUNOHOST 2.7 FORTHCOMING HELPERS -# ============================================================================= - -# Create a dedicated php-fpm config -# -# usage: ynh_add_fpm_config -ynh_add_fpm7.2_config () { - ynh_add_fpm_config --phpversion="7.2" -} - -# -# Composer helpers -# - -# Install and initialize Composer in the given directory -# usage: init_composer -init_composer() { - ynh_install_composer --phpversion="7.2" --workdir="$final_path" - - # update dependencies to create composer.lock - ynh_composer_exec --phpversion="7.2" --workdir="$final_path" --commands="install --no-dev --prefer-dist" \ - || ynh_die "Unable to update monica core dependencies" -} - -# -# PHP7 helpers -# pkg_dependencies="php7.2-cli php7.2-json php7.2-opcache php7.2-mysql php7.2-mbstring php7.2-zip php7.2-bcmath php7.2-intl php7.2-xml php7.2-curl php7.2-gd php7.2-gmp" -ynh_install_php7.2 () { - ynh_install_php --phpversion="7.2" --package="$pkg_dependencies" + +# Execute a command with Composer +# +# usage: ynh_composer_exec --phpversion=phpversion [--workdir=$final_path] --commands="commands" +# | arg: -w, --workdir - The directory from where the command will be executed. Default $final_path. +# | arg: -c, --commands - Commands to execute. +ynh_composer_exec () { + # Declare an array to define the options of this helper. + local legacy_args=vwc + declare -Ar args_array=( [v]=phpversion= [w]=workdir= [c]=commands= ) + local phpversion + local workdir + local commands + # Manage arguments with getopts + ynh_handle_getopts_args "$@" + workdir="${workdir:-$final_path}" + phpversion="${phpversion:-7.0}" + + COMPOSER_HOME="$workdir/.composer" \ + php${phpversion} "$workdir/composer.phar" $commands \ + -d "$workdir" --quiet --no-interaction +} + +# Install and initialize Composer in the given directory +# +# usage: ynh_install_composer --phpversion=phpversion [--workdir=$final_path] +# | arg: -w, --workdir - The directory from where the command will be executed. Default $final_path. +ynh_install_composer () { + # Declare an array to define the options of this helper. + local legacy_args=vw + declare -Ar args_array=( [v]=phpversion= [w]=workdir= ) + local phpversion + local workdir + # Manage arguments with getopts + ynh_handle_getopts_args "$@" + workdir="${workdir:-$final_path}" + phpversion="${phpversion:-7.0}" + + curl -sS https://getcomposer.org/installer \ + | COMPOSER_HOME="$workdir/.composer" \ + php${phpversion} -- --quiet --install-dir="$workdir" \ + || ynh_die "Unable to install Composer." + + # update dependencies to create composer.lock + ynh_composer_exec --phpversion="${phpversion}" --workdir="$workdir" --commands="install --no-dev" \ + || ynh_die "Unable to update core dependencies with Composer." } diff --git a/scripts/backup b/scripts/backup index 67cf487..4331717 100755 --- a/scripts/backup +++ b/scripts/backup @@ -6,60 +6,69 @@ # 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..." 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..." -ynh_backup "$final_path" +ynh_backup --src_path="$final_path" #================================================= # BACKUP THE NGINX CONFIGURATION #================================================= +ynh_script_progression --message="Backing up nginx web server configuration..." -ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf" +ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf" #================================================= # BACKUP THE MYSQL DATABASE #================================================= +ynh_script_progression --message="Backing up the MySQL database..." -ynh_mysql_dump_db "$db_name" > db.sql +ynh_mysql_dump_db --database="$db_name" > db.sql #================================================= # BACKUP THE PHP-FPM CONFIGURATION #================================================= -ynh_backup "/etc/php/7.2/fpm/pool.d/$app.conf" +ynh_backup --src_path="/etc/php/7.2/fpm/pool.d/$app.conf" #================================================= # BACKUP THE CRON FILE #================================================= -ynh_backup "/etc/cron.d/$app" +ynh_backup --src_path="/etc/cron.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/helpers/ynh_composer__2 b/scripts/helpers/ynh_composer__2 index 1b6aa80..5c8775b 100644 --- a/scripts/helpers/ynh_composer__2 +++ b/scripts/helpers/ynh_composer__2 @@ -2,7 +2,8 @@ # Execute a command with Composer # -# usage: ynh_composer_exec --phpversion=phpversion [--workdir=$final_path] --commands="commands" +# usage: ynh_composer_exec [--phpversion=phpversion] [--workdir=$final_path] --commands="commands" +# | arg: -v, --phpversion - PHP version to use with composer # | arg: -w, --workdir - The directory from where the command will be executed. Default $final_path. # | arg: -c, --commands - Commands to execute. ynh_composer_exec () { @@ -24,18 +25,22 @@ ynh_composer_exec () { # Install and initialize Composer in the given directory # -# usage: ynh_install_composer --phpversion=phpversion [--workdir=$final_path] +# usage: ynh_install_composer [--phpversion=phpversion] [--workdir=$final_path] [--install_args="--optimize-autoloader"] +# | arg: -v, --phpversion - PHP version to use with composer # | arg: -w, --workdir - The directory from where the command will be executed. Default $final_path. +# | arg: -a, --install_args - Additional arguments provided to the composer install. Argument --no-dev already include ynh_install_composer () { # Declare an array to define the options of this helper. - local legacy_args=vw - declare -Ar args_array=( [v]=phpversion= [w]=workdir= ) + local legacy_args=vwa + declare -Ar args_array=( [v]=phpversion= [w]=workdir= [a]=install_args=) local phpversion local workdir + local install_args # Manage arguments with getopts ynh_handle_getopts_args "$@" workdir="${workdir:-$final_path}" phpversion="${phpversion:-7.0}" + install_args="${install_args:-}" curl -sS https://getcomposer.org/installer \ | COMPOSER_HOME="$workdir/.composer" \ @@ -43,6 +48,6 @@ ynh_install_composer () { || ynh_die "Unable to install Composer." # update dependencies to create composer.lock - ynh_composer_exec --phpversion="${phpversion}" --workdir="$workdir" --commands="install --no-dev" \ + ynh_composer_exec --phpversion="${phpversion}" --workdir="$workdir" --commands="install --no-dev $install_args" \ || ynh_die "Unable to update core dependencies with Composer." } diff --git a/scripts/install b/scripts/install index cd1cc9b..99331b7 100755 --- a/scripts/install +++ b/scripts/install @@ -27,73 +27,99 @@ is_public=$YNH_APP_ARG_IS_PUBLIC language=$YNH_APP_ARG_LANGUAGE random_key=$(ynh_string_random 32) -# This is a multi-instance app, meaning it can be installed several times independently -# The id of the app as stated in the manifest is available as $YNH_APP_ID -# The instance number is available as $YNH_APP_INSTANCE_NUMBER (equals "1", "2", ...) -# The app instance name is available as $YNH_APP_INSTANCE_NAME -# - the first time the app is installed, YNH_APP_INSTANCE_NAME = ynhexample -# - the second time the app is installed, YNH_APP_INSTANCE_NAME = ynhexample__2 -# - ynhexample__{N} for the subsequent installations, with N=3,4, ... -# The app instance name is probably what you are interested the most, since this is -# guaranteed to be unique. This is a good unique identifier to define installation path, -# db names, ... +### If it's a multi-instance app, meaning it can be installed several times independently +### The id of the app as stated in the manifest is available as $YNH_APP_ID +### The instance number is available as $YNH_APP_INSTANCE_NUMBER (equals "1", "2", ...) +### The app instance name is available as $YNH_APP_INSTANCE_NAME +### - the first time the app is installed, YNH_APP_INSTANCE_NAME = ynhexample +### - the second time the app is installed, YNH_APP_INSTANCE_NAME = ynhexample__2 +### - ynhexample__{N} for the subsequent installations, with N=3,4, ... +### The app instance name is probably what interests you most, since this is +### guaranteed to be unique. This is a good unique identifier to define installation path, +### db names, ... app=$YNH_APP_INSTANCE_NAME #================================================= # CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS #================================================= -# 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 - +### If the app uses nginx as web server (written in HTML/PHP in most cases), the final path should be "/var/www/$app". +### If the app provides an internal web server (or uses another application server such as uwsgi), the final path should be "/opt/yunohost/$app" final_path=/var/www/$app -test ! -e "$final_path" || ynh_die "This path already contains a folder" +test ! -e "$final_path" || ynh_die --message="This path already contains a folder" + +# Register (book) web path +ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url #================================================= # STORE SETTINGS FROM MANIFEST #================================================= -ynh_app_setting_set $app domain $domain -ynh_app_setting_set $app path $path_url -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 random_key $random_key +ynh_app_setting_set --app=$app --key=domain --value=$domain +ynh_app_setting_set --app=$app --key=path --value=$path_url +ynh_app_setting_set --app=$app --key=admin --value=$admin +ynh_app_setting_set --app=$app --key=is_public --value=$is_public +ynh_app_setting_set --app=$app --key=language --value=$language +ynh_app_setting_set --app=$app --key=random_key --value=$random_key #================================================= # STANDARD MODIFICATIONS #================================================= # INSTALL DEPENDENCIES #================================================= +ynh_script_progression --message="Installing dependencies..." -ynh_install_php7.2 + +### `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_php --phpversion="7.2" --package="$extra_pkg_dependencies" #================================================= # CREATE A MYSQL DATABASE #================================================= +ynh_script_progression --message="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 +### Use these lines if you need a database for the application. +### `ynh_mysql_setup_db` will create a database, an associated user and a ramdom password. +### The password will be stored as 'mysqlpwd' into the app settings, +### and will be available as $db_pwd +### If you're not using these lines: +### - Remove the section "BACKUP THE MYSQL DATABASE" in the backup script +### - Remove also the section "REMOVE THE MYSQL DATABASE" in the remove script +### - As well as the section "RESTORE THE MYSQL DATABASE" in the restore script + +db_name=$(ynh_sanitize_dbid --db_name=$app) +db_user=$db_name +ynh_app_setting_set --app=$app --key=db_name --value=$db_name +ynh_mysql_setup_db --db_user=$db_user --db_name=$db_name #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= +ynh_script_progression --message="Setting up source files..." -ynh_app_setting_set $app final_path $final_path +### `ynh_setup_source` is used to install an app from a zip or tar.gz file, +### downloaded from an upstream source, like a git repository. +### `ynh_setup_source` use the file conf/app.src + +ynh_app_setting_set --app=$app --key=final_path --value=$final_path # Download, check integrity, uncompress and patch the source from app.src -ynh_setup_source "$final_path" +ynh_setup_source --dest_dir="$final_path" -init_composer +ynh_install_composer #================================================= # NGINX CONFIGURATION #================================================= +ynh_script_progression --message="Configuring nginx web server..." +### `ynh_add_nginx_config` will use the file conf/nginx.conf # Create a dedicated nginx config ynh_add_nginx_config @@ -101,16 +127,30 @@ ynh_add_nginx_config #================================================= # CREATE DEDICATED USER #================================================= +ynh_script_progression --message="Configuring system user..." # Create a system user -ynh_system_user_create $app +ynh_system_user_create --username=$app #================================================= # PHP-FPM 7.2 CONFIGURATION #================================================= +ynh_script_progression --message="Configuring php-fpm..." + + +### `ynh_add_fpm_config` is used to set up a PHP config. +### You can remove it if your app doesn't use PHP. +### `ynh_add_fpm_config` will use the files conf/php-fpm.conf +### If you're not using these lines: +### - You can remove these files in conf/. +### - Remove the section "BACKUP THE PHP-FPM CONFIGURATION" in the backup script +### - Remove also the section "REMOVE PHP-FPM CONFIGURATION" in the remove script +### - As well as the section "RESTORE THE PHP-FPM CONFIGURATION" in the restore script +### With the reload at the end of the script. +### - And the section "PHP-FPM CONFIGURATION" in the upgrade script # Create a dedicated php-fpm7.2 config -ynh_add_fpm7.2_config +ynh_add_fpm_config --phpversion="7.2" #================================================= # SPECIFIC SETUP @@ -120,17 +160,17 @@ ynh_add_fpm7.2_config email=$(ynh_user_get_info $admin 'mail') # setup application config -sudo cp ../conf/.env $final_path/.env +cp ../conf/.env $final_path/.env db_name=$(ynh_sanitize_dbid $app) -ynh_replace_string "__DOMAIN__" "$domain" "$final_path/.env" -ynh_replace_string "random_key" "$random_key" "$final_path/.env" -ynh_replace_string "yunouser" "$db_name" "$final_path/.env" -ynh_replace_string "yunopass" "$db_pwd" "$final_path/.env" -ynh_replace_string "yunobase" "$db_name" "$final_path/.env" -ynh_replace_string "yunomail" "$email" "$final_path/.env" -ynh_replace_string "yunodomain" "$domain" "$final_path/.env" -ynh_replace_string "language" "$language" "$final_path/.env" +ynh_replace_string --match_string="__DOMAIN__" --replace_string="$domain" --target_file="$final_path/.env" +ynh_replace_string --match_string="random_key" --replace_string="$random_key" --target_file="$final_path/.env" +ynh_replace_string --match_string="yunouser" --replace_string="$db_name" --target_file="$final_path/.env" +ynh_replace_string --match_string="yunopass" --replace_string="$db_pwd" --target_file="$final_path/.env" +ynh_replace_string --match_string="yunobase" --replace_string="$db_name" --target_file="$final_path/.env" +ynh_replace_string --match_string="yunomail" --replace_string="$email" --target_file="$final_path/.env" +ynh_replace_string --match_string="yunodomain" --replace_string="$domain" --target_file="$final_path/.env" +ynh_replace_string --match_string="language" --replace_string="$language" --target_file="$final_path/.env" # setup application config @@ -139,16 +179,16 @@ ynh_replace_string "language" "$language" "$final_path/.env" ( cd $final_path && sudo /usr/bin/php7.2 artisan passport:client --password -n > key.txt ) mobile_id=$( cd $final_path && tail -2 key.txt | head -1 | cut -c 12- ) mobile_key=$( cd $final_path && tail -1 key.txt | cut -c 16- ) -ynh_replace_string "__IDENTITY__" "$mobile_id" "$final_path/.env" -ynh_replace_string "__KEY__" "$mobile_key" "$final_path/.env" -ynh_app_setting_set $app mobile_id $mobile_id -ynh_app_setting_set $app mobile_key $mobile_key +ynh_replace_string --match_string="__IDENTITY__" --replace_string="$mobile_id" --target_file="$final_path/.env" +ynh_replace_string --match_string="__KEY__" --replace_string="$mobile_key" --target_file="$final_path/.env" +ynh_app_setting_set --app=$app --key=mobile_id --value=$mobile_id +ynh_app_setting_set --app=$app --key=mobile_key --value=$mobile_key (cd $final_path && rm -f key.txt) # create a cronjob to run the scheduler echo "* * * * * -u $app /usr/bin/php7.2 $final_path/artisan schedule:run" > /tmp/cron$app -sudo mv /tmp/cron$app /etc/cron.d/$app +mv /tmp/cron$app /etc/cron.d/$app #================================================= # GENERIC FINALIZATION @@ -164,32 +204,40 @@ chown -R $app: $final_path #================================================= # Calculate and store the config file checksum into the app settings -ynh_store_file_checksum "$final_path/.env" +ynh_store_file_checksum --file="$final_path/.env" #================================================= # SETUP SSOWAT #================================================= +ynh_script_progression --message="Configuring SSOwat..." + -if [ $is_public -eq 0 ] -then # Remove the public access - ynh_app_setting_delete $app skipped_uris -fi # Make app public if necessary if [ $is_public -eq 1 ] then # unprotected_uris allows SSO credentials to be passed anyway. - ynh_app_setting_set $app unprotected_uris "/" + ynh_app_setting_set --app=$app --key=unprotected_uris --value="/" fi #================================================= # RELOAD NGINX #================================================= -service php7.2-fpm start -systemctl reload php7.2-fpm -systemctl reload nginx +#service php7.2-fpm start +#systemctl reload php7.2-fpm +#systemctl reload nginx # Set default php to php5 or php7.0 -if [ "$(lsb_release --codename --short)" == "jessie" ]; then - update-alternatives --set php /usr/bin/php5 -else - update-alternatives --set php /usr/bin/php7.0 -fi +#if [ "$(lsb_release --codename --short)" == "jessie" ]; then +# update-alternatives --set php /usr/bin/php5 +#else +# update-alternatives --set php /usr/bin/php7.0 +#fi + +ynh_script_progression --message="Reloading nginx web server..." + +ynh_systemd_action --service_name=nginx --action=reload + +#================================================= +# END OF SCRIPT +#================================================= + +ynh_script_progression --message="Installation of $app completed" --time --last diff --git a/scripts/remove b/scripts/remove index 2584009..36f489b 100755 --- a/scripts/remove +++ b/scripts/remove @@ -12,40 +12,44 @@ source /usr/share/yunohost/helpers #================================================= # LOAD SETTINGS #================================================= +ynh_script_progression --message="Loading installation settings..." app=$YNH_APP_INSTANCE_NAME -domain=$(ynh_app_setting_get $app domain) -db_name=$(ynh_app_setting_get $app db_name) +domain=$(ynh_app_setting_get --app=$app --key=domain) +db_name=$(ynh_app_setting_get --app=$app --key=db_name) db_user=$db_name -final_path=$(ynh_app_setting_get $app final_path) +final_path=$(ynh_app_setting_get --app=$app --key=final_path) #================================================= # STANDARD REMOVE #================================================= # REMOVE DEPENDENCIES #================================================= +ynh_script_progression --message="Removing dependencies..." # Remove metapackage and its dependencies ynh_remove_app_dependencies - #================================================= # REMOVE THE MYSQL DATABASE #================================================= +ynh_script_progression --message="Removing the MySQL database..." # Remove a database if it exists, along with the associated user -ynh_mysql_remove_db $db_user $db_name +ynh_mysql_remove_db --db_user=$db_user --db_name=$db_name #================================================= # REMOVE APP MAIN DIR #================================================= +ynh_script_progression --message="Removing app main directory..." # Remove the app directory securely -ynh_secure_remove "$final_path" +ynh_secure_remove --file="$final_path" #================================================= # REMOVE NGINX CONFIGURATION #================================================= +ynh_script_progression --message="Removing nginx web server configuration..." # Remove the dedicated nginx config ynh_remove_nginx_config @@ -53,6 +57,7 @@ ynh_remove_nginx_config #================================================= # REMOVE PHP-FPM 7.2 CONFIGURATION #================================================= +ynh_script_progression --message="Removing php-fpm configuration..." # Remove the dedicated php-fpm7.2 config ynh_remove_fpm_config @@ -70,13 +75,20 @@ ynh_remove_php #================================================= # Remove a cron file -ynh_secure_remove "/etc/cron.d/$app" +ynh_secure_remove --file="/etc/cron.d/$app" #================================================= # GENERIC FINALIZATION #================================================= # REMOVE DEDICATED USER #================================================= +ynh_script_progression --message="Removing the dedicated system user..." # Delete a system user ynh_system_user_delete $app + +#================================================= +# END OF SCRIPT +#================================================= + +ynh_script_progression --message="Removal of $app completed" diff --git a/scripts/restore b/scripts/restore index 21b5020..ce3d628 100755 --- a/scripts/restore +++ b/scripts/restore @@ -6,40 +6,43 @@ # 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 settings..." app=$YNH_APP_INSTANCE_NAME -domain=$(ynh_app_setting_get $app domain) -path_url=$(ynh_app_setting_get $app path) -final_path=$(ynh_app_setting_get $app final_path) -db_name=$(ynh_app_setting_get $app db_name) +domain=$(ynh_app_setting_get --app=$app --key=domain) +path_url=$(ynh_app_setting_get --app=$app --key=path) +final_path=$(ynh_app_setting_get --app=$app --key=final_path) +db_name=$(ynh_app_setting_get --app=$app --key=db_name) +db_user=$db_name #================================================= # CHECK IF THE APP CAN BE RESTORED #================================================= +ynh_script_progression --message="Validating restoration parameters..." -ynh_webpath_available $domain $path_url \ - || ynh_die "Path not available: ${domain}${path_url}" +ynh_webpath_available --domain=$domain --path_url=$path_url \ + || ynh_die --message="Path not available: ${domain}${path_url}" test ! -d $final_path \ - || ynh_die "There is already a directory: $final_path " + || ynh_die --message="There is already a directory: $final_path " #================================================= # STANDARD RESTORATION STEPS @@ -48,7 +51,7 @@ test ! -d $final_path \ #================================================= # Define and install dependencies -ynh_install_php7.2 +ynh_install_php --phpversion="7.2" --package="$pkg_dependencies" #================================================= # RESTORE THE NGINX CONFIGURATION @@ -60,22 +63,24 @@ ynh_restore_file "/etc/nginx/conf.d/$domain.d/$app.conf" # RESTORE THE APP MAIN DIR #================================================= -ynh_restore_file "$final_path" +ynh_restore_file --origin_path="$final_path" #================================================= # RESTORE THE MYSQL DATABASE #================================================= +ynh_script_progression --message="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 +db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd) +ynh_mysql_setup_db --db_user=$db_user --db_name=$db_name --db_pwd=$db_pwd +ynh_mysql_connect_as --user=$db_user --password=$db_pwd --database=$db_name < ./db.sql #================================================= # RECREATE THE DEDICATED USER #================================================= +ynh_script_progression --message="Recreating the dedicated system user..." # Create the dedicated user (if not existing) -ynh_system_user_create $app +ynh_system_user_create --username=$app #================================================= # SPECIFIC RESTORATION @@ -104,19 +109,21 @@ ynh_restore_file "/etc/php/7.2/fpm/pool.d/$app.conf" # RESTORE THE CRON FILE #================================================= -ynh_restore_file "/etc/cron.d/$app" +ynh_restore_file --origin_path="/etc/cron.d/$app" #================================================= # GENERIC FINALIZATION #================================================= # RELOAD NGINX AND PHP-FPM #================================================= +ynh_script_progression --message="Reloading nginx web server and php-fpm..." --time --weight=1 + +ynh_systemd_action --service_name=php7.2-fpm --action=reload +ynh_systemd_action --service_name=nginx --action=reload + +#================================================= +# END OF SCRIPT +#================================================= + +ynh_script_progression --message="Restoration completed for $app" -systemctl reload php7.2-fpm -systemctl reload nginx -# Set default php to php5 or php7.0 -if [ "$(lsb_release --codename --short)" == "jessie" ]; then - update-alternatives --set php /usr/bin/php5 -else - update-alternatives --set php /usr/bin/php7.0 -fi diff --git a/scripts/upgrade b/scripts/upgrade index c9b1123..e8c2d38 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -12,37 +12,51 @@ source /usr/share/yunohost/helpers #================================================= # LOAD SETTINGS #================================================= +ynh_script_progression --message="Loading installation settings..." app=$YNH_APP_INSTANCE_NAME -domain=$(ynh_app_setting_get $app domain) -path_url=$(ynh_app_setting_get $app path) -admin=$(ynh_app_setting_get $app admin) -is_public=$(ynh_app_setting_get $app is_public) -final_path=$(ynh_app_setting_get $app final_path) -db_name=$(ynh_app_setting_get $app db_name) -db_pwd=$(ynh_app_setting_get $app mysqlpwd) -language=$(ynh_app_setting_get $app language) -random_key=$(ynh_app_setting_get $app random_key) +domain=$(ynh_app_setting_get --app=$app --key=domain) +path_url=$(ynh_app_setting_get --app=$app --key=path) +admin=$(ynh_app_setting_get --app=$app --key=admin) +is_public=$(ynh_app_setting_get --app=$app --key=is_public) +final_path=$(ynh_app_setting_get --app=$app --key=final_path) +db_name=$(ynh_app_setting_get --app=$app --key=db_name) +db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd) +language=$(ynh_app_setting_get --app=$app --key=language) +random_key=$(ynh_app_setting_get --app=$app --key=random_key) +version=$(ynh_read_manifest --key="version") + #================================================= # ENSURE DOWNWARD COMPATIBILITY #================================================= +ynh_script_progression --message="Ensuring downward compatibility..." +# Fix is_public as a boolean value if [ "$is_public" = "Yes" ]; then - ynh_app_setting_set $app is_public 1 # Fix is_public as a boolean value + ynh_app_setting_set --app=$app --key=is_public --value=1 is_public=1 elif [ "$is_public" = "No" ]; then - ynh_app_setting_set $app is_public 0 + ynh_app_setting_set --app=$app --key=is_public --value=0 is_public=0 fi -if [ -z $db_name ]; then # If db_name doesn't exist, create it - db_name=$(ynh_sanitize_dbid $app) - ynh_app_setting_set $app db_name $db_name +# If db_name doesn't exist, create it +if [ -z "$db_name" ]; then + db_name=$(ynh_sanitize_dbid --db_name=$app) + ynh_app_setting_set --app=$app --key=db_name --value=$db_name fi + +# If final_path doesn't exist, create it +if [ -z "$final_path" ]; then + final_path=/var/www/$app + ynh_app_setting_set --app=$app --key=final_path --value=$final_path +fi + #================================================= # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP #================================================= +ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." # Backup the current version of the app ynh_backup_before_upgrade @@ -67,16 +81,24 @@ path_url=$(ynh_normalize_url_path $path_url) #================================================= # Download, check integrity, uncompress and patch the source from app.src -ynh_setup_source "$final_path" +ynh_setup_source --dest_dir="$final_path" + +#================================================= +# UPGRADE DEPENDENCIES +#================================================= +ynh_script_progression --message="Upgrading dependencies..." + +ynh_install_php --phpversion="7.2" --package="$pkg_dependencies" #================================================= # INSTALL COMPOSER #================================================= -init_composer +ynh_install_composer #================================================= # NGINX CONFIGURATION #================================================= +ynh_script_progression --message="Upgrading nginx web server configuration..." # Create a dedicated nginx config ynh_add_nginx_config @@ -84,24 +106,27 @@ ynh_add_nginx_config #================================================= # CREATE DEDICATED USER #================================================= +ynh_script_progression --message="Making sure dedicated system user exists..." -# Create a system user -ynh_system_user_create $app +# Create a dedicated user (if not existing) +ynh_system_user_create --username=$app #================================================= # SPECIFIC UPGRADE #================================================= +#================================================= +# PHP-FPM CONFIGURATION +#================================================= +ynh_script_progression --message="Upgrading php-fpm configuration..." -# install new dependencies -ynh_update_php_pkg #================================================= # PHP-FPM 7.2 CONFIGURATION #================================================= # Create a dedicated php-fpm7.2 config -ynh_add_fpm7.2_config +ynh_add_fpm_config --phpversion="7.2" # setup application config # Get admin email @@ -110,35 +135,40 @@ sudo cp ../conf/.env $final_path/.env db_name=$(ynh_sanitize_dbid $app) -ynh_replace_string "random_key" "$random_key" "$final_path/.env" -ynh_replace_string "yunouser" "$db_name" "$final_path/.env" -ynh_replace_string "yunopass" "$db_pwd" "$final_path/.env" -ynh_replace_string "yunobase" "$db_name" "$final_path/.env" -ynh_replace_string "yunomail" "$email" "$final_path/.env" -ynh_replace_string "yunodomain" "$domain" "$final_path/.env" -ynh_replace_string "language" "$language" "$final_path/.env" -ynh_replace_string "__DOMAIN__" "$domain" "$final_path/.env" +ynh_replace_string --match_string="random_key" --replace_string="$random_key" --target_file="$final_path/.env" +ynh_replace_string --match_string="yunouser" --replace_string="$db_name" --target_file="$final_path/.env" +ynh_replace_string --match_string="yunopass" --replace_string="$db_pwd" --target_file="$final_path/.env" +ynh_replace_string --match_string="yunobase" --replace_string="$db_name" --target_file="$final_path/.env" +ynh_replace_string --match_string="yunomail" --replace_string="$email" --target_file="$final_path/.env" +ynh_replace_string --match_string="yunodomain" --replace_string="$domain" --target_file="$final_path/.env" +ynh_replace_string --match_string="language" --replace_string="$language" --target_file="$final_path/.env" +ynh_replace_string --match_string="__DOMAIN__" --replace_string="$domain" --target_file="$final_path/.env" # Run monica update cd $final_path && sudo /usr/bin/php7.2 artisan monica:update --force if [ -f $final_path/storage/oauth-private.key ]; then - mobile_id=$(ynh_app_setting_get $app mobile_id) - mobile_key=$(ynh_app_setting_get $app mobile_key) - ynh_replace_string "__IDENTITY__" "$mobile_id" "$final_path/.env" - ynh_replace_string "__KEY__" "$mobile_key" "$final_path/.env" + mobile_id=$(ynh_app_setting_get --app=$app --key=mobile_id) + mobile_key=$(ynh_app_setting_get --app=$app --key=mobile_key) + ynh_replace_string --match_string="__IDENTITY__" --replace_string="$mobile_id" --target_file="$final_path/.env" + ynh_replace_string --match_string="__KEY__" --replace_string="$mobile_key" --target_file="$final_path/.env" else ( cd $final_path && sudo /usr/bin/php7.2 artisan passport:keys ) ( cd $final_path && sudo /usr/bin/php7.2 artisan passport:client --password -n > key.txt ) mobile_id=$( cd $final_path && tail -2 key.txt | head -1 | cut -c 12- ) mobile_key=$( cd $final_path && tail -1 key.txt | cut -c 16- ) - ynh_replace_string "__IDENTITY__" "$mobile_id" "$final_path/.env" - ynh_replace_string "__KEY__" "$mobile_key" "$final_path/.env" - ynh_app_setting_set $app mobile_id $mobile_id - ynh_app_setting_set $app mobile_key $mobile_key + ynh_replace_string --match_string="__IDENTITY__" --replace_string="$mobile_id" --target_file="$final_path/.env" + ynh_replace_string --match_string="__KEY__" --replace_string="$mobile_key" --target_file="$final_path/.env" + ynh_app_setting_set --app=$app --key=mobile_id --value=$mobile_id + ynh_app_setting_set --app=$app --key=mobile_key --value=$mobile_key (cd $final_path && rm -f key.txt) fi + +if [ "$version" -lt "2.15.0" ]; then + ( cd $final_path && sudo /usr/bin/php7.2 artisan monica:moveavatarstophotosdirectory) +fi + #================================================= # GENERIC FINALIZATION #================================================= @@ -151,26 +181,24 @@ chown -R $app: $final_path #================================================= # SETUP SSOWAT #================================================= +ynh_script_progression --message="Upgrading SSOwat configuration..." -if [ $is_public -eq 0 ] -then # Remove the public access - ynh_app_setting_delete $app skipped_uris -fi # Make app public if necessary if [ $is_public -eq 1 ] then # unprotected_uris allows SSO credentials to be passed anyway - ynh_app_setting_set $app unprotected_uris "/" + ynh_app_setting_set --app=$app --key=unprotected_uris --value="/" fi #================================================= # RELOAD NGINX #================================================= +ynh_script_progression --message="Reloading nginx web server..." -systemctl reload nginx -# Set default php to php5 or php7.0 -if [ "$(lsb_release --codename --short)" == "jessie" ]; then - update-alternatives --set php /usr/bin/php5 -else - update-alternatives --set php /usr/bin/php7.0 -fi +ynh_systemd_action --service_name=nginx --action=reload + +#================================================= +# END OF SCRIPT +#================================================= + +ynh_script_progression --message="Upgrade of $app completed"