diff --git a/README.md b/README.md index 9368a24..baf0e11 100644 --- a/README.md +++ b/README.md @@ -1,68 +1,70 @@ -# myTinyTodo for Yunohost / LaBriqueInter.net +# myTinyTodo for YunoHost - * en : A **simple** way to manage your todo list. - * fr : Un simple, mais **efficace** script de gestion de todo list (*GTD*). - * [Original Site](http://www.mytinytodo.net/) - * [Demo](http://www.mytinytodo.net/demo/) - * [Demo for mobile](http://www.mytinytodo.net/demo/?pda) - * Auteur : Max Pozdeev +[![Integration level](https://dash.yunohost.org/integration/mytinytodo.svg)](https://dash.yunohost.org/appci/app/mytinytodo) ![](https://ci-apps.yunohost.org/ci/badges/mytinytodo.status.svg) ![](https://ci-apps.yunohost.org/ci/badges/mytinytodo.maintain.svg) +[![Install myTinyTodo with YunoHost](https://install-app.yunohost.org/install-with-yunohost.svg)](https://install-app.yunohost.org/?app=mytinytodo) -## En image : +*[Lire ce readme en français.](./README_fr.md)* -![capture mytinytodo](http://www.mytinytodo.net/images/shot-v14b1.png) +> *This package allows you to install myTinyTodo quickly and simply on a YunoHost server. +If you don't have YunoHost, please consult [the guide](https://yunohost.org/#/install) to learn how to install it.* -## Francais : +## Overview +Simple way to manage your todo list in AJAX style. Written in PHP and jQuery. Data stored in MySQL database. -Pour le moment, je pars sur une installation simple. +**Shipped version:** 1.6.3 - * pas de multi-instance, - * mysql/mariadb uniquement (pas de sqlite), - * gestion des langues - * fr : French - * en : English - * de : German - * ru : Russian - * ar : Arabic - * zh-cn : Chinese (Simplified) +## Screenshots -## Anglais : +![](http://www.mytinytodo.net/images/shot-v14b1.png) - * Multiple lists - * Task notes - * Tags (and tag cloud) - * Due dates (input format: y-m-d, m/d/y, d.m.y, m/d, d.m) - * Priority (-1, 0, +1, +2) - * Different sortings including sort by drag-and-drop - * Search - * Password protection - * Smart syntax improves creation of tasks - * (usage: /priority/ Task /tags/) - * Print-friendly CSS - * Style for mobiles devices - * Distributed under the GNU GPL License +## Demo -## Mise à jour : +* [Official demo](http://www.mytinytodo.net/demo/) - * Juste pour moi, le projet n'a pas bougé depuis plusieurs années, si il y a des modifications, je ferais une archive maison. - * La mise a jour n'utilisera pas le mécanisme d'origine (setup.php) +## Configuration -```bash -yunohost app upgrade --verbose mytinytodo -u https://github.com/plabuse/mytinytodo_ynh + * How to configure this app: From an admin panel. + +## Documentation + + * Official documentation: https://www.mytinytodo.net/faq.php + * YunoHost documentation: If specific documentation is needed, feel free to contribute. + +## YunoHost specific features + +#### Multi-user support + +* Are LDAP and HTTP auth supported? +* Can the app be used by multiple users? + +#### Supported architectures + +* x86-64 - [![Build Status](https://ci-apps.yunohost.org/ci/logs/mytinytodo%20%28Apps%29.svg)](https://ci-apps.yunohost.org/ci/apps/mytinytodo/) +* ARMv8-A - [![Build Status](https://ci-apps-arm.yunohost.org/ci/logs/mytinytodo%20%28Apps%29.svg)](https://ci-apps-arm.yunohost.org/ci/apps/mytinytodo/) + +## Limitations + +* Any known limitations. + +## Additional information + +* Other info you would like to add about this app. + +## Links + + * Report a bug: https://github.com/YunoHost-Apps/mytinytodo_ynh/issues + * App website: http://www.mytinytodo.net/ + * YunoHost website: https://yunohost.org/ + +--- + +## Developer info + +Please send your pull request to the [testing branch](https://github.com/YunoHost-Apps/mytinytodo_ynh/tree/testing). + +To try the testing branch, please proceed like that. ``` - -## Pour tester la version compatible php7 : - - * 20180901 : Il faut utiliser la branche testing pour le moment. - -```bash -yunohost app install https://github.com/YunoHost-Apps/mytinytodo_ynh/tree/testing --debug +sudo yunohost app install https://github.com/YunoHost-Apps/mytinytodo_ynh/tree/testing --debug +or +sudo yunohost app upgrade mytinytodo -u https://github.com/YunoHost-Apps/mytinytodo_ynh/tree/testing --debug ``` - -## Astuces : - - * Pour saisir rapidement une tâche, avec une priorité et des mots clefs - -```python -/+2/ Faire la traduction en anglais du README.md /#yunohost, mytinytodo/ -``` - diff --git a/README_fr.md b/README_fr.md new file mode 100644 index 0000000..6dd44d6 --- /dev/null +++ b/README_fr.md @@ -0,0 +1,70 @@ +# myTinyTodo pour YunoHost + +[![Niveau d'intégration](https://dash.yunohost.org/integration/mytinytodo.svg)](https://dash.yunohost.org/appci/app/mytinytodo) ![](https://ci-apps.yunohost.org/ci/badges/mytinytodo.status.svg) ![](https://ci-apps.yunohost.org/ci/badges/mytinytodo.maintain.svg) +[![Installer myTinyTodo pour YunoHost](https://install-app.yunohost.org/install-with-yunohost.svg)](https://install-app.yunohost.org/?app=mytinytodo) + +*[Read this readme in english.](./README.md)* + +> *Ce package vous permet d'installer myTinyTodo rapidement et simplement sur un serveur YunoHost. +Si vous n'avez pas YunoHost, consultez [le guide](https://yunohost.org/#/install) pour apprendre comment l'installer.* + +## Vue d'ensemble +Un moyen simple de gérer votre liste de tâches dans le style AJAX. Écrit en PHP et jQuery. Données stockées dans la base de données MySQL. + +**Version incluse :** 1.6.3 + +## Captures d'écran + +![](http://www.mytinytodo.net/images/shot-v14b1.png) + +## Démo + +* [Démo officielle](http://www.mytinytodo.net/demo/) + +## Configuration + +Comment configurer cette application : via le panneau d'administration. + +## Documentation + + * Documentation officielle : https://www.mytinytodo.net/faq.php + * Documentation YunoHost : Si une documentation spécifique est nécessaire, n'hésitez pas à contribuer. + +## Caractéristiques spécifiques YunoHost + +#### Support multi-utilisateur + +* L'authentification LDAP et HTTP est-elle prise en charge ? **Non** +* L'application peut-elle être utilisée par plusieurs utilisateurs ? **Non** + +#### Architectures supportées + +* x86-64 - [![Build Status](https://ci-apps.yunohost.org/ci/logs/mytinytodo%20%28Apps%29.svg)](https://ci-apps.yunohost.org/ci/apps/mytinytodo/) +* ARMv8-A - [![Build Status](https://ci-apps-arm.yunohost.org/ci/logs/mytinytodo%20%28Apps%29.svg)](https://ci-apps-arm.yunohost.org/ci/apps/mytinytodo/) + +## Limitations + +* Limitations connues. + +## Informations additionnelles + +* Autres informations que vous souhaitez ajouter sur cette application. + +## Liens + + * Signaler un bug : https://github.com/YunoHost-Apps/mytinytodo_ynh/issues + * Site de l'application : http://www.mytinytodo.net/ + * Site web YunoHost : https://yunohost.org/ + +--- + +## Informations pour les développeurs + +Merci de faire vos pull request sur la [branche testing](https://github.com/YunoHost-Apps/mytinytodo_ynh/tree/testing). + +Pour essayer la branche testing, procédez comme suit. +``` +sudo yunohost app install https://github.com/YunoHost-Apps/mytinytodo_ynh/tree/testing --debug +ou +sudo yunohost app upgrade mytinytodo -u https://github.com/YunoHost-Apps/mytinytodo_ynh/tree/testing --debug +``` diff --git a/check_process b/check_process index da5027a..a6abd78 100644 --- a/check_process +++ b/check_process @@ -1,10 +1,9 @@ -;; Un test monoinstance - auto_remove=1 +;; Test complet ; Manifest - domain="domain.org" (DOMAIN) - path="/mytinytodo" (PATH) - is_public=1 (PUBLIC|public=1|private=0) + domain="domain.tld" (DOMAIN) + path="/path" (PATH) language="fr" + is_public=1 (PUBLIC|public=1|private=0) ; Checks pkg_linter=1 setup_sub_dir=1 @@ -15,21 +14,11 @@ upgrade=1 backup_restore=1 multi_instance=0 - wrong_user=0 - wrong_path=1 - incorrect_path=1 - corrupt_source=0 - fail_download_source=0 - port_already_use=0 - final_path_already_use=0 -;;; Levels - Level 1=auto - Level 2=auto - Level 3=auto - Level 4=1 - Level 5=1 - Level 6=auto - Level 7=auto - Level 8=0 - Level 9=0 - Level 10=0 + change_url=1 +;;; Options +Email= +Notification=none +;;; Upgrade options + ; commit=CommitHash + name=Name and date of the commit. + manifest_arg=domain=DOMAIN&path=PATH&admin=USER&language=fr&is_public=1&password=pass&port=666& diff --git a/conf/app.src b/conf/app.src index 66b887a..b50f8de 100644 --- a/conf/app.src +++ b/conf/app.src @@ -1,7 +1,8 @@ -SOURCE_URL>http://www.mytinytodo.net/latest.php -SOURCE_SUM=2cfea5e8121979b6a511f88276a6d4db -UPDATE_URL|http://pierre.levasseur.free.fr/mytinytodo/update.zip -UPDATE_SUM@f8ed8abbcb9055c34f402a31e4574106 -SOURCE_URL=https://github.com/ptrckkk/myTinyTodo/archive/master.zip -SOURCE_SUM=df901cd9ec71b72420457bca2111d9132bcef60f79be87e6c67bdf2070f13bf1 +SOURCE_URL=https://www.mytinytodo.net/latest.php +SOURCE_SUM=8bb32d48c96091403bfc9a54f574f92c87e018544ddb4c526b45a5d1a67a9831 +SOURCE_SUM_PRG=sha256sum SOURCE_FORMAT=zip +SOURCE_IN_SUBDIR=true +SOURCE_FILENAME= +SOURCE_EXTRACT=true + diff --git a/conf/config.php b/conf/config.php index 672a4c1..b2fabe5 100755 --- a/conf/config.php +++ b/conf/config.php @@ -1,26 +1,60 @@ y-m-d (default), 2 => m/d/y, 3 => d.m.y $config['duedateformat'] = 1; + +# First day of week: 0-Sunday, 1-Monday, 2-Tuesday, .. 6-Saturday $config['firstdayofweek'] = 1; + +# select session handling mechanism: files or default (php default) $config['session'] = 'files'; + +# Date/time formats $config['clock'] = 24; $config['dateformat'] = 'j M Y'; -$config['dateformat2'] = 'n/j/y'; $config['dateformatshort'] = 'j M'; -$config['template'] = 'default'; + +# Show task date in list $config['showdate'] = 0; + +# Autodetect mobile devices and switch theme +$config['detectmobile'] = 1; + ?> diff --git a/conf/nginx.conf b/conf/nginx.conf index 91394b5..cfdefca 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -1,34 +1,28 @@ -#--MULTISITE--if (!-e $request_filename) { - #--MULTISITE--rewrite /wp-admin$ $scheme://$host$uri/ permanent; - #--MULTISITE--rewrite ^__PATHTOCHANGE__(/[^/]+)?(/wp-.*) __PATHTOCHANGE__$2 last; - #--MULTISITE--rewrite ^__PATHTOCHANGE__(/[^/]+)?(/.*\.php)$ __PATHTOCHANGE__$2 last; -#--MULTISITE--} +#sub_path_only rewrite ^__PATH__$ __PATH__/ permanent; +location __PATH__/ { -location __PATHTOCHANGE__ { - alias __FINALPATH__/; - index index.php; - #if (!-e $request_filename) - #{ - # rewrite ^(.+)$ __PATHTOCHANGE__/index.php?q=$1 last; - #} - #if ($scheme = http) { - # rewrite ^ https://$server_name$request_uri? permanent; - #} - #client_max_body_size 30m; + # Path to source + alias __FINALPATH__/ ; - try_files $uri $uri/ __PATHTOCHANGE__/index.php?$args; - - location ~ [^/]\.php(/|$) { - fastcgi_split_path_info ^(.+?\.php)(/.*)$; - #fastcgi_pass unix:/var/run/php5-fpm-__NAMETOCHANGE__.sock; - fastcgi_pass unix:/var/run/php5-fpm.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; - } + # Force usage of https + if ($scheme = http) { + rewrite ^ https://$server_name$request_uri? permanent; + } - #--PRIVATE--# Include SSOWAT user panel. - #--PRIVATE--include conf.d/yunohost_panel.conf.inc; + index index.php; + + try_files $uri $uri/ index.php; + location ~ [^/]\.php(/|$) { + fastcgi_split_path_info ^(.+?\.php)(/.*)$; + fastcgi_pass unix:/var/run/php/php__PHPVERSION__-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; + } + + # Include SSOWAT user panel. + include conf.d/yunohost_panel.conf.inc; } diff --git a/conf/php-fpm.conf b/conf/php-fpm.conf new file mode 100644 index 0000000..ab1a471 --- /dev/null +++ b/conf/php-fpm.conf @@ -0,0 +1,430 @@ +; Start a new pool named 'www'. +; 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' +; - 'chdir' +; - 'php_values' +; - 'php_admin_values' +; When not set, the global prefix (or /usr) applies instead. +; Note: This directive can also be relative to the global prefix. +; 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 IPv4 address 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/php__PHPVERSION__-fpm-__NAMETOCHANGE__.sock + +; 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. +; 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 +; accepted from any ip address. +; Default Value: any +;listen.allowed_clients = 127.0.0.1 + +; 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 + +; 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. 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. +; pm.min_spare_servers - the minimum number of children in 'idle' +; state (waiting to process). If the number +; of 'idle' processes is less than this +; number then some children will be created. +; pm.max_spare_servers - the maximum number of children in 'idle' +; 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 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. 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 = 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 = 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 = 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 = 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 + +; 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: +; pool - the name of the pool; +; 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; +; 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' and 'ondemand'); +; Value are updated in real time. +; Example output: +; pool: www +; process manager: static +; 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', '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 = /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 +; that FPM is alive and responding, or to +; - create a graph of FPM availability (rrd or such); +; - remove a server from a group if it is not responding (load balancing); +; - trigger alerts for the operating team (24/7). +; 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 +;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 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 = 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 +; possible. However, all PHP paths will be relative to the chroot +; (error_log, sessions.save_path, ...). +; Default Value: not set +;chroot = + +; Chdir to this directory at the start. +; Note: relative path can be used. +; Default Value: current directory or / when chroot +chdir = __FINALPATH__ + +; Redirect worker stdout and stderr into main error log. If not set, stdout and +; stderr will be redirected to /dev/null according to FastCGI specs. +; Note: on highloaded environement, this can cause some delay in the page +; process time (several ms). +; Default Value: no +;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. +; Default Value: clean env +;env[HOSTNAME] = $HOSTNAME +;env[PATH] = /usr/local/bin:/usr/bin:/bin +;env[TMP] = /tmp +;env[TMPDIR] = /tmp +;env[TEMP] = /tmp + +; Additional php.ini defines, specific to this pool of workers. These settings +; 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'. +; 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. + +; Defining 'extension' will load the corresponding shared extension from +; extension_dir. Defining 'disable_functions' or 'disable_classes' will not +; overwrite previously defined php.ini values, but will append the new value +; instead. + +; Note: path INI options can be relative and will be expanded with the prefix +; (pool, global or /usr) + +; Default Value: nothing is defined by default except the values in php.ini and +; specified at startup with the -d argument +;php_admin_value[sendmail_path] = /usr/sbin/sendmail -t -i -f www@my.domain.com +;php_flag[display_errors] = off +;php_admin_value[error_log] = /var/log/fpm-php.www.log +;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 diff --git a/manifest.json b/manifest.json index adbdcb5..8404194 100644 --- a/manifest.json +++ b/manifest.json @@ -3,23 +3,23 @@ "id": "mytinytodo", "packaging_format": 1, "description": { - "en": "Simple open source to-do list script.", - "fr": "Un simple mais efficace script de gestion de todo list (GTD)." + "en": "Open source to-do list script.", + "fr": "Gestionnaire de todo list (GTD)." }, "url": "http://www.mytinytodo.net/", "license": "GPL-2.0", - "version": "1.4.3", + "version": "1.6.3~ynh1", "maintainer": { "name": "plabuse", "email": "pierre.levasseur@free.fr" }, "requirements": { - "yunohost": ">= 2.5.6" + "yunohost": ">= 3.8.1" }, "multi_instance": false, "services": [ "nginx", - "php5-fpm", + "php7.3-fpm", "mysql" ], "arguments": { @@ -28,8 +28,8 @@ "name": "domain", "type": "domain", "ask": { - "en": "Choose a domain name for mytinytodo", - "fr": "Choisissez un nom de domaine pour mytinytodo" + "en": "Choose a domain name for myTinyTodo", + "fr": "Choisissez un nom de domaine pour myTinyTodo" }, "example": "domaine.org" }, @@ -37,8 +37,8 @@ "name": "path", "type": "path", "ask": { - "en": "Choose a path for mytinytodo", - "fr": "Choisissez un chemin pour mytinytodo" + "en": "Choose a path for myTinyTodo", + "fr": "Choisissez un chemin pour myTinyTodo" }, "example": "/mytinytodo", "default": "/mytinytodo" @@ -50,19 +50,20 @@ "en": "Is it a public application?", "fr": "Est-ce une application publique ?" }, - "default": false + "help": { + "en": "If enabled, myTinyTodo will be accessible by people who do not have an account. This can be changed later via the webadmin.", + "fr": "Si cette case est cochée, myTinyTodo sera accessible aux personnes n’ayant pas de compte. Vous pourrez changer ceci plus tard via la webadmin." + }, + "default": true }, { "name": "language", + "type": "string", "ask": { "en": "Choose the application language", - "ru": "Выберите язык приложения", - "de": "Wählen Sie die Sprache der Anwendung", - "ar": "اختيار تطبيق لغة", - "zh-cn": "选择语言实现", "fr": "Choisissez la langue de l'application" }, - "choices": ["fr", "en", "de", "ar", "zh-cn", "ru"], + "choices": ["ar", "de", "en", "fr", "ru", "zh-cn"], "default": "fr" } ] diff --git a/scripts/_common.sh b/scripts/_common.sh index c14e458..507f449 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -1,564 +1,24 @@ #!/bin/bash #================================================= -# CHECKING +# COMMON VARIABLES #================================================= -CHECK_USER () { # Vérifie la validité de l'user admin -# $1 = Variable de l'user admin. - ynh_user_exists "$1" || ynh_die "Wrong user" -} +YNH_PHP_VERSION="7.3" -CHECK_DOMAINPATH () { # Vérifie la disponibilité du path et du domaine. - # sudo yunohost app checkurl $domain$path_url -a $app - # Check web path availability - ynh_webpath_available $domain $path_url - # Register (book) web path - ynh_webpath_register $app $domain $path_url -} +# dependencies used by the app +pkg_dependencies="" -CHECK_FINALPATH () { # Vérifie que le dossier de destination n'est pas déjà utilisé. - final_path=/var/www/$app - test ! -e "$final_path" || ynh_die "This path already contains a folder" -} - -CHECK_PHP_VERSION () { - phpfullversion=$(php -r "echo PHP_VERSION;") - # echo ${phpfullversion} - # 7.1.15-1+0~20180306120016.15+stretch~1.gbp78327e - - majeur=${phpfullversion::1} - # echo ${majeur} - # 7 - - if [ $majeur -ge 7 ]; then - # Quand la version de php est >= 7 - return 0 - else - # Dans les autres cas - return 1 - fi -} +extra_php_dependencies="php${YNH_PHP_VERSION}-mysql php${YNH_PHP_VERSION}-pdo" #================================================= -# DISPLAYING +# PERSONAL HELPERS #================================================= -NO_PRINT () { # Supprime l'affichage dans stdout pour la commande en argument. - set +x - $@ - set -x -} - -WARNING () { # Écrit sur le canal d'erreur pour passer en warning. - $@ >&2 -} - -SUPPRESS_WARNING () { # Force l'écriture sur la sortie standard - $@ 2>&1 -} - -QUIET () { # Redirige la sortie standard dans /dev/null - $@ > /dev/null -} - -ALL_QUIET () { # Redirige la sortie standard et d'erreur dans /dev/null - $@ > /dev/null 2>&1 -} - #================================================= -# SETUP +# EXPERIMENTAL HELPERS #================================================= -SETUP_SOURCE () { # Télécharge la source, décompresse et copie dans $final_path - src_url=$(cat ../conf/app.src | grep SOURCE_URL | cut -d'>' -f2) - src_checksum=$(cat ../conf/app.src | grep SOURCE_SUM | cut -d= -f2) - # Download sources from the upstream - wget -nv -O source.tar.gz $src_url - # Vérifie la somme de contrôle de la source téléchargée. - echo "$src_checksum source.tar.gz" | md5sum -c --status || ynh_die "Corrupt source" - # Extract source into the app dir - sudo mkdir -p $final_path - sudo tar -x -f source.tar.gz -C $final_path --strip-components 1 - # Copie les fichiers additionnels ou modifiés. - if test -e "../sources/ajouts"; then - sudo cp -a ../sources/ajouts/. "$final_path" - fi -} - -SETUP_SOURCE_ZIP () { # Télécharge la source, décompresse et copie dans $final_path -# Attention l'archive /tmp/xxx/mytinytodo/* - src_url=$(cat ../conf/app.src | grep SOURCE_URL | cut -d'>' -f2) - src_checksum=$(cat ../conf/app.src | grep SOURCE_SUM | cut -d= -f2) - # Download sources from the upstream - wget -nv -O source.zip $src_url - # Vérifie la somme de contrôle de la source téléchargée. - echo "$src_checksum source.zip" | md5sum -c --status || ynh_die "Corrupt source" - # Extract source into the app dir - sudo mkdir -p $final_path - temp_dir=$(mktemp -d) - unzip -quo source.zip -d $temp_dir # On passe par un dossier temporaire car unzip ne permet pas d'ignorer le dossier parent. - sudo cp -a $temp_dir/*/. $final_path - sudo rm -r $temp_dir - # Copie les fichiers additionnels ou modifiés. - if test -e "../sources/ajouts"; then - sudo cp -a ../sources/ajouts/. "$final_path" - fi -} - -SETUP_SOURCE_GIT () { - # Recuperation de la version compatible php7 - sudo mkdir -p $final_path - ynh_setup_source $final_path - # Copie les fichiers additionnels ou modifiés qui ne sont pas sur github. - if test -e "../sources/ajouts"; then - sudo cp -a ../sources/ajouts/lang/ar.php "$final_path/lang" - sudo cp -a ../sources/ajouts/lang/fr.php "$final_path/lang" - sudo cp -a ../sources/ajouts/lang/zh-cn.php "$final_path/lang" - fi -} - -UPDATE_SOURCE_ZIP () { # Télécharge la source, décompresse et copie dans $final_path -# Attention dans l'update le zip /tmp/xxx/db je n'ai pas respecte l'arboresence -# il n'y a pas de repertoire principal mytinytodo, la commande cp est differente - upd_url=$(cat ../conf/app.src | grep UPDATE_URL | cut -d'|' -f2) - upd_checksum=$(cat ../conf/app.src | grep UPDATE_SUM | cut -d'@' -f2) - # Download sources from the upstream - wget -nv -O source.zip $upd_url - # Vérifie la somme de contrôle de la source téléchargée. - echo "$upd_checksum source.zip" | md5sum -c --status || ynh_die "Corrupt source" - # Extract source into the app dir - sudo mkdir -p $final_path - temp_dir=$(mktemp -d) - unzip -quo source.zip -d $temp_dir # On passe par un dossier temporaire car unzip ne permet pas d'ignorer le dossier parent. - sudo cp -a $temp_dir/* $final_path - sudo rm -r $temp_dir - # Copie les fichiers additionnels ou modifiés. - if test -e "../sources/ajouts"; then - sudo cp -a ../sources/ajouts/. "$final_path" - fi -} - -POOL_FPM () { # Créer le fichier de configuration du pool php-fpm et le configure. - sed -i "s@__NAMETOCHANGE__@$app@g" ../conf/php-fpm.conf - sed -i "s@__FINALPATH__@$final_path@g" ../conf/php-fpm.conf - sed -i "s@__USER__@$app@g" ../conf/php-fpm.conf - finalphpconf=/etc/php5/fpm/pool.d/$app.conf - sudo cp ../conf/php-fpm.conf $finalphpconf - sudo chown root: $finalphpconf - finalphpini=/etc/php5/fpm/conf.d/20-$app.ini - sudo cp ../conf/php-fpm.ini $finalphpini - sudo chown root: $finalphpini - sudo systemctl reload php5-fpm -} - -YNH_CURL () { - data_post=$1 - url_access=$2 - sleep 1 - curl -kL -H "Host: $domain" --resolve $domain:443:127.0.0.1 --data "$data_post" "https://localhost$path_url$url_access" 2>&1 -} - #================================================= -# REMOVE +# FUTURE OFFICIAL HELPERS #================================================= - -REMOVE_NGINX_CONF () { # Suppression de la configuration nginx - if [ -e "/etc/nginx/conf.d/$domain.d/$app.conf" ]; then # Delete nginx config - echo "Delete nginx config" - sudo rm "/etc/nginx/conf.d/$domain.d/$app.conf" - sudo systemctl reload nginx - fi -} - -REMOVE_FPM_CONF () { # Suppression de la configuration du pool php-fpm - if [ -e "/etc/php5/fpm/pool.d/$app.conf" ]; then # Delete fpm config - echo "Delete fpm config" - sudo rm "/etc/php5/fpm/pool.d/$app.conf" - fi - if [ -e "/etc/php5/fpm/conf.d/20-$app.ini" ]; then # Delete php config - echo "Delete php config" - sudo rm "/etc/php5/fpm/conf.d/20-$app.ini" - fi - sudo systemctl reload php5-fpm -} - -SECURE_REMOVE () { # Suppression de dossier avec vérification des variables - chaine="$1" # L'argument doit être donné entre quotes simple '', pour éviter d'interpréter les variables. - no_var=0 - while (echo "$chaine" | grep -q '\$') # Boucle tant qu'il y a des $ dans la chaine - do - no_var=1 - global_var=$(echo "$chaine" | cut -d '$' -f 2) # Isole la première variable trouvée. - only_var=\$$(expr "$global_var" : '\([A-Za-z0-9_]*\)') # Isole complètement la variable en ajoutant le $ au début et en gardant uniquement le nom de la variable. Se débarrasse surtout du / et d'un éventuel chemin derrière. - real_var=$(eval "echo ${only_var}") # `eval "echo ${var}` permet d'interpréter une variable contenue dans une variable. - if test -z "$real_var" || [ "$real_var" = "/" ]; then - WARNING echo "Variable $only_var is empty, suppression of $chaine cancelled." - return 1 - fi - chaine=$(echo "$chaine" | sed "s@$only_var@$real_var@") # remplace la variable par sa valeur dans la chaine. - done - if [ "$no_var" -eq 1 ] - then - if [ -e "$chaine" ]; then - echo "Delete directory $chaine" - sudo rm -r "$chaine" - fi - return 0 - else - WARNING echo "No detected variable." - return 1 - fi -} - -#================================================= -# BACKUP -#================================================= - -BACKUP_FAIL_UPGRADE () { - WARNING echo "Upgrade failed." - app_bck=${app//_/-} # Replace all '_' by '-' - if sudo yunohost backup list | grep -q $app_bck-pre-upgrade$backup_number; then # Vérifie l'existence de l'archive avant de supprimer l'application et de restaurer - sudo yunohost app remove $app # Supprime l'application avant de la restaurer. - sudo yunohost backup restore --ignore-hooks $app_bck-pre-upgrade$backup_number --apps $app --force # Restore the backup if upgrade failed - ynh_die "The app was restored to the way it was before the failed upgrade." - fi -} - -BACKUP_BEFORE_UPGRADE () { # Backup the current version of the app, restore it if the upgrade fails - backup_number=1 - old_backup_number=2 - app_bck=${app//_/-} # Replace all '_' by '-' - if sudo yunohost backup list | grep -q $app_bck-pre-upgrade1; then # Vérifie l'existence d'une archive déjà numéroté à 1. - backup_number=2 # Et passe le numéro de l'archive à 2 - old_backup_number=1 - fi - - sudo yunohost backup create --ignore-hooks --apps $app --name $app_bck-pre-upgrade$backup_number # Créer un backup différent de celui existant. - if [ "$?" -eq 0 ]; then # Si le backup est un succès, supprime l'archive précédente. - if sudo yunohost backup list | grep -q $app_bck-pre-upgrade$old_backup_number; then # Vérifie l'existence de l'ancienne archive avant de la supprimer, pour éviter une erreur. - QUIET sudo yunohost backup delete $app_bck-pre-upgrade$old_backup_number - fi - else # Si le backup a échoué - ynh_die "Backup failed, the upgrade process was aborted." - fi -} - -HUMAN_SIZE () { # Transforme une taille en Ko en une taille lisible pour un humain - human=$(numfmt --to=iec --from-unit=1K $1) - echo $human -} - -CHECK_SIZE () { # Vérifie avant chaque backup que l'espace est suffisant - file_to_analyse=$1 - backup_size=$(sudo du --summarize "$file_to_analyse" | cut -f1) - free_space=$(sudo df --output=avail "/home/yunohost.backup" | sed 1d) - - if [ $free_space -le $backup_size ] - then - WARNING echo "Espace insuffisant pour sauvegarder $file_to_analyse." - WARNING echo "Espace disponible: $(HUMAN_SIZE $free_space)" - ynh_die "Espace nécessaire: $(HUMAN_SIZE $backup_size)" - fi -} - -#================================================= -# CONFIGURATION -#================================================= - -STORE_MD5_CONFIG () { # Enregistre la somme de contrôle du fichier de config -# $1 = Nom du fichier de conf pour le stockage dans settings.yml -# $2 = Nom complet et chemin du fichier de conf. - ynh_app_setting_set $app $1_file_md5 $(sudo md5sum "$2" | cut -d' ' -f1) -} - -CHECK_MD5_CONFIG () { # Créé un backup du fichier de config si il a été modifié. -# $1 = Nom du fichier de conf pour le stockage dans settings.yml -# $2 = Nom complet et chemin du fichier de conf. - if [ "$(ynh_app_setting_get $app $1_file_md5)" != $(sudo md5sum "$2" | cut -d' ' -f1) ]; then - sudo cp -a "$2" "$2.backup.$(date '+%d.%m.%y_%Hh%M,%Ss')" # Si le fichier de config a été modifié, créer un backup. - fi -} - -#================================================= -# PACKAGE CHECK BYPASSING... -#================================================= - -IS_PACKAGE_CHECK () { # Détermine une exécution en conteneur (Non testé) - return uname -n | grep -c 'pchecker_lxc' -} - -#================================================= -#================================================= -# FUTUR YNH HELPERS -#================================================= -# Importer ce fichier de fonction avant celui des helpers officiel -# Ainsi, les officiels prendront le pas sur ceux-ci le cas échéant -#================================================= - -# Ignore the yunohost-cli log to prevent errors with conditionals commands -# usage: ynh_no_log COMMAND -# Simply duplicate the log, execute the yunohost command and replace the log without the result of this command -# It's a very badly hack... -ynh_no_log() { - ynh_cli_log=/var/log/yunohost/yunohost-cli.log - sudo cp -a ${ynh_cli_log} ${ynh_cli_log}-move - eval $@ - ext_code=$? - sudo mv ${ynh_cli_log}-move ${ynh_cli_log} - return $? -} - -# Normalize the url path syntax -# Handle the slash at the beginning of path and its absence at ending -# Return a normalized url path -# -# example: url_path=$(ynh_normalize_url_path $url_path) -# ynh_normalize_url_path example -> /example -# ynh_normalize_url_path /example -> /example -# ynh_normalize_url_path /example/ -> /example -# -# usage: ynh_normalize_url_path path_to_normalize -# | arg: url_path_to_normalize - URL path to normalize before using it -ynh_normalize_url_path () { - path_url=$1 - test -n "$path_url" || ynh_die "ynh_normalize_url_path expect a URL path as first argument and received nothing." - if [ "${path_url:0:1}" != "/" ]; then # If the first character is not a / - path_url="/$path_url" # Add / at begin of path variable - fi - if [ "${path_url:${#path_url}-1}" == "/" ] && [ ${#path_url} -gt 1 ]; then # If the last character is a / and that not the only character. - path_url="${path_url:0:${#path_url}-1}" # Delete the last character - fi - echo $path_url -} - -# Create a database, an user and its password. Then store the password in the app's config -# -# User of database will be store in db_user's variable. -# Name of database will be store in db_name's variable. -# And password in db_pwd's variable. -# -# usage: ynh_mysql_generate_db user name -# | arg: user - Owner of the database -# | arg: name - Name of the database -ynh_mysql_generate_db () { - db_pwd=$(ynh_string_random) # Generate a random password - ynh_mysql_create_db "$2" "$1" "$db_pwd" # Create the database - ynh_app_setting_set $app mysqlpwd $db_pwd # Store the password in the app's config -} - -# Remove a database if it exist and the associated user -# -# usage: ynh_mysql_remove_db user name -# | arg: user - Proprietary of the database -# | arg: name - Name of the database -ynh_mysql_remove_db () { - if mysqlshow -u root -p$(sudo cat $MYSQL_ROOT_PWD_FILE) | grep -q "^| $2"; then # Check if the database exist - echo "Remove database $2" >&2 - ynh_mysql_drop_db $2 # Remove the database - ynh_mysql_drop_user $1 # Remove the associated user to database - else - echo "Database $2 not found" >&2 - fi -} - -# Correct the name given in argument for mariadb -# -# Avoid invalid name for your database -# -# Exemple: dbname=$(ynh_make_valid_dbid $app) -# -# usage: ynh_make_valid_dbid name -# | arg: name - name to correct -# | ret: the corrected name -ynh_make_valid_dbid () { - dbid=${1//[-.]/_} # Mariadb doesn't support - and . in the name of databases. It will be replace by _ - echo $dbid -} - -# Manage a fail of the script -# -# Print a warning to inform that the script was failed -# Execute the ynh_clean_setup function if used in the app script -# -# usage of ynh_clean_setup function -# This function provide a way to clean some residual of installation that not managed by remove script. -# To use it, simply add in your script: -# ynh_clean_setup () { -# instructions... -# } -# This function is optionnal. -# -# Usage: ynh_exit_properly is used only by the helper ynh_check_error. -# You must not use it directly. -ynh_exit_properly () { - ext_code=$? - if [ "$ext_code" -eq 0 ]; then - exit 0 # Exit without error if the script ended correctly - fi - - trap '' EXIT # Ignore new exit signals - set +eu # Do not exit anymore if a command fail or if a variable is empty - - echo -e "!!\n $app's script has encountered an error. Its execution was cancelled.\n!!" >&2 - - if type -t ynh_clean_setup > /dev/null; then # Check if the function exist in the app script. - ynh_clean_setup # Call the function to do specific cleaning for the app. - fi - - ynh_die # Exit with error status -} - -# Exit if an error occurs during the execution of the script. -# -# Stop immediatly the execution if an error occured or if a empty variable is used. -# The execution of the script is derivate to ynh_exit_properly function before exit. -# -# Usage: ynh_abort_if_errors -ynh_abort_if_errors () { - set -eu # Exit if a command fail, and if a variable is used unset. - trap ynh_exit_properly EXIT # Capturing exit signals on shell script -} - -# Install dependencies with a equivs control file -# -# usage: ynh_install_app_dependencies dep [dep [...]] -# | arg: dep - the package name to install in dependence -ynh_install_app_dependencies () { - dependencies=$@ - manifest_path="../manifest.json" - if [ ! -e "$manifest_path" ]; then - manifest_path="../settings/manifest.json" # Into the restore script, the manifest is not at the same place - fi - version=$(sudo python3 -c "import sys, json;print(json.load(open(\"$manifest_path\"))['version'])") # Retrieve the version number in the manifest file. - dep_app=${app//_/-} # Replace all '_' by '-' - - if ynh_package_is_installed "${dep_app}-ynh-deps"; then - echo "A package named ${dep_app}-ynh-deps is already installed" >&2 - else - cat > ./${dep_app}-ynh-deps.control << EOF # Make a control file for equivs-build -Section: misc -Priority: optional -Package: ${dep_app}-ynh-deps -Version: ${version} -Depends: ${dependencies// /, } -Architecture: all -Description: Fake package for ${app} (YunoHost app) dependencies - This meta-package is only responsible of installing its dependencies. -EOF - ynh_package_install_from_equivs ./${dep_app}-ynh-deps.control \ - || ynh_die "Unable to install dependencies" # Install the fake package and its dependencies - ynh_app_setting_set $app apt_dependencies $dependencies - fi -} - -# Remove fake package and its dependencies -# -# Dependencies will removed only if no other package need them. -# -# usage: ynh_remove_app_dependencies -ynh_remove_app_dependencies () { - dep_app=${app//_/-} # Replace all '_' by '-' - ynh_package_autoremove ${dep_app}-ynh-deps # Remove the fake package and its dependencies if they not still used. -} - -# Use logrotate to manage the logfile -# -# usage: ynh_use_logrotate [logfile] -# | arg: logfile - absolute path of logfile -# -# If no argument provided, a standard directory will be use. /var/log/${app} -# You can provide a path with the directory only or with the logfile. -# /parentdir/logdir/ -# /parentdir/logdir/logfile.log -# -# It's possible to use this helper several times, each config will added to same logrotate config file. -ynh_use_logrotate () { - if [ "$#" -gt 0 ]; then - if [ "$(echo ${1##*.})" == "log" ]; then # Keep only the extension to check if it's a logfile - logfile=$1 # In this case, focus logrotate on the logfile - else - logfile=$1/.log # Else, uses the directory and all logfile into it. - fi - else - logfile="/var/log/${app}/.log" # Without argument, use a defaut directory in /var/log - fi - cat > ./${app}-logrotate << EOF # Build a config file for logrotate -$logfile { - # Rotate if the logfile exceeds 100Mo - size 100M - # Keep 12 old log maximum - rotate 12 - # Compress the logs with gzip - compress - # Compress the log at the next cycle. So keep always 2 non compressed logs - delaycompress - # Copy and truncate the log to allow to continue write on it. Instead of move the log. - copytruncate - # Do not do an error if the log is missing - missingok - # Not rotate if the log is empty - notifempty - # Keep old logs in the same dir - noolddir -} -EOF - sudo mkdir -p $(dirname "$logfile") # Create the log directory, if not exist - cat ${app}-logrotate | sudo tee -a /etc/logrotate.d/$app > /dev/null # Append this config to the others for this app. If a config file already exist -} - -# Remove the app's logrotate config. -# -# usage: ynh_remove_logrotate -ynh_remove_logrotate () { - if [ -e "/etc/logrotate.d/$app" ]; then - sudo rm "/etc/logrotate.d/$app" - fi -} - -# Find a free port and return it -# -# example: port=$(ynh_find_port 8080) -# -# usage: ynh_find_port begin_port -# | arg: begin_port - port to start to search -ynh_find_port () { - port=$1 - test -n "$port" || ynh_die "The argument of ynh_find_port must be a valid port." - while netcat -z 127.0.0.1 $port # Check if the port is free - do - port=$((port+1)) # Else, pass to next port - done - echo $port -} - -# Create a system user -# -# usage: ynh_system_user_create user_name [home_dir] -# | arg: user_name - Name of the system user that will be create -# | arg: home_dir - Path of the home dir for the user. Usually the final path of the app. If this argument is omitted, the user will be created without home -ynh_system_user_create () { - if ! ynh_system_user_exists "$1" # Check if the user exists on the system - then # If the user doesn't exist - if [ $# -ge 2 ]; then # If a home dir is mentioned - user_home_dir="-d $2" - else - user_home_dir="--no-create-home" - fi - sudo useradd $user_home_dir --system --user-group $1 --shell /usr/sbin/nologin || ynh_die "Unable to create $1 system account" - fi -} - -# Delete a system user -# -# usage: ynh_system_user_delete user_name -# | arg: user_name - Name of the system user that will be create -ynh_system_user_delete () { - if ynh_system_user_exists "$1" # Check if the user exists on the system - then - echo "Remove the user $1" >&2 - sudo userdel $1 - else - echo "The user $1 was not found" >&2 - fi -} diff --git a/scripts/backup b/scripts/backup index 608f867..28f03b5 100644 --- a/scripts/backup +++ b/scripts/backup @@ -1,57 +1,66 @@ #!/bin/bash -set -eu - #================================================= -# GENERIC STARTING -#================================================= -# MANAGE FAILURE OF THE SCRIPT -#================================================= - +# GENERIC START #================================================= # IMPORT GENERIC HELPERS #================================================= -if [ ! -e _common.sh ]; then - # Rapatrie le fichier de fonctions si il n'est pas dans le dossier courant - sudo cp ../settings/scripts/_common.sh ./_common.sh - sudo chmod a+rx _common.sh -fi - -source _common.sh +source ../settings/scripts/_common.sh source /usr/share/yunohost/helpers -ynh_abort_if_errors # Active trap pour arrêter le script si une erreur est détectée. + +#================================================= +# MANAGE SCRIPT FAILURE +#================================================= + +# Exit if an error occurs during the execution of the script +ynh_abort_if_errors #================================================= # LOAD SETTINGS #================================================= +ynh_print_info --message="Loading installation settings..." app=$YNH_APP_INSTANCE_NAME -domain=$(ynh_app_setting_get $app domain) -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) +domain=$(ynh_app_setting_get --app=$app --key=domain) +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) +phpversion=$(ynh_app_setting_get --app=$app --key=phpversion) #================================================= -# STANDARD BACKUP STEPS +# DECLARE DATA AND CONF FILES TO BACKUP +#================================================= +ynh_print_info --message="Declaring files to be backed up..." + #================================================= # BACKUP OF THE MAIN DIR OF THE APP #================================================= -CHECK_SIZE "$final_path" -ynh_backup "$final_path" "sources" +ynh_backup --src_path="$final_path" #================================================= # BACKUP OF THE NGINX CONFIGURATION #================================================= -ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf" "nginx.conf" +ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf" #================================================= -# BACKUP OF THE SQL BDD +# BACKUP THE PHP-FPM CONFIGURATION #================================================= -ynh_mysql_dump_db "$db_name" > dump.sql -CHECK_SIZE "dump.sql" -ynh_backup "dump.sql" "db.sql" +ynh_backup --src_path="/etc/php/$phpversion/fpm/pool.d/$app.conf" + +#================================================= +# BACKUP THE MYSQL DATABASE +#================================================= +ynh_print_info --message="Backing up the MySQL database..." + +ynh_mysql_dump_db --database="$db_name" > db.sql + +#================================================= +# END OF SCRIPT +#================================================= + +ynh_print_info --message="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..e06912d --- /dev/null +++ b/scripts/change_url @@ -0,0 +1,110 @@ +#!/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 +#================================================= +ynh_script_progression --message="Loading installation settings..." --weight=1 + +# Needed for helper "ynh_add_nginx_config" +final_path=$(ynh_app_setting_get --app=$app --key=final_path) + +# Add settings here as needed by your application +#db_name=$(ynh_app_setting_get --app=$app --key=db_name) +#db_user=$db_name +#db_pwd=$(ynh_app_setting_get --app=$app --key=db_pwd) + +#================================================= +# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP +#================================================= +ynh_script_progression --message="Backing up the app before changing its URL (may take a while)..." --weight=2 + +# Backup the current version of the app +ynh_backup_before_upgrade +ynh_clean_setup () { + # Remove the new domain config file, the remove script won't do it as it doesn't know yet its location. + ynh_secure_remove --file="/etc/nginx/conf.d/$new_domain.d/$app.conf" + + # Restore it if the upgrade fails + ynh_restore_upgradebackup +} +# Exit if an error occurs during the execution of the script +ynh_abort_if_errors + +#================================================= +# 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 + +#================================================= +# MODIFY URL IN NGINX CONF +#================================================= +ynh_script_progression --message="Updating NGINX web server configuration..." --weight=2 + +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 --file="$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 --file="$nginx_conf_path" + mv $nginx_conf_path /etc/nginx/conf.d/$new_domain.d/$app.conf + # Store file checksum for the new config file location + ynh_store_file_checksum --file="/etc/nginx/conf.d/$new_domain.d/$app.conf" +fi + +#================================================= +# RELOAD NGINX +#================================================= +ynh_script_progression --message="Reloading NGINX web server..." --weight=1 + +ynh_systemd_action --service_name=nginx --action=reload + +#================================================= +# END OF SCRIPT +#================================================= + +ynh_script_progression --message="Change of URL completed for $app" --last diff --git a/scripts/install b/scripts/install index 936a807..7a005a5 100644 --- a/scripts/install +++ b/scripts/install @@ -1,134 +1,149 @@ #!/bin/bash -set -eu - -# https://github.com/YunoHost-Apps/wordpress_ynh/blob/code_refactoring/scripts/install - #================================================= -# GENERIC STARTING +# GENERIC START #================================================= # IMPORT GENERIC HELPERS #================================================= - + source _common.sh source /usr/share/yunohost/helpers - + #================================================= -# MANAGE FAILURE OF THE SCRIPT +# MANAGE SCRIPT FAILURE #================================================= - -ynh_abort_if_errors # Active trap pour arrêter le script si une erreur est détectée. + +# Exit if an error occurs during the execution of the script +ynh_abort_if_errors #================================================= # RETRIEVE ARGUMENTS FROM THE MANIFEST #================================================= - -app=$YNH_APP_INSTANCE_NAME - -# Retrieve arguments + domain=$YNH_APP_ARG_DOMAIN path_url=$YNH_APP_ARG_PATH is_public=$YNH_APP_ARG_IS_PUBLIC language=$YNH_APP_ARG_LANGUAGE - -path_url=$(ynh_normalize_url_path $path_url) # Vérifie et corrige la syntaxe du path. -CHECK_DOMAINPATH # Vérifie la disponibilité du path et du domaine. -CHECK_FINALPATH # Vérifie que le dossier de destination n'est pas déjà utilisé. - -sudo mkdir -p $final_path - + +app=$YNH_APP_INSTANCE_NAME + +#================================================= +# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS +#================================================= +ynh_script_progression --message="Validating installation parameters..." --weight=1 + +final_path=/var/www/$app +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 is_public $is_public -ynh_app_setting_set $app language $language -ynh_app_setting_set $app final_path $final_path - +ynh_script_progression --message="Storing installation settings..." --weight=1 + +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=is_public --value=$is_public +ynh_app_setting_set --app=$app --key=language --value=$language + #================================================= -# CREATE A SQL BDD +# CREATE A MYSQL DATABASE #================================================= - -db_name=$(ynh_make_valid_dbid $app) -ynh_app_setting_set $app db_name $db_name -# $1 ownerdelabase, $2 namedelabase -ynh_mysql_generate_db $db_name $db_name - -# Charge les commandes sql communes à tous les scripts. -# mysql --debug-check -u $db_user -p$db_pwd $db_user < ../conf/sql/common.sql -ynh_mysql_connect_as $db_name $db_pwd $db_name < ../conf/sql/mytinytodo.sql - +ynh_script_progression --message="Creating a MySQL database..." --weight=2 + +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 + +# # # Charge les commandes sql communes à tous les scripts. +# # # mysql --debug-check -u $db_user -p$db_pwd $db_user < ../conf/sql/common.sql +ynh_mysql_connect_as --user=$db_name --password=$db_pwd --database=$db_name < ../conf/sql/mytinytodo.sql + #================================================= -# CREATE DEDICATED USER +# DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= - -ynh_system_user_create $app # Créer un utilisateur système dédié à l'app mytinytodo - +ynh_script_progression --message="Setting up source files..." --weight=3 + +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 --dest_dir="$final_path" + #================================================= # NGINX CONFIGURATION #================================================= - -# Copie le fichier de config nginx -sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/$app.conf -# Modifie les variables dans le fichier de configuration nginx -#location directive -sudo sed -i "s@__PATHTOCHANGE__@$path_url@g" /etc/nginx/conf.d/$domain.d/$app.conf -#alias directive, il faut peut etre ajout un / apres final_path -sudo sed -i "s@__FINALPATH__@$final_path@g" /etc/nginx/conf.d/$domain.d/$app.conf - - -# verifier la valeur de $final_path pour moi il y a /var/www/mytinytodo -# la nom de la base et l'utilisateur de la base on la même valeur -# mise en place de la config de la base au niveau de mytinytodo - -sudo sed -i "s@__TODO_HOST__@localhost@g" ../conf/config.php -sudo sed -i "s@__TODO_DB__@$db_name@g" ../conf/config.php -sudo sed -i "s@__TODO_USER__@$db_name@g" ../conf/config.php -sudo sed -i "s@__TODO_PASSWORD__@$db_pwd@g" ../conf/config.php -sudo sed -i "s@__TODO_LANG__@$language@g" ../conf/config.php +ynh_script_progression --message="Configuring NGINX web server..." --weight=2 -# Recuperation des sources sur le internet et decompression -if CHECK_PHP_VERSION; then - # echo "Tu es en php 7 est +" - SETUP_SOURCE_GIT -else - # echo "Tu es dans une version inferieur a 7" - SETUP_SOURCE_ZIP -fi +# Create a dedicated NGINX config +ynh_add_nginx_config + +#================================================= +# CREATE DEDICATED USER +#================================================= +ynh_script_progression --message="Configuring system user..." --weight=1 + +# Create a system user +ynh_system_user_create --username=$app + +#================================================= +# PHP-FPM CONFIGURATION +#================================================= +ynh_script_progression --message="Configuring PHP-FPM..." --weight=2 + +# Create a dedicated PHP-FPM config +ynh_add_fpm_config --package="$extra_php_dependencies" +phpversion=$(ynh_app_setting_get --app=$app --key=phpversion) + +#================================================= +# MODIFY A CONFIG FILE +#================================================= + +# # verifier la valeur de $final_path pour moi il y a /var/www/mytinytodo +# # la nom de la base et l'utilisateur de la base on la même valeur +# # mise en place de la config de la base au niveau de myTinyTodo + +cp ../conf/config.php $final_path/db/config.php + +ynh_replace_string --match_string="__LANGUAGE__" --replace_string="$language" --target_file="$final_path/db/config.php" +ynh_replace_string --match_string="__DB_NAME__" --replace_string="$db_name" --target_file="$final_path/db/config.php" +ynh_replace_string --match_string="__DB_PASSWORD__" --replace_string="$db_pwd" --target_file="$final_path/db/config.php" -# Changement de droits pour que l'utilisateur puisse sauvegarder -# sa configuration dans config.php et les sessions dsans /tmp/sessions +ynh_secure_remove --file="$final_path/setup.php" +ynh_secure_remove --file="$final_path/db/todolist.db" -sudo cp ../conf/config.php $final_path/db/config.php +# #================================================= +# # SECURE FILES AND DIRECTORIES +# #================================================= -sudo rm -f $final_path/setup.php -sudo rm -f $final_path/db/todolist.db +# # Set permissions to app files +chmod 775 $final_path/db/config.php +chmod 775 $final_path/tmp/sessions -sudo chmod o+w $final_path/db/config.php -sudo chmod o+w $final_path/tmp/sessions +# je donne les droits a myTinyTodo sur /var/www/mytinyto/* +chown -R $app: $final_path -# je donne les droits a mytinytodo sur /var/www/mytinyto/* -sudo chown -R $app: $final_path - #================================================= # SETUP SSOWAT #================================================= -ynh_app_setting_set $app unprotected_uris "/" +ynh_script_progression --message="Configuring SSOwat..." --weight=1 -# 0 : pas d'acces publique -# 1 : acces publique autorise - -if [ $is_public -eq 0 ]; +# Make app public if necessary or protect it +if [ $is_public -eq 1 ] then - # Retire l'accès public - ynh_app_setting_delete $app unprotected_uris + ynh_permission_update --permission "main" --add "visitors" fi - + #================================================= # RELOAD NGINX #================================================= - -sudo systemctl reload nginx -sudo yunohost app ssowatconf +ynh_script_progression --message="Reloading NGINX web server..." --weight=1 + +ynh_systemd_action --service_name=nginx --action=reload + +#================================================= +# END OF SCRIPT +#================================================= + +ynh_script_progression --message="Installation of $app completed" --last diff --git a/scripts/remove b/scripts/remove index f45d33d..71e6329 100644 --- a/scripts/remove +++ b/scripts/remove @@ -1,9 +1,7 @@ #!/bin/bash -set -u - #================================================= -# GENERIC STARTING +# GENERIC START #================================================= # IMPORT GENERIC HELPERS #================================================= @@ -14,44 +12,61 @@ source /usr/share/yunohost/helpers #================================================= # LOAD SETTINGS #================================================= +ynh_script_progression --message="Loading installation settings..." --weight=1 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) +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 #================================================= # STANDARD REMOVE #================================================= -# REMOVE DEPENDENCIES +# REMOVE THE MYSQL DATABASE #================================================= +ynh_script_progression --message="Removing the MySQL database..." --weight=1 -# Inutile, car je n'ai rien installe comme outils -# ni de paquets complementaires. -#ynh_remove_app_dependencies +# Remove a database if it exists, along with the associated user +ynh_mysql_remove_db --db_user=$db_user --db_name=$db_name #================================================= -# REMOVE THE SQL BDD +# REMOVE APP MAIN DIR #================================================= +ynh_script_progression --message="Removing app main directory..." --weight=2 -ynh_mysql_remove_db $db_name $db_name # Suppression de la base de donnée et de l'utilisateur associé. +# Remove the app directory securely +ynh_secure_remove --file="$final_path" #================================================= -# REMOVE THE MAIN DIR OF THE APP +# REMOVE NGINX CONFIGURATION #================================================= +ynh_script_progression --message="Removing NGINX web server configuration..." --weight=1 -SECURE_REMOVE '/var/www/$app' # Suppression du dossier de l'application +# Remove the dedicated NGINX config +ynh_remove_nginx_config #================================================= -# REMOVE THE NGINX CONFIGURATION +# REMOVE PHP-FPM CONFIGURATION #================================================= +ynh_script_progression --message="Removing PHP-FPM configuration..." --weight=1 -REMOVE_NGINX_CONF # Suppression de la configuration nginx +# Remove the dedicated PHP-FPM config +ynh_remove_fpm_config #================================================= -# GENERIC FINALISATION +# GENERIC FINALIZATION #================================================= # REMOVE DEDICATED USER #================================================= +ynh_script_progression --message="Removing the dedicated system user..." --weight=1 -ynh_system_user_delete $app +# Delete a system user +ynh_system_user_delete --username=$app + +#================================================= +# END OF SCRIPT +#================================================= + +ynh_script_progression --message="Removal of $app completed" --last diff --git a/scripts/restore b/scripts/restore index 243b8be..d75d17e 100644 --- a/scripts/restore +++ b/scripts/restore @@ -1,96 +1,107 @@ #!/bin/bash -set -eu - #================================================= -# GENERIC STARTING -#================================================= -# MANAGE FAILURE OF THE SCRIPT -#================================================= - +# GENERIC START #================================================= # IMPORT GENERIC HELPERS #================================================= -if [ ! -e _common.sh ]; then - # Rapatrie le fichier de fonctions si il n'est pas dans le dossier courant - sudo cp ../settings/scripts/_common.sh ./_common.sh - sudo chmod a+rx _common.sh -fi - -source _common.sh +source ../settings/scripts/_common.sh source /usr/share/yunohost/helpers -ynh_abort_if_errors # Active trap pour arrêter le script si une erreur est détectée. + +#================================================= +# MANAGE SCRIPT FAILURE +#================================================= + +# Exit if an error occurs during the execution of the script +ynh_abort_if_errors #================================================= # LOAD SETTINGS #================================================= +ynh_script_progression --message="Loading installation settings..." --weight=1 app=$YNH_APP_INSTANCE_NAME -domain=$(ynh_app_setting_get $app domain) -path_url=$(ynh_app_setting_get $app path) -is_public=$(ynh_app_setting_get $app is_public) -language=$(ynh_app_setting_get $app language) -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) +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_user=$db_name +phpversion=$(ynh_app_setting_get --app=$app --key=phpversion) #================================================= # CHECK IF THE APP CAN BE RESTORED #================================================= +ynh_script_progression --message="Validating restoration parameters..." --weight=2 -#sudo yunohost app checkurl "${domain}${path_url}" -a "$app" \ -# || ynh_die "Path not available: ${domain}${path_url}" - -ynh_webpath_register ${app} ${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 RESTORE STEPS +# STANDARD RESTORATION STEPS #================================================= -# RESTORE OF THE NGINX CONFIGURATION +# RESTORE THE NGINX CONFIGURATION #================================================= -conf=/etc/nginx/conf.d/$domain.d/$app.conf -if [ -f $conf ]; then - ynh_die "There is already a nginx conf file at this path: $conf " -fi -sudo cp -a ./nginx.conf $conf +ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" #================================================= -# RESTORE OF THE MAIN DIR OF THE APP +# RESTORE THE APP MAIN DIR #================================================= +ynh_script_progression --message="Restoring the app main directory..." --weight=2 -sudo cp -a ./sources/. $final_path +ynh_restore_file --origin_path="$final_path" #================================================= -# RESTORE OF THE SQL BDD +# RECREATE THE DEDICATED USER #================================================= +ynh_script_progression --message="Recreating the dedicated system user..." --weight=3 -db_pwd=$(ynh_app_setting_get $app mysqlpwd) -ynh_mysql_create_db $db_name $db_name $db_pwd -ynh_mysql_connect_as $db_name $db_pwd $db_name < ./db.sql - -#================================================= -# RECREATE OF THE DEDICATED USER -#================================================= - -ynh_system_user_create $app # Recreate the dedicated user, if not exist +# Create the dedicated user (if not existing) +ynh_system_user_create --username=$app #================================================= # RESTORE USER RIGHTS #================================================= -# Les fichiers appartiennent à l'user wordpress, pour permettre les mises à jour. -sudo chown -R $app: $final_path +chown -R $app: $final_path +chmod 775 $final_path/db/config.php +chmod 775 $final_path/tmp/sessions #================================================= -# GENERIC FINALISATION -#================================================= -# RELOAD NGINX +# RESTORE THE PHP-FPM CONFIGURATION #================================================= -sudo systemctl reload nginx +ynh_restore_file --origin_path="/etc/php/$phpversion/fpm/pool.d/$app.conf" + +# Recreate a dedicated PHP-FPM config +ynh_add_fpm_config --package="$extra_php_dependencies" + +#================================================= +# RESTORE THE MYSQL DATABASE +#================================================= +ynh_script_progression --message="Restoring the MySQL database..." --weight=5 + +db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd) +ynh_mysql_setup_db --db_user=$db_name --db_name=$db_name --db_pwd=$db_pwd +ynh_mysql_connect_as --user=$db_name --password=$db_pwd --database=$db_name < ./db.sql + +#================================================= +# GENERIC FINALIZATION +#================================================= +# RELOAD NGINX AND PHP-FPM +#================================================= +ynh_script_progression --message="Reloading NGINX web server and PHP-FPM..." --weight=2 + +ynh_systemd_action --service_name=php$phpversion-fpm --action=reload +ynh_systemd_action --service_name=nginx --action=reload + +#================================================= +# END OF SCRIPT +#================================================= + +ynh_script_progression --message="Restoration completed for $app" --last diff --git a/scripts/upgrade b/scripts/upgrade index ed40c71..50f390b 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -1,13 +1,7 @@ #!/bin/bash -set -eu - #================================================= -# GENERIC STARTING -#================================================= -# MANAGE FAILURE OF THE SCRIPT -#================================================= - +# GENERIC START #================================================= # IMPORT GENERIC HELPERS #================================================= @@ -15,108 +9,147 @@ set -eu source _common.sh source /usr/share/yunohost/helpers -ynh_abort_if_errors # Active trap pour arrêter le script si une erreur est détectée. - #================================================= # LOAD SETTINGS #================================================= +ynh_script_progression --message="Loading installation settings..." --weight=1 app=$YNH_APP_INSTANCE_NAME -domain=$(ynh_app_setting_get $app domain) -path_url=$(ynh_app_setting_get $app path) -is_public=$(ynh_app_setting_get $app is_public) -language=$(ynh_app_setting_get $app language) -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) +is_public=$(ynh_app_setting_get --app=$app --key=is_public) +language=$(ynh_app_setting_get --app=$app --key=language) +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 +phpversion=$(ynh_app_setting_get --app=$app --key=phpversion) #================================================= -# CHECK IF THE APP CAN BE RESTORED +# CHECK VERSION #================================================= -#sudo yunohost app checkurl "${domain}${path_url}" -a "$app" \ -# || ynh_die "Path not available: ${domain}${path_url}" - -ynh_webpath_register ${app} ${domain} ${path_url} \ - || ynh_die "Path not available: ${domain}${path_url}" - -# Mise en commentaire, c'est une mise a jour, le repertoire -# existe c'est normal, donc le controle n'est pas judicieux. -#test ! -d $final_path \ -# || ynh_die "There is already a directory: $final_path " +upgrade_type=$(ynh_check_app_version_changed) #================================================= -# STANDARD RESTORE STEPS -#================================================= -# RESTORE OF THE NGINX CONFIGURATION +# ENSURE DOWNWARD COMPATIBILITY #================================================= +ynh_script_progression --message="Ensuring downward compatibility..." --weight=1 -#conf=/etc/nginx/conf.d/$domain.d/$app.conf -#if [ -f $conf ]; then -# ynh_die "There is already a nginx conf file at this path: $conf " +# +# N.B. : the followings setting migrations snippets are provided as *EXAMPLES* +# of what you may want to do in some cases (e.g. a setting was not defined on +# some legacy installs and you therefore want to initiaze stuff during upgrade) +# + +# 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 -#sudo cp -a ./nginx.conf $conf #================================================= -# RESTORE OF THE MAIN DIR OF THE APP +# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP +#================================================= +ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --weight=3 + +# Backup the current version of the app +ynh_backup_before_upgrade +ynh_clean_setup () { + # Restore it if the upgrade fails + ynh_restore_upgradebackup +} +# Exit if an error occurs during the execution of the script +ynh_abort_if_errors + +#================================================= +# DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= -# Recuperation du zip contenant les corrections et -# le script de maj de la base -# il faudrait un numero de version pour le script de -# la base. Pour le moment je recupere un fichier sql -# update.sql qui passe dans la version superieur. +if [ "$upgrade_type" == "UPGRADE_APP" ] +then + ynh_script_progression --message="Upgrading source files..." --weight=2 -UPDATE_SOURCE_ZIP + # Create a temporary directory + tmpdir="$(mktemp -d)" + + # Backup the config file in the temp dir + cp -ar "$final_path/db" "$tmpdir/db" + + # Remove the app directory securely + ynh_secure_remove --file="$final_path" + + # Download, check integrity, uncompress and patch the source from app.src + ynh_setup_source --dest_dir="$final_path" + + # Copy the admin saved settings from tmp directory to final path + cp -ar "$tmpdir/db" "$final_path/db" + + # Remove the tmp directory securely + ynh_secure_remove --file="$tmpdir" +fi + +#================================================= +# NGINX CONFIGURATION +#================================================= +ynh_script_progression --message="Upgrading NGINX web server configuration..." --weight=1 + +# Create a dedicated NGINX config +ynh_add_nginx_config + +#================================================= +# CREATE DEDICATED USER +#================================================= +ynh_script_progression --message="Making sure dedicated system user exists..." --weight=1 + +# Create a dedicated user (if not existing) +ynh_system_user_create --username=$app + +#================================================= +# PHP-FPM CONFIGURATION +#================================================= +ynh_script_progression --message="Upgrading PHP-FPM configuration..." --weight=2 + +# Create a dedicated PHP-FPM config +ynh_add_fpm_config #================================================= # RESTORE OF THE SQL BDD #================================================= -db_pwd=$(ynh_app_setting_get $app mysqlpwd) -# il ne faut recreer la base, c'est une maj -#ynh_mysql_create_db $db_name $db_name $db_pwd +# db_pwd=$(ynh_app_setting_get $app mysqlpwd) +# # il ne faut recreer la base, c'est une maj +# #ynh_mysql_create_db $db_name $db_name $db_pwd -# il faut prendre le script de mise a jour -ynh_mysql_connect_as $db_name $db_pwd $db_name < $final_path/db/update.sql - -#================================================= -# RECREATE OF THE DEDICATED USER -#================================================= - -ynh_system_user_create $app # Recreate the dedicated user, if not exist +# # il faut prendre le script de mise a jour +# ynh_mysql_connect_as $db_name $db_pwd $db_name < $final_path/db/update.sql #================================================= # RESTORE USER RIGHTS #================================================= -# Les fichiers appartiennent à l'user wordpress, pour permettre les mises à jour. +ynh_secure_remove --file="$final_path/setup.php" +ynh_secure_remove --file="$final_path/db/todolist.db" -sudo rm -f $final_path/setup.php -sudo rm -f $final_path/db/todolist.db -sudo chmod o+w $final_path/db/config.php -sudo chmod o+w $final_path/tmp/sessions -sudo chown -R $app: $final_path +chmod 775 $final_path/db/config.php +chmod 755 $final_path/tmp/sessions +chown -R $app: $final_path #================================================= -# SETUP SSOWAT +# RELOAD NGINX #================================================= -ynh_app_setting_set $app unprotected_uris "/" +ynh_script_progression --message="Reloading NGINX web server..." --weight=1 -# 0 : pas d'acces publique -# 1 : acces publique autorise - -if [ $is_public -eq 0 ]; -then - # Retire l'accès public - ynh_app_setting_delete $app unprotected_uris -fi +ynh_systemd_action --service_name=nginx --action=reload #================================================= -# GENERIC FINALISATION -#================================================= -# RELOAD NGINX +# END OF SCRIPT #================================================= -sudo systemctl reload nginx -sudo yunohost app ssowatconf +ynh_script_progression --message="Upgrade of $app completed" --last