Merge pull request #126 from mlocati/define-distro-vars

Define DISTRO and DISTRO_VERSION
pull/127/head
Michele Locati 2020-02-28 11:45:17 +01:00 committed by GitHub
commit 119c431aef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 38 additions and 64 deletions

View File

@ -18,44 +18,21 @@ resetIFS() {
' '
} }
# Get the distribution name # Set these variables:
# # - DISTRO containing distribution name (eg 'alpine', 'debian')
# Output: # - DISTO_VERSION containing distribution name and its version(eg 'alpine@3.10', 'debian@9')
# alpine|debian setDistro() {
getDistro() { if ! test -r /etc/os-release; then
getDistro_os_id='' printf 'The file /etc/os-release is not readable\n' >&2
if test -r /etc/os-release; then exit 1
getDistro_os_id="$(cat /etc/os-release | grep -E ^ID= | cut -d = -f 2)"
fi fi
printf '%s' "$getDistro_os_id" DISTRO="$(cat /etc/os-release | grep -E ^ID= | cut -d = -f 2)"
DISTRO_VERSION="$(printf '%s@%s' $DISTRO $(cat /etc/os-release | grep -E ^VERSION_ID= | cut -d = -f 2 | cut -d '"' -f 2 | cut -d . -f 1,2))"
} }
# Get the distribution name and the version # Set the PHP_MAJMIN_VERSION variable containing the PHP Major-Minor version as an integer value, in format MMmm (example: 506 for PHP 5.6.15)
# setPHPMajorMinor() {
# Example output: PHP_MAJMIN_VERSION=$(php-config --version | awk -F. '{print $1*100+$2}')
# alpine@3.10
# debian@9
getDistroVersion() {
getDistroVersion_distro="$(getDistro)"
if test -z "$getDistroVersion_distro"; then
return
fi
getDistroVersion_version=''
if test -r /etc/os-release; then
getDistroVersion_version="$(cat /etc/os-release | grep -E ^VERSION_ID= | cut -d = -f 2 | cut -d '"' -f 2 | cut -d . -f 1,2)"
fi
if test -z "$getDistroVersion_version"; then
return
fi
printf '%s@%s' "$getDistroVersion_distro" "$getDistroVersion_version"
}
# Get the PHP Major-Minor version as an integer value, in format MMmm (example: 506 for PHP 5.6.15)
#
# Output:
# The PHP numeric Major-Minor version
getPHPMajorMinor() {
php-config --version | awk -F. '{print $1*100+$2}'
} }
# Get the normalized list of already installed PHP modules # Get the normalized list of already installed PHP modules
@ -203,15 +180,13 @@ sortModulesToInstall() {
buildRequiredPackageLists() { buildRequiredPackageLists() {
buildRequiredPackageLists_persistent='' buildRequiredPackageLists_persistent=''
buildRequiredPackageLists_volatile='' buildRequiredPackageLists_volatile=''
buildRequiredPackageLists_distro="$(getDistro)"
buildRequiredPackageLists_distroVersion="$(getDistroVersion)"
buildRequiredPackageLists_phpv=$1 buildRequiredPackageLists_phpv=$1
case "$buildRequiredPackageLists_distro" in case "$DISTRO" in
alpine) alpine)
apk update apk update
;; ;;
esac esac
case "$buildRequiredPackageLists_distroVersion" in case "$DISTRO_VERSION" in
alpine@*) alpine@*)
buildRequiredPackageLists_volatile="$PHPIZE_DEPS" buildRequiredPackageLists_volatile="$PHPIZE_DEPS"
if test -z "$(apk info 2>/dev/null | grep -E ^libssl)"; then if test -z "$(apk info 2>/dev/null | grep -E ^libssl)"; then
@ -234,7 +209,7 @@ buildRequiredPackageLists() {
break break
fi fi
shift shift
case "$1@$buildRequiredPackageLists_distro" in case "$1@$DISTRO" in
amqp@alpine) amqp@alpine)
buildRequiredPackageLists_persistent="$buildRequiredPackageLists_persistent rabbitmq-c" buildRequiredPackageLists_persistent="$buildRequiredPackageLists_persistent rabbitmq-c"
buildRequiredPackageLists_volatile="$buildRequiredPackageLists_volatile rabbitmq-c-dev" buildRequiredPackageLists_volatile="$buildRequiredPackageLists_volatile rabbitmq-c-dev"
@ -359,7 +334,7 @@ buildRequiredPackageLists() {
imap@debian) imap@debian)
buildRequiredPackageLists_persistent="$buildRequiredPackageLists_persistent libc-client2007e" buildRequiredPackageLists_persistent="$buildRequiredPackageLists_persistent libc-client2007e"
buildRequiredPackageLists_volatile="$buildRequiredPackageLists_volatile libkrb5-dev" buildRequiredPackageLists_volatile="$buildRequiredPackageLists_volatile libkrb5-dev"
case "$buildRequiredPackageLists_distroVersion" in case "$DISTRO_VERSION" in
debian@9) debian@9)
buildRequiredPackageLists_volatile="$buildRequiredPackageLists_volatile $buildRequiredPackageLists_libssldev comerr-dev krb5-multidev libc-client2007e libgssrpc4 libkadm5clnt-mit11 libkadm5srv-mit11 libkdb5-8 libpam0g-dev libssl-doc mlock" buildRequiredPackageLists_volatile="$buildRequiredPackageLists_volatile $buildRequiredPackageLists_libssldev comerr-dev krb5-multidev libc-client2007e libgssrpc4 libkadm5clnt-mit11 libkadm5srv-mit11 libkdb5-8 libpam0g-dev libssl-doc mlock"
;; ;;
@ -526,7 +501,7 @@ buildRequiredPackageLists() {
;; ;;
redis@alpine) redis@alpine)
if test $buildRequiredPackageLists_phpv -ge 700; then if test $buildRequiredPackageLists_phpv -ge 700; then
case "$buildRequiredPackageLists_distroVersion" in case "$DISTRO_VERSION" in
alpine@3.7) alpine@3.7)
buildRequiredPackageLists_persistent="$buildRequiredPackageLists_persistent zstd" buildRequiredPackageLists_persistent="$buildRequiredPackageLists_persistent zstd"
;; ;;
@ -539,7 +514,7 @@ buildRequiredPackageLists() {
;; ;;
redis@debian) redis@debian)
if test $buildRequiredPackageLists_phpv -ge 700; then if test $buildRequiredPackageLists_phpv -ge 700; then
case "$buildRequiredPackageLists_distroVersion" in case "$DISTRO_VERSION" in
debian@8) debian@8)
## There's no APT package for libzstd ## There's no APT package for libzstd
;; ;;
@ -654,7 +629,7 @@ buildRequiredPackageLists() {
zip@debian) zip@debian)
buildRequiredPackageLists_persistent="$buildRequiredPackageLists_persistent libzip[0-9]$" buildRequiredPackageLists_persistent="$buildRequiredPackageLists_persistent libzip[0-9]$"
buildRequiredPackageLists_volatile="$buildRequiredPackageLists_volatile cmake gnutls-dev $buildRequiredPackageLists_libssldev libzip-dev libbz2-dev zlib1g-dev" buildRequiredPackageLists_volatile="$buildRequiredPackageLists_volatile cmake gnutls-dev $buildRequiredPackageLists_libssldev libzip-dev libbz2-dev zlib1g-dev"
case "$buildRequiredPackageLists_distroVersion" in case "$DISTRO_VERSION" in
debian@8) debian@8)
# Debian Jessie doesn't seem to provide libmbedtls # Debian Jessie doesn't seem to provide libmbedtls
;; ;;
@ -672,7 +647,7 @@ buildRequiredPackageLists() {
if test -z "$buildRequiredPackageLists_persistent$buildRequiredPackageLists_volatile"; then if test -z "$buildRequiredPackageLists_persistent$buildRequiredPackageLists_volatile"; then
return return
fi fi
case "$buildRequiredPackageLists_distro" in case "$DISTRO" in
debian) debian)
DEBIAN_FRONTEND=noninteractive apt-get update -q DEBIAN_FRONTEND=noninteractive apt-get update -q
;; ;;
@ -697,7 +672,7 @@ buildRequiredPackageLists() {
PACKAGES_VOLATILE="${PACKAGES_VOLATILE# }" PACKAGES_VOLATILE="${PACKAGES_VOLATILE# }"
fi fi
if test -n "$PACKAGES_PERSISTENT$PACKAGES_VOLATILE"; then if test -n "$PACKAGES_PERSISTENT$PACKAGES_VOLATILE"; then
case "$buildRequiredPackageLists_distro" in case "$DISTRO" in
debian) debian)
PACKAGES_PREVIOUS="$(dpkg --get-selections | grep -E '\sinstall$' | awk '{ print $1 }')" PACKAGES_PREVIOUS="$(dpkg --get-selections | grep -E '\sinstall$' | awk '{ print $1 }')"
;; ;;
@ -714,7 +689,7 @@ buildRequiredPackageLists() {
# Space-separated list of every APT/APK packages that will be installed # Space-separated list of every APT/APK packages that will be installed
expandPackagesToBeInstalled() { expandPackagesToBeInstalled() {
expandPackagesToBeInstalled_result='' expandPackagesToBeInstalled_result=''
case "$(getDistro)" in case "$DISTRO" in
alpine) alpine)
expandPackagesToBeInstalled_log="$(apk add --simulate $@ 2>&1 || printf '\nERROR: apk failed\n')" expandPackagesToBeInstalled_log="$(apk add --simulate $@ 2>&1 || printf '\nERROR: apk failed\n')"
if test -n "$(printf '%s' "$expandPackagesToBeInstalled_log" | grep -E '^ERROR:')"; then if test -n "$(printf '%s' "$expandPackagesToBeInstalled_log" | grep -E '^ERROR:')"; then
@ -776,7 +751,7 @@ installRequiredPackages() {
printf '# Packages to be kept after installation: %s\n' "$PACKAGES_PERSISTENT" printf '# Packages to be kept after installation: %s\n' "$PACKAGES_PERSISTENT"
printf '# Packages to be used only for installation: %s\n' "$PACKAGES_VOLATILE" printf '# Packages to be used only for installation: %s\n' "$PACKAGES_VOLATILE"
case "$(getDistro)" in case "$DISTRO" in
alpine) alpine)
apk add $PACKAGES_PERSISTENT $PACKAGES_VOLATILE apk add $PACKAGES_PERSISTENT $PACKAGES_VOLATILE
;; ;;
@ -799,7 +774,7 @@ installRequiredPackages() {
# 1.2 # 1.2
# 1.2.3 # 1.2.3
getInstalledPackageVersion() { getInstalledPackageVersion() {
case "$(getDistro)" in case "$DISTRO" in
alpine) alpine)
apk info "$1" | head -n1 | cut -c $((${#1} + 2))- | grep -o -E '^[0-9]+(\.[0-9]+){0,2}' apk info "$1" | head -n1 | cut -c $((${#1} + 2))- | grep -o -E '^[0-9]+(\.[0-9]+){0,2}'
;; ;;
@ -866,7 +841,7 @@ installBundledModule() {
fi fi
;; ;;
imap) imap)
case "$(getDistroVersion)" in case "$DISTRO_VERSION" in
debian@9) debian@9)
installBundledModule_tmp="$(pwd)" installBundledModule_tmp="$(pwd)"
cd /tmp cd /tmp
@ -879,7 +854,7 @@ installBundledModule() {
PHP_OPENSSL=yes docker-php-ext-configure imap --with-kerberos --with-imap-ssl PHP_OPENSSL=yes docker-php-ext-configure imap --with-kerberos --with-imap-ssl
;; ;;
interbase | pdo_firebird) interbase | pdo_firebird)
case "$(getDistro)" in case "$DISTRO" in
alpine) alpine)
if ! test -d /tmp/src/firebird; then if ! test -d /tmp/src/firebird; then
mv "$(getPackageSource https://github.com/FirebirdSQL/firebird/releases/download/R2_5_9/Firebird-2.5.9.27139-0.tar.bz2)" /tmp/src/firebird mv "$(getPackageSource https://github.com/FirebirdSQL/firebird/releases/download/R2_5_9/Firebird-2.5.9.27139-0.tar.bz2)" /tmp/src/firebird
@ -898,7 +873,7 @@ installBundledModule() {
esac esac
;; ;;
ldap) ldap)
case "$(getDistro)" in case "$DISTRO" in
debian) debian)
docker-php-ext-configure ldap --with-libdir=lib/$(gcc -dumpmachine) docker-php-ext-configure ldap --with-libdir=lib/$(gcc -dumpmachine)
;; ;;
@ -926,7 +901,7 @@ installBundledModule() {
docker-php-ext-configure pdo_odbc --with-pdo-odbc=unixODBC,/usr docker-php-ext-configure pdo_odbc --with-pdo-odbc=unixODBC,/usr
;; ;;
snmp) snmp)
case "$(getDistro)" in case "$DISTRO" in
alpine) alpine)
mkdir -p -m 0755 /var/lib/net-snmp/mib_indexes mkdir -p -m 0755 /var/lib/net-snmp/mib_indexes
;; ;;
@ -936,7 +911,7 @@ installBundledModule() {
docker-php-ext-configure sybase_ct --with-sybase-ct=/usr docker-php-ext-configure sybase_ct --with-sybase-ct=/usr
;; ;;
tidy) tidy)
case "$(getDistro)" in case "$DISTRO" in
alpine) alpine)
if ! test -f /usr/include/buffio.h; then if ! test -f /usr/include/buffio.h; then
ln -s /usr/include/tidybuffio.h /usr/include/buffio.h ln -s /usr/include/tidybuffio.h /usr/include/buffio.h
@ -958,7 +933,7 @@ installBundledModule() {
docker-php-ext-install -j$(nproc) "$2" docker-php-ext-install -j$(nproc) "$2"
case "$2" in case "$2" in
imap) imap)
case "$(getDistroVersion)" in case "$DISTRO_VERSION" in
debian@9) debian@9)
dpkg -r libc-client2007e-dev dpkg -r libc-client2007e-dev
;; ;;
@ -1039,10 +1014,9 @@ installPECLModule() {
installPECLModule_actual="$2" installPECLModule_actual="$2"
installPECLModule_stdin='\n' installPECLModule_stdin='\n'
installPECLModule_manuallyInstalled=0 installPECLModule_manuallyInstalled=0
installPECLModule_distroVersion="$(getDistroVersion)"
case "$2" in case "$2" in
amqp) amqp)
case "$installPECLModule_distroVersion" in case "$DISTRO_VERSION" in
debian@8) debian@8)
# in Debian Jessie we have librammitmq version 0.5.2 # in Debian Jessie we have librammitmq version 0.5.2
installPECLModule_actual="$2-1.9.3" installPECLModule_actual="$2-1.9.3"
@ -1055,7 +1029,7 @@ installPECLModule() {
fi fi
;; ;;
decimal) decimal)
case "$(getDistro)" in case "$DISTRO" in
alpine) alpine)
installPECLModule_src="$(getPackageSource https://codeload.github.com/bematech/libmpdec/tar.gz/master)" installPECLModule_src="$(getPackageSource https://codeload.github.com/bematech/libmpdec/tar.gz/master)"
cd -- "$installPECLModule_src" cd -- "$installPECLModule_src"
@ -1195,7 +1169,7 @@ installPECLModule() {
installPECLModule_actual="$2-3.0.5" installPECLModule_actual="$2-3.0.5"
else else
installPECLModule_tmp= installPECLModule_tmp=
case "$(getDistro)" in case "$DISTRO" in
alpine) alpine)
installPECLModule_tmp='librdkafka' installPECLModule_tmp='librdkafka'
;; ;;
@ -1343,7 +1317,6 @@ removeStringFromList() {
# Cleanup everything at the end of the execution # Cleanup everything at the end of the execution
cleanup() { cleanup() {
cleanup_distro="$(getDistro)"
if test -n "$UNNEEDED_PACKAGE_LINKS"; then if test -n "$UNNEEDED_PACKAGE_LINKS"; then
printf '### REMOVING UNNEEDED PACKAGE LINKS ###\n' printf '### REMOVING UNNEEDED PACKAGE LINKS ###\n'
for cleanup_link in $UNNEEDED_PACKAGE_LINKS; do for cleanup_link in $UNNEEDED_PACKAGE_LINKS; do
@ -1354,7 +1327,7 @@ cleanup() {
fi fi
if test -n "$PACKAGES_VOLATILE"; then if test -n "$PACKAGES_VOLATILE"; then
printf '### REMOVING UNNEEDED PACKAGES ###\n' printf '### REMOVING UNNEEDED PACKAGES ###\n'
case "$cleanup_distro" in case "$DISTRO" in
alpine) alpine)
apk del --purge $PACKAGES_VOLATILE apk del --purge $PACKAGES_VOLATILE
;; ;;
@ -1364,14 +1337,14 @@ cleanup() {
esac esac
fi fi
if test -n "$PACKAGES_PREVIOUS"; then if test -n "$PACKAGES_PREVIOUS"; then
case "$cleanup_distro" in case "$DISTRO" in
debian) debian)
printf '### RESTORING PREVIOUSLY INSTALLED PACKAGES ###\n' printf '### RESTORING PREVIOUSLY INSTALLED PACKAGES ###\n'
DEBIAN_FRONTEND=noninteractive apt-get install --no-upgrade -qqy $PACKAGES_PREVIOUS DEBIAN_FRONTEND=noninteractive apt-get install --no-upgrade -qqy $PACKAGES_PREVIOUS
;; ;;
esac esac
fi fi
case "$cleanup_distro" in case "$DISTRO" in
alpine) alpine)
rm -rf /var/cache/apk/* rm -rf /var/cache/apk/*
;; ;;
@ -1387,7 +1360,8 @@ cleanup() {
resetIFS resetIFS
mkdir -p /tmp/src mkdir -p /tmp/src
IPE_ERRFLAG_FILE="$(mktemp -p /tmp/src)" IPE_ERRFLAG_FILE="$(mktemp -p /tmp/src)"
PHP_MAJMIN_VERSION=$(getPHPMajorMinor) setDistro
setPHPMajorMinor
case "$PHP_MAJMIN_VERSION" in case "$PHP_MAJMIN_VERSION" in
505 | 506 | 700 | 701 | 702 | 703 | 704) ;; 505 | 506 | 700 | 701 | 702 | 703 | 704) ;;
*) *)