From 23111f726bed9dac4f358599190ed155917c6c04 Mon Sep 17 00:00:00 2001 From: Jimmy Monin Date: Sun, 27 May 2018 13:00:46 +0200 Subject: [PATCH 1/6] Use core functionality (since 2.7.12) to avoid backing up large data prior to upgrades. By the way, don't check free space as the core already does that. --- scripts/_common.sh | 22 ---------------------- scripts/backup | 5 +++-- 2 files changed, 3 insertions(+), 24 deletions(-) diff --git a/scripts/_common.sh b/scripts/_common.sh index 9ae8228..a9bf588 100755 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -1,23 +1 @@ #!/bin/bash - -#================================================= -# BACKUP -#================================================= - -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=$(du --summarize "$file_to_analyse" | cut -f1) - free_space=$(df --output=avail "/home/yunohost.backup" | sed 1d) - - if [ $free_space -le $backup_size ] - then - echo "Espace insuffisant pour sauvegarder $file_to_analyse." >&2 - echo "Espace disponible: $(HUMAN_SIZE $free_space)" >&2 - ynh_die "Espace nécessaire: $(HUMAN_SIZE $backup_size)" - fi -} diff --git a/scripts/backup b/scripts/backup index ba76507..d71c4f2 100644 --- a/scripts/backup +++ b/scripts/backup @@ -42,8 +42,9 @@ ynh_backup "$final_path" # BACKUP OF THE DATA DIR #================================================= -CHECK_SIZE "/home/yunohost.app/$app" -ynh_backup "/home/yunohost.app/$app" +# The 1 parameter indicates the directory is "big", +# so that it won't be backed up before upgrade +ynh_backup "/home/yunohost.app/$app" 1 #================================================= # BACKUP OF THE NGINX CONFIGURATION From e14d49247810d8e193131e0a0f70f0cbfd89e278 Mon Sep 17 00:00:00 2001 From: Jimmy Monin Date: Sun, 27 May 2018 13:07:09 +0200 Subject: [PATCH 2/6] Fix linter errors --- manifest.json | 6 +++--- scripts/backup | 16 +++++++--------- scripts/restore | 16 +++++++--------- 3 files changed, 17 insertions(+), 21 deletions(-) diff --git a/manifest.json b/manifest.json index dddcd71..947f5bd 100644 --- a/manifest.json +++ b/manifest.json @@ -3,15 +3,15 @@ "id": "jirafeau", "packaging_format": 1, "requirements": { - "yunohost": ">= 2.4.0" + "yunohost": ">= 2.7.12" }, "description": { "en": "Upload a file in a simple way and give a unique link to it", "fr": "Hébergez simplement un fichier et partagez-le avec un lien unique" }, "url": "https://gitlab.com/mojo42/Jirafeau", - "version": "3.4.1~ynh1", - "license": "AGPLv3", + "version": "3.4.1~ynh2", + "license": "AGPL-3.0-only", "maintainer": { "name": "julien", "email": "julien.malik@paraiso.me" diff --git a/scripts/backup b/scripts/backup index d71c4f2..3c83d69 100644 --- a/scripts/backup +++ b/scripts/backup @@ -1,14 +1,5 @@ #!/bin/bash -#================================================= -# GENERIC STARTING -#================================================= -# MANAGE FAILURE OF THE SCRIPT -#================================================= - -# Exit on command errors and treat unset variables as an error -set -eu - #================================================= # IMPORT GENERIC HELPERS #================================================= @@ -21,6 +12,13 @@ fi source _common.sh source /usr/share/yunohost/helpers +#================================================= +# MANAGE SCRIPT FAILURE +#================================================= + +# Exit if an error occurs during the execution of the script +ynh_abort_if_errors + #================================================= # LOAD SETTINGS #================================================= diff --git a/scripts/restore b/scripts/restore index 6b84bbb..4d7ccd3 100644 --- a/scripts/restore +++ b/scripts/restore @@ -1,14 +1,5 @@ #!/bin/bash -#================================================= -# GENERIC STARTING -#================================================= -# MANAGE FAILURE OF THE SCRIPT -#================================================= - -# Exit on command errors and treat unset variables as an error -set -eu - #================================================= # IMPORT GENERIC HELPERS #================================================= @@ -21,6 +12,13 @@ set -eu # source _common.sh source /usr/share/yunohost/helpers +#================================================= +# MANAGE SCRIPT FAILURE +#================================================= + +# Exit if an error occurs during the execution of the script +ynh_abort_if_errors + #================================================= # LOAD SETTINGS #================================================= From fd197b87120434a31332908b9309ccfbb4675329 Mon Sep 17 00:00:00 2001 From: Jimmy Monin Date: Sun, 27 May 2018 16:50:30 +0200 Subject: [PATCH 3/6] Fix alias traversal bug --- conf/nginx.conf | 3 ++- scripts/install | 5 +++++ scripts/upgrade | 5 +++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/conf/nginx.conf b/conf/nginx.conf index 4ea1cfc..04ae035 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -1,4 +1,5 @@ -location __PATH__ { +#sub_path_only rewrite ^__PATH__$ __PATH__/ permanent; +location __PATH__/ { alias __FINALPATH__/ ; if ($scheme = http) { rewrite ^ https://$server_name$request_uri? permanent; diff --git a/scripts/install b/scripts/install index c77a41c..1237815 100755 --- a/scripts/install +++ b/scripts/install @@ -66,6 +66,11 @@ ynh_setup_source "$final_path" # Télécharge la source, décompresse et copie d # Create a dedicated nginx config ynh_add_nginx_config +if [ "$path_url" != "/" ] +then + ynh_replace_string "^#sub_path_only" "" "/etc/nginx/conf.d/$domain.d/$app.conf" +fi +ynh_store_file_checksum "/etc/nginx/conf.d/$domain.d/$app.conf" #================================================= # CREATE DEDICATED USER diff --git a/scripts/upgrade b/scripts/upgrade index 05b5e2f..12ae7fd 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -73,6 +73,11 @@ ynh_setup_source "$final_path" # Create a dedicated nginx config ynh_add_nginx_config +if [ "$path_url" != "/" ] +then + ynh_replace_string "^#sub_path_only" "" "/etc/nginx/conf.d/$domain.d/$app.conf" +fi +ynh_store_file_checksum "/etc/nginx/conf.d/$domain.d/$app.conf" #================================================= # CREATE DEDICATED USER From 40f75dd0712ed6bcb6bd2464ec3b56d236eb522e Mon Sep 17 00:00:00 2001 From: Jimmy Monin Date: Sun, 27 May 2018 16:51:43 +0200 Subject: [PATCH 4/6] Add change_url script --- check_process | 2 +- scripts/_common.sh | 15 +++++++ scripts/change_url | 105 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 121 insertions(+), 1 deletion(-) create mode 100644 scripts/change_url diff --git a/check_process b/check_process index bc00531..f3b0810 100644 --- a/check_process +++ b/check_process @@ -19,7 +19,7 @@ multi_instance=0 incorrect_path=1 port_already_use=0 - change_url=0 + change_url=1 ;;; Levels Level 1=auto Level 2=auto diff --git a/scripts/_common.sh b/scripts/_common.sh index a9bf588..d92d1ad 100755 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -1 +1,16 @@ #!/bin/bash + +#================================================= +# EXPERIMENTAL HELPERS +#================================================= + +# 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/change_url b/scripts/change_url new file mode 100644 index 0000000..7ae12c8 --- /dev/null +++ b/scripts/change_url @@ -0,0 +1,105 @@ +#!/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 +#================================================= + +final_path=$(ynh_app_setting_get "$app" final_path) + +#================================================= +# CHECK PATHS SYNTAX +#================================================= + +test -n "$old_path" || old_path="/" +test -n "$new_path" || new_path="/" +new_path=$(ynh_normalize_url_path $new_path) +old_path=$(ynh_normalize_url_path $old_path) + +#================================================= +# CHECK WHICH PARTS SHOULD BE CHANGED +#================================================= + +change_domain=0 +if [ "$old_domain" != "$new_domain" ] +then + change_domain=1 +fi + +change_path=0 +if [ "$old_path" != "$new_path" ] +then + change_path=1 +fi + +#================================================= +# STANDARD MODIFICATIONS +#================================================= +# MODIFY URL IN NGINX CONF +#================================================= + +nginx_conf_path=/etc/nginx/conf.d/$old_domain.d/$app.conf + +# Change the path in the nginx config file +if [ $change_path -eq 1 ] +then + # Make a backup of the original nginx config file if modified + ynh_backup_if_checksum_is_different "$nginx_conf_path" + # Set global variables for nginx helper + domain="$old_domain" + path_url="$new_path" + # Store path_url setting + ynh_app_setting_set $app path_url "$path_url" + # Create a dedicated nginx config + ynh_add_nginx_config + if [ "$path_url" != "/" ] + then + ynh_replace_string "^#sub_path_only" "" "$nginx_conf_path" + fi + ynh_store_file_checksum "$nginx_conf_path" +fi + +# Change the domain for nginx +if [ $change_domain -eq 1 ] +then + # Delete file checksum for the old conf file location + ynh_delete_file_checksum "$nginx_conf_path" + mv $nginx_conf_path /etc/nginx/conf.d/$new_domain.d/$app.conf + # Store file checksum for the new config file location + ynh_store_file_checksum "/etc/nginx/conf.d/$new_domain.d/$app.conf" +fi + +#================================================= +# SPECIFIC MODIFICATIONS +#================================================= + +# Change domain name in parameters.yml +ynh_replace_string "\$cfg['web_root'] = .*" "\$cfg['web_root'] = 'https://' . '$new_domain' . '${new_path%/}' . '/';" "$final_path/lib/config.local.php" + +#================================================= +# GENERIC FINALISATION +#================================================= +# RELOAD NGINX +#================================================= + +systemctl reload nginx From 6d0a8de9bd79c3f112d567eb7a1291b4ef82ca80 Mon Sep 17 00:00:00 2001 From: Jimmy Monin Date: Sun, 27 May 2018 16:57:18 +0200 Subject: [PATCH 5/6] Avoid use of deprecated checkurl function --- scripts/restore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/restore b/scripts/restore index 4d7ccd3..e930d85 100644 --- a/scripts/restore +++ b/scripts/restore @@ -34,7 +34,7 @@ db_name=$(ynh_app_setting_get $app db_name) # CHECK IF THE APP CAN BE RESTORED #================================================= -sudo yunohost app checkurl "${domain}${path_url}" -a "$app" \ +ynh_webpath_available $domain $path_url \ || ynh_die "Path not available: ${domain}${path_url}" test ! -d $final_path \ || ynh_die "There is already a directory: $final_path " From f739f8e28caa417c2d94e50dc25a1afca5743fe1 Mon Sep 17 00:00:00 2001 From: Jimmy Monin Date: Wed, 30 May 2018 19:01:30 +0200 Subject: [PATCH 6/6] Fix potential timeouts (fixes #44) --- conf/nginx.conf | 2 ++ 1 file changed, 2 insertions(+) diff --git a/conf/nginx.conf b/conf/nginx.conf index 04ae035..47f2a36 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -18,6 +18,8 @@ location __PATH__/ { fastcgi_param REMOTE_USER $remote_user; fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_param SCRIPT_FILENAME $request_filename; + fastcgi_read_timeout 30m; + fastcgi_send_timeout 30m; } location ~ ^__PATH__/lib/.*\.php { deny all;