Better error handling
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
set -e
|
||||||
|
|
||||||
# Try to find the USB Ethernet interface first
|
# Try to find the USB Ethernet interface first
|
||||||
iface=$(ip -o link | awk -F': ' '/enx|enp.*u/{print $2}' | head -n 1)
|
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"
|
echo "Using USB Ethernet interface: $iface"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Assign IP address (only for USB interface, skip eth0)
|
# Bring interface up before assigning IP
|
||||||
# if [[ $iface != "eth0" ]]; then
|
|
||||||
sudo ip addr add 192.168.192.10/24 dev "$iface" 2>/dev/null
|
|
||||||
# fi
|
|
||||||
|
|
||||||
# Bring interface up
|
|
||||||
sudo ip link set "$iface" up
|
sudo ip link set "$iface" up
|
||||||
|
|
||||||
# Scan port 9100 on the printer IP
|
# Assign IP address if not already set
|
||||||
nmap -p 9100 192.168.192.168
|
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
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user