run (1140B)
1 #!/bin/sh 2 3 #this script runs busybox's udhcpc if preconditions are ok. 4 #return=preconditions:explanations 5 #1=cable is plugged: 6 # if no cable, just return and sleep. 7 # Automatic handling would be better, but it's hard to 8 # find real doc on how kernel works there (no, I don't 9 # like udev). 10 11 . /etc/runit/common 12 13 IFACE="$(echo ${SVNAME} | cut -f2 -d-)" 14 15 test -n "$IFACE" || badconf "Unable to retrieve interface name from \"$SVNAME\"" 16 ip link show "$IFACE" > /dev/null || badconf "Unknown IFACE" 17 18 #try to detect plugged cable before trying using the NIC 19 #it could be done in ./finish, but there is then no way to skip DELAY 20 #which is annoying at best (except to kill the right sleep process). 21 # 22 #ethtool is used here, since it's the less annoying method. 23 #other ones would be: 24 #(unreliable) cat /sys/class/net/$IFACE/carrier 25 #(I feel a trap) cat /sys/class/net/$IFACE/operstate 26 test -e /sbin/ethtool && while $(/sbin/ethtool $IFACE | grep -q 'Link detected: no') 27 do 28 test "$VERBOSE" = "yes" && echo "$IFACE unpluged, sleep for ${DELAY:=60}" 29 sleep $DELAY 30 done 31 32 echo "Starting udhcpc on $IFACE..." 33 exec udhcpc -i ${IFACE} -f -R -n