diff --git a/src/scripts/darwin.sh b/src/scripts/darwin.sh index 5a2970f6..089c13f7 100644 --- a/src/scripts/darwin.sh +++ b/src/scripts/darwin.sh @@ -148,9 +148,9 @@ get_brewed_php() { cellar="$brew_prefix"/Cellar php_cellar="$cellar"/php if [ -d "$cellar" ] && ! [[ "$(find "$cellar" -maxdepth 1 -name "php@$version*" | wc -l 2>/dev/null)" -eq 0 ]]; then - php_semver | cut -c 1-3 + php_semver elif [ -d "$php_cellar" ] && ! [[ "$(find "$php_cellar" -maxdepth 1 -name "$version*" | wc -l 2>/dev/null)" -eq 0 ]]; then - php_semver | cut -c 1-3 + php_semver else echo 'false'; fi @@ -160,17 +160,24 @@ get_brewed_php() { add_php() { action=$1 existing_version=$2 - add_brew_tap "$php_tap" - update_dependencies suffix="$(get_php_formula_suffix)" - php_formula="shivammathur/php/php@$version$suffix" + php_keg="php@$version$suffix" + php_formula="shivammathur/php/$php_keg" + if [[ "$existing_version" = "false" || -n "$suffix" || "$action" = "upgrade" ]]; then + update_dependencies + add_brew_tap + fi if [[ "$existing_version" != "false" && -z "$suffix" ]]; then - ([ "$action" = "upgrade" ] && brew upgrade -f --overwrite "$php_formula") || brew unlink "$php_formula" + if [ "$action" = "upgrade" ]; then + brew upgrade -f --overwrite "$php_formula" + else + brew unlink "$php_keg" + fi else brew install -f --overwrite "$php_formula" fi sudo chown -R "$(id -un)":"$(id -gn)" "$brew_prefix" - brew link --force --overwrite "$php_formula" + brew link --force --overwrite "$php_keg" } # Function to get formula suffix @@ -222,18 +229,18 @@ setup_php() { update=true check_pre_installed existing_version=$(get_brewed_php) + status="Found" if [[ "$version" =~ ${old_versions:?} ]]; then run_script "php5-darwin" "${version/./}" >/dev/null 2>&1 status="Installed" - elif [ "$existing_version" != "$version" ]; then + elif [ "${existing_version:0:3}" != "$version" ]; then add_php "install" "$existing_version" >/dev/null 2>&1 status="Installed" - elif [ "$existing_version" = "$version" ]; then - if [ "${update:?}" = "true" ]; then + elif [[ "${existing_version:0:3}" = "$version" && "${update:?}" = "true" ]]; then + brew_php_version="$(brew info --json "php@$version" 2>/dev/null | jq -r '.[].versions.stable')" + if [ "$brew_php_version" != "$existing_version" ]; then add_php "upgrade" "$existing_version" >/dev/null 2>&1 - status="Updated to" - else - status="Found" + status="Upgraded" fi fi php_config="$(command -v php-config)"