77 lines
2.4 KiB
Bash
Executable File
77 lines
2.4 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# HomeKit Bridge Startup Script
|
|
# This script sets up the virtual environment, installs dependencies, and starts the bridge
|
|
|
|
set -e # Exit on error
|
|
|
|
# Determine script directory (apps/homekit)
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
|
|
# Navigate to workspace root (two levels up from apps/homekit)
|
|
WORKSPACE_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
|
|
cd "$WORKSPACE_ROOT"
|
|
|
|
echo "🏠 HomeKit Bridge Startup"
|
|
echo "========================="
|
|
echo " Working dir: $WORKSPACE_ROOT"
|
|
echo ""
|
|
|
|
# Virtual environment path
|
|
VENV_DIR="$SCRIPT_DIR/venv"
|
|
|
|
# Check if virtual environment exists
|
|
if [ ! -d "$VENV_DIR" ]; then
|
|
echo "📦 Virtual environment not found. Creating..."
|
|
# Try to use Python 3.12 or 3.13 (3.14 has compatibility issues with HAP-Python)
|
|
if command -v python3.13 &> /dev/null; then
|
|
PYTHON_CMD=python3.13
|
|
elif command -v python3.12 &> /dev/null; then
|
|
PYTHON_CMD=python3.12
|
|
elif command -v python3.11 &> /dev/null; then
|
|
PYTHON_CMD=python3.11
|
|
else
|
|
PYTHON_CMD=python3
|
|
echo "⚠️ Warning: Using default python3. HAP-Python may not work with Python 3.14+"
|
|
fi
|
|
echo " Using: $PYTHON_CMD"
|
|
$PYTHON_CMD -m venv "$VENV_DIR"
|
|
echo "✅ Virtual environment created at $VENV_DIR"
|
|
fi
|
|
|
|
# Activate virtual environment
|
|
echo "🔧 Activating virtual environment..."
|
|
source "$VENV_DIR/bin/activate"
|
|
|
|
# Install/update dependencies
|
|
echo "📥 Installing dependencies from requirements.txt..."
|
|
pip install --upgrade pip -q
|
|
pip install -r "$SCRIPT_DIR/requirements.txt" -q
|
|
echo "✅ Dependencies installed"
|
|
|
|
# Set environment variables (with defaults)
|
|
export HOMEKIT_NAME="${HOMEKIT_NAME:-Home Automation Bridge}"
|
|
export HOMEKIT_PIN="${HOMEKIT_PIN:-031-45-154}"
|
|
export HOMEKIT_PORT="${HOMEKIT_PORT:-51826}"
|
|
export API_BASE="${API_BASE:-http://172.19.1.11:8001}"
|
|
export HOMEKIT_API_TOKEN="${HOMEKIT_API_TOKEN:-}"
|
|
export HOMEKIT_PERSIST_FILE="${HOMEKIT_PERSIST_FILE:-$SCRIPT_DIR/homekit.state}"
|
|
|
|
# Display configuration
|
|
echo ""
|
|
echo "⚙️ Configuration:"
|
|
echo " Bridge Name: $HOMEKIT_NAME"
|
|
echo " Bridge PIN: $HOMEKIT_PIN"
|
|
echo " Bridge Port: $HOMEKIT_PORT"
|
|
echo " API Base URL: $API_BASE"
|
|
echo " Persist File: $HOMEKIT_PERSIST_FILE"
|
|
echo ""
|
|
|
|
# Start the bridge
|
|
echo "🚀 Starting HomeKit Bridge..."
|
|
echo " (Press Ctrl+C to stop)"
|
|
echo ""
|
|
|
|
# Run the bridge from workspace root with correct module path
|
|
python -m apps.homekit.main
|