#!/bin/bash # ============================================================ # Zorro's Print Agent - macOS Auto-Start Installer # # Run this from the same folder as zorros_print_agent.py on the # Mac that stays on at the store. It installs a LaunchAgent so the # kitchen print spooler starts on login and restarts if it exits. # ============================================================ set -euo pipefail APP_DIR="${HOME}/.zorros-print-agent" ENV_FILE="${APP_DIR}/print-agent.env" RUNNER="${APP_DIR}/run_print_agent.sh" PLIST_DIR="${HOME}/Library/LaunchAgents" PLIST_PATH="${PLIST_DIR}/com.zorros.printagent.plist" LABEL="com.zorros.printagent" SOURCE_DIR="$(cd "$(dirname "$0")" && pwd)" SOURCE_AGENT="${SOURCE_DIR}/zorros_print_agent.py" echo "" echo " ZORRO'S PRINT AGENT - MAC AUTO-START" echo " This installs the kitchen print spooler as a login service." echo "" if [ ! -f "${SOURCE_AGENT}" ]; then echo "ERROR: zorros_print_agent.py must be in the same folder as this installer." exit 1 fi if ! command -v python3 >/dev/null 2>&1; then echo "ERROR: python3 was not found." echo "Install Python from https://python.org/downloads, then run this again." exit 1 fi mkdir -p "${APP_DIR}" "${PLIST_DIR}" cp "${SOURCE_AGENT}" "${APP_DIR}/zorros_print_agent.py" echo "Installing Python dependency: requests" python3 -m pip install requests --quiet --disable-pip-version-check echo "" echo "Checking phone-order readiness before setup..." python3 "${SOURCE_AGENT}" --status || true echo "" if [ -z "${PRINT_BRIDGE_TOKEN:-}" ]; then printf "Enter the print bridge token from Veli: " read -r -s PRINT_BRIDGE_TOKEN echo "" fi if [ -z "${PRINT_BRIDGE_TOKEN:-}" ]; then echo "ERROR: PRINT_BRIDGE_TOKEN is required." exit 1 fi printf "Printer IP [${PRINTER_IP:-192.168.213.109}]: " read -r INPUT_PRINTER_IP PRINTER_IP="${INPUT_PRINTER_IP:-${PRINTER_IP:-192.168.213.109}}" printf "Printer port [${PRINTER_PORT:-9100}]: " read -r INPUT_PRINTER_PORT PRINTER_PORT="${INPUT_PRINTER_PORT:-${PRINTER_PORT:-9100}}" cat > "${ENV_FILE}" < "${RUNNER}" < "${PLIST_PATH}" < Label ${LABEL} ProgramArguments /bin/bash ${RUNNER} RunAtLoad KeepAlive WorkingDirectory ${APP_DIR} StandardOutPath ${APP_DIR}/print-agent.out.log StandardErrorPath ${APP_DIR}/print-agent.err.log EOF echo "" echo "Testing Railway token + printer path with one setup ticket..." set +e source "${ENV_FILE}" python3 "${APP_DIR}/zorros_print_agent.py" --test-bridge-print TEST_STATUS=$? set -e if [ "${TEST_STATUS}" -ne 0 ]; then echo "" echo "WARNING: Setup ticket test failed." echo "The service will still install, but check Wi-Fi, printer IP, and PRINT_BRIDGE_TOKEN." fi echo "" echo "Installing LaunchAgent..." launchctl unload "${PLIST_PATH}" >/dev/null 2>&1 || true launchctl load "${PLIST_PATH}" echo "" echo "DONE. Zorro's print spooler is installed." echo "It will start when this Mac logs in and restart if it exits." echo "" echo "Useful commands:" echo " launchctl list | grep ${LABEL}" echo " tail -f ${APP_DIR}/print-agent.out.log" echo " tail -f ${APP_DIR}/print-agent.err.log"