#!/bin/bash set -e SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)" THIRDPARTY_DIR="$PROJECT_ROOT/thirdparty" mkdir -p "$THIRDPARTY_DIR" echo "==========================================" echo "Fetching Dependencies into: $THIRDPARTY_DIR" echo "==========================================" download_and_extract() { local name="$1" local url="$2" local archive_name="$3" local target_dir_name="$4" local archive_path="$THIRDPARTY_DIR/$archive_name" local target_path="$THIRDPARTY_DIR/$target_dir_name" if [ -d "$target_path" ]; then echo "[$name] Already extracted in $target_path. Skipping." return 0 fi if [ ! -f "$archive_path" ]; then echo "[$name] Downloading $archive_name to $THIRDPARTY_DIR ..." curl -L "$url" -o "$archive_path" else echo "[$name] Archive $archive_name already exists in $THIRDPARTY_DIR." fi echo "[$name] Extracting $archive_name ..." if [[ "$archive_name" == *.tar.gz ]] || [[ "$archive_name" == *.tgz ]]; then if ! tar -xzf "$archive_path" -C "$THIRDPARTY_DIR"; then echo "[$name] Extraction failed! Removing corrupt archive $archive_path." rm -f "$archive_path" exit 1 fi elif [[ "$archive_name" == *.tar.bz2 ]]; then if ! tar -xjf "$archive_path" -C "$THIRDPARTY_DIR"; then echo "[$name] Extraction failed! Removing corrupt archive $archive_path." rm -f "$archive_path" exit 1 fi elif [[ "$archive_name" == *.zip ]]; then if ! unzip -q "$archive_path" -d "$THIRDPARTY_DIR"; then echo "[$name] Extraction failed! Removing corrupt archive $archive_path." rm -f "$archive_path" exit 1 fi fi echo "[$name] Unpacked successfully." } # 1. zlib download_and_extract \ "zlib" \ "https://github.com/madler/zlib/archive/refs/tags/v1.3.1.tar.gz" \ "zlib-1.3.1.tar.gz" \ "zlib-1.3.1" # 2. bzip2 download_and_extract \ "bzip2" \ "https://sourceware.org/pub/bzip2/bzip2-1.0.8.tar.gz" \ "bzip2-1.0.8.tar.gz" \ "bzip2-1.0.8" # 3. libpng download_and_extract \ "libpng" \ "https://downloads.sourceforge.net/project/libpng/libpng16/1.6.43/libpng-1.6.43.tar.gz" \ "libpng-1.6.43.tar.gz" \ "libpng-1.6.43" # 4. libzip download_and_extract \ "libzip" \ "https://github.com/nih-at/libzip/releases/download/v1.10.1/libzip-1.10.1.tar.gz" \ "libzip-1.10.1.tar.gz" \ "libzip-1.10.1" # 5. Boost download_and_extract \ "Boost" \ "https://archives.boost.io/release/1.84.0/source/boost_1_84_0.tar.gz" \ "boost_1_84_0.tar.gz" \ "boost_1_84_0" echo "==========================================" echo "All dependencies downloaded and unpacked!" echo "=========================================="