Skip to content
Closed
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 101 additions & 0 deletions scripts/install_dependencies.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
#!/bin/bash
# A solution for consolidating dependency installation commands for different operating systems (for macOS, Debian/Ubuntu, RedHat/CentOS)
# Allows minimal repetition in command installations in multiple CI workflow files.
# CI logs on which commands are being run.

# Instructions:
# 1. Run this command: chmod +x ./scripts/install_dependencies.sh
# 2. Run the installer: ./scripts/install_dependencies.sh

set -euo pipefail
set -x

OS="$(uname -s)"
echo "Installing dependencies for $OS OS"

# macOS
if [[ "$OSTYPE" == "darwin"* ]]; then
# Use Homebrew for macOS package management
echo "Detected macOS."
export PATH="/opt/homebrew/bin:/opt/homebrew/sbin:$PATH"
brew update

# Packages to install
declare -A packages
packages=(
["cmake"]="cmake"
["gcc"]="gcc"
["python3"]="[email protected]"
["boost"]="boost"
["protobuf"]="protobuf"
)

# Install missing packages
for exe in "${!packages[@]}"; do
formula="${packages[$exe]}"
if ! command -v "$exe" >/dev/null 2>&1; then
echo "Installing $formula..."
brew install --verbose "$formula"
else
echo "$exe already installed"
fi
done
Copy link
Contributor

@qodo-merge-pro qodo-merge-pro bot Oct 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: Modify the macOS package check to use brew list instead of command -v. This correctly detects installed Homebrew libraries like boost and protobuf, preventing unnecessary reinstallations. [possible issue, importance: 8]

Suggested change
# Install missing packages
for exe in "${!packages[@]}"; do
formula="${packages[$exe]}"
if ! command -v "$exe" >/dev/null 2>&1; then
echo "Installing $formula..."
brew install --verbose "$formula"
else
echo "$exe already installed"
fi
done
# Install missing packages
for exe in "${!packages[@]}"; do
formula="${packages[$exe]}"
if ! brew list --formula | grep -q "^${formula%%@*}$"; then
echo "Installing $formula..."
brew install --verbose "$formula"
else
echo "$formula already installed"
fi
done


# Verification
echo "Verifying installations..."
which cmake; cmake --version
which gcc; gcc --version
which python3; python3 --version
brew list boost || echo "boost not found"
brew list protobuf || echo "protobuf not found"

echo "macOS dependencies installed successfully."


# Debian/Ubuntu
elif [[ -f /etc/debian_version ]]; then
echo "Detected Debian/Ubuntu"
sudo apt-get update -y

# Install all required packages (this time with openmpi and fftw)
pkgs="tar wget make cmake gcc g++ python3 python3-dev openmpi-bin libopenmpi-dev fftw3 libfftw3-dev protobuf-compiler libboost-all-dev"
sudo apt-get install -y $pkgs

# Verification
echo "Verifying installations..."
cmake --version || echo "cmake not found"
gcc --version || echo "gcc not found"
python3 --version || echo "python3 not found"
mpirun --version || echo "mpirun not found"
ldconfig -p | grep -q libfftw3 || echo "FFTW library not found"
Copy link
Contributor

@qodo-merge-pro qodo-merge-pro bot Oct 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: Replace the command || echo constructs in the verification steps with if ! command; then echo; fi blocks. This ensures the custom error messages are displayed correctly when set -e is active. [possible issue, importance: 7]

Suggested change
# Verification
echo "Verifying installations..."
cmake --version || echo "cmake not found"
gcc --version || echo "gcc not found"
python3 --version || echo "python3 not found"
mpirun --version || echo "mpirun not found"
ldconfig -p | grep -q libfftw3 || echo "FFTW library not found"
# Verification
echo "Verifying installations..."
if ! cmake --version; then echo "cmake not found"; fi
if ! gcc --version; then echo "gcc not found"; fi
if ! python3 --version; then echo "python3 not found"; fi
if ! mpirun --version; then echo "mpirun not found"; fi
if ! ldconfig -p | grep -q libfftw3; then echo "FFTW library not found"; fi


echo "Linux dependencies installed successfully."


# RedHat/CentOS
elif [[ -f /etc/redhat-release ]]; then
echo "Detected RedHat/CentOS"
sudo yum install -y epel-release

# Install all required packages (this time with openmpi and fftw)
pkgs="tar wget make cmake3 gcc gcc-c++ python3 openmpi fftw protobuf boost-devel"
sudo yum install -y $pkgs

# Verification
echo "Verifying installations..."
cmake3 --version || echo "cmake3 not found"
gcc --version || echo "gcc not found"
python3 --version || echo "python3 not found"
mpirun --version || echo "mpirun not found"
rpm -q fftw || echo "FFTW library not found"

echo "RedHat/CentOS dependencies installed successfully."


# If Unsupported OS
else
echo "Unsupported OS: $OSTYPE"
exit 1
fi

echo "Dependencies installed successfully."