Switch to liip for old PHP on darwin

This commit is contained in:
Shivam Mathur 2020-02-23 09:44:33 +05:30
parent 6d21e6dc05
commit 9d77946f60
No known key found for this signature in database
GPG Key ID: 3E13E4C8591ACC2A
3 changed files with 59 additions and 90 deletions

2
dist/index.js vendored
View File

@ -2748,7 +2748,7 @@ function addExtensionDarwin(extension_csv, version, pipe) {
}
script +=
'\nadd_extension ' +
extension +
ext_name +
' "' +
install_command +
'" ' +

View File

@ -69,7 +69,7 @@ export async function addExtensionDarwin(
}
script +=
'\nadd_extension ' +
extension +
ext_name +
' "' +
install_command +
'" ' +

View File

@ -33,14 +33,8 @@ add_extension() {
elif php -m | grep -i -q -w "$extension"; then
add_log "$tick" "$extension" "Enabled"
elif ! php -m | grep -i -q -w "$extension"; then
if [[ "$version" =~ $old_versions ]]; then
(sudo port install php"$nodot_version"-"$extension" >/dev/null 2>&1 && add_log "$tick" "$extension" "Installed and enabled") ||
(eval "$install_command" >/dev/null 2>&1 && echo "$prefix=$ext_dir/$extension.so" >>"$ini_file" && add_log "$tick" "$extension" "Installed and enabled") ||
(eval "$install_command" >/dev/null 2>&1 && test -f "$ext_dir/$extension.so" && add_log "$tick" "$extension" "Installed and enabled") ||
add_log "$cross" "$extension" "Could not install $extension on PHP $semver"
else
(eval "$install_command" >/dev/null 2>&1 && add_log "$tick" "$extension" "Installed and enabled") ||
add_log "$cross" "$extension" "Could not install $extension on PHP $semver"
fi
fi
}
@ -88,11 +82,6 @@ add_unstable_extension() {
add_tool() {
url=$1
tool=$2
if [ "$tool" = "composer" ]; then
brew install composer >/dev/null 2>&1
composer -q global config process-timeout 0
add_log "$tick" "$tool" "Added"
else
tool_path_dir=/usr/local/bin
tool_path="$tool_path_dir/$tool"
if [ ! -e "$tool_path" ]; then
@ -102,13 +91,15 @@ add_tool() {
status_code=$(sudo curl -s -w "%{http_code}" -o "$tool_path" -L "$url")
if [ "$status_code" = "200" ]; then
sudo chmod a+x "$tool_path"
if [ "$tool" = "phive" ]; then
if [ "$tool" = "composer" ]; then
composer -q global config process-timeout 0
elif [ "$tool" = "phive" ]; then
add_extension curl "sudo pecl install -f curl" extension >/dev/null 2>&1
add_extension mbstring "sudo pecl install -f mbstring" extension >/dev/null 2>&1
add_extension xml "sudo pecl install -f xml" extension >/dev/null 2>&1
elif [ "$tool" = "cs2pr" ]; then
sudo sed -i '' 's/exit(9)/exit(0)/' "$tool_path"
tr -d '\r' < "$tool_path" | sudo tee "$tool_path.tmp" >/dev/null 2>&1 && sudo mv "$tool_path.tmp" "$tool_path"
tr -d '\r' <"$tool_path" | sudo tee "$tool_path.tmp" >/dev/null 2>&1 && sudo mv "$tool_path.tmp" "$tool_path"
sudo chmod a+x "$tool_path"
elif [ "$tool" = "wp-cli" ]; then
sudo cp -p "$tool_path" "$tool_path_dir"/wp
@ -117,7 +108,6 @@ add_tool() {
else
add_log "$cross" "$tool" "Could not setup $tool"
fi
fi
}
# Function to add a tool using composer
@ -134,13 +124,11 @@ add_composer_tool() {
# Function to configure PECL
configure_pecl() {
if [[ ! "$version" =~ $old_versions ]]; then
for tool in pear pecl; do
sudo "$tool" config-set php_ini "$ini_file" >/dev/null 2>&1
sudo "$tool" config-set auto_discover 1 >/dev/null 2>&1
sudo "$tool" channel-update "$tool".php.net >/dev/null 2>&1
done
fi
}
# Function to log PECL, it is installed along with PHP
@ -148,44 +136,33 @@ add_pecl() {
add_log "$tick" "PECL" "Added"
}
# Function to add PECL when macports is used
add_pecl_old() {
pecl_version='master'
if [ "$1" = "53" ]; then
pecl_version='v1.9.5'
fi
curl -o pear.phar -sSL https://github.com/pear/pearweb_phars/raw/$pecl_version/install-pear-nozlib.phar
sudo php pear.phar -d /opt/local/lib/php$1 -b /usr/local/bin && rm -rf pear.phar
# Function to get api version for PHP 5.3, 5.4 and 5.5
get_old_apiv() {
case $version in
5.3) echo "20090626" ;;
5.4) echo "20100525" ;;
5.5) echo "20121212" ;;
esac
}
add_macports() {
uri=$(curl -sSL https://github.com/macports/macports-base/releases | grep -Eo "(\/.*Catalina.pkg)" | head -n 1)
curl -o port.pkg -sSL https://github.com"$uri"
sudo installer -pkg port.pkg -target / && rm -rf port.pkg
}
sync_macports() {
while true; do
status=0
sudo port sync || status=$?
if [[ "$status" -eq 0 ]]; then
break
fi
sleep 2
# Function to setup PHP 5.3, 5.4 and 5.5
setup_php_old() {
php5=/usr/local/php5
ext_dir_parent="$php5"/lib/php/extensions
ext_dir_name=no-debug-non-zts-$(get_old_apiv)
ext_dir="$ext_dir_parent/$ext_dir_name"
sudo mv "$ext_dir" /tmp >/dev/null 2>&1 && sudo rm -rf "$php5"
sudo curl -s https://php-osx.liip.ch/install.sh | bash -s "$version" >/dev/null 2>&1
sudo rsync -a /tmp/"$ext_dir_name"/ "$ext_dir" >/dev/null 2>&1
sudo rm -rf "$php5"/php.d/*developer.ini "$php5"/php.d/*xdebug.ini /tmp/ext
for tool in pear peardev pecl php php-config phpize; do
sudo ln -sf "$php5"/bin/"$tool" /usr/local/bin/"$tool"
done
}
port_setup_php() {
sudo port install php$1 php$1-curl php$1-mbstring php$1-xmlrpc php$1-openssl php$1-opcache
sudo cp /opt/local/etc/php$1/php.ini-development /opt/local/etc/php$1/php.ini
sudo port select --set php php$1
sudo ln -sf /opt/local/bin/* /usr/local/bin
add_pecl_old "$1"
}
# Function to setup PHP >=5.6
setup_php() {
action=$1
step_log "Setup PHP"
export HOMEBREW_NO_INSTALL_CLEANUP=TRUE >/dev/null 2>&1
brew tap shivammathur/homebrew-php >/dev/null 2>&1
brew "$action" shivammathur/php/php@"$version" >/dev/null 2>&1
@ -196,22 +173,14 @@ setup_php() {
tick="✓"
cross="✗"
version=$1
nodot_version=${1/./}
old_versions="5.[3-5]"
existing_version=$(php-config --version | cut -c 1-3)
[[ -z "${update}" ]] && update='false' || update="${update}"
# Setup PHP
step_log "Setup PHP"
if [[ "$version" =~ $old_versions ]]; then
export PATH="/opt/local/bin:/opt/local/sbin:$PATH"
export TERM=xterm
step_log "Setup Macports"
add_macports >/dev/null 2>&1
add_log "$tick" "Macports" "Installed"
sync_macports >/dev/null 2>&1
add_log "$tick" "Macports" "Synced"
step_log "Setup PHP"
port_setup_php $nodot_version >/dev/null 2>&1
setup_php_old
status="Installed"
elif [ "$existing_version" != "$version" ]; then
setup_php "install"
@ -220,13 +189,13 @@ elif [ "$existing_version" = "$version" ] && [ "$update" = "true" ]; then
setup_php "upgrade"
status="Updated to"
else
step_log "Setup PHP"
status="Found"
fi
ini_file=$(php -d "date.timezone=UTC" --ini | grep "Loaded Configuration" | sed -e "s|.*:s*||" | sed "s/ //g")
sudo chmod 777 "$ini_file"
echo "date.timezone=UTC" >>"$ini_file"
ext_dir=$(php -i | grep -Ei "extension_dir => /(usr|opt)" | sed -e "s|.*=> s*||")
echo "detect_unicode=Off" >>"$ini_file"
ext_dir=$(php -i | grep -Ei "extension_dir => /usr" | sed -e "s|.*=> s*||")
sudo mkdir -p "$ext_dir"
semver=$(php -v | head -n 1 | cut -f 2 -d ' ')
configure_pecl