From 764209306b31f858c03316d6749bc9c1743af7c3 Mon Sep 17 00:00:00 2001 From: Maniack Crudelis Date: Sun, 17 Feb 2019 20:57:31 +0100 Subject: [PATCH] Add progression with ynh_print_info --- README.md | 2 +- conf/nginx.conf | 30 +++++++++++++++--------------- manifest.json | 2 +- scripts/_common.sh | 25 +++++++++++++++++++++++++ scripts/backup | 13 +++++++++++++ scripts/install | 20 ++++++++++++++++++++ scripts/remove | 14 ++++++++++++++ scripts/restore | 15 +++++++++++++++ scripts/upgrade | 21 ++++++++++++++++++++- scripts/upgrade.d/upgrade.last.sh | 4 ++-- 10 files changed, 126 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 83e2e54..2a25708 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ If you don't have YunoHost, please see [here](https://yunohost.org/#/install) to own data. A personal cloud which run on your own server. With Nextcloud you can synchronize your files over your devices. -**Shipped version:** 15.0.2 +**Shipped version:** 15.0.4 ## Screenshots diff --git a/conf/nginx.conf b/conf/nginx.conf index ba6c554..1170d66 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -16,13 +16,13 @@ location ^~ __PATH__ { } # Add headers to serve security related headers - add_header Strict-Transport-Security "max-age=15768000;"; - add_header X-Content-Type-Options nosniff; - add_header X-XSS-Protection "1; mode=block"; - add_header X-Robots-Tag none; - add_header X-Download-Options noopen; - add_header X-Permitted-Cross-Domain-Policies none; - add_header Referrer-Policy no-referrer; + more_set_headers "Strict-Transport-Security: max-age=15768000"; + more_set_headers "X-Content-Type-Options: nosniff"; + more_set_headers "X-XSS-Protection: 1; mode=block"; + more_set_headers "X-Robots-Tag: none"; + more_set_headers "X-Download-Options: noopen"; + more_set_headers "X-Permitted-Cross-Domain-Policies: none"; + more_set_headers "Referrer-Policy: no-referrer"; # Set max upload size client_max_body_size 10G; @@ -81,15 +81,15 @@ location ^~ __PATH__ { # Adding the cache control header for js and css files location ~* \.(?:css|js)$ { - add_header Cache-Control "public, max-age=7200"; + more_set_headers "Cache-Control: public, max-age=7200"; # Add headers to serve security related headers - add_header Strict-Transport-Security "max-age=15768000;"; - add_header X-Content-Type-Options nosniff; - add_header X-XSS-Protection "1; mode=block"; - add_header X-Robots-Tag none; - add_header X-Download-Options noopen; - add_header X-Permitted-Cross-Domain-Policies none; - add_header Referrer-Policy no-referrer; + more_set_headers "Strict-Transport-Security: max-age=15768000"; + more_set_headers "X-Content-Type-Options: nosniff"; + more_set_headers "X-XSS-Protection: 1; mode=block"; + more_set_headers "X-Robots-Tag: none"; + more_set_headers "X-Download-Options: noopen"; + more_set_headers "X-Permitted-Cross-Domain-Policies: none"; + more_set_headers "Referrer-Policy: no-referrer"; # Optional: Don't log access to assets access_log off; diff --git a/manifest.json b/manifest.json index f0197d9..a146c94 100644 --- a/manifest.json +++ b/manifest.json @@ -6,7 +6,7 @@ "en": "Access & share your files, calendars, contacts, mail & more from any device, on your terms", "fr": "Consultez et partagez vos fichiers, agendas, carnets d'adresses, emails et bien plus depuis les appareils de votre choix, sous vos conditions" }, - "version": "15.0.2~ynh1", + "version": "15.0.4~ynh2", "url": "https://nextcloud.com", "license": "AGPL-3.0", "maintainer": { diff --git a/scripts/_common.sh b/scripts/_common.sh index 9301891..2529d02 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -275,6 +275,31 @@ ynh_handle_app_migration () { fi } +ynh_smart_mktemp () { + local min_size="${1:-300}" + # Transform the minimum size from megabytes to kilobytes + min_size=$(( $min_size * 1024 )) + + # Check if there's enough free space in a directory + is_there_enough_space () { + local free_space=$(df --output=avail "$1" | sed 1d) + test $free_space -ge $min_size + } + + if is_there_enough_space /tmp; then + local tmpdir=/tmp + elif is_there_enough_space /var; then + local tmpdir=/var + elif is_there_enough_space /; then + local tmpdir=/ + elif is_there_enough_space /home; then + local tmpdir=/home + else + ynh_die "Insufficient free space to continue..." + fi + + echo "$(sudo mktemp --directory --tmpdir="$tmpdir")" +} #================================================= # FUTURE OFFICIAL HELPERS diff --git a/scripts/backup b/scripts/backup index 67f05ce..f548f90 100755 --- a/scripts/backup +++ b/scripts/backup @@ -19,6 +19,7 @@ ynh_abort_if_errors #================================================= # LOAD SETTINGS #================================================= +ynh_print_info "Loading installation settings..." app=$YNH_APP_INSTANCE_NAME @@ -31,24 +32,28 @@ db_name=$(ynh_app_setting_get $app db_name) #================================================= # BACKUP THE APP MAIN DIR #================================================= +ynh_print_info "Backing up the main app directory..." ynh_backup "$final_path" #================================================= # BACKUP THE NGINX CONFIGURATION #================================================= +ynh_print_info "Backing up nginx web server configuration..." ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf" #================================================= # BACKUP THE PHP-FPM CONFIGURATION #================================================= +ynh_print_info "Backing up php-fpm configuration..." ynh_backup "/etc/php/7.0/fpm/pool.d/$app.conf" #================================================= # BACKUP THE MYSQL DATABASE #================================================= +ynh_print_info "Backing up the MySQL database..." ynh_mysql_dump_db "$db_name" > db.sql @@ -57,6 +62,7 @@ ynh_mysql_dump_db "$db_name" > db.sql #================================================= # BACKUP LOGROTATE #================================================= +ynh_print_info "Backing up logrotate configuration..." ynh_backup "/etc/logrotate.d/$app" @@ -69,8 +75,15 @@ ynh_backup "/etc/cron.d/$app" #================================================= # BACKUP THE DATA DIRECTORY #================================================= +ynh_print_info "Backing up data directory..." # The 1 parameter indicates the directory is "big", # so that it won't be backed up before upgrade # This argument has to be the third one. ynh_backup "/home/yunohost.app/${app}/data" "/home/yunohost.app/${app}/data" 1 + +#================================================= +# END OF SCRIPT +#================================================= + +ynh_print_info "Backup script completed for $app. (YunoHost will then actually copy those files to the archive)." diff --git a/scripts/install b/scripts/install index 2c301c0..0f66303 100755 --- a/scripts/install +++ b/scripts/install @@ -30,6 +30,7 @@ app=$YNH_APP_INSTANCE_NAME #================================================= # CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS #================================================= +ynh_print_info "Validating installation parameters..." final_path=/var/www/$app test ! -e "$final_path" || ynh_die "This path already contains a folder" @@ -43,6 +44,7 @@ ynh_webpath_register $app $domain $path_url #================================================= # STORE SETTINGS FROM MANIFEST #================================================= +ynh_print_info "Storing installation settings..." ynh_app_setting_set $app domain $domain ynh_app_setting_set $app path $path_url @@ -54,12 +56,14 @@ ynh_app_setting_set $app user_home $user_home #================================================= # INSTALL DEPENDENCIES #================================================= +ynh_print_info "Installing dependencies..." ynh_install_app_dependencies $pkg_dependencies #================================================= # CREATE A MYSQL DATABASE #================================================= +ynh_print_info "Creating a MySQL database..." db_name=$(ynh_sanitize_dbid $app) ynh_app_setting_set $app db_name $db_name @@ -68,6 +72,7 @@ ynh_mysql_setup_db $db_name $db_name #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= +ynh_print_info "Setting up source files..." # Load the last available version source upgrade.d/upgrade.last.sh @@ -85,6 +90,7 @@ ynh_setup_source "$final_path" #================================================= # NGINX CONFIGURATION #================================================= +ynh_print_info "Configuring nginx web server..." # Do not serve .well-known if it's already served on the domain if is_url_handled "https://$domain/.well-known/caldav" ; then @@ -98,6 +104,7 @@ ynh_add_nginx_config #================================================= # CREATE DEDICATED USER #================================================= +ynh_print_info "Configuring system user..." # Create a system user ynh_system_user_create $app @@ -105,6 +112,7 @@ ynh_system_user_create $app #================================================= # PHP-FPM CONFIGURATION #================================================= +ynh_print_info "Configuring php-fpm..." # Create a dedicated php-fpm config ynh_add_fpm_config @@ -123,6 +131,7 @@ mkdir -p "$datadir" #================================================= # INSTALL NEXTCLOUD #================================================= +ynh_print_info "Installing nextcloud..." # Define a function to execute commands with `occ` exec_occ() { @@ -144,6 +153,7 @@ exec_occ maintenance:install \ #================================================= # CONFIGURE NEXTCLOUD #================================================= +ynh_print_info "Configuring nextcloud..." # Ensure that UpdateNotification app is disabled exec_occ app:disable updatenotification @@ -268,6 +278,7 @@ ynh_replace_string "__GROUP__" "$app" ../hooks/post_user_create #================================================= # YUNOHOST MULTIMEDIA INTEGRATION #================================================= +ynh_print_info "Adding multimedia directories..." # Build YunoHost multimedia directories ynh_multimedia_build_main_dir @@ -296,6 +307,7 @@ chmod 755 /home/yunohost.app #================================================= # SETUP LOGROTATE #================================================= +ynh_print_info "Configuring log rotation..." # Use logrotate to manage application logfile(s) ynh_use_logrotate "$datadir/nextcloud.log" @@ -303,6 +315,7 @@ ynh_use_logrotate "$datadir/nextcloud.log" #================================================= # SETUP SSOWAT #================================================= +ynh_print_info "Configuring SSOwat..." ynh_app_setting_set $app unprotected_uris "/" ynh_app_setting_set $app skipped_regex \ @@ -311,5 +324,12 @@ ynh_app_setting_set $app skipped_regex \ #================================================= # RELOAD NGINX #================================================= +ynh_print_info "Reloading nginx web server..." systemctl reload nginx + +#================================================= +# END OF SCRIPT +#================================================= + +ynh_print_info "Installation of $app completed" diff --git a/scripts/remove b/scripts/remove index 907a7e7..de10894 100755 --- a/scripts/remove +++ b/scripts/remove @@ -12,6 +12,7 @@ source /usr/share/yunohost/helpers #================================================= # LOAD SETTINGS #================================================= +ynh_print_info "Loading installation settings..." app=$YNH_APP_INSTANCE_NAME @@ -24,6 +25,7 @@ final_path=$(ynh_app_setting_get $app final_path) #================================================= # REMOVE DEPENDENCIES #================================================= +ynh_print_info "Removing dependencies" # Remove metapackage and its dependencies ynh_remove_app_dependencies @@ -31,6 +33,7 @@ ynh_remove_app_dependencies #================================================= # REMOVE THE MYSQL DATABASE #================================================= +ynh_print_info "Removing the MySQL database" # Remove a database if it exists, along with the associated user ynh_mysql_remove_db $db_name $db_name @@ -38,6 +41,7 @@ ynh_mysql_remove_db $db_name $db_name #================================================= # REMOVE APP MAIN DIR #================================================= +ynh_print_info "Removing app main directory" # Remove the app directory securely ynh_secure_remove "$final_path" @@ -45,6 +49,7 @@ ynh_secure_remove "$final_path" #================================================= # REMOVE NGINX CONFIGURATION #================================================= +ynh_print_info "Removing nginx web server configuration" # Remove the dedicated nginx config ynh_remove_nginx_config @@ -52,6 +57,7 @@ ynh_remove_nginx_config #================================================= # REMOVE PHP-FPM CONFIGURATION #================================================= +ynh_print_info "Removing php-fpm configuration" # Remove the dedicated php-fpm config ynh_remove_fpm_config @@ -59,6 +65,7 @@ ynh_remove_fpm_config #================================================= # REMOVE LOGROTATE CONFIGURATION #================================================= +ynh_print_info "Removing logrotate configuration" # Remove the app-specific logrotate config ynh_remove_logrotate @@ -88,6 +95,13 @@ done #================================================= # REMOVE DEDICATED USER #================================================= +ynh_print_info "Removing the dedicated system user" # Delete a system user ynh_system_user_delete $app + +#================================================= +# END OF SCRIPT +#================================================= + +ynh_print_info "Removal of $app completed" diff --git a/scripts/restore b/scripts/restore index 1a2209c..b077fea 100755 --- a/scripts/restore +++ b/scripts/restore @@ -19,6 +19,7 @@ ynh_abort_if_errors #================================================= # LOAD SETTINGS #================================================= +ynh_print_info "Loading settings..." app=$YNH_APP_INSTANCE_NAME @@ -30,6 +31,7 @@ db_name=$(ynh_app_setting_get $app db_name) #================================================= # CHECK IF THE APP CAN BE RESTORED #================================================= +ynh_print_info "Validating restoration parameters..." ynh_webpath_available $domain $path_url \ || ynh_die "Path not available: ${domain}${path_url}" @@ -47,12 +49,14 @@ ynh_restore_file "/etc/nginx/conf.d/$domain.d/$app.conf" #================================================= # RESTORE THE APP MAIN DIR #================================================= +ynh_print_info "Restoring the app main directory..." ynh_restore_file "$final_path" #================================================= # RESTORE THE MYSQL DATABASE #================================================= +ynh_print_info "Restoring the MySQL database..." db_pwd=$(ynh_app_setting_get $app mysqlpwd) ynh_mysql_setup_db $db_name $db_name $db_pwd @@ -61,6 +65,7 @@ ynh_mysql_connect_as $db_name $db_pwd $db_name < ./db.sql #================================================= # RECREATE THE DEDICATED USER #================================================= +ynh_print_info "Recreating the dedicated system user..." # Create the dedicated user (if not existing) ynh_system_user_create $app @@ -76,6 +81,7 @@ ynh_restore_file "/etc/php/7.0/fpm/pool.d/$app.conf" #================================================= # REINSTALL DEPENDENCIES #================================================= +ynh_print_info "Reinstalling dependencies..." # Define and install dependencies ynh_install_app_dependencies $pkg_dependencies @@ -95,6 +101,7 @@ ynh_restore_file "/etc/logrotate.d/$app" #================================================= # RESTORE THE DATA DIRECTORY #================================================= +ynh_print_info "Restoring data directory..." datadir="/home/yunohost.app/$app/data" @@ -127,6 +134,7 @@ done #================================================= # YUNOHOST MULTIMEDIA INTEGRATION #================================================= +ynh_print_info "Adding multimedia directories..." # Build YunoHost multimedia directories ynh_multimedia_build_main_dir @@ -138,6 +146,13 @@ ynh_multimedia_addaccess $app #================================================= # RELOAD NGINX AND PHP-FPM #================================================= +ynh_print_info "Reloading nginx web server and php-fpm..." systemctl reload php7.0-fpm systemctl reload nginx + +#================================================= +# END OF SCRIPT +#================================================= + +ynh_print_info "Restoration completed for $app" diff --git a/scripts/upgrade b/scripts/upgrade index 78bdce9..064d446 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -12,6 +12,7 @@ source /usr/share/yunohost/helpers #================================================= # LOAD SETTINGS #================================================= +ynh_print_info "Loading installation settings..." app=$YNH_APP_INSTANCE_NAME @@ -25,6 +26,7 @@ user_home=$(ynh_app_setting_get $app user_home) #================================================= # ENSURE DOWNWARD COMPATIBILITY #================================================= +ynh_print_info "Ensuring downward compatibility..." # If db_name doesn't exist, create it if [ -z $db_name ]; then @@ -44,6 +46,7 @@ ynh_app_setting_delete $app backup_core_only #================================================= # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP #================================================= +ynh_print_info "Backing up the app before upgrading (may take a while)..." # Made a backup only after the version 11.0.0 # Before, the datas will be always saved. @@ -104,6 +107,7 @@ path_url=$(ynh_normalize_url_path $path_url) #================================================= # NGINX CONFIGURATION #================================================= +ynh_print_info "Upgrading nginx web server configuration..." ynh_backup_if_checksum_is_different "/etc/nginx/conf.d/$domain.d/$app.conf" @@ -123,6 +127,7 @@ ynh_add_nginx_config #================================================= # CREATE DEDICATED USER #================================================= +ynh_print_info "Making sure dedicated system user exists..." # Create a dedicated user (if not existing) ynh_system_user_create $app @@ -130,6 +135,7 @@ ynh_system_user_create $app #================================================= # PHP-FPM CONFIGURATION #================================================= +ynh_print_info "Upgrading php-fpm configuration..." # Create a dedicated php-fpm config ynh_add_fpm_config @@ -137,6 +143,7 @@ ynh_add_fpm_config #================================================= # UPGRADE DEPENDENCIES #================================================= +ynh_print_info "Upgrading dependencies..." ynh_install_app_dependencies $pkg_dependencies @@ -195,7 +202,7 @@ do ynh_replace_string "__SHA256_SUM__" "$nextcloud_source_sha256" "../conf/app.src" # Create a temporary directory - tmpdir=$(mktemp -d) + tmpdir="$(ynh_smart_mktemp 300)" # Install the next nextcloud version in $tmpdir ynh_setup_source "$tmpdir" @@ -214,6 +221,7 @@ do # Replace the old nextcloud by the new one ynh_secure_remove "$final_path" mv "$tmpdir" "$final_path" + ynh_secure_remove "$tmpdir" # Set write access for the following commands chown -R $app: "$final_path" "$datadir" @@ -234,6 +242,7 @@ done #================================================= # CONFIGURE NEXTCLOUD #================================================= +ynh_print_info "Reconfiguring nextcloud..." # Verify the checksum and backup the file if it's different ynh_backup_if_checksum_is_different "$final_path/config/config.php" @@ -329,6 +338,7 @@ ynh_replace_string "__GROUP__" "$app" ../hooks/post_user_create #================================================= # YUNOHOST MULTIMEDIA INTEGRATION #================================================= +ynh_print_info "Updating multimedia directories..." # Build YunoHost multimedia directories ynh_multimedia_build_main_dir @@ -365,6 +375,7 @@ they are probably disabled and you'll have to manually enable them again." #================================================= # SETUP LOGROTATE #================================================= +ynh_print_info "Upgrading logrotate configuration..." # Use logrotate to manage app-specific logfile(s) ynh_use_logrotate --non-append @@ -374,6 +385,7 @@ ynh_use_logrotate --non-append #================================================= # SETUP SSOWAT #================================================= +ynh_print_info "Upgrading SSOwat configuration..." ynh_app_setting_set $app unprotected_uris "/" ynh_app_setting_set $app skipped_regex \ @@ -382,6 +394,7 @@ ynh_app_setting_set $app skipped_regex \ #================================================= # RELOAD NGINX #================================================= +ynh_print_info "Reloading nginx web server..." systemctl reload nginx @@ -405,3 +418,9 @@ you don't see Nextcloud as installed." chmod +x /tmp/$script_post_migration (cd /tmp; echo "/tmp/$script_post_migration > /tmp/$script_post_migration.log 2>&1" | at now + 2 minutes) fi + +#================================================= +# END OF SCRIPT +#================================================= + +ynh_print_info "Upgrade of $app completed" diff --git a/scripts/upgrade.d/upgrade.last.sh b/scripts/upgrade.d/upgrade.last.sh index 1a77d52..80d65dd 100755 --- a/scripts/upgrade.d/upgrade.last.sh +++ b/scripts/upgrade.d/upgrade.last.sh @@ -1,10 +1,10 @@ #!/bin/bash # Last available nextcloud version -next_version="15.0.2" +next_version="15.0.4" # Nextcloud tarball checksum sha256 -nextcloud_source_sha256="c1f4cc33e39994ddbe6777370b62c30b7ae52136a0530c0b9922770803ca0fea" +nextcloud_source_sha256="f87db047c174f563e391a22c959d9ace767ca14ef0f97fc394f3061fc63d8f77" # This function will only be executed upon applying the last upgrade referenced above last_upgrade_operations () {