- Close printer handles (contextlib.closing) in CLI and TUI - Whitelist 4chan image extensions + numeric tim (path traversal) - Cap downloads at 16 MB - clean: unlink instead of rmtree, cover legacy dir, add -y flag - TUI: escape captured output as rich Text; propagate failure exit code - Pass --ip/--port through to connect_receipt.sh via env - Fix double-space textln calls - CI matrix 3.10/3.12/3.13 - pytest pythonpath so tests run without editable install - Print retry narrowed to OSError/escpos errors Co-Authored-By: Claude Code <[email protected]>
45 lines
1.3 KiB
Bash
Executable File
45 lines
1.3 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 addr show dev "$iface" | grep -q "${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
|
|
if timeout 2 bash -c "exec 3<>/dev/tcp/$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
|