diff --git a/README.md b/README.md index cbf9be7..931ab45 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ If you don't have YunoHost, please see [here](https://yunohost.org/#/install) to ## Overview Free and open-source content management framework. -**Shipped version:** 8 +**Shipped version:** 8.7.1 ## Screenshots diff --git a/README_fr.md b/README_fr.md index 8a1684e..29adfc1 100644 --- a/README_fr.md +++ b/README_fr.md @@ -11,7 +11,7 @@ Si vous n'avez pas YunoHost, regardez [ici](https://yunohost.org/#/install) pour ## Vue d'ensemble Framework de gestion de contenu libre et open-source. -**Version incluse:** 7 +**Version incluse:** 8.7.1 ## Captures d'écran @@ -25,7 +25,7 @@ Framework de gestion de contenu libre et open-source. #### Support multi-utilisateurs -le module d'authentification LDAP peut être installé +Le module d'authentification LDAP peut être installé #### Supported architectures diff --git a/conf/cron b/conf/cron index 26b9e62..f2456a1 100644 --- a/conf/cron +++ b/conf/cron @@ -1 +1,6 @@ -H * * * * __APP__ /usr/bin/env PATH=__FINALPATH__/vendor/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin COLUMNS=72 drush --quiet @__APP__.prod core:cron \ No newline at end of file +SHELL=/bin/sh +PATH=__FINALPATH__/vendor/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin + +# m h dom mon dow user command +30 * * * * __APP__ drush --quiet @__APP__.prod core:cron +# diff --git a/manifest.json b/manifest.json index b717e43..fdc507e 100644 --- a/manifest.json +++ b/manifest.json @@ -6,7 +6,7 @@ "en": "Drupal for YunoHost application.", "fr": "Drupal pour YunoHost." }, - "version": "8.0~ynh1", + "version": "8.7.1~ynh1", "url": "https://www.drupal.org", "license": "GPL-2.0-or-later", "maintainer": { diff --git a/scripts/change_url b/scripts/change_url index bb99a8a..32f2a28 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -31,6 +31,7 @@ final_path=$(ynh_app_setting_get --app=$app --key=final_path) # Add settings here as needed by your application #db_name=$(ynh_app_setting_get --app=$app --key=db_name) +#db_user=$db_name #db_pwd=$(ynh_app_setting_get --app=$app --key=db_pwd) #================================================= @@ -89,10 +90,10 @@ ynh_print_info --message="Updating Drush alias..." cp -f "../conf/example.site.yml" "$final_path/drush/sites/$app.site.yml" -ynh_replace_string "__FINALPATH__" "$final_path" "$final_path/drush/sites/$app.site.yml" -ynh_replace_string "__APP__" "$app" "$final_path/drush/sites/$app.site.yml" -ynh_replace_string "__DOMAIN__" "$domain" "$final_path/drush/sites/$app.site.yml" -ynh_replace_string "__PATH_URL__" "$path_url" "$final_path/drush/sites/$app.site.yml" +ynh_replace_string --match_string="__FINALPATH__" --replace_string="$final_path" --target_file="$final_path/drush/sites/$app.site.yml" +ynh_replace_string --match_string="__APP__" --replace_string="$app" --target_file="$final_path/drush/sites/$app.site.yml" +ynh_replace_string --match_string="__DOMAIN__" --replace_string="$domain" --target_file="$final_path/drush/sites/$app.site.yml" +ynh_replace_string --match_string="__PATH_URL__" --replace_string="$path_url" --target_file="$final_path/drush/sites/$app.site.yml" #================================================= # GENERIC FINALISATION @@ -101,7 +102,7 @@ ynh_replace_string "__PATH_URL__" "$path_url" "$final_path/drush/sites/$app.site #================================================= ynh_print_info --message="Reloading nginx web server..." -systemctl reload nginx +ynh_systemd_action --service_name=nginx --action=reload #================================================= # END OF SCRIPT diff --git a/scripts/install b/scripts/install index 5d27273..68805a3 100644 --- a/scripts/install +++ b/scripts/install @@ -10,16 +10,13 @@ source _common.sh source ynh_add_extra_apt_repos__3 source ynh_install_php__3 source ynh_composer__2 +source ynh_add_swap source /usr/share/yunohost/helpers #================================================= # MANAGE SCRIPT FAILURE #================================================= -ynh_clean_setup () { - read -p "key" - true -} # Exit if an error occurs during the execution of the script ynh_abort_if_errors @@ -35,7 +32,7 @@ language=$YNH_APP_ARG_LANGUAGE password=$YNH_APP_ARG_PASSWORD install_profil=$YNH_APP_ARG_INSTALL_PROFIL -admin_mail=$(ynh_user_get_info $admin 'mail') +admin_mail=$(ynh_user_get_info --username=$admin --key=mail) app=$YNH_APP_INSTANCE_NAME @@ -45,7 +42,7 @@ app=$YNH_APP_INSTANCE_NAME ynh_print_info --message="Validating installation parameters..." final_path=/var/www/$app -test ! -e "$final_path" || ynh_die "This path already contains a folder" +test ! -e "$final_path" || ynh_die --message="This path already contains a folder" # Register (book) web path ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url @@ -70,6 +67,12 @@ ynh_app_setting_set --app=$app --key=install_profil --value=$install_profil ynh_print_info --message="Installing dependencies..." ynh_install_app_dependencies $pkg_dependencies + +#================================================= +# INSTALL PHP +#================================================= +ynh_print_info --message="Installing PHP..." + ynh_install_php --phpversion="7.2" --package="$extra_pkg_dependencies" #================================================= @@ -77,7 +80,7 @@ ynh_install_php --phpversion="7.2" --package="$extra_pkg_dependencies" #================================================= ynh_print_info --message="Creating a MySQL database..." -db_name=$(ynh_sanitize_dbid $app) +db_name=$(ynh_sanitize_dbid --db_name=$app) db_user=$db_name ynh_app_setting_set --app=$app --key=db_name --value=$db_name ynh_mysql_setup_db --db_user=$db_user --db_name=$db_name @@ -90,7 +93,6 @@ ynh_print_info --message="Setting up source files..." ynh_app_setting_set --app=$app --key=final_path --value=$final_path # Download, check integrity, uncompress and patch the source from app.src ynh_setup_source --dest_dir="$final_path" -#mkdir -p "$final_path" #================================================= # NGINX CONFIGURATION @@ -110,6 +112,13 @@ ynh_system_user_create --username=$app --home_dir="$final_path" #================================================= # SPECIFIC SETUP +#================================================= +# ADD SWAPP +#================================================= +ynh_print_info --message="Adding swap..." + +ynh_add_swap --size=512 + #================================================= # CREATE DRUSH ALIAS #================================================= @@ -119,10 +128,10 @@ mkdir -p "$final_path/drush/sites/" cp -f "../conf/example.site.yml" "$final_path/drush/sites/$app.site.yml" -ynh_replace_string "__FINALPATH__" "$final_path" "$final_path/drush/sites/$app.site.yml" -ynh_replace_string "__APP__" "$app" "$final_path/drush/sites/$app.site.yml" -ynh_replace_string "__DOMAIN__" "$domain" "$final_path/drush/sites/$app.site.yml" -ynh_replace_string "__PATH_URL__" "$path_url" "$final_path/drush/sites/$app.site.yml" +ynh_replace_string --match_string="__FINALPATH__" --replace_string="$final_path" --target_file="$final_path/drush/sites/$app.site.yml" +ynh_replace_string --match_string="__APP__" --replace_string="$app" --target_file="$final_path/drush/sites/$app.site.yml" +ynh_replace_string --match_string="__DOMAIN__" --replace_string="$domain" --target_file="$final_path/drush/sites/$app.site.yml" +ynh_replace_string --match_string="__PATH_URL__" --replace_string="$path_url" --target_file="$final_path/drush/sites/$app.site.yml" #================================================= # INSTALL COMPOSER @@ -132,7 +141,7 @@ ynh_print_info --message="Installing Composer..." mkdir -p "$final_path/.composer" cp -f "../conf/composer.json" "$final_path/composer.json" -ynh_replace_string "__APP__" "$app" "$final_path/composer.json" +ynh_replace_string --match_string="__APP__" --replace_string="$app" --target_file="$final_path/composer.json" ynh_install_composer --phpversion="7.2" --workdir="$final_path" @@ -154,20 +163,12 @@ popd #================================================= # SET THE CRON FILE #================================================= -ynh_print_info --message="Set the cron file" +ynh_print_info --message="Setting the cron file" cp ../conf/cron /etc/cron.d/$app -ynh_replace_string "__FINALPATH__" "$final_path" /etc/cron.d/$app -ynh_replace_string "__APP__" "$app" /etc/cron.d/$app - -#================================================= -# PHP-FPM CONFIGURATION -#================================================= -ynh_print_info --message="Configuring php-fpm..." - -# Create a dedicated php-fpm config -ynh_add_fpm_config --phpversion="7.2" +ynh_replace_string --match_string="__FINALPATH__" --replace_string="$final_path" --target_file="/etc/cron.d/$app" +ynh_replace_string --match_string="__APP__" --replace_string="$app" --target_file="/etc/cron.d/$app" #================================================= # STORE THE CONFIG FILE CHECKSUM @@ -178,6 +179,14 @@ ynh_store_file_checksum --file="$final_path/$app/sites/default/settings.php" #================================================= # GENERIC FINALIZATION +#================================================= +# PHP-FPM CONFIGURATION +#================================================= +ynh_print_info --message="Configuring php-fpm..." + +# Create a dedicated php-fpm config +ynh_add_fpm_config --phpversion="7.2" + #================================================= # SECURE FILES AND DIRECTORIES #================================================= @@ -202,7 +211,7 @@ fi #================================================= ynh_print_info --message="Reloading nginx web server..." -systemctl reload nginx +ynh_systemd_action --service_name=nginx --action=reload #================================================= # END OF SCRIPT diff --git a/scripts/remove b/scripts/remove index 00d5d58..96e92a6 100644 --- a/scripts/remove +++ b/scripts/remove @@ -9,6 +9,7 @@ source _common.sh source ynh_add_extra_apt_repos__3 source ynh_install_php__3 +source ynh_add_swap source /usr/share/yunohost/helpers #================================================= @@ -29,7 +30,7 @@ final_path=$(ynh_app_setting_get --app=$app --key=final_path) #================================================= # REMOVE THE MYSQL DATABASE #================================================= -ynh_print_info --message="Removing the MySQL database" +ynh_print_info --message="Removing the MySQL database..." # Remove a database if it exists, along with the associated user ynh_mysql_remove_db --db_user=$db_user --db_name=$db_name @@ -37,7 +38,7 @@ ynh_mysql_remove_db --db_user=$db_user --db_name=$db_name #================================================= # REMOVE PHP-FPM CONFIGURATION #================================================= -ynh_print_info --message="Removing php-fpm configuration" +ynh_print_info --message="Removing php-fpm configuration..." # Remove the dedicated php-fpm config ynh_remove_fpm_config @@ -45,7 +46,7 @@ ynh_remove_fpm_config #================================================= # REMOVE DEPENDENCIES #================================================= -ynh_print_info --message="Removing dependencies" +ynh_print_info --message="Removing dependencies..." # Remove metapackage and its dependencies ynh_remove_app_dependencies @@ -54,7 +55,7 @@ ynh_remove_php #================================================= # REMOVE APP MAIN DIR #================================================= -ynh_print_info --message="Removing app main directory" +ynh_print_info --message="Removing app main directory..." # Remove the app directory securely ynh_secure_remove --file="$final_path" @@ -62,11 +63,18 @@ ynh_secure_remove --file="$final_path" #================================================= # REMOVE NGINX CONFIGURATION #================================================= -ynh_print_info --message="Removing nginx web server configuration" +ynh_print_info --message="Removing nginx web server configuration..." # Remove the dedicated nginx config ynh_remove_nginx_config +#================================================= +# REMOVE SWAPP +#================================================= +ynh_print_info --message="Removing swap..." + +ynh_del_swap + #================================================= # SPECIFIC REMOVE #================================================= @@ -81,7 +89,7 @@ ynh_secure_remove --file="/etc/cron.d/$app" #================================================= # REMOVE DEDICATED USER #================================================= -ynh_print_info --message="Removing the dedicated system user" +ynh_print_info --message="Removing the dedicated system user..." # Delete a system user ynh_system_user_delete --username=$app diff --git a/scripts/restore b/scripts/restore index f7763d5..fa3c0d6 100644 --- a/scripts/restore +++ b/scripts/restore @@ -10,6 +10,7 @@ source ../settings/scripts/_common.sh source ../settings/scripts/ynh_add_extra_apt_repos__3 source ../settings/scripts/ynh_install_php__3 +source ../settings/scripts/ynh_add_swap source /usr/share/yunohost/helpers #================================================= @@ -30,6 +31,7 @@ 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) db_name=$(ynh_app_setting_get --app=$app --key=db_name) +db_user=$db_name #================================================= # CHECK IF THE APP CAN BE RESTORED @@ -71,12 +73,6 @@ ynh_system_user_create --username=$app --home_dir="$final_path" # Restore permissions on app files chown -R $app: $final_path -#================================================= -# RESTORE THE PHP-FPM CONFIGURATION -#================================================= - -ynh_restore_file --origin_path="/etc/php/7.2/fpm/pool.d/$app.conf" - #================================================= # SPECIFIC RESTORATION #================================================= @@ -94,8 +90,14 @@ ynh_install_php --phpversion="7.2" --package="$extra_pkg_dependencies" ynh_print_info --message="Restoring the MySQL database..." db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd) -ynh_mysql_setup_db --db_user=$db_name --db_name=$db_name --db_pwd=$db_pwd -ynh_mysql_connect_as --user=$db_name --password=$db_pwd --database=$db_name < ./db.sql +ynh_mysql_setup_db --db_user=$db_user --db_name=$db_name --db_pwd=$db_pwd +ynh_mysql_connect_as --user=$db_user --password=$db_pwd --database=$db_name < ./db.sql + +#================================================= +# RESTORE THE PHP-FPM CONFIGURATION +#================================================= + +ynh_restore_file --origin_path="/etc/php/7.2/fpm/pool.d/$app.conf" #================================================= # RESTORE THE CRON FILE @@ -103,6 +105,13 @@ ynh_mysql_connect_as --user=$db_name --password=$db_pwd --database=$db_name < ./ ynh_restore_file --origin_path="/etc/cron.d/$app" +#================================================= +# ADD SWAPP +#================================================= +ynh_print_info --message="Adding swap..." + +ynh_add_swap --size=512 + #================================================= # GENERIC FINALIZATION #================================================= @@ -110,8 +119,8 @@ ynh_restore_file --origin_path="/etc/cron.d/$app" #================================================= ynh_print_info --message="Reloading nginx web server and php-fpm..." -systemctl reload php7.2-fpm -systemctl reload nginx +ynh_systemd_action --service_name=php7.2-fpm --action=reload +ynh_systemd_action --service_name=nginx --action=reload #================================================= # END OF SCRIPT diff --git a/scripts/upgrade b/scripts/upgrade index cda7a3c..647b197 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -10,6 +10,7 @@ source _common.sh source ynh_add_extra_apt_repos__3 source ynh_install_php__3 source ynh_composer__2 +source ynh_add_swap source /usr/share/yunohost/helpers #================================================= @@ -27,6 +28,12 @@ final_path=$(ynh_app_setting_get --app=$app --key=final_path) language=$(ynh_app_setting_get --app=$app --key=language) db_name=$(ynh_app_setting_get --app=$app --key=db_name) +##================================================= +# CHECK VERSION +#================================================= + +upgrade_type=$(ynh_check_app_version_changed) + #================================================= # ENSURE DOWNWARD COMPATIBILITY #================================================= @@ -42,13 +49,13 @@ elif [ "$is_public" = "No" ]; then fi # If db_name doesn't exist, create it -if [ -z $db_name ]; then +if [ -z "$db_name" ]; then db_name=$(ynh_sanitize_dbid --db_name=$app) ynh_app_setting_set --app=$app --key=db_name --value=$db_name fi # If final_path doesn't exist, create it -if [ -z $final_path ]; then +if [ -z "$final_path" ]; then final_path=/var/www/$app ynh_app_setting_set --app=$app --key=final_path --value=$final_path fi @@ -61,7 +68,7 @@ ynh_print_info --message="Backing up the app before upgrading (may take a while) # Backup the current version of the app ynh_backup_before_upgrade ynh_clean_setup () { - read -p "key"# restore it if the upgrade fails + # restore it if the upgrade fails ynh_restore_upgradebackup } # Exit if an error occurs during the execution of the script @@ -69,14 +76,6 @@ ynh_abort_if_errors #================================================= # STANDARD UPGRADE STEPS -#================================================= -# DOWNLOAD, CHECK AND UNPACK SOURCE -#================================================= -ynh_print_info --message="Upgrading source files..." - -# Download, check integrity, uncompress and patch the source from app.src -#ynh_setup_source --dest_dir="$final_path" - #================================================= # NGINX CONFIGURATION #================================================= @@ -111,6 +110,13 @@ ynh_add_fpm_config --phpversion="7.2" #================================================= # SPECIFIC UPGRADE +#================================================= +# ADD SWAPP +#================================================= +ynh_print_info --message="Adding swap..." + +ynh_add_swap --size=512 + #================================================= # UPDATE COMPOSER #================================================= @@ -152,6 +158,18 @@ ynh_backup_if_checksum_is_different --file="$final_path/$app/sites/default/setti # Recalculate and store the checksum of the file for the next upgrade. ynh_store_file_checksum --file="$final_path/$app/sites/default/settings.php" +#================================================= +# SET THE CRON FILE +#================================================= +ynh_print_info --message="Setting the cron file" + +cp -f ../conf/cron /etc/cron.d/$app + +ynh_replace_string --match_string="__FINALPATH__" --replace_string="$final_path" --target_file="/etc/cron.d/$app" +ynh_replace_string --match_string="__APP__" --replace_string="$app" --target_file="/etc/cron.d/$app" + +ynh_systemd_action --service_name=cron --action=restart + #================================================= # GENERIC FINALIZATION #================================================= @@ -178,7 +196,7 @@ fi #================================================= ynh_print_info --message="Reloading nginx web server..." -systemctl reload nginx +ynh_systemd_action --service_name=nginx --action=reload #================================================= # END OF SCRIPT diff --git a/scripts/ynh_add_swap b/scripts/ynh_add_swap new file mode 100644 index 0000000..d7ec44b --- /dev/null +++ b/scripts/ynh_add_swap @@ -0,0 +1,93 @@ +#!/bin/bash + +# Add swap +# +# usage: ynh_add_swap --size=SWAP in Mb +# | arg: -s, --size= - Amount of SWAP to add in Mb. +ynh_add_swap () { + # Declare an array to define the options of this helper. + declare -Ar args_array=( [s]=size= ) + local size + # Manage arguments with getopts + ynh_handle_getopts_args "$@" + + local swap_max_size=$(( $size * 1024 )) + + local free_space=$(df --output=avail / | sed 1d) + # Because we don't want to fill the disk with a swap file, divide by 2 the available space. + local usable_space=$(( $free_space / 2 )) + + SD_CARD_CAN_SWAP=${SD_CARD_CAN_SWAP:-0} + + # Swap on SD card only if it's is specified + if ynh_is_main_device_a_sd_card && [ "$SD_CARD_CAN_SWAP" == "0" ] + then + ynh_print_warn --message="The main mountpoint of your system '/' is on an SD card, swap will not be added to prevent some damage of this one, but that can cause troubles for the app $app. If you still want activate the swap, you can relaunch the command preceded by 'SD_CARD_CAN_SWAP=1'" + return + fi + + # Compare the available space with the size of the swap. + # And set a acceptable size from the request + if [ $usable_space -ge $swap_max_size ] + then + local swap_size=$swap_max_size + elif [ $usable_space -ge $(( $swap_max_size / 2 )) ] + then + local swap_size=$(( $swap_max_size / 2 )) + elif [ $usable_space -ge $(( $swap_max_size / 3 )) ] + then + local swap_size=$(( $swap_max_size / 3 )) + elif [ $usable_space -ge $(( $swap_max_size / 4 )) ] + then + local swap_size=$(( $swap_max_size / 4 )) + else + echo "Not enough space left for a swap file" >&2 + local swap_size=0 + fi + + # If there's enough space for a swap, and no existing swap here + if [ $swap_size -ne 0 ] && [ ! -e /swap_$app ] + then + # Preallocate space for the swap file, fallocate may sometime not be used, use dd instead in this case + if ! fallocate -l ${swap_size}K /swap_$app + then + dd if=/dev/zero of=/swap_$app bs=1024 count=${swap_size} + fi + chmod 0600 /swap_$app + # Create the swap + mkswap /swap_$app + # And activate it + swapon /swap_$app + # Then add an entry in fstab to load this swap at each boot. + echo -e "/swap_$app swap swap defaults 0 0 #Swap added by $app" >> /etc/fstab + fi +} + +ynh_del_swap () { + # If there a swap at this place + if [ -e /swap_$app ] + then + # Clean the fstab + sed -i "/#Swap added by $app/d" /etc/fstab + # Desactive the swap file + swapoff /swap_$app + # And remove it + rm /swap_$app + fi +} + +# Check if the device of the main mountpoint "/" is an SD card +# +# [internal] +# +# return 0 if it's an SD card, else 1 +ynh_is_main_device_a_sd_card () { + local main_device=$(lsblk --output PKNAME --noheadings $(findmnt / --nofsroot --uniq --output source --noheadings --first-only)) + + if echo $main_device | grep --quiet "mmc" && [ $(tail -n1 /sys/block/$main_device/queue/rotational) == "0" ] + then + return 0 + else + return 1 + fi +}