`./receipt.py serve` (receipt_web.py, the new [web] extra) serves a page for printing a note or an uploaded image. The site's nginx gates /receipt/ on the admin session and proxies to it over Tailscale, adding X-Receipt-Token; nothing but /healthz answers without it, and POSTs also need X-Requested-With: receipt. Jobs run one at a time behind a lock around run_action(), and uploads print from memory. run_action(), _dispatch() and setup_network_quiet() move from the TUI to receipt.py so the server doesn't need textual. --no-setup (needs_setup()) skips the sudo connect script everywhere it would run; serve always sets it. cmd_print takes in-memory `data`. deploy/ has the systemd user units. receipt-update.timer runs update.sh every 5 minutes: it fast-forwards the clone from Gitea, runs the tests and restarts receipt-web, rolling back if they fail. Also included from earlier uncommitted work: the CI matrix moved to the right place, connect_receipt.sh no longer re-parses CLI values in bash -c, RECEIPT_PRINTER_IP/PORT are validated, pyusb is declared, the ruff S rules are on, and the img/ cache and junk/ are no longer tracked. Co-Authored-By: Claude Opus 5.5 <[email protected]>
46 lines
1.4 KiB
Bash
Executable File
46 lines
1.4 KiB
Bash
Executable File
#!/bin/bash
|
|
# Bring up the network interface for the Epson TM-T20II and verify it is reachable.
|
|
set -euo pipefail
|
|
|
|
# Overridable by the CLI, which exports these to match --ip/--port.
|
|
PRINTER_IP="${RECEIPT_PRINTER_IP:-192.168.192.168}"
|
|
PRINTER_PORT="${RECEIPT_PRINTER_PORT:-9100}"
|
|
# Our address on the printer's /24, host part .10
|
|
HOST_ADDR="${PRINTER_IP%.*}.10/24"
|
|
|
|
# Prefer a USB Ethernet interface; fall back to eth0
|
|
iface=$(ip -o link | awk -F': ' '/enx|enp.*u/{print $2}' | head -n 1)
|
|
|
|
if [ -z "$iface" ]; then
|
|
if ip link show eth0 &>/dev/null; then
|
|
iface="eth0"
|
|
echo "USB Ethernet not found. Using eth0."
|
|
else
|
|
echo "No suitable interface found." >&2
|
|
exit 1
|
|
fi
|
|
else
|
|
echo "Using USB Ethernet interface: $iface"
|
|
fi
|
|
|
|
# Bring interface up before assigning IP
|
|
sudo ip link set "$iface" up
|
|
|
|
# Assign our address on the printer's subnet if not already set
|
|
if ! ip -o addr show dev "$iface" | grep -qw "${HOST_ADDR%/*}"; then
|
|
sudo ip addr add "$HOST_ADDR" dev "$iface"
|
|
fi
|
|
|
|
# Wait for the printer port to become reachable (interface may need a moment)
|
|
for attempt in {1..5}; do
|
|
# No `bash -c "...$VAR..."`: the values come from the CLI and must never be re-parsed.
|
|
if timeout 2 bash -c 'exec 3<>/dev/tcp/"$0"/"$1"' "$PRINTER_IP" "$PRINTER_PORT" 2>/dev/null; then
|
|
echo "Printer reachable at $PRINTER_IP:$PRINTER_PORT"
|
|
exit 0
|
|
fi
|
|
sleep 1
|
|
done
|
|
|
|
echo "Printer port $PRINTER_PORT is not open at $PRINTER_IP." >&2
|
|
exit 1
|