2020-01-22 02:30:13 +07:00
|
|
|
# Function to log result of a operation
|
2020-01-21 19:28:09 +07:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2020-01-22 02:30:13 +07:00
|
|
|
# Function to update php ppa
|
2020-01-21 19:28:09 +07:00
|
|
|
update_ppa() {
|
|
|
|
if [ "$ppa_updated" = "false" ]; then
|
|
|
|
find /etc/apt/sources.list.d -type f -name 'ondrej-ubuntu-php*.list' -exec sudo DEBIAN_FRONTEND=noninteractive apt-get update -o Dir::Etc::sourcelist="{}" ';' >/dev/null 2>&1
|
|
|
|
ppa_updated="true"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2020-01-22 02:30:13 +07:00
|
|
|
# Function to install phalcon
|
2020-01-21 19:28:09 +07:00
|
|
|
install_phalcon() {
|
|
|
|
extension=$1
|
|
|
|
version=$2
|
|
|
|
(sudo DEBIAN_FRONTEND=noninteractive apt-get install -y "php$version-$extension" >/dev/null 2>&1 && add_log "$tick" "$extension" "Installed and enabled") ||
|
|
|
|
(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"
|
|
|
|
}
|
|
|
|
|
2020-02-02 16:53:02 +07:00
|
|
|
ini_file="/etc/php/$2/cli/conf.d/50-phalcon.ini"
|
2020-01-21 19:28:09 +07:00
|
|
|
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')
|
|
|
|
ppa_updated="false"
|
|
|
|
tick="✓"
|
|
|
|
cross="✗"
|
2019-10-27 07:12:49 +07:00
|
|
|
|
2020-01-21 19:28:09 +07:00
|
|
|
if [ "$extension_major_version" = "4" ]; then
|
|
|
|
if [ -e "$ext_dir/psr.so" ]; then
|
2020-02-02 16:53:02 +07:00
|
|
|
echo "extension=psr.so" | sudo tee -a "$ini_file" >/dev/null 2>&1
|
2020-01-21 19:28:09 +07:00
|
|
|
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)
|
2020-01-21 19:28:09 +07:00
|
|
|
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
|
2020-01-21 19:28:09 +07:00
|
|
|
add_log "$tick" "$1" "Enabled"
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
install_phalcon "$1" "$2"
|
2019-12-31 14:55:59 +07:00
|
|
|
fi
|
2020-01-21 19:28:09 +07:00
|
|
|
else
|
|
|
|
install_phalcon "$1" "$2"
|
|
|
|
fi
|
2019-10-29 23:39:49 +07:00
|
|
|
fi
|
2019-10-27 07:12:49 +07:00
|
|
|
|
2020-01-21 19:28:09 +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)
|
2020-01-21 19:28:09 +07:00
|
|
|
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
|
2020-01-21 19:28:09 +07:00
|
|
|
add_log "$tick" "$1" "Enabled"
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
install_phalcon "$1" "$2"
|
|
|
|
fi
|
|
|
|
fi
|