HEX
Server: Apache
System: Linux server1.panigaletech.com 5.4.0-1103-aws #111~18.04.1-Ubuntu SMP Tue May 23 20:04:10 UTC 2023 x86_64
User: ubuntu (1000)
PHP: 7.4.30
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: /var/lib/dpkg/info/newrelic-php5.postinst
#!/bin/sh
# postinst script for newrelic-php5
#
# see: dh_installdeb(1)

. /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
      ;;
    8.5*)
      echo 20250925
      ;;
    *)
      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 20250925"
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:

# Common to both initial and upgrade installs
if [ ! -d /var/log/newrelic ]; then
  install -d -m 0755 -o root -g root /var/log/newrelic > /dev/null 2>&1
fi

mydir=/usr/lib/newrelic-php5

# If /usr/sbin/phpquery is available, we're in the new world with the potential
# for parallel PHP package installations. On the bright side, we can use
# phpquery to enumerate what's available.
if is_phpquery_available; then
  db_get newrelic-php5/license-key
  LICENSE_KEY="$RET"

  db_get newrelic-php5/application-name
  APPLICATION_NAME="$RET"

  # At present, the Xenial php7.0 packages are using /etc/php/mods-available
  # for no apparent reason. Let's spray a configuration file there too if we
  # need to. (This has to happen before we call install_agent_to_new_package,
  # as that calls phpenmod which expects a configuration file in
  # /etc/php/mods-available on Xenial only.
  if [ -d /etc/php/mods-available ]; then
    if [ ! -f /etc/php/mods-available/newrelic.ini ]; then
      python3 "$mydir/scripts/install/configure" "$LICENSE_KEY" "$APPLICATION_NAME" < "$mydir/scripts/newrelic.ini.template" > /etc/php/mods-available/newrelic.ini
    fi
  fi

  for version in $(/usr/sbin/phpquery -V); do
    install_agent_to_new_package "$version" "$mydir"
  done

  echo 'Please restart your Web server(s) to complete installation.' 1>&2
elif is_php5_packaged; then
  arch=$(get_architecture)

  # If the user has a php5-common package installed, then we'll do an install
  # based on that.
  pdir=
  if [ -d /usr/lib/php5 ]; then
    pdir=/usr/lib/php5
  elif [ -d /usr/lib64/php5 ]; then
    pdir=/usr/lib64/php5
    if [ "${arch}" = "x86" ]; then
      pdir=
    fi
  fi

  # Put the extension in the correct place.
  if [ -n "${arch}" -a -n "${pdir}" -a -n "${mydir}" -a -d ${mydir} ]; then
    for api in $PHP_API_VERSIONS; do
      if [ -d ${pdir}/${api} ]; then
        rm -f ${pdir}/${api}/newrelic.so > /dev/null 2>&1
        ln -s ${mydir}/agent/${arch}/newrelic-${api}.so ${pdir}/${api}/newrelic.so > /dev/null 2>&1
      fi
      if [ -d "${pdir}/${api}+lfs" ]; then
        rm -f "${pdir}/${api}+lfs/newrelic.so" > /dev/null 2>&1
        ln -s ${mydir}/agent/${arch}/newrelic-${api}.so "${pdir}/${api}+lfs/newrelic.so" > /dev/null 2>&1
      fi
    done

    # 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.
    for api in $DEPRECATED_PHP_API_VERSIONS; do
      if [ -d ${pdir}/${api} ]; then
        rm -f ${pdir}/${api}/newrelic.so > /dev/null 2>&1
        cp ${mydir}/agent/${arch}/newrelic-${api}.so ${pdir}/${api}/newrelic.so > /dev/null 2>&1
      fi
      if [ -d "${pdir}/${api}+lfs" ]; then
        rm -f "${pdir}/${api}+lfs/newrelic.so" > /dev/null 2>&1
        cp ${mydir}/agent/${arch}/newrelic-${api}.so "${pdir}/${api}+lfs/newrelic.so" > /dev/null 2>&1
      fi
    done

    if needs_config; then
      db_get newrelic-php5/license-key
      LICENSE_KEY="$RET"

      db_get newrelic-php5/application-name
      APPLICATION_NAME="$RET"

      python3 ${mydir}/scripts/install/configure "$LICENSE_KEY" "$APPLICATION_NAME" < ${mydir}/scripts/newrelic.ini.template > "$CONFIG_PATH"

      if [ -x /usr/sbin/php5enmod ]; then
        /usr/sbin/php5enmod newrelic
      fi

      # Let's not try to guess whether the user is using apache, nginx,
      # lighttpd, litespeed, or something else.
      echo 'Please restart your Web server(s) to complete installation.' 1>&2
    elif are_newrelic_ini_files_consistent; then
      # Nothing needs to happen; just print the message.
      echo 'Please restart your Web server(s) to complete installation.' 1>&2
    else
      # Inconsistent files: tell the user and don't overwrite anything.
      echo 'You have differing newrelic.ini files in /etc/php5. If this is unintended,' 1>&2
      echo 'please find the newrelic.ini that contains the correct license key and' 1>&2
      echo 'application name, copy it over the other newrelic.ini files, and run' 1>&2
      echo 'newrelic-install as root to complete installation.' 1>&2
    fi
  # We only want to output a message to users who are performing fresh
  # installations, rather than upgrades. We can detect that by seeing if a
  # previous version number was given to the script.
  elif [ -z "$2" ]; then
    echo 'Please run newrelic-install as root to complete installation.' 1>&2
  fi
else
  # We only want to output a message to users who are performing fresh
  # installations, rather than upgrades. We can detect that by seeing if a
  # previous version number was given to the script.
  if [ -z "$2" ]; then
    echo 'Please run newrelic-install as root to complete installation.' 1>&2
  fi
fi



exit 0