Refactor add_extension

This commit is contained in:
Shivam Mathur 2022-01-13 06:33:07 +05:30
parent 62d47dd238
commit 9ea5899759
No known key found for this signature in database
GPG Key ID: 3E13E4C8591ACC2A
3 changed files with 24 additions and 23 deletions

View File

@ -78,22 +78,17 @@ add_brew_extension() {
fi
}
# Function to setup extensions.
add_extension() {
# Helper function to add an extension.
add_extension_helper() {
local extension=$1
prefix=$2
enable_extension "$extension" "$prefix"
if check_extension "$extension"; then
add_log "${tick:?}" "$extension" "Enabled"
if [[ "$version" =~ ${old_versions:?} ]] && [ "$extension" = "imagick" ]; then
run_script "php5-darwin" "${version/./}" "$extension" >/dev/null 2>&1
else
if [[ "$version" =~ ${old_versions:?} ]] && [ "$extension" = "imagick" ]; then
run_script "php5-darwin" "${version/./}" "$extension" >/dev/null 2>&1
else
pecl_install "$extension" >/dev/null 2>&1 &&
if [[ "$version" =~ ${old_versions:?} ]]; then echo "$prefix=$ext_dir/$extension.so" >>"$ini_file"; fi
fi
add_extension_log "$extension" "Installed and enabled"
pecl_install "$extension" >/dev/null 2>&1 &&
if [[ "$version" =~ ${old_versions:?} ]]; then echo "$prefix=$ext_dir/$extension.so" >>"$ini_file"; fi
fi
add_extension_log "$extension" "Installed and enabled"
}
# Function to handle request to add phpize and php-config.

View File

@ -109,6 +109,18 @@ configure_pecl() {
fi
}
# Function to add an extension.
add_extension() {
local extension=$1
prefix=$2
enable_extension "$extension" "$prefix"
if check_extension "$extension"; then
add_log "${tick:?}" "$extension" "Enabled"
else
add_extension_helper "$extension" "$prefix"
fi
}
# Function to get the PECL version of an extension.
get_pecl_version() {
local extension=$1

View File

@ -68,19 +68,13 @@ check_package() {
apt-cache policy "$1" 2>/dev/null | grep -q 'Candidate'
}
# Function to add extensions.
add_extension() {
# Helper function to add an extension.
add_extension_helper() {
local extension=$1
prefix=$2
package=php"$version"-"$extension"
enable_extension "$extension" "$prefix"
if check_extension "$extension"; then
add_log "${tick:?}" "$extension" "Enabled"
else
add_ppa ondrej/php >/dev/null 2>&1 || update_ppa ondrej/php
(check_package "$package" && install_packages "$package") || pecl_install "$extension"
add_extension_log "$extension" "Installed and enabled"
fi
add_ppa ondrej/php >/dev/null 2>&1 || update_ppa ondrej/php
(check_package "$package" && install_packages "$package") || pecl_install "$extension"
add_extension_log "$extension" "Installed and enabled"
sudo chmod 777 "${ini_file[@]}"
}