From 62bd8f3ca4b377bac4a576fb3fe89a031c577770 Mon Sep 17 00:00:00 2001 From: Shivam Mathur Date: Sun, 6 Mar 2022 11:38:28 +0530 Subject: [PATCH] Improve enabling extensions --- src/scripts/darwin.sh | 2 +- src/scripts/extensions/add_extensions.sh | 17 +++++++++++------ src/scripts/linux.sh | 1 + 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/scripts/darwin.sh b/src/scripts/darwin.sh index d6facaa0..6726c217 100644 --- a/src/scripts/darwin.sh +++ b/src/scripts/darwin.sh @@ -28,7 +28,7 @@ disable_extension_helper() { disable_extension_dependents "$extension" fi sudo sed -Ei '' "/=(.*\/)?\"?$extension(.so)?$/d" "${ini_file:?}" - sudo rm -rf "$scan_dir"/*"$extension"* + sudo rm -rf "$scan_dir"/*"$extension"* /tmp/php"$version"_extensions mkdir -p /tmp/extdisabled/"$version" echo '' | sudo tee /tmp/extdisabled/"$version"/"$extension" >/dev/null 2>&1 } diff --git a/src/scripts/extensions/add_extensions.sh b/src/scripts/extensions/add_extensions.sh index af79cb8d..a7ecfe2b 100644 --- a/src/scripts/extensions/add_extensions.sh +++ b/src/scripts/extensions/add_extensions.sh @@ -8,10 +8,14 @@ add_extension_log() { # Function to test if extension is loaded. check_extension() { local extension=$1 + local extension_list=/tmp/php${version:?}_extensions + if [ ! -e "$extension_list" ]; then + php -m > "$extension_list" + fi if [ "$extension" != "mysql" ]; then - php -m | grep -i -q -w "$extension" + grep -i -q -w "$extension" "$extension_list" || php -m | grep -i -q -w "$extension" else - php -m | grep -i -q "$extension" + grep -i -q "$extension" "$extension_list" || php -m | grep -i -q "$extension" fi } @@ -38,11 +42,11 @@ enable_cache_extension_dependencies() { # Function to enable existing extensions. enable_extension() { - modules_dir="/var/lib/php/modules/${version:?}" - [ -d "$modules_dir" ] && sudo find "$modules_dir" -path "*disabled*$1" -delete - enable_extension_dependencies "$1" "$2" - enable_cache_extension_dependencies "$1" "$2" if ! check_extension "$1" && shared_extension "$1"; then + modules_dir="/var/lib/php/modules/${version:?}" + [ -d "$modules_dir" ] && sudo find "$modules_dir" -path "*disabled*$1" -delete + enable_extension_dependencies "$1" "$2" + enable_cache_extension_dependencies "$1" "$2" echo "$2=${ext_dir:?}/$1.so" | sudo tee -a "${pecl_file:-${ini_file[@]}}" >/dev/null fi } @@ -108,6 +112,7 @@ disable_all_shared() { sudo sed -i.orig -E -e "/^(zend_)?extension\s*=/d" "${ini_file[@]}" "$pecl_file" 2>/dev/null || true sudo find "${ini_dir:-$scan_dir}"/.. -name "*.ini" -not -path "*php.ini" -not -path "*phar.ini" -not -path "*pecl.ini" -not -path "*mods-available*" -delete >/dev/null 2>&1 || true mkdir -p /tmp/extdisabled/"$version" + sudo rm -f /tmp/php"$version"_extensions sudo find "$ext_dir" -name '*.so' -print0 | xargs -0 -n 1 basename -s .so | xargs -n 1 -I{} touch /tmp/extdisabled/"$version"/{} add_log "${tick:?}" "none" "Disabled all shared extensions" } diff --git a/src/scripts/linux.sh b/src/scripts/linux.sh index c98700d3..8e7ade47 100644 --- a/src/scripts/linux.sh +++ b/src/scripts/linux.sh @@ -31,6 +31,7 @@ disable_extension_helper() { fi sudo sed -Ei "/=(.*\/)?\"?$extension(.so)?$/d" "${ini_file[@]}" "$pecl_file" sudo find "$ini_dir"/.. -name "*$extension.ini" -not -path "*phar.ini" -not -path "*pecl.ini" -not -path "*mods-available*" -delete >/dev/null 2>&1 || true + sudo rm -f /tmp/php"$version"_extensions mkdir -p /tmp/extdisabled/"$version" echo '' | sudo tee /tmp/extdisabled/"$version"/"$extension" >/dev/null 2>&1 }