diff --git a/install.sh b/install.sh index 77bed5b..15e5a46 100755 --- a/install.sh +++ b/install.sh @@ -2,7 +2,7 @@ set -e # Vixy Eye Service Mk2 - Installer -# Deploys to ~/eyes-mk2, creates venv, installs systemd service +# Deploys to ~/eyes-mk2, creates venv, installs system-level systemd service # # Usage: # ./install.sh # install and start service @@ -16,9 +16,9 @@ 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 +if systemctl is-active "$SERVICE_NAME" &>/dev/null; then echo "[install] stopping existing $SERVICE_NAME service" - systemctl --user stop "$SERVICE_NAME" + sudo systemctl stop "$SERVICE_NAME" fi # --- Copy files --- @@ -41,36 +41,37 @@ 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 --- +# --- Install systemd service (system-level, runs on boot without login) --- 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" +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 -# 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" +sudo systemctl daemon-reload +sudo systemctl enable "$SERVICE_NAME" +sudo systemctl 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 " 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: systemctl --user restart $SERVICE_NAME" + echo " Then: sudo systemctl restart $SERVICE_NAME" fi