#!/bin/bash set -e # Parse arguments DEV_MODE=false if [ "$1" == "--dev" ]; then DEV_MODE=true echo "🛠️ Development mode enabled" fi # Detect platform if [[ "$OSTYPE" == "linux-gnu"* ]]; then PLATFORM="linux-x86_64" elif [[ "$OSTYPE" == "darwin"* ]]; then ARCH=$(uname -m) if [[ "$ARCH" == "arm64" ]]; then PLATFORM="macos-arm64" else echo "ERROR: Only macOS ARM64 is supported" exit 1 fi else echo "ERROR: Unsupported platform: $OSTYPE" exit 1 fi echo "Detected platform: $PLATFORM" # Check if vendor directory exists VENDOR_PATH="vendor/$PLATFORM" if [ "$DEV_MODE" = true ]; then VENDOR_PATH="vendor/$PLATFORM-dev" fi if [ ! -d "$VENDOR_PATH" ]; then echo "ERROR: $VENDOR_PATH not found!" if [ "$DEV_MODE" = true ]; then echo "Run 'make vendor-linux-dev' to generate dev wheels" else echo "Run 'make vendor-linux' or 'make vendor-macos' to generate wheels" fi exit 1 fi # Check for Python 3.12 if ! command -v python3.12 &> /dev/null; then echo "ERROR: Python 3.12 not found!" echo "Please install Python 3.12:" echo " macOS: brew install python@3.12" echo " Linux: apt-get install python3.12 python3.12-venv" exit 1 fi # Create venv VENV_DIR=".venv" if [ ! -d "$VENV_DIR" ] || [ ! -f "$VENV_DIR/bin/python3.12" ]; then echo "Creating Python 3.12 virtual environment..." python3.12 -m venv "$VENV_DIR" echo "✓ Virtual environment created: $VENV_DIR" else echo "Using existing venv: $VENV_DIR" fi # Activate venv source "$VENV_DIR/bin/activate" # Verify Python version PYTHON_VERSION=$(python --version 2>&1 | grep -oE '3\.[0-9]+') echo "Using Python $PYTHON_VERSION from: $(which python)" if [[ "$PYTHON_VERSION" != "3.12" ]]; then echo "ERROR: Expected Python 3.12, got $PYTHON_VERSION" exit 1 fi # Verify checksums if [ -f "$VENDOR_PATH/SHA256SUMS" ]; then echo "" echo "Verifying checksums..." (cd "$VENDOR_PATH" && sha256sum -c SHA256SUMS --quiet) || { echo "ERROR: Checksum verification failed!" exit 1 } echo "✓ Checksums verified" fi # Install echo "" if [ "$DEV_MODE" = true ]; then echo "Installing from $VENDOR_PATH (includes dev dependencies)..." pip install --upgrade pip --quiet pip install --no-index --find-links="$VENDOR_PATH" -r requirements-dev.txt else echo "Installing from $VENDOR_PATH..." pip install --upgrade pip --quiet pip install --no-index --find-links="$VENDOR_PATH" -r requirements.txt fi # Test echo "" echo "Running tests..." if [ "$DEV_MODE" = true ]; then # Run full test suite if pytest available if python -c "import pytest" >/dev/null 2>&1; then python -m pytest -v tests/test_vectors.py || { echo "ERROR: Tests failed!" exit 1 } else echo "⚠️ pytest not found in dev install!" fi else # Only mention pytest in production mode echo "⚠️ Skipping pytest (use --dev for full test suite)" fi echo "" echo "Running built-in smoke test..." python src/pyhdwallet.py test || { echo "ERROR: Smoke test failed!" exit 1 } echo "" echo "==========================================" echo "✓ Installation complete and verified!" echo "==========================================" echo "" echo "Virtual environment: $VENV_DIR" echo "Python version: $(python --version)" if [ "$DEV_MODE" = true ]; then echo "Mode: Development (pytest installed)" else echo "Mode: Production (runtime only)" fi echo "" echo "To activate this environment:" echo " source $VENV_DIR/bin/activate" echo "" if [ "$DEV_MODE" = false ]; then echo "For development with pytest:" echo " ./install_offline.sh --dev" echo "" fi echo "Generate a wallet:" echo " python src/pyhdwallet.py gen --help"