#!/bin/bash set -e # Vixy Eye Service Mk2 - Installer # Deploys to ~/eyes-mk2, creates venv, installs system-level systemd service # # Usage: # ./install.sh # install and start service # ./install.sh --learn # also run --learn to pin left/right USB serials INSTALL_DIR="$HOME/eyes-mk2" VENV_DIR="$INSTALL_DIR/.venv" SERVICE_NAME="vixy-eyes-mk2" SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" echo "[install] Vixy Eye Service Mk2" # --- Stop existing service if running --- if systemctl is-active "$SERVICE_NAME" &>/dev/null; then echo "[install] stopping existing $SERVICE_NAME service" sudo systemctl stop "$SERVICE_NAME" fi # --- Copy files --- echo "[install] deploying to $INSTALL_DIR" mkdir -p "$INSTALL_DIR" cp "$SCRIPT_DIR/eye_service_mk2.py" "$INSTALL_DIR/" cp "$SCRIPT_DIR/requirements.txt" "$INSTALL_DIR/" # --- Copy firmware for reference --- if [ -d "$SCRIPT_DIR/vixy_eye" ]; then cp -r "$SCRIPT_DIR/vixy_eye" "$INSTALL_DIR/firmware" fi # --- Create/update venv --- if [ ! -d "$VENV_DIR" ]; then echo "[install] creating venv" python3 -m venv "$VENV_DIR" fi echo "[install] installing dependencies" "$VENV_DIR/bin/pip" install --quiet --upgrade pip "$VENV_DIR/bin/pip" install --quiet -r "$INSTALL_DIR/requirements.txt" # --- Ensure user is in dialout group for serial access --- if ! groups "$USER" | grep -q dialout; then echo "[install] adding $USER to dialout group (may need re-login)" sudo usermod -aG dialout "$USER" fi # --- Learn USB serial numbers if requested --- if [ "$1" = "--learn" ]; then echo "[install] learning eye USB serials (both eyes must be plugged in)" "$VENV_DIR/bin/python" "$INSTALL_DIR/eye_service_mk2.py" --learn fi # --- Install systemd service (system-level, runs on boot without login) --- echo "[install] installing systemd service" sed -e "s|/home/alex/eyes-mk2|$INSTALL_DIR|g" \ -e "s|User=alex|User=$USER|g" \ "$SCRIPT_DIR/vixy-eyes-mk2.service" | sudo tee /etc/systemd/system/"$SERVICE_NAME".service >/dev/null sudo systemctl daemon-reload sudo systemctl enable "$SERVICE_NAME" sudo systemctl start "$SERVICE_NAME" echo "[install] done" echo "" echo " status: sudo systemctl status $SERVICE_NAME" echo " logs: journalctl -u $SERVICE_NAME -f" echo " stop: sudo systemctl stop $SERVICE_NAME" echo " restart: sudo systemctl restart $SERVICE_NAME" echo "" if [ "$1" != "--learn" ]; then echo " If this is the first install, plug in both eyes and run:" echo " $INSTALL_DIR/.venv/bin/python $INSTALL_DIR/eye_service_mk2.py --learn" echo " Then: sudo systemctl restart $SERVICE_NAME" fi