Improve enabling extensions

This commit is contained in:
Shivam Mathur 2022-03-06 11:38:28 +05:30
parent 4056d3f353
commit 62bd8f3ca4
No known key found for this signature in database
GPG Key ID: 3E13E4C8591ACC2A
3 changed files with 13 additions and 7 deletions

View File

@ -28,7 +28,7 @@ disable_extension_helper() {
disable_extension_dependents "$extension" disable_extension_dependents "$extension"
fi fi
sudo sed -Ei '' "/=(.*\/)?\"?$extension(.so)?$/d" "${ini_file:?}" 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" mkdir -p /tmp/extdisabled/"$version"
echo '' | sudo tee /tmp/extdisabled/"$version"/"$extension" >/dev/null 2>&1 echo '' | sudo tee /tmp/extdisabled/"$version"/"$extension" >/dev/null 2>&1
} }

View File

@ -8,10 +8,14 @@ add_extension_log() {
# Function to test if extension is loaded. # Function to test if extension is loaded.
check_extension() { check_extension() {
local extension=$1 local extension=$1
local extension_list=/tmp/php${version:?}_extensions
if [ ! -e "$extension_list" ]; then
php -m > "$extension_list"
fi
if [ "$extension" != "mysql" ]; then 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 else
php -m | grep -i -q "$extension" grep -i -q "$extension" "$extension_list" || php -m | grep -i -q "$extension"
fi fi
} }
@ -38,11 +42,11 @@ enable_cache_extension_dependencies() {
# Function to enable existing extensions. # Function to enable existing extensions.
enable_extension() { enable_extension() {
if ! check_extension "$1" && shared_extension "$1"; then
modules_dir="/var/lib/php/modules/${version:?}" modules_dir="/var/lib/php/modules/${version:?}"
[ -d "$modules_dir" ] && sudo find "$modules_dir" -path "*disabled*$1" -delete [ -d "$modules_dir" ] && sudo find "$modules_dir" -path "*disabled*$1" -delete
enable_extension_dependencies "$1" "$2" enable_extension_dependencies "$1" "$2"
enable_cache_extension_dependencies "$1" "$2" enable_cache_extension_dependencies "$1" "$2"
if ! check_extension "$1" && shared_extension "$1"; then
echo "$2=${ext_dir:?}/$1.so" | sudo tee -a "${pecl_file:-${ini_file[@]}}" >/dev/null echo "$2=${ext_dir:?}/$1.so" | sudo tee -a "${pecl_file:-${ini_file[@]}}" >/dev/null
fi 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 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 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" 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"/{} 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" add_log "${tick:?}" "none" "Disabled all shared extensions"
} }

View File

@ -31,6 +31,7 @@ disable_extension_helper() {
fi fi
sudo sed -Ei "/=(.*\/)?\"?$extension(.so)?$/d" "${ini_file[@]}" "$pecl_file" 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 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" mkdir -p /tmp/extdisabled/"$version"
echo '' | sudo tee /tmp/extdisabled/"$version"/"$extension" >/dev/null 2>&1 echo '' | sudo tee /tmp/extdisabled/"$version"/"$extension" >/dev/null 2>&1
} }