Files
pyhdwallet/install_offline.sh

192 lines
4.9 KiB
Bash
Executable File

#!/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
ARCH=$(uname -m)
case "$ARCH" in
x86_64)
PLATFORM="linux-x86_64"
CHECKSUM_CMD="sha256sum"
;;
aarch64|arm64)
PLATFORM="linux-aarch64"
CHECKSUM_CMD="sha256sum"
;;
*)
echo "ERROR: Unsupported Linux architecture: $ARCH"
exit 1
;;
esac
elif [[ "$OSTYPE" == "darwin"* ]]; then
ARCH=$(uname -m)
if [[ "$ARCH" == "arm64" ]]; then
PLATFORM="macos-arm64"
CHECKSUM_CMD="shasum -a 256"
else
echo "ERROR: Only macOS ARM64 is supported"
exit 1
fi
else
echo "ERROR: Unsupported platform: $OSTYPE"
exit 1
fi
echo "Detected platform: $PLATFORM ($(uname -m))"
# 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!"
echo ""
echo "Available vendor directories:"
ls -d vendor/*/ 2>/dev/null || echo " (none)"
echo ""
if [ "$DEV_MODE" = true ]; then
echo "To build dev wheels for your platform:"
case "$PLATFORM" in
linux-x86_64)
echo " make vendor-linux-dev"
;;
linux-aarch64)
echo " make vendor-linux-arm-dev"
;;
macos-arm64)
echo " make vendor-macos-dev"
;;
esac
else
echo "To build runtime wheels for your platform:"
case "$PLATFORM" in
linux-x86_64)
echo " make vendor-linux"
;;
linux-aarch64)
echo " make vendor-linux-arm"
;;
macos-arm64)
echo " make vendor-macos"
;;
esac
echo ""
echo "Or build all platforms at once:"
echo " make vendor-all"
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 " Debian/Ubuntu: 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" && $CHECKSUM_CMD -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
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)"
echo "Platform: $PLATFORM"
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"