From 02517f08821d0e18a7bbffd71ff33faaa7e7d464 Mon Sep 17 00:00:00 2001 From: Michele Locati Date: Wed, 20 Jan 2021 10:53:51 +0100 Subject: [PATCH] Install the Microsoft SQL Server ODBC Driver when installing sqlsrv/pdo_sqlsrv --- data/special-requirements | 2 ++ install-php-extensions | 53 +++++++++++++++++++++++++++++++-------- 2 files changed, 45 insertions(+), 10 deletions(-) diff --git a/data/special-requirements b/data/special-requirements index 4d1a32c..8b85fd3 100644 --- a/data/special-requirements +++ b/data/special-requirements @@ -1,4 +1,6 @@ enchant !7.2-alpine3.12 !7.3-alpine3.12 !7.4-alpine3.12 parallel zts +pdo_sqlsrv !7.0-alpine3.7 !7.1-alpine3.7 !7.1-alpine3.8 !7.2-alpine3.7 !7.2-alpine3.8 !7.3-alpine3.8 pthreads zts +sqlsrv !7.0-alpine3.7 !7.1-alpine3.7 !7.1-alpine3.8 !7.1-alpine3.9 !7.1-alpine3.10 !7.2-alpine3.7 !7.2-alpine3.8 !7.3-alpine3.8 tdlib !alpine3.7 !jessie diff --git a/install-php-extensions b/install-php-extensions index 139692e..25afde5 100755 --- a/install-php-extensions +++ b/install-php-extensions @@ -667,14 +667,6 @@ buildRequiredPackageLists() { buildRequiredPackageLists_persistent="$buildRequiredPackageLists_persistent libpq5" buildRequiredPackageLists_volatile="$buildRequiredPackageLists_volatile libpq-dev" ;; - pdo_sqlsrv@alpine) - buildRequiredPackageLists_persistent="$buildRequiredPackageLists_persistent libstdc++ unixodbc" - buildRequiredPackageLists_volatile="$buildRequiredPackageLists_volatile unixodbc-dev" - ;; - pdo_sqlsrv@debian) - buildRequiredPackageLists_persistent="$buildRequiredPackageLists_persistent libodbc1 odbcinst" - buildRequiredPackageLists_volatile="$buildRequiredPackageLists_volatile unixodbc-dev" - ;; pgsql@alpine) buildRequiredPackageLists_persistent="$buildRequiredPackageLists_persistent postgresql-libs" buildRequiredPackageLists_volatile="$buildRequiredPackageLists_volatile postgresql-dev" @@ -772,13 +764,16 @@ buildRequiredPackageLists() { buildRequiredPackageLists_persistent="$buildRequiredPackageLists_persistent libcurl3-gnutls" buildRequiredPackageLists_volatile="$buildRequiredPackageLists_volatile libcurl4-gnutls-dev libxml2-dev" ;; - sqlsrv@alpine) + sqlsrv@alpine | pdo_sqlsrv@alpine) buildRequiredPackageLists_persistent="$buildRequiredPackageLists_persistent libstdc++ unixodbc" buildRequiredPackageLists_volatile="$buildRequiredPackageLists_volatile unixodbc-dev" ;; - sqlsrv@debian) + sqlsrv@debian | pdo_sqlsrv@debian) buildRequiredPackageLists_persistent="$buildRequiredPackageLists_persistent unixodbc" buildRequiredPackageLists_volatile="$buildRequiredPackageLists_volatile unixodbc-dev" + if ! isMicrosoftSqlServerODBCInstalled; then + buildRequiredPackageLists_volatile="$buildRequiredPackageLists_volatile gnupg apt-transport-https" + fi ;; ssh2@alpine) buildRequiredPackageLists_persistent="$buildRequiredPackageLists_persistent libssh2" @@ -1170,6 +1165,41 @@ installOracleInstantClient() { esac } +# Check if the Microsoft SQL Server ODBC Driver is installed +# +# Return: +# 0 (true): if the string is in the list +# 1 (false): if the string is not in the list +isMicrosoftSqlServerODBCInstalled() { + test -d /opt/microsoft/msodbcsql*/ +} + +# Install the Microsoft SQL Server ODBC Driver +installMicrosoftSqlServerODBC() { + printf 'Installing the Microsoft SQL Server ODBC Driver\n' + case "$DISTRO" in + alpine) + # https://docs.microsoft.com/en-us/sql/connect/odbc/linux-mac/installing-the-microsoft-odbc-driver-for-sql-server#alpine17 + rm -rf /tmp/src/msodbcsql.apk + curl -sSLf -o /tmp/src/msodbcsql.apk https://download.microsoft.com/download/e/4/e/e4e67866-dffd-428c-aac7-8d28ddafb39b/msodbcsql17_17.6.1.1-1_amd64.apk + printf '\n' | apk add --allow-untrusted /tmp/src/msodbcsql.apk + rm -rf /tmp/src/msodbcsql.apk + ;; + debian) + # https://docs.microsoft.com/en-us/sql/connect/odbc/linux-mac/installing-the-microsoft-odbc-driver-for-sql-server#debian17 + printf -- '- installing the Microsoft APT key\n' + curl -sSLf https://packages.microsoft.com/keys/microsoft.asc | apt-key add - + if ! test -f /etc/apt/sources.list.d/mssql-release.list; then + printf -- '- adding the Microsoft APT source list\n' + curl -sSLf https://packages.microsoft.com/config/debian/$DISTRO_VERSION_NUMBER/prod.list >/etc/apt/sources.list.d/mssql-release.list + DEBIAN_FRONTEND=noninteractive apt-get -q update + fi + printf -- '- installing the APT package\n' + DEBIAN_FRONTEND=noninteractive ACCEPT_EULA=Y apt-get -qy install '^msodbcsql[0-9]+$' + ;; + esac +} + # Install Composer installComposer() { installComposer_version="$(getWantedPHPModuleVersion @composer)" @@ -1681,6 +1711,9 @@ installRemoteModule() { installRemoteModule_version=5.8.1 fi fi + if ! isMicrosoftSqlServerODBCInstalled; then + installMicrosoftSqlServerODBC + fi ;; propro) if test -z "$installRemoteModule_version"; then