diff --git a/conf/composer.json b/conf/composer.json index e5d85f0..7694e1c 100644 --- a/conf/composer.json +++ b/conf/composer.json @@ -1,13 +1,14 @@ { - "name": "drupal/recommended-project", - "description": "Project template for Drupal 9 projects with a relocated document root", + "name": "drupal-composer/drupal-project", + "description": "Project template for Drupal 10 projects with Composer", "type": "project", "license": "GPL-2.0-or-later", - "homepage": "https://www.drupal.org/project/drupal", - "support": { - "docs": "https://www.drupal.org/docs/user_guide/en/index.html", - "chat": "https://www.drupal.org/node/314178" - }, + "authors": [ + { + "name": "", + "role": "" + } + ], "repositories": [ { "type": "composer", @@ -15,14 +16,17 @@ } ], "require": { - "composer/installers": "^1.9", - "drupal/core-composer-scaffold": "^9.3", - "drupal/core-project-message": "^9.3", - "drupal/core-recommended": "^9.3", - "drush/drush": "^11.0.0" + "php": ">=8.1", + "composer/installers": "^2.1", + "cweagans/composer-patches": "^1.7", + "drupal/core-composer-scaffold": "^10.0.0", + "drupal/core-recommended": "^10.0.0", + "drush/drush": "^11.4.0", + "vlucas/phpdotenv": "^5.1", + "webflo/drupal-finder": "^1.2" }, "require-dev": { - "drupal/core-dev": "^9.3" + "drupal/core-dev": "^10.0.0" }, "conflict": { "drupal/drupal": "*" @@ -30,7 +34,35 @@ "minimum-stability": "dev", "prefer-stable": true, "config": { - "sort-packages": true + "discard-changes": true, + "sort-packages": true, + "allow-plugins": { + "composer/installers": true, + "cweagans/composer-patches": true, + "drupal/core-composer-scaffold": true, + "dealerdirect/phpcodesniffer-composer-installer": true, + "phpstan/extension-installer": true + } + }, + "autoload": { + "classmap": [ + "scripts/composer/ScriptHandler.php" + ], + "files": ["load.environment.php"] + }, + "scripts": { + "pre-install-cmd": [ + "DrupalProject\\composer\\ScriptHandler::checkComposerVersion" + ], + "pre-update-cmd": [ + "DrupalProject\\composer\\ScriptHandler::checkComposerVersion" + ], + "post-install-cmd": [ + "DrupalProject\\composer\\ScriptHandler::createRequiredFiles" + ], + "post-update-cmd": [ + "DrupalProject\\composer\\ScriptHandler::createRequiredFiles" + ] }, "extra": { "drupal-scaffold": { @@ -46,26 +78,19 @@ "__APP__/themes/contrib/{$name}": ["type:drupal-theme"], "drush/Commands/contrib/{$name}": ["type:drupal-drush"], "__APP__/modules/custom/{$name}": ["type:drupal-custom-module"], - "__APP__/themes/custom/{$name}": ["type:drupal-custom-theme"] + "__APP__/themes/custom/{$name}": ["type:drupal-custom-theme"], + "web/core": ["type:drupal-core"], + "web/libraries/{$name}": ["type:drupal-library"], + "web/modules/contrib/{$name}": ["type:drupal-module"], + "web/profiles/contrib/{$name}": ["type:drupal-profile"], + "web/themes/contrib/{$name}": ["type:drupal-theme"], + "drush/Commands/contrib/{$name}": ["type:drupal-drush"] }, - "drupal-core-project-message": { - "include-keys": ["homepage", "support"], - "post-create-project-cmd-message": [ - " ", - " Congratulations, you’ve installed the Drupal codebase ", - " from the drupal/recommended-project template! ", - " ", - "", - "Next steps:", - - " * Install the site: https://www.drupal.org/docs/8/install", - " * Read the user guide: https://www.drupal.org/docs/user_guide/en/index.html", - " * Get support: https://www.drupal.org/support", - " * Get involved with the Drupal community:", - " https://www.drupal.org/getting-involved", - " * Remove the plugin that prints this message:", - " composer remove drupal/core-project-message" - ] + "composer-exit-on-patch-failure": true, + "patchLevel": { + "drupal/core": "-p2" + }, + "patches": { } } } diff --git a/manifest.toml b/manifest.toml index 1a3376f..8527e1f 100644 --- a/manifest.toml +++ b/manifest.toml @@ -7,7 +7,7 @@ name = "Drupal" description.en = "Content management framework" description.fr = "Système de gestion de contenu" -version = "9.5.10~ynh2" +version = "9.5.3~ynh3" maintainers = ["yalh76"] @@ -85,10 +85,8 @@ ram.runtime = "50M" "php8.2-xml", "php8.2-ldap", "php8.2-mbstring", - "php8.2-json", "php8.2-simplexml", "php8.2-curl", - "php8.2-readline", ] [resources.database] diff --git a/scripts/_common.sh b/scripts/_common.sh index 43e79e2..2c147c8 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -25,3 +25,95 @@ _ynh_exec_with_drush_php() { #================================================= # FUTURE OFFICIAL HELPERS #================================================= + +# 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 +} diff --git a/scripts/install b/scripts/install index 2767f9d..8213027 100644 --- a/scripts/install +++ b/scripts/install @@ -7,7 +7,6 @@ #================================================= source _common.sh -source ynh_add_swap source /usr/share/yunohost/helpers #================================================= diff --git a/scripts/remove b/scripts/remove index ae12191..f48d34d 100644 --- a/scripts/remove +++ b/scripts/remove @@ -24,11 +24,6 @@ ynh_remove_fpm_config # Remove the cron file ynh_secure_remove --file="/etc/cron.d/$app" -#================================================= -# REMOVE SWAP -#================================================= -ynh_script_progression --message="Removing swap..." - ynh_del_swap #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index bc225c0..50dd4b9 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -24,7 +24,7 @@ ynh_script_progression --message="Ensuring downward compatibility..." --weight=1 ynh_script_progression --message="Upgrading source files..." --weight=1 # Download, check integrity, uncompress and patch the source from app.src -ynh_setup_source --dest_dir="$install_dir" --full_replace --keep="app composer.json" +ynh_setup_source --dest_dir="$install_dir" ynh_store_file_checksum --file="$install_dir/composer.json" mkdir -p "$install_dir/$app"