Optimize Linux and macOS setup

This commit is contained in:
Shivam Mathur 2022-01-18 08:44:46 +05:30
parent 2b729b1130
commit 2ee6797b63
No known key found for this signature in database
GPG Key ID: 3E13E4C8591ACC2A
3 changed files with 20 additions and 11 deletions

View File

@ -167,7 +167,7 @@ fix_dependencies() {
get_brewed_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
php-config --version 2>/dev/null | cut -c 1-3
php_semver | cut -c 1-3
else
echo 'false';
fi
@ -198,6 +198,7 @@ php_extra_version() {
# Function to Setup PHP.
setup_php() {
step_log "Setup PHP"
php_config="$(command -v php-config 2>/dev/null)"
existing_version=$(get_brewed_php)
if [[ "$version" =~ ${old_versions:?} ]]; then
run_script "php5-darwin" "${version/./}" >/dev/null 2>&1
@ -214,13 +215,13 @@ setup_php() {
fi
php_config="$(command -v php-config)"
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
ini_file="$ini_dir"/php.ini
sudo mkdir -m 777 -p "$ext_dir" "$HOME/.composer"
sudo chmod 777 "$ini_file" "${tool_path_dir:?}"
semver=$(php_semver)
extra_version=$(php_extra_version)
semver="$(php_semver)"
extra_version="$(php_extra_version)"
configure_php
if [ "${semver%.*}" != "$version" ]; then
add_log "${cross:?}" "PHP" "Could not setup PHP $version"
@ -236,8 +237,10 @@ setup_php() {
version=$1
dist=$2
php_formula=shivammathur/php/php@"$version"
brew_prefix="$(brew --prefix)"
brew_repo="$(brew --repository)"
brew_path="$(command -v brew)"
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
core_repo="$tap_dir"/homebrew/homebrew-core
scripts="${dist}"/../src/scripts

View File

@ -182,7 +182,8 @@ php_extra_version() {
setup_php() {
step_log "Setup 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
add_php >/dev/null 2>&1
else
@ -195,6 +196,7 @@ setup_php() {
status="Switched to"
fi
fi
php_config="$(command -v php-config)"
else
if [ "$update" = "true" ]; then
update_php >/dev/null 2>&1
@ -206,13 +208,12 @@ setup_php() {
add_log "${cross:?}" "PHP" "Could not setup PHP $version"
exit 1
fi
php_config="$(command -v 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
pecl_file="$scan_dir"/99-pecl.ini
semver=$(php_semver)
extra_version=$(php_extra_version)
semver="$(php_semver)"
extra_version="$(php_extra_version)"
export ext_dir
mapfile -t ini_file < <(sudo find "$ini_dir/.." -name "php.ini" -exec readlink -m {} +)
link_pecl_file

View 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
}
# 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.
php_src_tag() {
commit=$(php_extra_version | grep -Eo "[0-9a-zA-Z]+")