#!/bin/bash
echo "------------------------------------"
echo "Package Installer for radar_data_reader"
echo "------------------------------------"
echo ""
echo "Checking for pip..."
PYTHON_CMD=""
if command -v python3 &>/dev/null && python3 -m pip --version &>/dev/null; then PYTHON_CMD="python3"
elif command -v python &>/dev/null && python -m pip --version &>/dev/null; then PYTHON_CMD="python"
else echo "ERROR: Python pip module not found for python3 or python."; echo "Install pip: https://pip.pypa.io/en/stable/installation/"; exit 1; fi
echo "pip found ($PYTHON_CMD)."

SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
REQ_FILE="$SCRIPT_DIR/requirements.txt"
echo "Installing packages from '$SCRIPT_DIR' using '$REQ_FILE'..."
echo ""
"$PYTHON_CMD" -m pip install --no-index --find-links "$SCRIPT_DIR" -r "$REQ_FILE" --disable-pip-version-check
INSTALL_STATUS=$?
echo ""
if [ $INSTALL_STATUS -ne 0 ]; then 
    echo "--------------------------"; echo "ERROR: Installation Failed."; echo "--------------------------"; echo "Check messages above."; exit 1; 
else 
    echo "--------------------------"; echo "Installation Successful!"; echo "--------------------------"; exit 0; 
fi
