From 5fdbcb7468bcaa32efde3b7a73ee0f89a42836ca Mon Sep 17 00:00:00 2001 From: Adam French Date: Sat, 7 Mar 2026 14:39:19 +0000 Subject: [PATCH] Better error handling --- connect_recipt.sh | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/connect_recipt.sh b/connect_recipt.sh index 2da9f35..1b5a02f 100755 --- a/connect_recipt.sh +++ b/connect_recipt.sh @@ -1,4 +1,5 @@ #!/bin/bash +set -e # Try to find the USB Ethernet interface first iface=$(ip -o link | awk -F': ' '/enx|enp.*u/{print $2}' | head -n 1) @@ -16,14 +17,17 @@ else echo "Using USB Ethernet interface: $iface" fi -# Assign IP address (only for USB interface, skip eth0) -# if [[ $iface != "eth0" ]]; then - sudo ip addr add 192.168.192.10/24 dev "$iface" 2>/dev/null -# fi - -# Bring interface up +# Bring interface up before assigning IP sudo ip link set "$iface" up -# Scan port 9100 on the printer IP -nmap -p 9100 192.168.192.168 +# Assign IP address if not already set +if ! ip addr show dev "$iface" | grep -q "192.168.192.10"; then + sudo ip addr add 192.168.192.10/24 dev "$iface" +fi + +# Scan port 9100 on the printer IP and verify it is open +if ! nmap -p 9100 --open 192.168.192.168 | grep -q "9100/tcp open"; then + echo "Printer port 9100 is not open." + exit 1 +fi