From b7d2abacc3ba8f8049cbc23b8d1677a3043d63a6 Mon Sep 17 00:00:00 2001 From: Robles Rodolphe Date: Sat, 11 Apr 2020 13:02:18 +0200 Subject: [PATCH] Update to version 0.9.5 with the last commit (#16) * try to update source to 0.9.5 * try to update source to 0.9.5 * refactoring and try to update version * try to debug * try to debug * try to debug * try to debug * try to debug * try to debug * try to debug * try to debug * try to debug * try to debug * try to debug * try to debug * try to debug * try to debug * try to debug * try to debug * try to debug * try to debug * try update garradin * try the upgrade without php7.2 * try to debug * try to debug * try to debug * try to debug * add hooks to copy file config.dist.php in config.local.php with good options * add hooks to copy file config.dist.php in config.local.php with good options * try again to correct values * try again to correct values * try again to correct values * change the upgrade file * change the upgrade file * try to backup sql for the upgrade * try to save sqlite bdd since upgarade * try to save sqlite bdd since upgarade * try to save sqlite bdd since upgarade * make the upgrade with backup of the bdd * syntax error on file backup * syntax error on file backup * change the hook post_upgrade * change the hook post_upgrade * delete folder hooks and update the scripts install and upgrade * correct url for backup file config.local.php * correct url for backup files * correct url for backup files * delete the backup of config.local.php because this file must be edited with this upgrade * delete the backup of config.local.php because this file must be edited with this upgrade * change the script backup * change the script backup * add a missing bracket in script restore * prepare package_check * prepare package_check * delete php.ini not used and add the values (commented) on php_fpm.conf * delete sudo for bash commands * remove file script jenkins * syntax error * try ro change PATH nginx.conf * the garrdin must be insstalled on a sub-domain, back to put the correct path * try to delete slash at the end of PATH in nginx.conf * change path_url in config.local.php for sripts install and upgrade * change also the path for change_url * change also the path for change_url * change also the path for change_url * change also the path for change_url * change also the path for change_url * change also the path for change_url * change also the path for change_url * change also the path for change_url * try to debug upgrade * error syntax * chnage the code in upgrade to look for exist or not file association.bdd * try to debug update script conditions * try change install and update to debug scripts * try to debug update script conditions * try to debug update script conditions * try to debug update script conditions * check_url available for check_package * try to make better check_packages dependencies * try to make better check_packages dependencies * try to make possible install on root path and change url from or to root path * try to make possible install on root path and change url from or to root path * try to make possible install on root path and change url from or to root path * try to make possible install on root path and change url from or to root path * try to make possible install on root path and change url from or to root path * try to make possible install on root path and change url from or to root path * try to make possible install on root path and change url from or to root path * try to make possible install on root path and change url from or to root path * try to make possible install on root path and change url from or to root path * try to make possible install on root path and change url from or to root path * try to make possible install on root path and change url from or to root path * try to make possible install on root path and change url from or to root path * try to make possible install on root path and change url from or to root path * come back to precedent config por nginx * just a test to watch if it is possible like this install on root path * come back to this code, have not found how to install on root path with this version * but back check_up as origin * add a search for nginx.conf * try change nginx.conf and how to add a line on config.local.php * try change nginx.conf and how to add a line on config.local.php * try change nginx.conf * try change nginx.conf * try change nginx.conf * change install * try change nginx.conf * try change nginx.conf * try change nginx.conf * try change nginx.conf * try change nginx.conf * try change nginx.conf * try change nginx.conf * try change nginx.conf * try change nginx.conf * try change nginx.conf * success, change check_path * few change to delete blanks * delete sudo not need on install * comment ynh_delete_file_checksum in common.sh * delete ynh_delete_file_checksum in common.sh * delete sudo on upgrade, no need * put condition in install and update for config.local.php * put condition in install and update for config.local.php * try to save secret key if exist on update * try to save secret key if exist on update * try to save secret key if exist on update * try to save secret key if exist on update * try to keep secret key script on install * back to previous version * try to keep secret key script on install * try to keep secret key script on install * try create secret key script on install * create secret key script on install * put same lenght for secret key then the example in config.dist.php script for install * try to debug slash for root directory in install and upgrade * try to debug slash for root directory in cahnge_url * try to debug slash for root directory in change_url * try to debug slash for root directory in change_url * try to put clean upgrade script * try to debug change_url script * try to debug change_url script * try to debug change_url script * try to debug change_url script * try to debug change_url script * try to debug change_url script * try to debug change_url script * try to debug change_url script * try to debug change_url script * try to debug change_url script * try to debug change_url script * change manifest * change url debug * change Readme * change url debug * change url debug * add a line in config.local.php for domain in change_url script * add a line in config.local.php for domain in change_url script * add a line in config.local.php for domain in change_url script * add a lines for doamin in config.local.php in change_url install and upgrade script * comme back to previous version * sripts modified, try to resolve change url * sripts modified, try to resolve change url * sripts modified, try to resolve change url * sripts modified, try to resolve change url * sripts modified, try to resolve change url * sripts modified, try to resolve change url * sripts modified, try to resolve change url * sripts modified, try to resolve change url * sripts modified, try to resolve change url * sripts modified, try to resolve change url * remove file_checksum md5 not needed * cleaning syntax --- README.md | 10 +-- check_process | 8 +-- conf/app.src | 4 +- conf/nginx.conf | 45 +++++-------- conf/php-fpm.conf | 41 +++++++----- conf/php-fpm.ini | 10 --- manifest.json | 6 +- scripts/_common.sh | 17 ++--- scripts/backup | 37 +++++------ scripts/change_url | 75 +++++++++++++-------- scripts/install | 73 +++++++++++++------- scripts/remove | 20 ++++-- scripts/restore | 57 ++++++++-------- scripts/upgrade | 161 ++++++++++++++++++++++++++++++++------------- 14 files changed, 338 insertions(+), 226 deletions(-) delete mode 100644 conf/php-fpm.ini diff --git a/README.md b/README.md index e074cb9..d4c6a25 100644 --- a/README.md +++ b/README.md @@ -11,17 +11,17 @@ site de garradin : http://garradin.eu [![Integration level](https://dash.yunohost.org/integration/garradin.svg)](https://ci-apps.yunohost.org/jenkins/job/garradin%20%28Community%29/lastBuild/consoleFull)
[![Install Garradin with YunoHost](https://install-app.yunohost.org/install-with-yunohost.png)](https://install-app.yunohost.org/?app=garradin) -## Installation : +## Installation : - CLI `sudo yunohost app install https://github.com/Yunohost-Apps/garradin_ynh` - À travers l'interface d'administration -### TODO list : -- Backup de la base de donnée SQlite (AIDE REQUISE) ? +### TODO list : +- Permissions de certains fichiers sensibles ? -#### Problèmes / Avertissements : -- le système SSO n'est pas implémenté, ni l'installation directe. L'utilisateur admin devra créer son compte avec le formulaire de création de compte qu'il trouvera à la fin de l'installation. Plusieurs raisons m'ont poussé à ne pas implémenter le SSO : +#### Problèmes / Avertissements : +- le système SSO n'est pas implémenté, ni l'installation directe. L'utilisateur admin devra créer son compte avec le formulaire de création de compte qu'il trouvera à la fin de l'installation. Plusieurs raisons m'ont poussé à ne pas implémenter le SSO : - Le SSO n'est pas implémenté dans l'app originale. - Avoir 150+ utilisateurs dans Yunohost n'est pas très pratique, ni très sécurisé, et revient en fin de compte à centraliser les services. - Ce formulaire laisse le choix à l'administrateur de choisir les modalités de création de son compte. On pourrait peut-être me reprocher de ne pas avoir intégré ce formulaire dans le formulaire d'installation que l'utilisateur remplit avant l'installation de ce paquet. Il est vrai que j'aurais pu mettre les ~dix champs qui compose le formulaire de Garradin, mais je ne trouvais pas cela très pratique. diff --git a/check_process b/check_process index 562dcd7..6da1a82 100644 --- a/check_process +++ b/check_process @@ -1,4 +1,4 @@ -;; Test complet +; Test complet ; Manifest domain="domain.tld" (DOMAIN) path="/path" (PATH) @@ -15,16 +15,16 @@ multi_instance=1 incorrect_path=1 port_already_use=0 - change_url=0 + change_url=1 ;;; Levels Level 1=auto Level 2=auto Level 3=auto - Level 4=na + Level 4=na # l'utilisateur est à créer. LDAP non supporté par le paquet de base (obligation d'utiliser de MySql) Level 5=auto Level 6=auto Level 7=auto Level 8=0 Level 9=0 - Level 10=0 + Level 10=0 \ No newline at end of file diff --git a/conf/app.src b/conf/app.src index 3704ec4..e58db5a 100644 --- a/conf/app.src +++ b/conf/app.src @@ -1,5 +1,5 @@ -SOURCE_URL=https://fossil.kd2.org/garradin/uv/garradin-0.9.2.tar.bz2 -SOURCE_SUM=d0a95b0aea2b2001dcd30088f6ebddf65f7a4fce5db2aaa3359c3692b1ded0e9 +SOURCE_URL=https://fossil.kd2.org/garradin/uv/garradin-0.9.5.tar.bz2 +SOURCE_SUM=48f8d62d8c86b3aef2d090b2a7d04873c9642d6efc451389f58a5d6e89d89612 SOURCE_SUM_PRG=sha256sum SOURCE_FORMAT=tar.bz2 SOURCE_IN_SUBDIR=true diff --git a/conf/nginx.conf b/conf/nginx.conf index 24b6b95..8328b41 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -1,38 +1,27 @@ location __PATH__ { - # Path to source - alias __FINALPATH__/www/ ; +# Path to source +alias __FINALPATH__/www/ ; - if ($scheme = http) { +if ($scheme = http) { rewrite ^ https://$server_name$request_uri? permanent; - } +} - # Example PHP configuration (remove if not used) - index index.php; + # Example PHP configuration (remove if not used) + index index.php /_route.php; + try_files $uri $uri/ index.php /_route.php; - # Common parameter to increase upload size limit in conjuction with dedicated php-fpm file - #client_max_body_size 50M; - - try_files $uri $uri/ index.php; - location ~ [^/]\.php(/|$) { - fastcgi_split_path_info ^(.+?\.php)(/.*)$; - fastcgi_pass unix:/var/run/php5-fpm-__NAME__.sock; - - # If you don't use a dedicated fpm config for your app, - # use a general fpm pool. - # This is to be used INSTEAD of line above - # Don't forget to adjust scripts install/upgrade/remove/backup accordingly - # - #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; - } +location ~ [^/]\.php(/|$) { + fastcgi_split_path_info ^(.+?\.php)(/.*)$; + fastcgi_pass unix:/var/run/php/php7.0-fpm-__NAME__.sock; + fastcgi_index index.php; + include fastcgi_params; + fastcgi_param REMOTE_USER $remote_user; + fastcgi_param PATH_INFO $fastcgi_path_info; + fastcgi_param SCRIPT_FILENAME $request_filename; +} # PHP configuration end # Include SSOWAT user panel. include conf.d/yunohost_panel.conf.inc; -} +} \ No newline at end of file diff --git a/conf/php-fpm.conf b/conf/php-fpm.conf index 8affbc2..3f4bc72 100644 --- a/conf/php-fpm.conf +++ b/conf/php-fpm.conf @@ -30,7 +30,7 @@ group = __USER__ ; specific port; ; '/path/to/unix/socket' - to listen on a unix socket. ; Note: This value is mandatory. -listen = /var/run/php5-fpm-__NAMETOCHANGE__.sock +listen = /var/run/php/php7.0-fpm-__NAMETOCHANGE__.sock ; Set listen(2) backlog. A value of '-1' means unlimited. ; Default Value: 128 (-1 on FreeBSD and OpenBSD) @@ -38,13 +38,13 @@ listen = /var/run/php5-fpm-__NAMETOCHANGE__.sock ; Set permissions for unix socket, if one is used. In Linux, read/write ; permissions must be set in order to allow connections from a web server. Many -; BSD-derived systems allow connections regardless of permissions. +; BSD-derived systems allow connections regardless of permissions. ; Default Values: user and group are set as the running user ; mode is set to 0660 listen.owner = www-data listen.group = www-data ;listen.mode = 0660 - + ; List of ipv4 addresses of FastCGI clients which are allowed to connect. ; 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 @@ -117,7 +117,7 @@ pm.max_spare_servers = 3 ; Note: Used only when pm is set to 'ondemand' ; Default Value: 10s ;pm.process_idle_timeout = 10s; - + ; The number of requests each child process should execute before respawning. ; This can be useful to work around memory leaks in 3rd party libraries. For ; endless request processing specify '0'. Equivalent to PHP_FCGI_MAX_REQUESTS. @@ -170,7 +170,7 @@ pm.max_requests = 500 ; ; By default the status page only outputs short status. Passing 'full' in the ; query string will also return status for each pool process. -; Example: +; Example: ; http://www.foo.bar/status?full ; http://www.foo.bar/status?json&full ; http://www.foo.bar/status?html&full @@ -283,7 +283,7 @@ pm.max_requests = 500 ; - .... ; %p: PID of the child that serviced the request ; %P: PID of the parent of the child that serviced the request -; %q: the query string +; %q: the query string ; %Q: the '?' character if query string exists ; %r: the request URI (without the query string, see %q and %Q) ; %R: remote IP address @@ -298,40 +298,40 @@ pm.max_requests = 500 ; ; Default: "%R - %u %t \"%m %r\" %s" ;access.format = "%R - %u %t \"%m %r%Q%q\" %s %f %{mili}d %{kilo}M %C%%" - + ; The log file for slow requests ; Default Value: not set ; Note: slowlog is mandatory if request_slowlog_timeout is set slowlog = /var/log/nginx/__NAMETOCHANGE__.slow.log - + ; 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 - + ; The timeout for serving a single request after which the worker process will ; be killed. This option should be used when the 'max_execution_time' ini option ; does not stop script execution for some reason. A value of '0' means 'off'. ; Available units: s(econds)(default), m(inutes), h(ours), or d(ays) ; Default Value: 0 request_terminate_timeout = 1d - + ; Set open file descriptor rlimit. ; Default Value: system defined value ;rlimit_files = 1024 - + ; Set max core size rlimit. ; Possible Values: 'unlimited' or an integer greater or equal to 0 ; Default Value: system defined value ;rlimit_core = 0 - + ; Chroot to this directory at the start. This value must be defined as an ; absolute path. When this value is not set, chroot is not used. ; Note: you can prefix with '$prefix' to chroot to the pool prefix or one ; of its subdirectories. If the pool prefix is not set, the global prefix ; will be used instead. -; Note: chrooting is a great security feature and should be used whenever +; Note: chrooting is a great security feature and should be used whenever ; possible. However, all PHP paths will be relative to the chroot ; (error_log, sessions.save_path, ...). ; Default Value: not set @@ -356,7 +356,7 @@ catch_workers_output = yes ; Note: set an empty value to allow all extensions. ; Default Value: .php ;security.limit_extensions = .php .php3 .php4 .php5 - + ; Pass environment variables like LD_LIBRARY_PATH. All $VARIABLEs are taken from ; the current environment. ; Default Value: clean env @@ -370,7 +370,7 @@ catch_workers_output = yes ; overwrite the values previously defined in the php.ini. The directives are the ; same as the PHP SAPI: ; php_value/php_flag - you can set classic ini defines which can -; be overwritten from PHP call 'ini_set'. +; be overwritten from PHP call 'ini_set'. ; php_admin_value/php_admin_flag - these directives won't be overwritten by ; PHP call 'ini_set' ; For php_*flag, valid values are on, off, 1, 0, true, false, yes or no. @@ -390,3 +390,14 @@ catch_workers_output = yes ;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_value[upload_max_filesize] = 50M +; php_value[post_max_size] = 50M +; php_valuemail.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 \ No newline at end of file diff --git a/conf/php-fpm.ini b/conf/php-fpm.ini deleted file mode 100644 index 5c27d59..0000000 --- a/conf/php-fpm.ini +++ /dev/null @@ -1,10 +0,0 @@ -; Common values to change to increase file upload limit -; upload_max_filesize = 50M -; post_max_size = 50M -; mail.add_x_header = Off - -; Other common parameters -; max_execution_time = 600 -; max_input_time = 300 -; memory_limit = 256M -; short_open_tag = On diff --git a/manifest.json b/manifest.json index fe81f6c..46f61bf 100644 --- a/manifest.json +++ b/manifest.json @@ -3,13 +3,13 @@ "id": "garradin", "packaging_format": 1, "requirements": { - "yunohost": ">= 2.7.2" + "yunohost": ">=3.5.0" }, "description": { "en": "Software to manage association", "fr": "Logiciel libre de gestion d'association" }, - "version": "0.9.2~ynh1", + "version": "0.9.5~ynh3", "url": "http://garradin.eu/a-propos/", "license": "GPL-3.0-or-later", "maintainer": { @@ -19,7 +19,7 @@ "multi_instance": true, "services": [ "nginx", - "php5-fpm" + "php7.0-fpm" ], "arguments": { "install" : [ diff --git a/scripts/_common.sh b/scripts/_common.sh index 24bd7ba..6248f06 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -1,13 +1,10 @@ #!/bin/bash +#================================================= +# COMMON VARIABLES +#================================================= + +# dependencies used by the app +pkg_dependencies="php7.0-sqlite3" + # ============= FUTURE YUNOHOST HELPER ============= -# Delete a file checksum from the app settings -# -# $app should be defined when calling this helper -# -# usage: ynh_remove_file_checksum file -# | arg: file - The file for which the checksum will be deleted -ynh_delete_file_checksum () { - local checksum_setting_name=checksum_${1//[\/ ]/_} # Replace all '/' and ' ' by '_' - ynh_app_setting_delete $app $checksum_setting_name -} diff --git a/scripts/backup b/scripts/backup index 7b2dac6..27102aa 100644 --- a/scripts/backup +++ b/scripts/backup @@ -6,12 +6,8 @@ # 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 #================================================= @@ -24,40 +20,37 @@ ynh_abort_if_errors #================================================= # LOAD SETTINGS #================================================= +ynh_script_progression --message="Loading installation settings..." --time --weight=1 app=$YNH_APP_INSTANCE_NAME -final_path=$(ynh_app_setting_get $app final_path) -domain=$(ynh_app_setting_get $app domain) +final_path=$(ynh_app_setting_get --app=$app --key=final_path) +domain=$(ynh_app_setting_get --app=$app --key=domain) #================================================= # STANDARD BACKUP STEPS #================================================= # BACKUP THE APP MAIN DIR #================================================= +ynh_script_progression --message="Backing up the main app directory..." --time --weight=1 -ynh_backup "$final_path" +ynh_backup --src_path="$final_path" #================================================= # BACKUP THE NGINX CONFIGURATION #================================================= +ynh_script_progression --message="Backing up nginx web server configuration..." --time --weight=1 -ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf" +ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf" #================================================= # BACKUP THE PHP-FPM CONFIGURATION #================================================= +ynh_script_progression --message="Backing up php-fpm configuration..." --time --weight=1 -ynh_backup "/etc/php5/fpm/pool.d/$app.conf" -ynh_backup "/etc/php5/fpm/conf.d/20-$app.ini" +ynh_backup --src_path="/etc/php/7.0/fpm/pool.d/$app.conf" -# Backup directory location for the app from where the script is executed and -# which will be compressed afterward -backup_dir=$YNH_APP_BACKUP_DIR - -# Backup sources & data -ynh_backup "/var/www/$app" "sources" - -# Copy Nginx conf -sudo mkdir -p ./conf -ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf" "conf/nginx.conf" +#================================================= +# END OF SCRIPT +#================================================= +ynh_script_progression --message="Backup script completed for $app. (YunoHost will then actually copy those files to the archive)." --time --last diff --git a/scripts/change_url b/scripts/change_url index 4972ad6..7244972 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -22,28 +22,34 @@ new_path=$YNH_APP_NEW_PATH app=$YNH_APP_INSTANCE_NAME #================================================= -# CHECK THE SYNTAX OF THE PATHS +# LOAD SETTINGS #================================================= +ynh_script_progression --message="Loading installation settings..." --time --weight=1 -test -n "$old_path" || old_path="/" -test -n "$new_path" || new_path="/" -new_path=$(ynh_normalize_url_path $new_path) -old_path=$(ynh_normalize_url_path $old_path) +# Needed for helper "ynh_add_nginx_config" +final_path=$(ynh_app_setting_get --app=$app --key=final_path) + +# #================================================= +# # CHECK THE SYNTAX OF THE PATHS +# #================================================= + +# test -n "$old_path" || old_path="/" +# test -n "$new_path" || new_path="/" +# new_path=$(ynh_normalize_url_path $new_path) +# old_path=$(ynh_normalize_url_path $old_path) #================================================= # CHECK WHICH PARTS SHOULD BE CHANGED #================================================= change_domain=0 -if [ "$old_domain" != "$new_domain" ] -then - change_domain=1 +if [ "$old_domain" != "$new_domain" ]; then + change_domain=1 fi change_path=0 -if [ "$old_path" != "$new_path" ] -then - change_path=1 +if [ "$old_path" != "$new_path" ]; then + change_path=1 fi #================================================= @@ -51,31 +57,38 @@ fi #================================================= # MODIFY URL IN NGINX CONF #================================================= - +ynh_script_progression --message="Updating nginx web server configuration..." --time --weight=1 nginx_conf_path=/etc/nginx/conf.d/$old_domain.d/$app.conf +final_path=/var/www/$app # Change the path in the nginx config file if [ $change_path -eq 1 ] then # Make a backup of the original nginx config file if modified - ynh_backup_if_checksum_is_different "$nginx_conf_path" - # Replace locations starting with old_path - # Look for every location possible patterns (see https://nginx.org/en/docs/http/ngx_http_core_module.html#location) - ynh_replace_string "location\( \(=\|~\|~\*\|\^~\)\)\? $old_path" "location\1 $new_path" "$nginx_conf_path" - # Replace path in "return" directives - ynh_replace_string "return \([[:digit:]]\{3\}\) $old_path" "return \1 $new_path" "$nginx_conf_path" - # Calculate and store the nginx config file checksum - ynh_store_file_checksum "$nginx_conf_path" + ynh_backup_if_checksum_is_different --file="$nginx_conf_path" + # Set global variables for nginx helper + domain="$old_domain" + path_url="$new_path" + # Create a dedicated nginx config + ynh_add_nginx_config +fi + +# change the config.local.conf +if [ $change_path -eq 1 ] && [ "$new_path" == "/" ]; then + ynh_replace_string --match_string="const WWW_URI = '$old_path/';" --replace_string="const WWW_URI = '$new_path';" --target_file="$final_path/config.local.php" +elif [ $change_path -eq 1 ] && [ "$old_path" == "/" ]; then + ynh_replace_string --match_string="const WWW_URI = '$old_path';" --replace_string="const WWW_URI = '$new_path/';" --target_file="$final_path/config.local.php" +else [ $change_path -eq 1 ] + ynh_replace_string --match_string="const WWW_URI = '$old_path/';" --replace_string="const WWW_URI = '$new_path/';" --target_file="$final_path/config.local.php" fi # Change the domain for nginx -if [ $change_domain -eq 1 ] -then +if [ $change_domain -eq 1 ]; then # Delete file checksum for the old conf file location - ynh_delete_file_checksum "$nginx_conf_path" - mv $nginx_conf_path /etc/nginx/conf.d/$new_domain.d/$app.conf + ynh_delete_file_checksum --file="$nginx_conf_path" + mv $nginx_conf_path /etc/nginx/conf.d/$new_domain.d/$app.conf # Store file checksum for the new config file location - ynh_store_file_checksum "/etc/nginx/conf.d/$new_domain.d/$app.conf" + #ynh_store_file_checksum --file="/etc/nginx/conf.d/$new_domain.d/$app.conf" fi #================================================= @@ -83,5 +96,15 @@ fi #================================================= # RELOAD NGINX #================================================= +ynh_script_progression --message="Reloading nginx web server..." --time --weight=1 -systemctl reload nginx +ynh_systemd_action --service_name=nginx --action=reload + +#================================================= +# last configuration +#================================================= +#================================================= +# END OF SCRIPT +#================================================= + +ynh_script_progression --message="Change of URL completed for $app" --time --last \ No newline at end of file diff --git a/scripts/install b/scripts/install index 908093e..744f84c 100644 --- a/scripts/install +++ b/scripts/install @@ -29,6 +29,7 @@ app=$YNH_APP_INSTANCE_NAME #================================================= # CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS #================================================= +ynh_script_progression --message="Validating installation parameters..." --time --weight=1 final_path=/var/www/$app test ! -e "$final_path" || ynh_die "This path already contains a folder" @@ -39,59 +40,57 @@ 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 +ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url #================================================= # STORE SETTINGS FROM MANIFEST #================================================= +ynh_script_progression --message="Storing installation settings..." --time --weight=1 -ynh_app_setting_set $app path_url $path_url -ynh_app_setting_set $app domain $domain -ynh_app_setting_set $app is_public $is_public +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 #================================================= # Install dependency to convert tracks to a readable format for the browser #================================================= +ynh_script_progression --message="Installing dependencies..." --time --weight=1 -if [ "$(lsb_release --codename --short)" != "jessie" ] +if [ "$(lsb_release --codename --short)" != "jessie" ] then - ynh_install_app_dependencies php-sqlite3 + ynh_install_app_dependencies $pkg_dependencies else - ynh_install_app_dependencies php5-sqlite + ynh_die --message="Votre version de Debian n'est pas compatible..." --time --weight=1 fi #================================================= # CREATE DEDICATED USER #================================================= - +ynh_script_progression --message="Configuring system user..." --time --weight=1 # Create a system user -ynh_system_user_create $app +ynh_system_user_create --username=$app #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= +ynh_script_progression --message="Setting up source files..." --time --weight=1 -ynh_app_setting_set $app final_path $final_path +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" -#================================================= -# Files owned by user app -#================================================= - -sudo chown $app:$app $final_path -R -sudo chmod 755 $final_path -R #================================================= # NGINX CONFIGURATION #================================================= - +ynh_script_progression --message="Configuring nginx web server..." --time --weight=1 # Create a dedicated nginx config ynh_add_nginx_config #================================================= # PHP-FPM CONFIGURATION #================================================= +ynh_script_progression --message="Configuring php-fpm..." --time --weight=1 # Create a dedicated php-fpm config ynh_add_fpm_config @@ -99,20 +98,50 @@ ynh_add_fpm_config #================================================= # SETUP SSOWAT #================================================= +ynh_script_progression --message="Configuring SSOwat..." --time --weight=1 if [ $is_public -eq 0 ] -then # Remove the public access - ynh_app_setting_delete $app skipped_uris +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 "/" + # unprotected_uris allows SSO credentials to be passed anyway. + ynh_app_setting_set --app=$app --key=unprotected_uris --value="/" fi #================================================= # RELOAD NGINX #================================================= +ynh_script_progression --message="Reloading nginx web server..." --time --weight=1 systemctl reload nginx + +#================================================= +# MODIFY A CONFIG FILE +#================================================= +# copy config.dist.php creating config.local.php +cp -a $final_path/config.dist.php $final_path/config.local.php +# create a key for the secret key CSFR; +key=$(ynh_string_random --length=50) +# edit config.local.php +ynh_replace_string --match_string="const SECRET_KEY = '3xUhIgGwuovRKOjVsVPQ5yUMfXUSIOX2GKzcebsz5OINrYC50r';" --replace_string="const SECRET_KEY = '$key';" --target_file="$final_path/config.local.php" +if [ "$path_url" == "/" ]; then + ynh_replace_string --match_string="//const WWW_URI = '/asso/';" --replace_string="const WWW_URI = '$path_url';" --target_file="$final_path/config.local.php" +else + ynh_replace_string --match_string="//const WWW_URI = '/asso/';" --replace_string="const WWW_URI = '$path_url/';" --target_file="$final_path/config.local.php" +fi + +#================================================= +# Files owned by user app +#================================================= + +chown $app:$app $final_path -R +chmod 755 $final_path -R + +#================================================= +# END OF SCRIPT +#================================================= + +ynh_script_progression --message="Installation of $app completed" --time --last \ No newline at end of file diff --git a/scripts/remove b/scripts/remove index 537c7fc..aac63fd 100644 --- a/scripts/remove +++ b/scripts/remove @@ -12,15 +12,17 @@ source /usr/share/yunohost/helpers #================================================= # LOAD SETTINGS #================================================= +ynh_script_progression --message="Loading installation settings..." --time --weight=1 app=$YNH_APP_INSTANCE_NAME -domain=$(ynh_app_setting_get $app domain) -final_path=$(ynh_app_setting_get $app final_path) +domain=$(ynh_app_setting_get --app=$app --key=domain) +final_path=$(ynh_app_setting_get --app=$app --key=final_path) #================================================= # REMOVE DEPENDENCIES #================================================= +ynh_script_progression --message="Removing dependencies..." --time --weight=1 # Remove metapackage and its dependencies ynh_remove_app_dependencies @@ -28,13 +30,15 @@ ynh_remove_app_dependencies #================================================= # REMOVE APP MAIN DIR #================================================= +ynh_script_progression --message="Removing app main directory..." --time --weight=1 # 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..." --time --weight=1 # Remove the dedicated nginx config ynh_remove_nginx_config @@ -42,6 +46,7 @@ ynh_remove_nginx_config #================================================= # REMOVE PHP-FPM CONFIGURATION #================================================= +ynh_script_progression --message="Removing php-fpm configuration..." --time --weight=1 # Remove the dedicated php-fpm config ynh_remove_fpm_config @@ -51,6 +56,13 @@ ynh_remove_fpm_config #================================================= # REMOVE DEDICATED USER #================================================= +ynh_script_progression --message="Removing the dedicated system user..." --time --weight=1 # Delete a system user -ynh_system_user_delete $app +ynh_system_user_delete --username=$app + +#================================================= +# END OF SCRIPT +#================================================= + +ynh_script_progression --message="Removal of $app completed" --time --last \ No newline at end of file diff --git a/scripts/restore b/scripts/restore index 043dfe2..53d9726 100644 --- a/scripts/restore +++ b/scripts/restore @@ -6,12 +6,8 @@ # 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 #================================================= @@ -24,16 +20,18 @@ ynh_abort_if_errors #================================================= # LOAD SETTINGS #================================================= +ynh_script_progression --message="Loading settings..." --time --weight=1 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) +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) #================================================= # CHECK IF THE APP CAN BE RESTORED #================================================= +ynh_script_progression --message="Validating restoration parameters..." --time --weight=1 ynh_webpath_available $domain $path_url \ || ynh_die "Path not available: ${domain}${path_url}" @@ -51,15 +49,17 @@ ynh_restore_file "/etc/nginx/conf.d/$domain.d/$app.conf" #================================================= # RESTORE THE APP MAIN DIR #================================================= +ynh_script_progression --message="Restoring the app main directory..." --time --weight=1 ynh_restore_file "$final_path" #================================================= # RECREATE THE DEDICATED USER #================================================= +ynh_script_progression --message="Recreating the dedicated system user..." --time --weight=1 # Create the dedicated user (if not existing) -ynh_system_user_create $app +ynh_system_user_create --username=$app #================================================= # RESTORE USER RIGHTS @@ -71,37 +71,32 @@ chown -R $app:$app $final_path #================================================= # RESTORE THE PHP-FPM CONFIGURATION #================================================= -if [ "$(lsb_release --codename --short)" != "jessie" ] -then - ynh_restore_file "/etc/php/7.0/fpm/pool.d/$app.conf" - ynh_restore_file "/etc/php/7.0/fpm/conf.d/20-$app.ini" -else - ynh_restore_file "/etc/php5/fpm/pool.d/$app.conf" - ynh_restore_file "/etc/php5/fpm/conf.d/20-$app.ini" -fi +ynh_script_progression --message="Restore php-fpm configuration..." --time --weight=1 + +ynh_restore_file --origin_path="/etc/php/7.0/fpm/pool.d/$app.conf" #================================================= # SPECIFIC RESTORATION #================================================= # REINSTALL DEPENDENCIES #================================================= +ynh_script_progression --message="Reinstalling dependencies..." --time --weight=1 -if [ "$(lsb_release --codename --short)" != "jessie" ] -then - ynh_install_app_dependencies php7.0-sqlite3 -else - ynh_install_app_dependencies php5-sqlite -fi +# Define and install dependencies +ynh_install_app_dependencies $pkg_dependencies #================================================= # GENERIC FINALIZATION #================================================= # RELOAD NGINX AND PHP-FPM #================================================= -if [ "$(lsb_release --codename --short)" != "jessie" ] -then - systemctl reload php7.0-fpm -else - systemctl reload php5-fpm -fi -systemctl reload nginx +ynh_script_progression --message="Reloading nginx web server and php-fpm..." --time --weight=1 + +ynh_systemd_action --service_name=php7.0-fpm --action=reload +ynh_systemd_action --service_name=nginx --action=reload + +#================================================= +# END OF SCRIPT +#================================================= + +ynh_script_progression --message="Restoration completed for $app" --time --last \ No newline at end of file diff --git a/scripts/upgrade b/scripts/upgrade index 8490bf5..eaeffbf 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -12,35 +12,66 @@ source /usr/share/yunohost/helpers #================================================= # LOAD SETTINGS #================================================= +ynh_script_progression --message="Loading installation settings..." --time --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) +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) || ynh_die "This path already contains a folder" +#================================================= +# CHECK VERSION +#================================================= + +### This helper will compare the version of the currently installed app and the version of the upstream package. +### $upgrade_type can have 2 different values +### - UPGRADE_APP if the upstream app version has changed +### - UPGRADE_PACKAGE if only the YunoHost package has changed +### ynh_check_app_version_changed will stop the upgrade if the app is up to date. +### UPGRADE_APP should be used to upgrade the core app only if there's an upgrade to do. +upgrade_type=$(ynh_check_app_version_changed) #================================================= # ENSURE DOWNWARD COMPATIBILITY #================================================= +ynh_script_progression --message="Ensuring downward compatibility..." --time --weight=1 # Fix is_public as a boolean value if [ "$is_public" = "Yes" ]; then - ynh_app_setting_set $app is_public 1 + 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 final_path doesn't exist, create it -if [ -z $final_path ]; then - final_path=/var/www/$app - ynh_app_setting_set $app final_path $final_path +if [ -z "$final_path" ]; then + final_path=/var/www/$app + ynh_app_setting_set --app=$app --key=final_path --value=$final_path +fi + +#================================================= +# Backup Data +#================================================= +ynh_script_progression --message="Backing up the data before upgrading (may take a while)..." --time --weight=1 + +bdd=$final_path/association.sqlite +squelettes=$final_path/www/squelettes + +if [ -d "$squelettes" ]; then + cp -ar $squelettes /tmp/squelettes +fi + +if [ -e "$bdd" ]; then + cp -a $bdd /tmp/association.sqlite fi #================================================= # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP #================================================= +ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --time --weight=1 # Backup the current version of the app ynh_backup_before_upgrade @@ -51,80 +82,122 @@ ynh_clean_setup () { # Exit if an error occurs during the execution of the script ynh_abort_if_errors -#================================================= -# Install dependency to convert tracks to a readable format for the browser -#================================================= - -if [ "$(lsb_release --codename --short)" != "jessie" ] -then - ynh_install_app_dependencies php-sqlite3 -else - ynh_install_app_dependencies php5-sqlite -fi - -#================================================= -# CHECK THE PATH -#================================================= +# #================================================= +# # CHECK THE PATH +# #================================================= # Normalize the URL path syntax -path_url=$(ynh_normalize_url_path $path_url) +# N.B. : this is for app installations before YunoHost 2.7 +# where this value might be something like /foo/ or foo/ +# instead of /foo .... +# If nobody installed your app before 2.7, then you may +# safely remove this line +path_url=$(ynh_normalize_url_path --path_url=$path_url) -#================================================= -# STANDARD UPGRADE STEPS #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= +ynh_script_progression --message="Upgrading source files..." --time --weight=1 + +if [ "$upgrade_type" == "UPGRADE_APP" ] +then + # Download, check integrity, uncompress and patch the source from app.src + ynh_setup_source --dest_dir="$final_path" +fi + +#================================================= +# UPGRADE DEPENDENCIES +#================================================= +ynh_script_progression --message="Upgrading dependencies..." --time --weight=1 + +ynh_install_app_dependencies $pkg_dependencies + +#================================================= +# CREATE DEDICATED USER +#================================================= +ynh_script_progression --message="Making sure dedicated system user exists..." --time --weight=1 + +# Create a dedicated user (if not existing) +ynh_system_user_create --username=$app -# Download, check integrity, uncompress and patch the source from app.src -ynh_setup_source "$final_path" #================================================= # NGINX CONFIGURATION #================================================= +ynh_script_progression --message="Upgrading nginx web server configuration..." --time --weight=1 # Create a dedicated nginx config ynh_add_nginx_config -#================================================= -# CREATE DEDICATED USER -#================================================= - -# Create a system user -ynh_system_user_create $app - #================================================= # PHP-FPM CONFIGURATION #================================================= +ynh_script_progression --message="Upgrading php-fpm configuration..." --time --weight=1 # Create a dedicated php-fpm config ynh_add_fpm_config #================================================= -# GENERIC FINALIZATION +# Change options in file config.dist.php +# and copy in local.dist.php #================================================= -# SECURE FILES AND DIRECTORIES +ynh_script_progression --message="final configuration needed..." --time --weight=1 + +key=$(ynh_string_random --length=50) +cp -a $final_path/config.dist.php $final_path/config.local.php +ynh_replace_string --match_string="const SECRET_KEY = '3xUhIgGwuovRKOjVsVPQ5yUMfXUSIOX2GKzcebsz5OINrYC50r';" --replace_string="const SECRET_KEY = '$key';" --target_file="$final_path/config.local.php" +if [ "$path_url" == "/" ] +then + ynh_replace_string --match_string="//const WWW_URI = '/asso/';" --replace_string="const WWW_URI = '$path_url';" --target_file="$final_path/config.local.php" +else + ynh_replace_string --match_string="//const WWW_URI = '/asso/';" --replace_string="const WWW_URI = '$path_url/';" --target_file="$final_path/config.local.php" +fi +#======================================================= +# backup bdd, squelettes directory and config.local.php +#======================================================= +ynh_script_progression --message="restore data..." --time --weight=1 + +backup_bdd=/tmp/association.sqlite +backup_squelettes=/tmp/squelettes + +if [ -d "$backup_squelettes" ] +then + cp -ar $backup_squelettes $final_path/www/squelettes +fi + +if [ -e "$backup_bdd" ] +then + cp -a $backup_bdd $final_path/association.sqlite +fi + +#================================================= +# Files owned by user app #================================================= -# Set right permissions for curl installation -chown -R $app:$app $final_path +# Set permissions on app files +chown $app:$app $final_path -R +chmod 755 $final_path -R #================================================= # SETUP SSOWAT #================================================= +ynh_script_progression --message="Upgrading SSOwat configuration..." --time --weight=1 -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..." --time --weight=1 -systemctl reload nginx +ynh_systemd_action --service_name=nginx --action=reload + +#================================================= +# END OF SCRIPT +#================================================= +ynh_script_progression --message="Upgrade of $app completed" --time --last \ No newline at end of file