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

85 lines
2.7 KiB
Bash
Raw Normal View History

2020-01-22 02:30:13 +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 add ppa:ondrej/php
add_ppa() {
if ! apt-cache policy | grep -q ondrej/php; then
cleanup_lists
LC_ALL=C.UTF-8 sudo apt-add-repository ppa:ondrej/php -y
if [ "$DISTRIB_RELEASE" = "16.04" ]; then
sudo "$debconf_fix" apt-get update
fi
fi
}
# Function to update the package lists
update_lists() {
if [ ! -e /tmp/setup_php ]; then
[ "$DISTRIB_RELEASE" = "20.04" ] && add_ppa >/dev/null 2>&1
cleanup_lists
sudo "$debconf_fix" apt-get update >/dev/null 2>&1
echo '' | sudo tee "/tmp/setup_php" >/dev/null 2>&1
fi
}
2020-01-22 02:30:13 +07:00
# Function to install phalcon
install_phalcon() {
extension=$1
version=$2
(update_ppa && sudo DEBIAN_FRONTEND=noninteractive apt-get install -y "php$version-$extension" >/dev/null 2>&1 && add_log "$tick" "$extension" "Installed and enabled") ||
add_log "$cross" "$extension" "Could not install $extension on PHP $semver"
}
debconf_fix="DEBIAN_FRONTEND=noninteractive"
2020-02-02 16:53:02 +07:00
ini_file="/etc/php/$2/cli/conf.d/50-phalcon.ini"
ext_dir=$(php -i | grep "extension_dir => /usr" | sed -e "s|.*=> s*||")
semver=$(php -v | head -n 1 | cut -f 2 -d ' ' | cut -f 1 -d '-')
extension_major_version=$(echo "$1" | grep -i -Po '\d')
tick="✓"
cross="✗"
2019-10-27 07:12:49 +07:00
if [ "$extension_major_version" = "4" ]; then
2020-05-09 08:50:08 +07:00
if [ -e "$ext_dir/psr.so" ] && ! php -m | grep -i -q -w psr; then
2020-02-02 16:53:02 +07:00
echo "extension=psr.so" | sudo tee -a "$ini_file" >/dev/null 2>&1
fi
if [ -e "$ext_dir/phalcon.so" ]; then
if php -m | grep -i -q -w psr; then
2020-02-02 16:53:02 +07:00
phalcon_version=$(php -d="extension=phalcon" -r "echo phpversion('phalcon');" | cut -d'.' -f 1)
if [ "$phalcon_version" != "$extension_major_version" ]; then
install_phalcon "$1" "$2"
else
2020-02-02 16:53:02 +07:00
echo "extension=phalcon.so" | sudo tee -a "$ini_file" >/dev/null 2>&1
add_log "$tick" "$1" "Enabled"
fi
else
install_phalcon "$1" "$2"
fi
else
install_phalcon "$1" "$2"
fi
2019-10-29 23:39:49 +07:00
fi
2019-10-27 07:12:49 +07:00
if [ "$extension_major_version" = "3" ]; then
if [ -e "$ext_dir/phalcon.so" ]; then
2020-02-02 16:53:02 +07:00
phalcon_version=$(php -d="extension=phalcon.so" -r "echo phpversion('phalcon');" | cut -d'.' -f 1)
if [ "$phalcon_version" != "$extension_major_version" ]; then
install_phalcon "$1" "$2"
else
2020-02-02 16:53:02 +07:00
echo "extension=phalcon.so" | sudo tee -a "$ini_file" >/dev/null 2>&1
add_log "$tick" "$1" "Enabled"
fi
else
install_phalcon "$1" "$2"
fi
fi