#!/bin/bash # ============================================================ # Zorro's Print Agent — Mac/Linux One-Click Installer # Run this once on any computer at the shop. # It installs dependencies and starts the print agent. # ============================================================ echo "" echo " ZORRO'S PRINT AGENT SETUP" echo " Railway: https://zorro-phone-agent-production.up.railway.app" echo "" export PRINTER_IP="${PRINTER_IP:-192.168.213.109}" export PRINTER_PORT="${PRINTER_PORT:-9100}" echo " Printer: ${PRINTER_IP}:${PRINTER_PORT}" echo "" # Check Python if ! command -v python3 &>/dev/null; then echo "ERROR: Python3 not found." echo "Install from https://python.org/downloads then run this again." exit 1 fi # Install requests echo "Installing dependencies..." python3 -m pip install requests --quiet echo "" echo "Checking phone-order readiness before setup..." python3 "$(dirname "$0")/zorros_print_agent.py" --status || true echo "" if [ -z "${PRINT_BRIDGE_TOKEN:-}" ]; then printf "Enter the print bridge token from Veli: " read -r -s PRINT_BRIDGE_TOKEN export PRINT_BRIDGE_TOKEN echo "" fi if [ -z "${PRINT_BRIDGE_TOKEN:-}" ]; then echo "ERROR: PRINT_BRIDGE_TOKEN is required." exit 1 fi # Check printer reachability echo "Testing printer connection at ${PRINTER_IP}:${PRINTER_PORT}..." python3 -c " import os, socket printer_ip = os.environ.get('PRINTER_IP', '192.168.213.109') printer_port = int(os.environ.get('PRINTER_PORT', '9100')) try: s = socket.create_connection((printer_ip, printer_port), timeout=3) s.close() print(' Printer REACHABLE') except Exception as e: print(f' Printer NOT reachable: {e}') print(' Make sure this computer is on the same WiFi as the printer.') " printf "Print one local-only setup test ticket now? [y/N]: " read -r RUN_TEST_PRINT if [ "$RUN_TEST_PRINT" = "y" ] || [ "$RUN_TEST_PRINT" = "Y" ]; then python3 "$(dirname "$0")/zorros_print_agent.py" --test-print fi # Test Railway connection echo "Testing Railway connection..." python3 -c " import urllib.request try: r = urllib.request.urlopen('https://zorro-phone-agent-production.up.railway.app/api/print/health', timeout=5) print(' Railway REACHABLE') except Exception as e: print(f' Railway not reachable: {e}') " printf "Print one Railway bridge setup ticket now? [y/N]: " read -r RUN_BRIDGE_TEST if [ "$RUN_BRIDGE_TEST" = "y" ] || [ "$RUN_BRIDGE_TEST" = "Y" ]; then python3 "$(dirname "$0")/zorros_print_agent.py" --test-bridge-print fi echo "" echo "Starting print agent... (Press Ctrl+C to stop)" echo "" python3 "$(dirname "$0")/zorros_print_agent.py"