diff --git a/README.md b/README.md index e043afd..7dbd5ea 100644 --- a/README.md +++ b/README.md @@ -57,6 +57,12 @@ If PHP PEAR is down you can install PHP without PEAR. Specify `PHP_WITHOUT_PEAR` PHP_WITHOUT_PEAR=yes asdf install php ``` +#### Patch support + +``` +PHP_APPLY_PATCHES=$'dir/1.patch\n2.patch\nhttp://example.com/3.patch' asdf install php 7.1.1 +``` + ## Usage Check [asdf](https://github.com/asdf-vm/asdf) readme for instructions on how to diff --git a/bin/install b/bin/install index a4b60c8..2d2a968 100755 --- a/bin/install +++ b/bin/install @@ -6,6 +6,7 @@ install_php() { local install_type=$1 local version=$2 local install_path=$3 + local start_dir=$(pwd) if [ "$TMPDIR" = "" ]; then local tmp_download_dir=$(mktemp -d) @@ -79,6 +80,8 @@ install_php() { cd $(untar_path $install_type $version $tmp_download_dir) + apply_custom_patches "$start_dir" || exit 1 + # Target is OS-specific # target=$(get_target) @@ -109,6 +112,43 @@ install_composer() { $bin_path/php -r "unlink('composer-setup.php');" } +apply_custom_patches() { + local start_dir=$1 + while read -r line; do + if [ "$line" = "" ]; then + continue + fi + # define earlier, so that the exit 1 shorthand below works + local content + if [[ "$line" =~ ^[Hh][Tt][Tt][Pp][Ss]?:// ]]; then + echo "Applying patch from URL: $line" + content=$(curl -Sfs "$line") || exit 1 + else + local abs_path=$(get_absolute_path "$start_dir" "$line") + echo "Applying local patch: $abs_path" + content=$(<"$abs_path") || exit 1 + fi + + local striplevel=0 + grep -q '^diff --git a/' <<< "$content" && striplevel=1 + patch -p$striplevel --force <<< "$content" || exit 1 + done <<< "$PHP_APPLY_PATCHES" +} + +get_absolute_path() { + local start_dir=$1 + local rel_path=$2 + local rel_dir=$(dirname "$rel_path") + local rel_base=$(basename "$rel_path") + + ( + cd "$start_dir" \ + && cd "$rel_dir" 2>/dev/null \ + && echo "$(pwd)/$rel_base" \ + || echo "$rel_path" + ) +} + construct_configure_options() { local install_path=$1