Skip to content

Commit

Permalink
Install to support multiple php versions
Browse files Browse the repository at this point in the history
  • Loading branch information
v1v committed Aug 11, 2020
1 parent 5c39a79 commit 9230888
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 10 deletions.
4 changes: 4 additions & 0 deletions packaging/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ GIT_SHA ?= $(shell git rev-parse HEAD || echo "unknown")
help: ## Display this help text
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}'

.PHONY: clean
clean: ## Clean the generated packages
rm -f $(PWD)/$(OUTPUT)/*.*

.PHONY: prepare
prepare: ## Build docker image for the packaging
@docker build -t $(IMAGE) .
Expand Down
32 changes: 26 additions & 6 deletions packaging/post-install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
############################ GLOBAL VARIABLES ##################################
################################################################################
PHP_AGENT_DIR=/opt/elastic/apm-agent-php
EXTENSION_FILE_PATH="${PHP_AGENT_DIR}/extensions/elastic_apm.so"
EXTENSION_DIR="${PHP_AGENT_DIR}/extensions"
BOOTSTRAP_FILE_PATH="${PHP_AGENT_DIR}/src/bootstrap_php_part.php"
BACKUP_EXTENSION=".agent.bck"

Expand All @@ -29,6 +29,15 @@ function php_ini_file_path() {
| awk '{print $1}'
}

################################################################################
#### Function php_api ##########################################################
function php_api() {
php_command -i \
| grep 'PHP API' \
| sed -e 's#.* =>##g' \
| awk '{print $1}'
}

################################################################################
#### Function is_extension_installed ###########################################
function is_extension_installed() {
Expand All @@ -46,18 +55,29 @@ elastic_apm.bootstrap_php_part_file=${BOOTSTRAP_FILE_PATH}
EOF
}

################################################################################
#### Function get_extension_file ###############################################
function get_extension_file() {
PHP_API=$(php_api)
echo "${EXTENSION_DIR}/elastic_apm-${PHP_API}.so"
}

################################################################################
############################### MAIN ###########################################
################################################################################
echo 'Installing Elastic PHP agent'
PHP_INI_FILE_PATH="$(php_ini_file_path)/php.ini"
if [ -e "${PHP_INI_FILE_PATH}" ] ; then
if grep -q "${EXTENSION_FILE_PATH}" "${PHP_INI_FILE_PATH}" ; then
echo ' extension configuration already exists for the Elastic PHP agent.'
echo ' skipping ... '
if [ -e "${EXTENSION_FILE_PATH}" ] ; then
if grep -q "${EXTENSION_FILE_PATH}" "${PHP_INI_FILE_PATH}" ; then
echo ' extension configuration already exists for the Elastic PHP agent.'
echo ' skipping ... '
else
cp -fa "${PHP_INI_FILE_PATH}" "${PHP_INI_FILE_PATH}${BACKUP_EXTENSION}"
add_extension_configuration_to_file "${PHP_INI_FILE_PATH}"
fi
else
cp -fa "${PHP_INI_FILE_PATH}" "${PHP_INI_FILE_PATH}${BACKUP_EXTENSION}"
add_extension_configuration_to_file "${PHP_INI_FILE_PATH}"
echo 'Failed. Elastic PHP agent extension not supported for the current PHP API version.'
fi
else
add_extension_configuration_to_file "${PHP_INI_FILE_PATH}"
Expand Down
4 changes: 2 additions & 2 deletions packaging/test/centos/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ set -xe

if [ "${TYPE}" == "rpm" ] ; then
## Install rpm package and configure the agent accordingly
rpm -ivh build/packages/**/*.rpm
rpm -ivh build/packages/*.rpm
else
## Install tar package and configure the agent accordingly
tar -xf build/packages/**/*.tar -C /
tar -xf build/packages/*.tar -C /
# shellcheck disable=SC1091
source /.scripts/after_install
fi
Expand Down
4 changes: 2 additions & 2 deletions packaging/test/ubuntu/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ set -xe

if [ "${TYPE}" == "deb" ] ; then
## Install debian package and configure the agent accordingly
dpkg -i build/packages/**/*.deb
dpkg -i build/packages/*.deb
else
## Install tar package and configure the agent accordingly
tar -xf build/packages/**/*.tar -C /
tar -xf build/packages/*.tar -C /
# shellcheck disable=SC1091
source /.scripts/after_install
fi
Expand Down

0 comments on commit 9230888

Please sign in to comment.