From e510f0da883410ba198f8ab588daa9ce8f4b6d78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20Pi=C3=A9dallu?= Date: Wed, 19 Jun 2024 15:00:25 +0200 Subject: [PATCH 1/3] helpers.v2.1/php: Download composer in /opt/yunohost/composer instead of in workdir. --- helpers/helpers.v2.1.d/composer | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/helpers/helpers.v2.1.d/composer b/helpers/helpers.v2.1.d/composer index b9608f693c..0daa751581 100644 --- a/helpers/helpers.v2.1.d/composer +++ b/helpers/helpers.v2.1.d/composer @@ -1,5 +1,7 @@ #!/bin/bash +composer_install_dir="/opt/yunohost/composer" + # Install and initialize Composer in the given directory # # The installed version is defined by `$composer_version` which should be defined @@ -13,16 +15,27 @@ ynh_composer_install() { [[ -n "${composer_version}" ]] || ynh_die "\$composer_version should be defined before calling ynh_composer_install. (In the past, this was called \$YNH_COMPOSER_VERSION)" - [[ ! -e "$workdir/composer.phar" ]] || ynh_safe_rm $workdir/composer.phar - local composer_url="https://getcomposer.org/download/$composer_version/composer.phar" + local composer_phar_path="$composer_install_dir/composer_${composer_version}.phar" + + # Remove legacy composer.phar in work directory + if [ -f "$workdir/composer.phar" ]; then + ynh_safe_rm "$workdir/composer.phar" + fi + + # Early exit if already downloaded + if [ -f "$composer_phar_path" ]; then + return + fi + + mkdir -p "$composer_install_dir" # NB. we have to declare the var as local first, # otherwise 'local foo=$(false) || echo 'pwet'" does'nt work # because local always return 0 ... local out # Timeout option is here to enforce the timeout on dns query and tcp connect (c.f. man wget) - out=$(wget --tries 3 --no-dns-cache --timeout 900 --no-verbose --output-document=$workdir/composer.phar $composer_url 2>&1) \ + out=$(wget --tries 3 --no-dns-cache --timeout 900 --no-verbose --output-document="$composer_phar_path" "$composer_url" 2>&1) \ || ynh_die "$out" } @@ -36,10 +49,11 @@ ynh_composer_install() { # usage: ynh_composer_exec commands ynh_composer_exec() { local workdir="${composer_workdir:-$install_dir}" + local composer_phar_path="$composer_install_dir/composer_${composer_version}.phar" COMPOSER_HOME="$workdir/.composer" \ COMPOSER_MEMORY_LIMIT=-1 \ sudo -E -u "${composer_user:-$app}" \ - php${php_version} "$workdir/composer.phar" $@ \ + "php${php_version}" "$composer_phar_path" $@ \ -d "$workdir" --no-interaction --no-ansi 2>&1 } From f2696fddabc41245fc418d678493705a999209ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20Pi=C3=A9dallu?= Date: Wed, 19 Jun 2024 15:06:09 +0200 Subject: [PATCH 2/3] helpers.v2.1/utils: ynh_setup_source : replace --full_replace with --merge_with_existing, making cleanup before installation the default behaviour. --- helpers/helpers.v1.d/sources | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/helpers/helpers.v1.d/sources b/helpers/helpers.v1.d/sources index 9bb0b1c999..247668b8cc 100644 --- a/helpers/helpers.v1.d/sources +++ b/helpers/helpers.v1.d/sources @@ -60,7 +60,7 @@ # - Uncompress the archive to `$dest_dir`. # - If `in_subdir` is true, the first level directory of the archive will be removed. # - If `in_subdir` is a numeric value, the N first level directories will be removed. -# - Patches named `sources/patches/${src_id}-*.patch` will be applied to `$dest_dir` +# - Patches named `sources/patches/${src_id}/*.patch` will be applied to `$dest_dir` # - Extra files in `sources/extra_files/$src_id` will be copied to dest_dir # # Requires YunoHost version 2.6.4 or higher. @@ -261,16 +261,16 @@ ynh_setup_source() { fi # Apply patches - if [ -d "$YNH_APP_BASEDIR/sources/patches/" ]; then - local patches_folder=$(realpath $YNH_APP_BASEDIR/sources/patches/) - if (($(find $patches_folder -type f -name "${source_id}-*.patch" 2>/dev/null | wc --lines) > "0")); then - pushd "$dest_dir" - for p in $patches_folder/${source_id}-*.patch; do - echo $p - patch --strip=1 <$p || ynh_print_warn --message="Packagers /!\\ patch $p failed to apply" - done - popd - fi + local patches_folder=$(realpath "$YNH_APP_BASEDIR/patches/$source_id") + if [ -d "$patches_folder" ]; then + pushd "$dest_dir" + for patchfile in "$patches_folder/"*.patch; do + echo "$patchfile" + if ! patch --strip=1 < "$patchfile"; then + ynh_print_warn --message="Warn your packagers /!\\ patch $patchfile failed to apply" + fi + done + popd fi # Add supplementary files From 7d2500f7f3f3e708d088cc5a7d9a3ae4f57df87b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20Pi=C3=A9dallu?= Date: Wed, 19 Jun 2024 15:14:25 +0200 Subject: [PATCH 3/3] helpers.v2.1: Add ynh_in_ci_tests to check if the scripts are running in CI or not --- helpers/helpers.v1.d/sources | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/helpers/helpers.v1.d/sources b/helpers/helpers.v1.d/sources index 247668b8cc..d8805c4930 100644 --- a/helpers/helpers.v1.d/sources +++ b/helpers/helpers.v1.d/sources @@ -267,8 +267,11 @@ ynh_setup_source() { for patchfile in "$patches_folder/"*.patch; do echo "$patchfile" if ! patch --strip=1 < "$patchfile"; then - ynh_print_warn --message="Warn your packagers /!\\ patch $patchfile failed to apply" - fi + if ynh_in_ci_tests; then + ynh_die --message"Patch $patchfile failed to apply!" + else + ynh_print_warn --message="Warn your packagers /!\\ patch $patchfile failed to apply" + fi fi done popd fi