77 lines
2.5 KiB
Bash
Executable File
77 lines
2.5 KiB
Bash
Executable File
#!/bin/bash
|
|
set -e
|
|
|
|
# Vixy Eye Service Mk2 - Installer
|
|
# Deploys to ~/eyes-mk2, creates venv, installs 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 --user is-active "$SERVICE_NAME" &>/dev/null; then
|
|
echo "[install] stopping existing $SERVICE_NAME service"
|
|
systemctl --user 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"
|
|
|
|
# --- 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 ---
|
|
echo "[install] installing systemd service"
|
|
mkdir -p "$HOME/.config/systemd/user"
|
|
cp "$SCRIPT_DIR/vixy-eyes-mk2.service" "$HOME/.config/systemd/user/$SERVICE_NAME.service"
|
|
|
|
# Patch paths in case home dir differs from build machine
|
|
sed -i "s|/home/alex/eyes-mk2|$INSTALL_DIR|g" \
|
|
"$HOME/.config/systemd/user/$SERVICE_NAME.service"
|
|
sed -i "s|User=alex|User=$USER|g" \
|
|
"$HOME/.config/systemd/user/$SERVICE_NAME.service"
|
|
|
|
systemctl --user daemon-reload
|
|
systemctl --user enable "$SERVICE_NAME"
|
|
systemctl --user start "$SERVICE_NAME"
|
|
|
|
echo "[install] done"
|
|
echo ""
|
|
echo " status: systemctl --user status $SERVICE_NAME"
|
|
echo " logs: journalctl --user -u $SERVICE_NAME -f"
|
|
echo " stop: systemctl --user stop $SERVICE_NAME"
|
|
echo " restart: systemctl --user 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: systemctl --user restart $SERVICE_NAME"
|
|
fi
|