File: //tmp/newrelic-php5.config.VDvy6I
#!/bin/sh
. /usr/share/debconf/confmodule
# Insert the contents of newrelic-php5.config here.
# Start of included newrelic-php5.common code.
# Shell functions common to the config and postinst maintainer scripts. We need
# to inject them into those scripts at build time.
# Test whether all /etc/php5/{apache2,cgi,cli,fpm}/conf.d/newrelic.ini files
# are consistent. We'll do this by taking a SHA-512 checksum of each file and
# comparing them to each other: this may result in false positives if there are
# whitespace or comment only changes, but that's OK, since the fallback
# behavior is to warn the user and not try anything clever.
are_newrelic_ini_files_consistent () {
get_config_path
known_hash=""
# This enumerates the possible subdirectories under /etc/php5, as of Trusty.
for sapi_dir in apache2 cgi cli fpm; do
if test -f "/etc/php5/$sapi_dir/conf.d/newrelic.ini"; then
sapi_hash=$(sha512sum "/etc/php5/$sapi_dir/conf.d/newrelic.ini" | cut -d ' ' -f 1)
if test -n "$known_hash"; then
if test "$known_hash" != "$sapi_hash"; then
return 1
fi
else
known_hash="$sapi_hash"
fi
fi
done
return 0
}
get_architecture () {
local arch
arch=$(uname -m 2> /dev/null)
case $arch in
i[3456789]86 | i86pc)
echo x86
;;
x86_64 | amd64)
echo x64
;;
*)
echo "Unknown architecture: $arch" 1>&2
return 1
;;
esac
}
get_config_path () {
if [ -x /usr/sbin/php5enmod ]; then
CONFIG_PATH=/etc/php5/mods-available/newrelic.ini
else
CONFIG_PATH=/etc/php5/conf.d/newrelic.ini
fi
}
# Usage: install_agent_to_new_package VERSION SOURCEDIR
# Dependencies: $LICENSE_KEY and $APPLICATION_NAME from debconf.
install_agent_to_new_package () {
local api arch extdir inidir
arch=$(get_architecture)
if [ -z "$arch" ]; then
# get_architecture will have already printed an error message.
return 1
fi
api=$(version_to_api $1)
if [ $? -ne 0 ]; then
# Unsupported version: Since an error message has
# already been displayed, just return
return 1
fi
extdir="/usr/lib/php/$api"
if [ ! -d "$extdir" ]; then
echo "Unable to find extension directory: $extdir" 1>&2
return 1
fi
inidir="/etc/php/$1/mods-available"
if [ ! -d "$inidir" ]; then
echo "Unable to find module configuration directory: $inidir" 1>&2
return 1
fi
# Remove any existing symlink in the extension directory and link the new
# agent.
rm -f "$extdir/newrelic.so"
# For deprecated versions, we copy instead of link so that the file the link
# points to doesn't go away if the user inadvertently updates.
if echo $DEPRECATED_PHP_API_VERSIONS | grep -q ${api}; then
cp "$2/agent/$arch/newrelic-${api}.so" "$extdir/newrelic.so"
else
ln -s "$2/agent/$arch/newrelic-${api}.so" "$extdir/newrelic.so"
fi
# If there's no configuration file in the mods-available directory already,
# let's add one.
if [ ! -f "$inidir/newrelic.ini" ]; then
python3 "$2/scripts/install/configure" "$LICENSE_KEY" "$APPLICATION_NAME" < "$2/scripts/newrelic.ini.template" > "$inidir/newrelic.ini"
fi
# Activate the module.
phpenmod -v "$1" newrelic
}
# This function checks if PHP is installed via older style packages (generally
# defined as the standard packages shipped for PHP 5 in Debian, Ubuntu, and via
# Ondřej's PPA), where there's a php5-common package that can't provide
# information on what PHPs are installed or where they're located, but in
# practice we know where to place configuration and .so files because the
# packages are laid out in a standard way.
is_php5_packaged () {
for package in php5-common; do
# We need dpkg-query to tell us what state the package is in. It's possible
# for a package that's uninstalled to be known by dpkg, in which case
# dpkg-query will return an exit code of 0 and not 1, which means we can't
# discriminate based solely on the exit code.
#
# Instead, we'll get dpkg-query to tell us exactly what state the package
# is in. If it's anything other than "not-installed", the package is
# installed (or partly installed), and we should consider it available.
#
# Note that although it would be simpler to use ${db:Status-Status} instead
# of ${Status}, the oldest Debian and Ubuntu versions we support don't
# handle that virtual field, so we just have to grab the whole status and
# parse it using grep.
if dpkg-query -W -f '${Status}' "$package" 2>/dev/null | grep -wiv not-installed >/dev/null 2>&1; then
return 0
fi
done
return 1
}
# This function checks if PHP is installed via newer style packages (generally
# defined as the standard packages shipped for PHP 7 in Debian, Ubuntu, and via
# Ondřej's PPA). Specifically, we're looking for a /usr/sbin/phpquery
# executable, rather than a specifically named package, since phpquery can then
# tell us what versions are installed.
is_phpquery_available () {
test -x /usr/sbin/phpquery
return
}
needs_config () {
# Check if we need to configure the license key and application name.
# Unpackaged PHP installs never configure these. For packaged installs, we
# need to check if the newrelic.ini is already in place.
if is_php5_packaged; then
get_config_path
# We want to see if there are inconsistent newrelic.ini files: if so, then
# we shouldn't overwrite anything.
if are_newrelic_ini_files_consistent; then
test ! -f "$CONFIG_PATH"
return
fi
fi
return 1
}
# Usage: purge_agent_from_new_package VERSION
purge_agent_from_new_package () {
rm -f "/etc/php/$1/mods-available/newrelic.ini"
}
# Usage: uninstall_agent_from_new_package VERSION
uninstall_agent_from_new_package () {
local api extdir
# Attempt to remove the extension.
api=$(version_to_api $1)
extdir="/usr/lib/php/$api"
rm -f "$extdir/newrelic.so"
# Disable the module, but don't purge. (We'll do that separately if
# requested.)
phpdismod -v "$1" newrelic > /dev/null 2>&1
}
version_to_api () {
case "$1" in
7.2*)
echo 20170718
;;
7.3*)
echo 20180731
;;
7.4*)
echo 20190902
;;
8.0*)
echo 20200930
;;
8.1*)
echo 20210902
;;
8.2*)
echo 20220829
;;
8.3*)
echo 20230831
;;
8.4*)
echo 20240924
;;
*)
echo "Unknown PHP version: $1" 1>&2
return 1
;;
esac
}
# PHP version handling follows:
#
# There are three states a PHP version can be in. A version must only appear in
# one list below.
#
# Supported: the API number appears in $PHP_API_VERSIONS. These versions will
# always be installed, and the .so will be removed on both upgrade
# and uninstall.
#
# Deprecated: the API number appears in $DEPRECATED_PHP_API_VERSIONS. These
# versions will always be installed, but the .so will NOT be removed
# on upgrade, since the expectation is that the version will no
# longer appear in $PHP_API_VERSIONS thereafter.
#
# Unsupported: the API number appears in $UNSUPPORTED_PHP_API_VERSIONS. These
# versions were supported once upon a time, but are no longer
# supported.
#
# What this really means to you, the developer, if and when you're changing the
# agent's version support:
#
# Adding a version: add the new API number to $PHP_API_VERSIONS. Test it. Be
# of good cheer.
#
# Removing a version: for one release, remove the API number from
# $PHP_API_VERSIONS and add it to
# $DEPRECATED_PHP_API_VERSIONS. Document loudly that
# customers using that PHP version should pin to that
# package version. For the subsequent release, remove the
# version from $DEPRECATED_PHP_API_VERSIONS and add it to
# $UNSUPPORTED_PHP_API_VERSIONS.
PHP_API_VERSIONS="20170718 20180731 20190902 20200930 20210902 20220829 20230831 20240924"
DEPRECATED_PHP_API_VERSIONS=""
UNSUPPORTED_PHP_API_VERSIONS="20050922 20060613 20090626 20100525 20121212 20131226 20151012 20160303"
# End of included newrelic-php5.common code.
# vim: set ft=sh:
# Warn the user if they have an deprecated PHP in their PATH.
if which php 2>&1 1>/dev/null; then
PHP_VERSION=`php -n -r 'echo PHP_VERSION;' | cut -d . -f -2`
# replace following line with conditional that filters out deprecated PHP versions
# and update the file "newrelic-php5.templates" to change the deprecation
# text under "php-deprecation"
# an example for 7.0 and 7.1 is here for reference
if [ "$PHP_VERSION" = "7.0" ] || [ "$PHP_VERSION" = "7.1" ]; then
db_input high newrelic-php5/php-deprecation || true
fi
fi
# Collect the application name and license key if the user has the default
# packages installed and we can do a completely newrelic-install-free
# installation.
if is_phpquery_available; then
db_input high newrelic-php5/license-key || true
db_input high newrelic-php5/application-name || true
elif is_php5_packaged; then
if needs_config; then
db_input high newrelic-php5/license-key || true
db_input high newrelic-php5/application-name || true
fi
fi
db_go