| 
									
										
										
										
											2021-12-01 20:16:32 +01:00
										 |  |  | #!/bin/bash -e
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-07-22 10:50:12 +02:00
										 |  |  | #From https://stackoverflow.com/questions/4023830/how-to-compare-two-strings-in-dot-separated-version-format-in-bash | 
					
						
							|  |  |  | verlte() { | 
					
						
							|  |  |  |   [  "$1" == "$(echo -e "$1\n$2" | sort -V | head -n1)" ] | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-12-01 20:16:32 +01:00
										 |  |  | brew_install() { | 
					
						
							| 
									
										
										
										
											2022-07-22 10:50:12 +02:00
										 |  |  |     package=${1} | 
					
						
							|  |  |  |     required_version=${2} | 
					
						
							|  |  |  |     printf '\n🔎 Checking if %s installed\n' "${package}" | 
					
						
							|  |  |  |     version=$(brew list --version|grep "$1"|awk '{ print $2 }') | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if [ -n "${version}" ]; then | 
					
						
							|  |  |  |       if [ -n "$2" ] && ! verlte "${required_version}" "${version}"; then | 
					
						
							|  |  |  |         printf '🔽 %s is installed but its version %s is lower than the required %s\n' "${package}" "${version}" "${required_version}. Updating version..." | 
					
						
							|  |  |  |         brew update && brew upgrade "$1" && printf '✅ %s is installed\n' "${package}" | 
					
						
							|  |  |  |       else | 
					
						
							|  |  |  |         printf '✅ %s is already installed\n' "${package} with version ${version}" | 
					
						
							|  |  |  |       fi | 
					
						
							| 
									
										
										
										
											2021-12-01 20:16:32 +01:00
										 |  |  |     else | 
					
						
							| 
									
										
										
										
											2022-07-22 10:50:12 +02:00
										 |  |  |         brew install "$1" && printf '✅ %s is installed\n' "${package}" | 
					
						
							| 
									
										
										
										
											2021-12-01 20:16:32 +01:00
										 |  |  |     fi | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | arm64_darwin_preflight() { | 
					
						
							| 
									
										
										
										
											2022-09-08 02:32:30 -07:00
										 |  |  |   printf "✨ Creating/activating Virtual Environment\n" | 
					
						
							| 
									
										
										
										
											2021-12-01 20:16:32 +01:00
										 |  |  |   python3 -m venv venv | 
					
						
							|  |  |  |   source venv/bin/activate | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   printf "🔎 Checking if Scipy installed\n" | 
					
						
							|  |  |  |   if pip list | grep -F scipy; then | 
					
						
							|  |  |  |   	printf "✅ Scipy already installed\n" | 
					
						
							|  |  |  |   else | 
					
						
							|  |  |  |   	printf "Scipy not installed\n" | 
					
						
							|  |  |  |   	printf "⛅ Installing prerequisities for scipy" | 
					
						
							|  |  |  |   	brew install openblas | 
					
						
							|  |  |  |   	OPENBLAS="$(brew --prefix openblas)" | 
					
						
							|  |  |  |   	export OPENBLAS | 
					
						
							|  |  |  |   	##preinstall numpy and pythran from source | 
					
						
							|  |  |  |   	pip3 uninstall -y numpy pythran | 
					
						
							|  |  |  |   	pip3 install cython pybind11 | 
					
						
							| 
									
										
										
										
											2022-04-29 13:59:47 +05:30
										 |  |  |   	pip3 install --no-use-pep517 numpy | 
					
						
							| 
									
										
										
										
											2021-12-01 20:16:32 +01:00
										 |  |  |   	pip3 install pythran | 
					
						
							| 
									
										
										
										
											2022-04-29 13:59:47 +05:30
										 |  |  |   	pip3 install --no-use-pep517 scipy | 
					
						
							| 
									
										
										
										
											2021-12-01 20:16:32 +01:00
										 |  |  |   fi | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   brew_install "openssl@1.1" | 
					
						
							| 
									
										
										
										
											2022-09-08 02:32:30 -07:00
										 |  |  |   brew install "postgresql@14" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   # postgresql installs libs in a strange way | 
					
						
							|  |  |  |   # we first symlink /opt/postgresql@14 to /opt/postgresql | 
					
						
							|  |  |  |   if [ ! -z $(brew --prefix)/opt/postgresql ]; then | 
					
						
							|  |  |  |     printf "✨ Symlinking postgresql@14 to postgresql\n" | 
					
						
							| 
									
										
										
										
											2022-09-15 13:21:02 -07:00
										 |  |  |     ln -sf $(brew --prefix postgresql@14) $(brew --prefix)/opt/postgresql | 
					
						
							| 
									
										
										
										
											2022-09-08 02:32:30 -07:00
										 |  |  |   fi | 
					
						
							|  |  |  |   # we then symlink all libs under /opt/postgresql@14/lib/postgresql@14 to /opt/postgresql@14/lib | 
					
						
							|  |  |  |   if [ ! -z $(brew --prefix postgresql@14)/lib/postgresql@14 ]; then | 
					
						
							|  |  |  |     printf "✨ Patching up libs in $(brew --prefix postgresql@14)/lib/postgresql@14)\n" | 
					
						
							|  |  |  |     ln -sf $(brew --prefix postgresql@14)/lib/postgresql@14/* $(brew --prefix postgresql@14)/lib/ | 
					
						
							|  |  |  |   fi | 
					
						
							| 
									
										
										
										
											2021-12-01 20:16:32 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |   printf "\e[38;2;0;255;0m✅ Done\e[38;2;255;255;255m\n" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   printf "✨ Setting up environment variable:\n" | 
					
						
							|  |  |  |   GRPC_PYTHON_BUILD_SYSTEM_OPENSSL=1 | 
					
						
							|  |  |  |   export GRPC_PYTHON_BUILD_SYSTEM_OPENSSL | 
					
						
							|  |  |  |   GRPC_PYTHON_BUILD_SYSTEM_ZLIB=1 | 
					
						
							|  |  |  |   export GRPC_PYTHON_BUILD_SYSTEM_ZLIB | 
					
						
							| 
									
										
										
										
											2023-12-21 20:28:45 -05:00
										 |  |  |   CPPFLAGS="-I$(brew --prefix openssl@1.1)/include" | 
					
						
							| 
									
										
										
										
											2021-12-01 20:16:32 +01:00
										 |  |  |   export CPPFLAGS | 
					
						
							| 
									
										
										
										
											2023-12-21 20:28:45 -05:00
										 |  |  |   LDFLAGS="-L$(brew --prefix openssl@1.1)/lib" | 
					
						
							| 
									
										
										
										
											2021-12-01 20:16:32 +01:00
										 |  |  |   export LDFLAGS | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | cat << EOF | 
					
						
							|  |  |  |   export GRPC_PYTHON_BUILD_SYSTEM_OPENSSL=1 | 
					
						
							|  |  |  |   export GRPC_PYTHON_BUILD_SYSTEM_ZLIB=1 | 
					
						
							| 
									
										
										
										
											2023-12-21 20:28:45 -05:00
										 |  |  |   export CPPFLAGS="-I$(brew --prefix openssl@1.1)/include" | 
					
						
							|  |  |  |   export LDFLAGS="-L$(brew --prefix openssl@1.1)/lib -L$(brew --prefix postgresql@14)/lib/postgresql@14" | 
					
						
							| 
									
										
										
										
											2022-01-28 12:31:18 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-12-01 20:16:32 +01:00
										 |  |  | EOF | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-01-28 12:31:18 +05:30
										 |  |  |   if pip list | grep -F confluent-kafka; then | 
					
						
							|  |  |  |     printf "✅ confluent-kafka already installed\n" | 
					
						
							|  |  |  |   else | 
					
						
							|  |  |  |     pip3 install confluent-kafka | 
					
						
							|  |  |  |   fi | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-12-01 20:16:32 +01:00
										 |  |  |   printf "✨ Setting up prerequisities\n" | 
					
						
							| 
									
										
										
										
											2022-12-30 14:02:57 -05:00
										 |  |  |   # none for now, since jq was removed | 
					
						
							| 
									
										
										
										
											2021-12-01 20:16:32 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |   printf "\e[38;2;0;255;0m✅ Done\e[38;2;255;255;255m\n" | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | printf "🔎 Checking if current directory is metadata-ingestion folder\n" | 
					
						
							|  |  |  | if [ "$(basename "$(pwd)")"	 != "metadata-ingestion" ]; then | 
					
						
							|  |  |  | 	printf "💥 You should run this script in Datahub\'s metadata-ingestion folder but your folder is %s\n" "$(pwd)" | 
					
						
							|  |  |  | 	exit 123 | 
					
						
							|  |  |  | fi | 
					
						
							|  |  |  | printf '✅ Current folder is metadata-ingestion (%s) folder\n' "$(pwd)" | 
					
						
							| 
									
										
										
										
											2021-12-06 21:49:08 -08:00
										 |  |  | if [[ $(uname -m) == 'arm64' && $(uname) == 'Darwin' ]]; then | 
					
						
							| 
									
										
										
										
											2021-12-01 20:16:32 +01:00
										 |  |  |   printf "👟 Running preflight for m1 mac\n" | 
					
						
							|  |  |  |   arm64_darwin_preflight | 
					
						
							|  |  |  | fi | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | printf "\n\e[38;2;0;255;0m✅ Preflight was successful\e[38;2;255;255;255m\n" |