diff --git a/README.md b/README.md index 2a817d7..939fd62 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Wordpress for YunoHost -[![Integration level](https://dash.yunohost.org/integration/wordpress.svg)](https://ci-apps.yunohost.org/jenkins/job/wordpress%20%28Official%29/lastBuild/consoleFull) +[![Integration level](https://dash.yunohost.org/integration/wordpress.svg)](https://dash.yunohost.org/appci/app/wordpress) [![Install Wordpress with YunoHost](https://install-app.yunohost.org/install-with-yunohost.png)](https://install-app.yunohost.org/?app=wordpress) > *This package allow you to install wordpress quickly and simply on a YunoHost server. diff --git a/scripts/_common.sh b/scripts/_common.sh index 99c60e7..90d2ed8 100755 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -321,6 +321,88 @@ ynh_clean_check_starting () { ynh_secure_remove "$templog" 2>&1 } +#================================================= +# EXPERIMENTAL HELPERS +#================================================= + +# Print a message as INFO and show progression during an app script +# +# usage: ynh_script_progression --message=message [--weight=weight] [--time] +# | arg: -m, --message= - The text to print +# | arg: -w, --weight= - The weight for this progression. This value is 1 by default. Use a bigger value for a longer part of the script. +# | arg: -t, --time= - Print the execution time since the last call to this helper. Especially usefull to define weights. +# | arg: -l, --last= - Use for the last call of the helper, to fill te progression bar. +increment_progression=0 +previous_weight=0 +# Define base_time when the file is sourced +base_time=$(date +%s) +ynh_script_progression () { + # Declare an array to define the options of this helper. + declare -Ar args_array=( [m]=message= [w]=weight= [t]=time [l]=last ) + local message + local weight + local time + local last + # Manage arguments with getopts + ynh_handle_getopts_args "$@" + weight=${weight:-1} + time=${time:-0} + last=${last:-0} + + # Get execution time since the last $base_time + local exec_time=$(( $(date +%s) - $base_time )) + base_time=$(date +%s) + + # Get the number of occurrences of 'ynh_script_progression' in the script. Except those are commented. + local helper_calls="$(grep --count "^[^#]*ynh_script_progression" $0)" + # Get the number of call with a weight value + local weight_calls=$(grep --perl-regexp --count "^[^#]*ynh_script_progression.*(--weight|-w )" $0) + + # Get the weight of each occurrences of 'ynh_script_progression' in the script using --weight + local weight_valuesA="$(grep --perl-regexp "^[^#]*ynh_script_progression.*--weight" $0 | sed 's/.*--weight[= ]\([[:digit:]].*\)/\1/g')" + # Get the weight of each occurrences of 'ynh_script_progression' in the script using -w + local weight_valuesB="$(grep --perl-regexp "^[^#]*ynh_script_progression.*-w " $0 | sed 's/.*-w[= ]\([[:digit:]].*\)/\1/g')" + # Each value will be on a different line. + # Remove each 'end of line' and replace it by a '+' to sum the values. + local weight_values=$(( $(echo "$weight_valuesA" | tr '\n' '+') + $(echo "$weight_valuesB" | tr '\n' '+') 0 )) + + # max_progression is a total number of calls to this helper. + # Less the number of calls with a weight value. + # Plus the total of weight values + local max_progression=$(( $helper_calls - $weight_calls + $weight_values )) + + # Increment each execution of ynh_script_progression in this script by the weight of the previous call. + increment_progression=$(( $increment_progression + $previous_weight )) + # Store the weight of the current call in $previous_weight for next call + previous_weight=$weight + + # Set the scale of the progression bar + local scale=20 + # progress_string(1,2) should have the size of the scale. + local progress_string1="####################" + local progress_string0="...................." + + # Reduce $increment_progression to the size of the scale + if [ $last -eq 0 ] + then + local effective_progression=$(( $increment_progression * $scale / $max_progression )) + # If last is specified, fill immediately the progression_bar + else + local effective_progression=$scale + fi + + # Build $progression_bar from progress_string(1,2) according to $effective_progression + local progression_bar="${progress_string1:0:$effective_progression}${progress_string0:0:$(( $scale - $effective_progression ))}" + + local print_exec_time="" + if [ $time -eq 1 ] + then + print_exec_time=" [$(date +%Hh%Mm,%Ss --date="0 + $exec_time sec")]" + fi + + ynh_print_info "[$progression_bar] > ${message}${print_exec_time}" +} + #================================================= # Send an email to inform the administrator diff --git a/scripts/backup b/scripts/backup index ca8300d..827fb07 100644 --- a/scripts/backup +++ b/scripts/backup @@ -19,6 +19,7 @@ ynh_abort_if_errors #================================================= # LOAD SETTINGS #================================================= +ynh_script_progression --message="Load settings" --weight=2 app=$YNH_APP_INSTANCE_NAME @@ -32,6 +33,7 @@ db_pwd=$(ynh_app_setting_get $app mysqlpwd) #================================================= # BACKUP THE APP MAIN DIR #================================================= +ynh_script_progression --message="Backup the app main dir" --weight=2 CHECK_SIZE "$final_path" ynh_backup "$final_path" @@ -39,18 +41,21 @@ ynh_backup "$final_path" #================================================= # BACKUP NGINX CONFIGURATION #================================================= +ynh_script_progression --message="Backup nginx configuration" ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf" #================================================= # BACKUP PHP-FPM CONFIGURATION #================================================= +ynh_script_progression --message="Backup php-fpm configuration" ynh_backup "/etc/php/7.0/fpm/pool.d/$app.conf" #================================================= # BACKUP THE MYSQL DATABASE #================================================= +ynh_script_progression --message="Backup the mysql database" --weight=2 ynh_mysql_dump_db "$db_name" > db.sql CHECK_SIZE "db.sql" @@ -58,6 +63,13 @@ CHECK_SIZE "db.sql" #================================================= # BACKUP FAIL2BAN CONFIGURATION #================================================= +ynh_script_progression --message="Backup fail2ban configuration" ynh_backup "/etc/fail2ban/jail.d/$app.conf" ynh_backup "/etc/fail2ban/filter.d/$app.conf" + +#================================================= +# END OF SCRIPT +#================================================= + +ynh_script_progression --message="Backup completed" --last diff --git a/scripts/change_url b/scripts/change_url index 591da21..a96f0a0 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -12,6 +12,7 @@ source /usr/share/yunohost/helpers #================================================= # RETRIEVE ARGUMENTS #================================================= +ynh_script_progression --message="Retrieve arguments from the manifest" old_domain=$YNH_APP_OLD_DOMAIN old_path=$YNH_APP_OLD_PATH @@ -24,6 +25,7 @@ app=$YNH_APP_INSTANCE_NAME #================================================= # LOAD SETTINGS #================================================= +ynh_script_progression --message="Load settings" --weight=2 final_path=$(ynh_app_setting_get $app final_path) multisite=$(ynh_app_setting_get $app multisite) @@ -37,6 +39,7 @@ fi #================================================= # CHECK THE SYNTAX OF THE PATHS #================================================= +ynh_script_progression --message="Check the syntax of the paths" test -n "$old_path" || old_path="/" test -n "$new_path" || new_path="/" @@ -46,6 +49,7 @@ old_path=$(ynh_normalize_url_path $old_path) #================================================= # ACTIVATE MAINTENANCE MODE #================================================= +ynh_script_progression --message="Activate maintenance mode" --weight=2 path_url=$old_path domain=$old_domain @@ -79,6 +83,7 @@ ynh_abort_if_errors #================================================= # MODIFY URL IN NGINX CONF #================================================= +ynh_script_progression --message="Modify url in nginx configuration" --weight=3 nginx_conf_path=/etc/nginx/conf.d/$old_domain.d/$app.conf @@ -124,13 +129,21 @@ ynh_mysql_execute_as_root "UPDATE wp_options SET option_value='$new_domain$new_p #================================================= # RELOAD NGINX #================================================= +ynh_script_progression --message="Reload nginx" ynh_systemd_action --action=reload --service_name=nginx #================================================= # DEACTIVE MAINTENANCE MODE #================================================= +ynh_script_progression --message="Disable maintenance mode" --weight=5 path_url=$old_path domain=$old_domain ynh_maintenance_mode_OFF + +#================================================= +# END OF SCRIPT +#================================================= + +ynh_script_progression --message="Change of url completed" --last diff --git a/scripts/install b/scripts/install index 41f9534..8b42bb6 100644 --- a/scripts/install +++ b/scripts/install @@ -19,6 +19,7 @@ ynh_abort_if_errors #================================================= # RETRIEVE ARGUMENTS FROM THE MANIFEST #================================================= +ynh_script_progression --message="Retrieve arguments from the manifest" domain=$YNH_APP_ARG_DOMAIN path_url=$YNH_APP_ARG_PATH @@ -32,6 +33,7 @@ app=$YNH_APP_INSTANCE_NAME #================================================= # CHECK IF THE APP CAN BE INSTALLED WITH THIS ARGS #================================================= +ynh_script_progression --message="Check if the app can be installed" --weight=2 final_path=/var/www/$app test ! -e "$final_path" || ynh_die "This path already contains a folder" @@ -49,6 +51,7 @@ fi #================================================= # STORE SETTINGS FROM MANIFEST #================================================= +ynh_script_progression --message="Store settings from manifest" --weight=2 ynh_app_setting_set $app domain $domain ynh_app_setting_set $app path $path_url @@ -62,12 +65,14 @@ ynh_app_setting_set $app multisite $multisite #================================================= # INSTALL DEPENDENCIES #================================================= +ynh_script_progression --message="Install dependencies" --weight=9 ynh_install_app_dependencies php5-cli #================================================= # CREATE A MYSQL DATABASE #================================================= +ynh_script_progression --message="Create a mysql database" db_name=$(ynh_sanitize_dbid $app) ynh_app_setting_set $app db_name $db_name @@ -76,6 +81,7 @@ ynh_mysql_setup_db $db_name $db_name #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= +ynh_script_progression --message="Download, check and unpack source" --weight=4 ynh_app_setting_set $app final_path $final_path # Download, check integrity, uncompress and patch the source from app.src @@ -84,6 +90,7 @@ ynh_setup_source "$final_path" #================================================= # NGINX CONFIGURATION #================================================= +ynh_script_progression --message="Configure nginx" --weight=3 # Create a dedicated nginx config ynh_add_nginx_config @@ -91,6 +98,7 @@ ynh_add_nginx_config #================================================= # CREATE DEDICATED USER #================================================= +ynh_script_progression --message="Create a dedicated user" --weight=3 # Create a dedicated system user ynh_system_user_create $app @@ -98,6 +106,7 @@ ynh_system_user_create $app #================================================= # PHP-FPM CONFIGURATION #================================================= +ynh_script_progression --message="Configure php-fpm" --weight=2 # Create a dedicated php-fpm config ynh_add_fpm_config @@ -107,6 +116,7 @@ ynh_add_fpm_config #================================================= # CONFIGURE WP-CONFIG #================================================= +ynh_script_progression --message="Configure wp-config.php" cp ../conf/wp-config.php $final_path/wp-config.php # Change variables in Wordpress configuration @@ -128,6 +138,7 @@ done #================================================= # SETTING UP WITH CURL #================================================= +ynh_script_progression --message="Install wordpress with Curl" --weight=10 # Set right permissions for curl install chown -R $app: $final_path @@ -143,7 +154,7 @@ ynh_systemd_action --action=reload --service_name=nginx # Wordpress installation ynh_local_curl "/wp-admin/install.php?step=2" "&weblog_title=YunoBlog" "user_name=$admin_wordpress" "admin_password=$db_pwd" "admin_password2=$db_pwd" "admin_email=$admin_wordpress@$domain" "Submit=Install+WordPress" -ynh_print_info "Please wait during Wordpress installation" >&2 +ynh_print_info "Please wait during Wordpress installation" for i in `seq 1 300` do # The loop waits for wordpress to be installed, or 5 minutes. @@ -157,6 +168,7 @@ done #================================================= # INSTALL WORDPRESS PLUGINS #================================================= +ynh_script_progression --message="Install wordpress plugins" --weight=20 wget -nv https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar -O $final_path/wp-cli.phar wpcli_alias="php $final_path/wp-cli.phar --allow-root --path=$final_path" @@ -169,6 +181,7 @@ $wpcli_alias plugin install wp-fail2ban #================================================= # SET LANGUAGE #================================================= +ynh_script_progression --message="Set language" --weight=3 $wpcli_alias core language install $language $wpcli_alias site switch-language $language @@ -179,6 +192,8 @@ $wpcli_alias site switch-language $language if [ $multisite -eq 1 ] then + ynh_script_progression --message="Configure multisite" --weight=2 + ynh_replace_string "#--MULTISITE--" "" /etc/nginx/conf.d/$domain.d/$app.conf # Allow multisite ynh_replace_string "//--MULTISITE1--define" "define " $final_path/wp-config.php @@ -199,6 +214,7 @@ fi #================================================= # ACTIVATE WORDPRESS PLUGINS #================================================= +ynh_script_progression --message="Activate wordpress plugins" --weight=4 $wpcli_alias plugin activate simple-ldap-login $plugin_network # Do not activate http-authentication, this plugin is sometimes unstable @@ -227,6 +243,7 @@ chown root: $final_path/wp-config.php #================================================= # SETUP FAIL2BAN #================================================= +ynh_script_progression --message="Configure fail2ban" --weight=7 # Create a dedicated fail2ban config ynh_add_fail2ban_config --logpath="/var/log/auth.log" --failregex="Authentication (attempt for unknown user|failure for) .* from " --max_retry=5 @@ -234,6 +251,7 @@ ynh_add_fail2ban_config --logpath="/var/log/auth.log" --failregex="Authenticatio #================================================= # SETUP SSOWAT #================================================= +ynh_script_progression --message="Setup SSOwat" if [ $is_public -eq 0 ]; then @@ -244,6 +262,7 @@ fi #================================================= # RELOAD NGINX #================================================= +ynh_script_progression --message="Reload nginx" --weight=3 ynh_systemd_action --action=reload --service_name=nginx @@ -260,3 +279,9 @@ ynh_secure_remove $final_path/wp-cli.phar message="If you're facing an issue or want to improve this app, please open a new issue in this project: https://github.com/YunoHost-Apps/wordpress_ynh" ynh_send_readme_to_admin --app_message="$message" --recipients="$admin_wordpress" + +#================================================= +# END OF SCRIPT +#================================================= + +ynh_script_progression --message="Installation completed" --last diff --git a/scripts/remove b/scripts/remove index 1aabe41..e9475ff 100755 --- a/scripts/remove +++ b/scripts/remove @@ -12,6 +12,7 @@ source /usr/share/yunohost/helpers #================================================= # LOAD SETTINGS #================================================= +ynh_script_progression --message="Load settings" --weight=2 app=$YNH_APP_INSTANCE_NAME @@ -23,6 +24,7 @@ db_name=$(ynh_app_setting_get $app db_name) #================================================= # REMOVE DEPENDENCIES #================================================= +ynh_script_progression --message="Remove dependencies" --weight=11 # Remove metapackage and its dependencies ynh_remove_app_dependencies @@ -30,6 +32,7 @@ ynh_remove_app_dependencies #================================================= # REMOVE THE MYSQL DATABASE #================================================= +ynh_script_progression --message="Remove the mysql database" --weight=2 # Remove a database if it exists, along with the associated user ynh_mysql_remove_db $db_name $db_name @@ -37,6 +40,7 @@ ynh_mysql_remove_db $db_name $db_name #================================================= # REMOVE APP MAIN DIR #================================================= +ynh_script_progression --message="Remove app main directory" # Remove the app directory securely ynh_secure_remove "/var/www/$app" @@ -44,6 +48,7 @@ ynh_secure_remove "/var/www/$app" #================================================= # REMOVE NGINX CONFIGURATION #================================================= +ynh_script_progression --message="Remove nginx configuration" # Remove the dedicated nginx config ynh_remove_nginx_config @@ -51,6 +56,7 @@ ynh_remove_nginx_config #================================================= # REMOVE PHP-FPM CONFIGURATION #================================================= +ynh_script_progression --message="Remove php-fpm configuration" --weight=2 # Remove the dedicated php-fpm config ynh_remove_fpm_config @@ -58,6 +64,7 @@ ynh_remove_fpm_config #================================================= # REMOVE FAIL2BAN CONFIGURATION #================================================= +ynh_script_progression --message="Remove fail2ban configuration" --weight=8 # Remove the dedicated fail2ban config ynh_remove_fail2ban_config @@ -67,6 +74,13 @@ ynh_remove_fail2ban_config #================================================= # REMOVE DEDICATED USER #================================================= +ynh_script_progression --message="Remove the dedicated user" --weight=3 # Delete dedicated system user ynh_system_user_delete $app + +#================================================= +# END OF SCRIPT +#================================================= + +ynh_script_progression --message="Deletion completed" --last diff --git a/scripts/restore b/scripts/restore index dc36ff8..53f6d4f 100644 --- a/scripts/restore +++ b/scripts/restore @@ -19,6 +19,7 @@ ynh_abort_if_errors #================================================= # LOAD SETTINGS #================================================= +ynh_script_progression --message="Load settings" --weight=3 app=$YNH_APP_INSTANCE_NAME @@ -41,6 +42,7 @@ test ! -d $final_path \ #================================================= # ACTIVATE MAINTENANCE MODE #================================================= +ynh_script_progression --message="Activate maintenance mode" ynh_maintenance_mode_ON @@ -55,12 +57,14 @@ ynh_restore_file "/etc/nginx/conf.d/$domain.d/$app.conf" #================================================= # RESTORE THE APP MAIN DIR #================================================= +ynh_script_progression --message="Restore the app main directory" ynh_restore_file "$final_path" #================================================= # RESTORE THE MYSQL DATABASE #================================================= +ynh_script_progression --message="Restore the mysql database" --weight=3 db_pwd=$(ynh_app_setting_get $app mysqlpwd) ynh_mysql_setup_db $db_name $db_name $db_pwd @@ -69,6 +73,7 @@ ynh_mysql_connect_as $db_name $db_pwd $db_name < ./db.sql #================================================= # RECREATE THE DEDICATED USER #================================================= +ynh_script_progression --message="Recreate the dedicated user" --weight=3 # Create the dedicated user (if not existing) ynh_system_user_create $app @@ -92,6 +97,7 @@ ynh_restore_file "/etc/php/7.0/fpm/pool.d/$app.conf" #================================================= # RESTORE THE FAIL2BAN CONFIGURATION #================================================= +ynh_script_progression --message="Restore the fail2ban configuration" --weight=6 ynh_restore_file "/etc/fail2ban/jail.d/$app.conf" ynh_restore_file "/etc/fail2ban/filter.d/$app.conf" @@ -102,6 +108,7 @@ ynh_systemd_action --action=restart --service_name=fail2ban #================================================= # RELOAD NGINX AND PHP-FPM #================================================= +ynh_script_progression --message="Reload nginx and php-fpm" --weight=2 ynh_systemd_action --action=reload --service_name=php5-fpm ynh_systemd_action --action=reload --service_name=nginx @@ -109,6 +116,7 @@ ynh_systemd_action --action=reload --service_name=nginx #================================================= # DEACTIVE MAINTENANCE MODE #================================================= +ynh_script_progression --message="Disable maintenance mode" --weight=8 ynh_maintenance_mode_OFF @@ -119,3 +127,9 @@ ynh_maintenance_mode_OFF message="If you're facing an issue or want to improve this app, please open a new issue in this project: https://github.com/YunoHost-Apps/wordpress_ynh" ynh_send_readme_to_admin --app_message="$message" --recipients="$admin_wordpress" + +#================================================= +# END OF SCRIPT +#================================================= + +ynh_script_progression --message="Restoration completed" --last diff --git a/scripts/upgrade b/scripts/upgrade index 1fb911e..002e300 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -12,6 +12,7 @@ source /usr/share/yunohost/helpers #================================================= # LOAD SETTINGS #================================================= +ynh_script_progression --message="Load settings" --weight=5 app=$YNH_APP_INSTANCE_NAME @@ -33,6 +34,7 @@ upgrade_type=$(ynh_check_app_version_changed) #================================================= # ENSURE DOWNWARD COMPATIBILITY #================================================= +ynh_script_progression --message="Ensure downward compatibility" if [ -z "$admin_wordpress" ]; then ynh_mysql_execute_as_root "select MAX(user_login) from wp_users where user_status=0 INTO OUTFILE '/tmp/wordpressuser';" $db_name @@ -85,6 +87,7 @@ fi #================================================= # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP #================================================= +ynh_script_progression --message="Backup the app before upgrading" --weight=15 # Backup the current version of the app ynh_backup_before_upgrade @@ -105,18 +108,21 @@ path_url=$(ynh_normalize_url_path $path_url) #================================================= # ACTIVATE MAINTENANCE MODE #================================================= +ynh_script_progression --message="Activate maintenance mode" --weight=2 ynh_maintenance_mode_ON #================================================= # UPGRADE DEPENDENCIES #================================================= +ynh_script_progression --message="Upgrade dependencies" --weight=11 ynh_install_app_dependencies php5-cli #================================================= # NGINX CONFIGURATION #================================================= +ynh_script_progression --message="Reconfigure nginx" --weight=2 # Create a dedicated nginx config ynh_add_nginx_config @@ -124,6 +130,7 @@ ynh_add_nginx_config #================================================= # CREATE DEDICATED USER #================================================= +ynh_script_progression --message="Create a dedicated user" # Create a dedicated user (if not existing) ynh_system_user_create $app @@ -131,6 +138,7 @@ ynh_system_user_create $app #================================================= # PHP-FPM CONFIGURATION #================================================= +ynh_script_progression --message="Reconfigure php-fpm" --weight=4 # Create a dedicated php-fpm config ynh_add_fpm_config @@ -147,6 +155,7 @@ ynh_backup_if_checksum_is_different "$final_path/wp-config.php" #================================================= # CONFIGURE MULTISITE #================================================= +ynh_script_progression --message="Configure multisite" --weight=2 if [ $multisite -eq 1 ] then @@ -167,6 +176,7 @@ ynh_app_setting_set $app multisite $multisite #================================================= # UPDATE WORDPRESS PLUGINS #================================================= +ynh_script_progression --message="Update wordpress plugins" --weight=11 wget -nv https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar -O $final_path/wp-cli.phar wpcli_alias="php $final_path/wp-cli.phar --allow-root --path=$final_path" @@ -205,6 +215,7 @@ chown root: $final_path/wp-config.php #================================================= # UPGRADE FAIL2BAN #================================================= +ynh_script_progression --message="Reconfigure fail2ban" --weight=9 # Create a dedicated fail2ban config ynh_add_fail2ban_config --logpath="/var/log/auth.log" --failregex="Authentication (attempt for unknown user|failure for) .* from " --max_retry=5 @@ -212,6 +223,7 @@ ynh_add_fail2ban_config --logpath="/var/log/auth.log" --failregex="Authenticatio #================================================= # SETUP SSOWAT #================================================= +ynh_script_progression --message="Reconfigure SSOwat" # Remove skipped_uris if it's still present ynh_app_setting_delete $app skipped_uris @@ -226,6 +238,7 @@ fi #================================================= # RELOAD NGINX #================================================= +ynh_script_progression --message="Reload nginx" ynh_systemd_action --action=reload --service_name=nginx @@ -238,5 +251,12 @@ ynh_secure_remove $final_path/wp-cli.phar #================================================= # DEACTIVE MAINTENANCE MODE #================================================= +ynh_script_progression --message="Disable maintenance mode" --weight=5 ynh_maintenance_mode_OFF + +#================================================= +# END OF SCRIPT +#================================================= + +ynh_script_progression --message="Upgrade completed" --last