mirror of
https://github.com/shivammathur/setup-php.git
synced 2024-11-26 13:23:05 +07:00
Improve package checks for extensions
This commit is contained in:
parent
ea20ae1fbd
commit
d259dd49a2
@ -14,7 +14,6 @@ self_hosted_helper() {
|
|||||||
# Function to install a package
|
# Function to install a package
|
||||||
install_packages() {
|
install_packages() {
|
||||||
packages=("$@")
|
packages=("$@")
|
||||||
[[ "${packages[*]}" =~ php ]] && add_ppa ondrej/php >/dev/null 2>&1
|
|
||||||
$apt_install "${packages[@]}" >/dev/null 2>&1 || (update_lists && $apt_install "${packages[@]}" >/dev/null 2>&1)
|
$apt_install "${packages[@]}" >/dev/null 2>&1 || (update_lists && $apt_install "${packages[@]}" >/dev/null 2>&1)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -60,19 +59,22 @@ add_pdo_extension() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Function to check if a package exists
|
||||||
|
check_package() {
|
||||||
|
sudo apt-cache policy "$1" 2>/dev/null | grep -q 'Candidate'
|
||||||
|
}
|
||||||
|
|
||||||
# Function to add extensions.
|
# Function to add extensions.
|
||||||
add_extension() {
|
add_extension() {
|
||||||
local extension=$1
|
local extension=$1
|
||||||
prefix=$2
|
prefix=$2
|
||||||
|
package=php"$version"-"$extension"
|
||||||
enable_extension "$extension" "$prefix"
|
enable_extension "$extension" "$prefix"
|
||||||
if check_extension "$extension"; then
|
if check_extension "$extension"; then
|
||||||
add_log "${tick:?}" "$extension" "Enabled"
|
add_log "${tick:?}" "$extension" "Enabled"
|
||||||
else
|
else
|
||||||
if [[ "$version" =~ ${nightly_versions:?} ]]; then
|
add_ppa ondrej/php >/dev/null 2>&1 || update_ppa ondrej/php
|
||||||
pecl_install "$extension"
|
(check_package "$package" && install_packages "$package") || pecl_install "$extension"
|
||||||
else
|
|
||||||
install_packages "php$version-$extension" || pecl_install "$extension"
|
|
||||||
fi
|
|
||||||
add_extension_log "$extension" "Installed and enabled"
|
add_extension_log "$extension" "Installed and enabled"
|
||||||
fi
|
fi
|
||||||
sudo chmod 777 "${ini_file[@]}"
|
sudo chmod 777 "${ini_file[@]}"
|
||||||
@ -125,7 +127,7 @@ switch_version() {
|
|||||||
# Function to install packaged PHP
|
# Function to install packaged PHP
|
||||||
add_packaged_php() {
|
add_packaged_php() {
|
||||||
if [ "$runner" = "self-hosted" ] || [ "${use_package_cache:-true}" = "false" ]; then
|
if [ "$runner" = "self-hosted" ] || [ "${use_package_cache:-true}" = "false" ]; then
|
||||||
update_lists
|
add_ppa ondrej/php >/dev/null 2>&1 || update_ppa ondrej/php
|
||||||
IFS=' ' read -r -a packages <<<"$(echo "cli curl mbstring xml intl" | sed "s/[^ ]*/php$version-&/g")"
|
IFS=' ' read -r -a packages <<<"$(echo "cli curl mbstring xml intl" | sed "s/[^ ]*/php$version-&/g")"
|
||||||
install_packages "${packages[@]}"
|
install_packages "${packages[@]}"
|
||||||
else
|
else
|
||||||
|
@ -121,6 +121,7 @@ add_list() {
|
|||||||
ppa_search="deb .*$ppa_url $package_dist .*$branches"
|
ppa_search="deb .*$ppa_url $package_dist .*$branches"
|
||||||
if check_lists "$ppa" "$ppa_search"; then
|
if check_lists "$ppa" "$ppa_search"; then
|
||||||
echo "Repository $ppa already exists";
|
echo "Repository $ppa already exists";
|
||||||
|
return 1;
|
||||||
else
|
else
|
||||||
arch=$(dpkg --print-architecture)
|
arch=$(dpkg --print-architecture)
|
||||||
[ -e "$key_source" ] && key_file=$key_source || key_file="$key_dir"/"${ppa/\//-}"-keyring.gpg
|
[ -e "$key_source" ] && key_file=$key_source || key_file="$key_dir"/"${ppa/\//-}"-keyring.gpg
|
||||||
@ -129,6 +130,7 @@ add_list() {
|
|||||||
update_lists "$ppa" "$ppa_search"
|
update_lists "$ppa" "$ppa_search"
|
||||||
. /etc/os-release
|
. /etc/os-release
|
||||||
fi
|
fi
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
# Function to remove a PPA.
|
# Function to remove a PPA.
|
||||||
@ -150,6 +152,20 @@ add_ppa() {
|
|||||||
else
|
else
|
||||||
add_list "$ppa"
|
add_list "$ppa"
|
||||||
fi
|
fi
|
||||||
|
status="$?"
|
||||||
|
. /etc/os-release
|
||||||
|
return $status
|
||||||
|
}
|
||||||
|
|
||||||
|
# Function to update a PPA.
|
||||||
|
update_ppa() {
|
||||||
|
set_base_version
|
||||||
|
ppa=${1:-ondrej/php}
|
||||||
|
ppa_url=${2:-"$lp_ppa/$ppa/ubuntu"}
|
||||||
|
package_dist=${4:-"$VERSION_CODENAME"}
|
||||||
|
branches=${5:-main}
|
||||||
|
ppa_search="deb .*$ppa_url $package_dist .*$branches"
|
||||||
|
update_lists "$ppa" "$ppa_search"
|
||||||
. /etc/os-release
|
. /etc/os-release
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user