install-snowflake-driver.sh 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #!/usr/bin/env bash
  2. # Install the Snowflake ODBC driver on a Debian-based system.
  3. # https://developers.snowflake.com/odbc/
  4. set -xeuo pipefail
  5. if [ ! -f /etc/debian_version ]; then
  6. echo "This script is only intended for Debian-based systems"
  7. exit 1
  8. fi
  9. if dpkg -l snowflake-odbc 1>/dev/null 2>/dev/null ; then
  10. echo "Snowflake ODBC driver is already installed"
  11. exit 0
  12. fi
  13. VERSION="3.4.1"
  14. BASE_URL="https://sfc-repo.snowflakecomputing.com/odbc"
  15. ARCH="$(uname -m)"
  16. FILE="snowflake-odbc-${VERSION}.${ARCH}.deb"
  17. if [ "${ARCH}" == x86_64 ]; then
  18. URL="${BASE_URL}/linux/${VERSION}/${FILE}"
  19. SHA256="a96fcc89a3d3f2d16fc492976a01fefae57029bcd2e238ff4eff5a6693fa4f74"
  20. elif [ "${ARCH}" == aarch64 ]; then
  21. URL="${BASE_URL}/linux${ARCH}/${VERSION}/${FILE}"
  22. SHA256="c9f5c60ace416640683693037d5949aefea9555b9aa62501b6b6c692d140989c"
  23. else
  24. echo "Unsupported architecture: ${ARCH}"
  25. exit 1
  26. fi
  27. if [[ -f "${FILE}" && $(echo "$SHA256 *$FILE" | sha256sum -c) ]]; then
  28. echo "Snowflake ODBC driver package is already downloaded"
  29. else
  30. apt-get -qq update && apt-get install -yqq curl
  31. curl -fsSL -O --retry 5 "$URL"
  32. echo "$SHA256 *$FILE" | sha256sum -c
  33. fi
  34. apt-get -qq update
  35. apt-get install -yqq unixodbc-dev unixodbc odbcinst curl libreadline8
  36. apt-get install -yqq "./${FILE}"
  37. # Fix the path to the libodbcinst.so library in the simba.snowflake.ini file.
  38. ODBC_INST_LIB="/usr/lib/${ARCH}-linux-gnu/libodbcinst.so"
  39. sed -i -e "s#^ODBCInstLib=.*#ODBCInstLib=$ODBC_INST_LIB#" /usr/lib/snowflake/odbc/lib/simba.snowflake.ini
  40. # Remove references to SF_ACCOUNT from the odbc.ini file.
  41. # It will be configured dynamically.
  42. sed -i '/^SERVER/d' /etc/odbc.ini
  43. sed -i '/^ACCOUNT/d' /etc/odbc.ini
  44. ODBC_INI_CONTENT="[ODBC Data Sources]
  45. snowflake = SnowflakeDSIIDriver"
  46. if ! grep -Fxq "$ODBC_INI_CONTENT" /etc/odbc.ini; then
  47. cat >>/etc/odbc.ini <<EOF
  48. $ODBC_INI_CONTENT
  49. EOF
  50. fi