|
1 | 1 | #!/bin/bash |
2 | | -set -e |
| 2 | +# A solution for consolidating dependency installation commands for different operating systems (for macOS, Debian/Ubuntu, RedHat/CentOS) |
| 3 | +# Allows minimal repetition in command installations in multiple CI workflow files. |
| 4 | +# CI logs on which commands are being run. |
3 | 5 |
|
4 | | -echo "Installing required dependencies..." |
| 6 | +# Instructions: |
| 7 | +# 1. Run this command: chmod +x ./scripts/install_dependencies.sh |
| 8 | +# 2. Run the installer: ./scripts/install_dependencies.sh |
5 | 9 |
|
6 | | -# Detect OS and install packages |
| 10 | +set -euo pipefail |
| 11 | +set -x |
| 12 | + |
| 13 | +OS="$(uname -s)" |
| 14 | +echo "Installing dependencies for $OS OS" |
| 15 | + |
| 16 | +# macOS |
7 | 17 | if [[ "$OSTYPE" == "darwin"* ]]; then |
8 | | - echo "Detected macOS" |
| 18 | + # Use Homebrew for macOS package management |
| 19 | + echo "Detected macOS." |
| 20 | + export PATH="/opt/homebrew/bin:/opt/homebrew/sbin:$PATH" |
9 | 21 | brew update |
10 | | - brew install cmake protobuf boost [email protected] |
| 22 | + |
| 23 | + # Packages to install |
| 24 | + declare -A packages |
| 25 | + packages=( |
| 26 | + ["cmake"]="cmake" |
| 27 | + ["gcc"]="gcc" |
| 28 | + |
| 29 | + ["boost"]="boost" |
| 30 | + ["protobuf"]="protobuf" |
| 31 | + ) |
| 32 | + |
| 33 | + # Install missing packages |
| 34 | + for exe in "${!packages[@]}"; do |
| 35 | + formula="${packages[$exe]}" |
| 36 | + if ! command -v "$exe" >/dev/null 2>&1; then |
| 37 | + echo "Installing $formula..." |
| 38 | + brew install --verbose "$formula" |
| 39 | + else |
| 40 | + echo "$exe already installed" |
| 41 | + fi |
| 42 | + done |
| 43 | + |
| 44 | + # Verification |
| 45 | + echo "Verifying installations..." |
| 46 | + which cmake; cmake --version |
| 47 | + which gcc; gcc --version |
| 48 | + which python3; python3 --version |
| 49 | + brew list boost || echo "boost not found" |
| 50 | + brew list protobuf || echo "protobuf not found" |
| 51 | + |
| 52 | + echo "macOS dependencies installed successfully." |
| 53 | + |
| 54 | + |
| 55 | +# Debian/Ubuntu |
11 | 56 | elif [[ -f /etc/debian_version ]]; then |
12 | 57 | echo "Detected Debian/Ubuntu" |
13 | | - sudo apt-get update |
14 | | - sudo apt-get install -y build-essential cmake protobuf-compiler libboost-all-dev python3 python3-pip |
| 58 | + sudo apt-get update -y |
| 59 | + |
| 60 | + # Install all required packages (this time with openmpi and fftw) |
| 61 | + pkgs="tar wget make cmake gcc g++ python3 python3-dev openmpi-bin libopenmpi-dev fftw3 libfftw3-dev protobuf-compiler libboost-all-dev" |
| 62 | + sudo apt-get install -y $pkgs |
| 63 | + |
| 64 | + # Verification |
| 65 | + echo "Verifying installations..." |
| 66 | + cmake --version || echo "cmake not found" |
| 67 | + gcc --version || echo "gcc not found" |
| 68 | + python3 --version || echo "python3 not found" |
| 69 | + mpirun --version || echo "mpirun not found" |
| 70 | + ldconfig -p | grep -q libfftw3 || echo "FFTW library not found" |
| 71 | + |
| 72 | + echo "Linux dependencies installed successfully." |
| 73 | + |
| 74 | + |
| 75 | +# RedHat/CentOS |
15 | 76 | elif [[ -f /etc/redhat-release ]]; then |
16 | 77 | echo "Detected RedHat/CentOS" |
17 | 78 | sudo yum install -y epel-release |
18 | | - sudo yum install -y cmake3 protobuf-compiler boost-devel python3 |
| 79 | + |
| 80 | + # Install all required packages (this time with openmpi and fftw) |
| 81 | + pkgs="tar wget make cmake3 gcc gcc-c++ python3 openmpi fftw protobuf boost-devel" |
| 82 | + sudo yum install -y $pkgs |
| 83 | + |
| 84 | + # Verification |
| 85 | + echo "Verifying installations..." |
| 86 | + cmake3 --version || echo "cmake3 not found" |
| 87 | + gcc --version || echo "gcc not found" |
| 88 | + python3 --version || echo "python3 not found" |
| 89 | + mpirun --version || echo "mpirun not found" |
| 90 | + rpm -q fftw || echo "FFTW library not found" |
| 91 | + |
| 92 | + echo "RedHat/CentOS dependencies installed successfully." |
| 93 | + |
| 94 | + |
| 95 | +# If Unsupported OS |
19 | 96 | else |
20 | 97 | echo "Unsupported OS: $OSTYPE" |
21 | 98 | exit 1 |
|
0 commit comments