#!/usr/bin/env bash
set -e

# Resolve Python environment
PYTHON="$(command -v python)"

if [ -z "$PYTHON" ]; then
  echo "ERROR: No active Python environment found."
  exit 1
fi

echo "Using Python:"
echo "  $PYTHON"

# Location of bundled installer
INSTALLER_ROOT="$HOME/.emerge/installer"

if [ ! -f "$INSTALLER_ROOT/install.sh" ]; then
  echo "ERROR: MUMPS installer not found."
  echo "Expected:"
  echo "  $INSTALLER_ROOT/install.sh"
  exit 1
fi

# Run installer
bash "$INSTALLER_ROOT/install.sh"

# Install Python package into *this* environment
"$PYTHON" -m pip install "$HOME/.emerge/mumps_py"

echo
echo "MUMPS successfully installed for this Python environment."
