#!/bin/bash # USDA Vision Camera System Startup Script echo "USDA Vision Camera System - Startup Script" echo "==========================================" # Ensure we are running from the script directory SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" cd "$SCRIPT_DIR" echo "๐Ÿ“‚ Working directory: $SCRIPT_DIR" # Check if virtual environment exists if [ ! -d ".venv" ]; then echo "โŒ Virtual environment not found. Please run 'uv sync' first." exit 1 fi # Activate virtual environment echo "๐Ÿ”ง Activating virtual environment..." source .venv/bin/activate # Ensure project root is on PYTHONPATH for imports export PYTHONPATH="$SCRIPT_DIR:$PYTHONPATH" # Check if config file exists if [ ! -f "config.json" ]; then echo "โš ๏ธ Config file not found. Using default configuration." fi # Check storage directory if [ ! -d "/mnt/nfs_share" ]; then echo "๐Ÿ“ Creating storage directory..." sudo mkdir -p /mnt/nfs_share sudo chown $USER:$USER /mnt/nfs_share echo "โœ… Storage directory created at /mnt/nfs_share" fi # Check time synchronization echo "๐Ÿ• Checking time synchronization..." python tests/core/check_time.py echo "" # Run system tests first echo "๐Ÿงช Running system tests..." python tests/integration/test_system.py if [ $? -ne 0 ]; then echo "โŒ System tests failed. Please check the configuration." # When running as a service, don't prompt for user input if [ -t 0 ]; then # Interactive mode - prompt user read -p "Do you want to continue anyway? (y/N): " -n 1 -r echo if [[ ! $REPLY =~ ^[Yy]$ ]]; then exit 1 fi else # Non-interactive mode (service) - continue with warning echo "โš ๏ธ Running in non-interactive mode. Continuing despite test failures..." sleep 2 fi fi echo "" echo "๐Ÿš€ Starting USDA Vision Camera System..." echo " - MQTT monitoring will begin automatically" echo " - Camera recording will start when machines turn on" echo " - API server will be available at http://localhost:8000" echo " - Press Ctrl+C to stop the system" echo "" # Start the system python main.py "$@" echo "๐Ÿ‘‹ USDA Vision Camera System stopped."