setup-php/src/scripts/ext/phalcon_darwin.sh

48 lines
1.8 KiB
Bash
Raw Normal View History

2020-02-16 00:21:02 +07:00
# Function to log result of a operation
add_log() {
mark=$1
subject=$2
message=$3
if [ "$mark" = "$tick" ]; then
printf "\033[32;1m%s \033[0m\033[34;1m%s \033[0m\033[90;1m%s\033[0m\n" "$mark" "$subject" "$message"
else
printf "\033[31;1m%s \033[0m\033[34;1m%s \033[0m\033[90;1m%s\033[0m\n" "$mark" "$subject" "$message"
fi
}
# Function to install phalcon
install_phalcon() {
(
2020-05-09 08:50:08 +07:00
sed -i '' '/extension.*psr/d' "$ini_file"
2020-02-16 00:21:02 +07:00
brew tap shivammathur/homebrew-phalcon >/dev/null 2>&1
brew install phalcon@"$php_version"_"$extension_major" >/dev/null 2>&1
sudo cp /usr/local/opt/psr@"$php_version"/psr.so "$ext_dir" >/dev/null 2>&1
sudo cp /usr/local/opt/phalcon@"$php_version"_"$extension_major"/phalcon.so "$ext_dir" >/dev/null 2>&1
add_log "$tick" "$extension" "Installed and enabled"
) || add_log "$cross" "$extension" "Could not install $extension on PHP $semver"
}
tick="✓"
cross="✗"
2019-12-26 20:01:18 +07:00
extension=$1
extension_major=${extension: -1}
php_version=$2
2020-02-16 00:21:02 +07:00
semver=$(php -v | head -n 1 | cut -f 2 -d ' ')
2020-05-09 08:50:08 +07:00
ini_file=$(php --ini | grep "Loaded Configuration" | sed -e "s|.*:s*||" | sed "s/ //g")
ext_dir=$(php -i | grep "extension_dir => /usr" | sed -e "s|.*=> s*||")
if [ -e "$ext_dir/psr.so" ] && [ -e "$ext_dir/phalcon.so" ]; then
2020-05-09 08:50:08 +07:00
phalcon_version=$(php -d="extension=psr.so" -d="extension=phalcon.so" -r "echo phpversion('phalcon');" 2>/dev/null | cut -d'.' -f 1)
if php -m | grep -i -q -w psr; then
phalcon_version=$(php -d="extension=phalcon.so" -r "echo phpversion('phalcon');" 2>/dev/null | cut -d'.' -f 1)
fi
if [ "$phalcon_version" != "$extension_major" ]; then
2020-02-16 00:21:02 +07:00
install_phalcon
else
2020-05-09 08:50:08 +07:00
if ! php -m | grep -i -q -w psr; then echo "extension=psr.so" >>"$ini_file"; fi
2020-02-16 00:21:02 +07:00
echo "extension=phalcon.so" >>"$ini_file"
add_log "$tick" "$extension" "Enabled"
fi
else
2020-02-16 00:21:02 +07:00
install_phalcon
fi