mirror of
https://github.com/shivammathur/setup-php.git
synced 2024-11-26 13:23:05 +07:00
Optimize Linux and macOS setup
This commit is contained in:
parent
2b729b1130
commit
2ee6797b63
@ -167,7 +167,7 @@ fix_dependencies() {
|
|||||||
get_brewed_php() {
|
get_brewed_php() {
|
||||||
php_cellar="$brew_prefix"/Cellar/php
|
php_cellar="$brew_prefix"/Cellar/php
|
||||||
if [ -d "$php_cellar" ] && ! [[ "$(find "$php_cellar" -maxdepth 1 -name "$version*" | wc -l 2>/dev/null)" -eq 0 ]]; then
|
if [ -d "$php_cellar" ] && ! [[ "$(find "$php_cellar" -maxdepth 1 -name "$version*" | wc -l 2>/dev/null)" -eq 0 ]]; then
|
||||||
php-config --version 2>/dev/null | cut -c 1-3
|
php_semver | cut -c 1-3
|
||||||
else
|
else
|
||||||
echo 'false';
|
echo 'false';
|
||||||
fi
|
fi
|
||||||
@ -198,6 +198,7 @@ php_extra_version() {
|
|||||||
# Function to Setup PHP.
|
# Function to Setup PHP.
|
||||||
setup_php() {
|
setup_php() {
|
||||||
step_log "Setup PHP"
|
step_log "Setup PHP"
|
||||||
|
php_config="$(command -v php-config 2>/dev/null)"
|
||||||
existing_version=$(get_brewed_php)
|
existing_version=$(get_brewed_php)
|
||||||
if [[ "$version" =~ ${old_versions:?} ]]; then
|
if [[ "$version" =~ ${old_versions:?} ]]; then
|
||||||
run_script "php5-darwin" "${version/./}" >/dev/null 2>&1
|
run_script "php5-darwin" "${version/./}" >/dev/null 2>&1
|
||||||
@ -214,13 +215,13 @@ setup_php() {
|
|||||||
fi
|
fi
|
||||||
php_config="$(command -v php-config)"
|
php_config="$(command -v php-config)"
|
||||||
ext_dir="$(grep 'extension_dir=' "$php_config" | cut -d "'" -f 2)"
|
ext_dir="$(grep 'extension_dir=' "$php_config" | cut -d "'" -f 2)"
|
||||||
ini_dir="$(php --ini | grep '(php.ini)' | sed -e "s|.*: s*||")"
|
ini_dir="$(php_ini_path)"
|
||||||
scan_dir="$ini_dir"/conf.d
|
scan_dir="$ini_dir"/conf.d
|
||||||
ini_file="$ini_dir"/php.ini
|
ini_file="$ini_dir"/php.ini
|
||||||
sudo mkdir -m 777 -p "$ext_dir" "$HOME/.composer"
|
sudo mkdir -m 777 -p "$ext_dir" "$HOME/.composer"
|
||||||
sudo chmod 777 "$ini_file" "${tool_path_dir:?}"
|
sudo chmod 777 "$ini_file" "${tool_path_dir:?}"
|
||||||
semver=$(php_semver)
|
semver="$(php_semver)"
|
||||||
extra_version=$(php_extra_version)
|
extra_version="$(php_extra_version)"
|
||||||
configure_php
|
configure_php
|
||||||
if [ "${semver%.*}" != "$version" ]; then
|
if [ "${semver%.*}" != "$version" ]; then
|
||||||
add_log "${cross:?}" "PHP" "Could not setup PHP $version"
|
add_log "${cross:?}" "PHP" "Could not setup PHP $version"
|
||||||
@ -236,8 +237,10 @@ setup_php() {
|
|||||||
version=$1
|
version=$1
|
||||||
dist=$2
|
dist=$2
|
||||||
php_formula=shivammathur/php/php@"$version"
|
php_formula=shivammathur/php/php@"$version"
|
||||||
brew_prefix="$(brew --prefix)"
|
brew_path="$(command -v brew)"
|
||||||
brew_repo="$(brew --repository)"
|
brew_path_dir="$(dirname "$brew_path")"
|
||||||
|
brew_prefix="$brew_path_dir"/..
|
||||||
|
brew_repo="$brew_path_dir/$(dirname "$(readlink "$brew_path")")"/..
|
||||||
tap_dir="$brew_repo"/Library/Taps
|
tap_dir="$brew_repo"/Library/Taps
|
||||||
core_repo="$tap_dir"/homebrew/homebrew-core
|
core_repo="$tap_dir"/homebrew/homebrew-core
|
||||||
scripts="${dist}"/../src/scripts
|
scripts="${dist}"/../src/scripts
|
||||||
|
@ -182,7 +182,8 @@ php_extra_version() {
|
|||||||
setup_php() {
|
setup_php() {
|
||||||
step_log "Setup PHP"
|
step_log "Setup PHP"
|
||||||
sudo mkdir -m 777 -p /var/run /run/php
|
sudo mkdir -m 777 -p /var/run /run/php
|
||||||
if [ "$(php-config --version 2>/dev/null | cut -c 1-3)" != "$version" ]; then
|
php_config="$(command -v php-config)"
|
||||||
|
if [[ -z "$php_config" ]] || [ "$(php_semver | cut -c 1-3)" != "$version" ]; then
|
||||||
if [ ! -e "/usr/bin/php$version" ]; then
|
if [ ! -e "/usr/bin/php$version" ]; then
|
||||||
add_php >/dev/null 2>&1
|
add_php >/dev/null 2>&1
|
||||||
else
|
else
|
||||||
@ -195,6 +196,7 @@ setup_php() {
|
|||||||
status="Switched to"
|
status="Switched to"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
php_config="$(command -v php-config)"
|
||||||
else
|
else
|
||||||
if [ "$update" = "true" ]; then
|
if [ "$update" = "true" ]; then
|
||||||
update_php >/dev/null 2>&1
|
update_php >/dev/null 2>&1
|
||||||
@ -206,13 +208,12 @@ setup_php() {
|
|||||||
add_log "${cross:?}" "PHP" "Could not setup PHP $version"
|
add_log "${cross:?}" "PHP" "Could not setup PHP $version"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
php_config="$(command -v php-config)"
|
|
||||||
ext_dir="/usr/$(grep -Po "extension_dir=..[^/]*/\K[^'\"]*" "$php_config")"
|
ext_dir="/usr/$(grep -Po "extension_dir=..[^/]*/\K[^'\"]*" "$php_config")"
|
||||||
ini_dir=$(php --ini | grep "(php.ini)" | sed -e "s|.*: s*||")
|
ini_dir="$(php_ini_path)"
|
||||||
scan_dir="$ini_dir"/conf.d
|
scan_dir="$ini_dir"/conf.d
|
||||||
pecl_file="$scan_dir"/99-pecl.ini
|
pecl_file="$scan_dir"/99-pecl.ini
|
||||||
semver=$(php_semver)
|
semver="$(php_semver)"
|
||||||
extra_version=$(php_extra_version)
|
extra_version="$(php_extra_version)"
|
||||||
export ext_dir
|
export ext_dir
|
||||||
mapfile -t ini_file < <(sudo find "$ini_dir/.." -name "php.ini" -exec readlink -m {} +)
|
mapfile -t ini_file < <(sudo find "$ini_dir/.." -name "php.ini" -exec readlink -m {} +)
|
||||||
link_pecl_file
|
link_pecl_file
|
||||||
|
@ -147,6 +147,11 @@ php_semver() {
|
|||||||
grep -Eo 'version="[0-9]+(\.[0-9]+){2}((-?[a-zA-Z]+([0-9]+)?)?){2}' "${php_config:?}" | cut -d '"' -f 2
|
grep -Eo 'version="[0-9]+(\.[0-9]+){2}((-?[a-zA-Z]+([0-9]+)?)?){2}' "${php_config:?}" | cut -d '"' -f 2
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Function to get ini_path.
|
||||||
|
php_ini_path() {
|
||||||
|
cut -d '"' -f 2 < <(grep "ini_path=" "$php_config" || php --ini | grep '(php.ini)' | sed -e "s|.*: s*||")
|
||||||
|
}
|
||||||
|
|
||||||
# Function to get the tag for a php version.
|
# Function to get the tag for a php version.
|
||||||
php_src_tag() {
|
php_src_tag() {
|
||||||
commit=$(php_extra_version | grep -Eo "[0-9a-zA-Z]+")
|
commit=$(php_extra_version | grep -Eo "[0-9a-zA-Z]+")
|
||||||
|
Loading…
Reference in New Issue
Block a user