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

114 lines
3.6 KiB
Bash
Raw Normal View History

2020-07-15 11:15:40 +07:00
# Function to log result of a operation.
2020-07-26 17:18:19 +07:00
add_license_log() {
printf "::group::\033[34;1m%s \033[0m\033[90;1m%s \033[0m\n" "$ext" "Click to read the $ext related license information"
printf "Oracle Instant Client package is required for %s extension.\n" "$ext"
printf "It is provided under the Oracle Technology Network Development and Distribution License.\n"
printf "Refer to: \033[35;1m%s \033[0m\n" "https://www.oracle.com/downloads/licenses/instant-client-lic.html"
echo "::endgroup::"
2020-07-15 11:15:40 +07:00
}
# Function to install instantclient and SDK.
2020-07-26 17:18:19 +07:00
add_client() {
2020-07-15 11:15:40 +07:00
sudo mkdir -p -m 777 "$oracle_home"
if [ ! -e "$oracle_client" ]; then
for package in basiclite sdk; do
if [ "$os" = 'Linux' ]; then
libs='/usr/lib/'
os_name='linux'
arch='linuxx64'
lib_ext='so'
elif [ "$os" = 'Darwin' ]; then
libs='/usr/local/lib/'
os_name='mac'
arch='macos'
lib_ext='dylib'
fi
2020-11-11 03:53:45 +07:00
get -q -n "/opt/oracle/$package.zip" "https://download.oracle.com/otn_software/$os_name/instantclient/instantclient-$package-$arch.zip"
2020-07-15 11:15:40 +07:00
unzip "/opt/oracle/$package.zip" -d "$oracle_home"
done
sudo ln -sf /opt/oracle/instantclient*/*.$lib_ext* $libs
sudo ln -sf /opt/oracle/instantclient* "$oracle_client"
fi
}
# Function to get PHP source.
get_php() {
2020-11-11 03:53:45 +07:00
[ ! -d "/opt/oracle/php-src-$tag" ] && get -s -n "" "https://github.com/php/php-src/archive/$tag.tar.gz" | tar xzf - -C "$oracle_home/"
2020-07-15 11:15:40 +07:00
}
# Function to get phpize location on darwin.
get_phpize() {
if [[ "${version:?}" =~ 5.[3-5] ]]; then
2020-07-26 17:18:19 +07:00
echo '/opt/local/bin/phpize'
2020-07-15 11:15:40 +07:00
else
2020-07-26 17:18:19 +07:00
echo "/usr/local/bin/$(readlink /usr/local/bin/phpize)"
2020-07-15 11:15:40 +07:00
fi
}
# Function to patch phpize to link to php headers on darwin.
patch_phpize() {
if [ "$os" = "Darwin" ]; then
sudo cp "$phpize_orig" "$phpize_orig.bck"
sudo sed -i '' 's~includedir=.*~includedir="$(xcrun --show-sdk-path)/usr/include/php"~g' "$phpize_orig"
fi
}
# Function to restore phpize.
restore_phpize() {
if [ "$os" = "Darwin" ]; then
sudo mv "$phpize_orig.bck" "$phpize_orig" || true
fi
}
# Function to patch pdo_oci.
patch_pdo_oci_config() {
2020-11-11 03:53:45 +07:00
get -q -n config.m4 https://raw.githubusercontent.com/php/php-src/PHP-8.0/ext/pdo_oci/config.m4
2020-10-18 17:55:41 +07:00
if [[ ${version:?} =~ 5.[3-6] ]]; then
sudo sed -i '' "/PHP_CHECK_PDO_INCLUDES/d" config.m4 2>/dev/null || sudo sed -i "/PHP_CHECK_PDO_INCLUDES/d" config.m4
fi
2020-07-15 11:15:40 +07:00
}
# Function to install the dependencies.
2020-07-26 17:18:19 +07:00
add_dependencies() {
2020-07-15 11:15:40 +07:00
if [ "$os" = 'Linux' ]; then
2020-07-26 17:18:19 +07:00
if [ "${runner:?}" = "self-hosted" ]; then
2020-12-19 00:10:16 +07:00
${apt_install:?} --no-upgrade --no-install-recommends libaio-dev
2020-07-15 11:15:40 +07:00
fi
2020-11-08 14:36:21 +07:00
! [[ ${version:?} =~ $nightly_versions ]] && add_devtools phpize
2020-07-15 11:15:40 +07:00
fi
}
2020-07-26 17:18:19 +07:00
# Function to install oci8 and pdo_oci.
add_oci_helper() {
if ! [ -e "${ext_dir:?}/$ext.so" ]; then
status='Installed and enabled'
phpize_orig=$(get_phpize)
tag=$(php_src_tag)
2020-07-26 17:18:19 +07:00
get_php
patch_phpize
2020-07-15 11:15:40 +07:00
(
cd "/opt/oracle/php-src-$tag/ext/$ext" || exit 1
[ "$ext" = "pdo_oci" ] && patch_pdo_oci_config
sudo phpize && ./configure --with-php-config="$(command -v php-config)" --with-"${ext/_/-}"=instantclient,"$oracle_client"
sudo make -j"$(nproc 2>/dev/null || sysctl -n hw.ncpu)"
2020-07-15 11:15:40 +07:00
sudo cp ./modules/* "$ext_dir/"
)
2020-07-26 17:18:19 +07:00
restore_phpize
2020-07-15 11:15:40 +07:00
fi
2020-07-26 17:18:19 +07:00
echo "extension=$ext.so" | sudo tee "${scan_dir:?}/99-$ext.ini"
2020-07-15 11:15:40 +07:00
}
2020-07-26 17:18:19 +07:00
# Function to add oci extension oci8 and pdo_oci.
add_oci() {
ext=$1
status='Enabled'
oracle_home='/opt/oracle'
oracle_client=$oracle_home/instantclient
os=$(uname -s)
add_client >/dev/null 2>&1
add_dependencies >/dev/null 2>&1
add_oci_helper >/dev/null 2>&1
add_extension_log "$ext" "$status"
check_extension "$ext" && add_license_log
}