#!/bin/bash
# Maat Journal decryption tool: installer for macOS and Linux.
# Creates a local virtual environment next to this script and installs the two dependencies.
set -e
cd "$(dirname "$0")"

if ! command -v python3 >/dev/null 2>&1; then
  echo "Python 3 was not found."
  echo "  macOS: install it from https://www.python.org/downloads/ or with Homebrew: brew install python"
  echo "  Linux: sudo apt install python3 python3-venv   (Debian/Ubuntu)"
  exit 1
fi

python3 -c 'import sys; sys.exit(0 if sys.version_info >= (3, 9) else 1)' || { echo "Python 3.9 or newer is required."; exit 1; }
python3 -c 'import venv' 2>/dev/null || { echo "The Python venv module is missing. On Debian/Ubuntu: sudo apt install python3-venv"; exit 1; }

[ -d venv ] && rm -rf venv
python3 -m venv venv
./venv/bin/python -m pip install --quiet --upgrade pip
./venv/bin/python -m pip install --quiet mnemonic pycryptodome

echo
echo "Ready. Decrypt an export with:"
echo "  ./venv/bin/python maat_decrypt.py --input your_export.json --format text"
echo "You will be asked for your 12-word recovery phrase. It is never saved."
