Better error handling

This commit is contained in:
2026-03-07 14:39:19 +00:00
parent 6e47e10a44
commit 5fdbcb7468

View File

@@ -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