#!/bin/bash # SSH Setup Script for Arduino UNO Q # Uses configuration from config.json set -e # Add lib directory to Python path SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" PROJECT_ROOT="$(dirname "$SCRIPT_DIR")" PYTHONPATH="$PROJECT_ROOT/lib:$PYTHONPATH" # Load configuration python3 -c " import sys sys.path.insert(0, '$PROJECT_ROOT/lib') from config_loader import config arduino_config = config.get_arduino_config() print(f'UNOQ_HOST={arduino_config[\"hostname\"]}') print(f'UNOQ_USER={arduino_config[\"user\"]}') print(f'SSH_KEY={arduino_config[\"ssh_key\"]}') " > /tmp/ssh_config.sh source /tmp/ssh_config.sh echo "Setting up SSH for Arduino UNO Q..." # Create SSH key if it doesn't exist if [ ! -f "$SSH_KEY" ]; then echo "Creating SSH key..." ssh-keygen -t ed25519 -f "$SSH_KEY" -N "" -C "arduino_unoq_key" fi # Test connection and copy key echo "Testing connection to Arduino UNO Q at $UNOQ_HOST..." if ping -c 1 "$UNOQ_HOST" &> /dev/null; then echo "Copying SSH key to Arduino UNO Q..." ssh-copy-id -i "$SSH_KEY.pub" "$UNOQ_USER@$UNOQ_HOST" || { echo "Manual setup required:" echo "1. Connect to Arduino UNO Q: ssh $UNOQ_USER@$UNOQ_HOST" echo "2. Create .ssh directory: mkdir -p ~/.ssh" echo "3. Add public key: echo '$(cat $SSH_KEY.pub)' >> ~/.ssh/authorized_keys" echo "4. Set permissions: chmod 600 ~/.ssh/authorized_keys" echo "5. Restart SSH: systemctl restart sshd" } else echo "Arduino UNO Q not reachable at $UNOQ_HOST" echo "Make sure:" echo "- USB-C cable is connected" echo "- Network interface is up (check IP in config.json)" echo "- SSH is enabled on the device" fi echo "SSH setup complete!" echo "Test connection: ssh -i $SSH_KEY $UNOQ_USER@$UNOQ_HOST" # Cleanup rm -f /tmp/ssh_config.sh