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

View File

@ -109,6 +109,18 @@ configure_pecl() {
fi 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. # Function to get the PECL version of an extension.
get_pecl_version() { get_pecl_version() {
local extension=$1 local extension=$1

View File

@ -68,19 +68,13 @@ check_package() {
apt-cache policy "$1" 2>/dev/null | grep -q 'Candidate' apt-cache policy "$1" 2>/dev/null | grep -q 'Candidate'
} }
# Function to add extensions. # Helper function to add an extension.
add_extension() { add_extension_helper() {
local extension=$1 local extension=$1
prefix=$2
package=php"$version"-"$extension" 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 add_ppa ondrej/php >/dev/null 2>&1 || update_ppa ondrej/php
(check_package "$package" && install_packages "$package") || pecl_install "$extension" (check_package "$package" && install_packages "$package") || pecl_install "$extension"
add_extension_log "$extension" "Installed and enabled" add_extension_log "$extension" "Installed and enabled"
fi
sudo chmod 777 "${ini_file[@]}" sudo chmod 777 "${ini_file[@]}"
} }