+resolve_url() {
+ file="$1"
+
+ # URL? use as-is.
+ tmp=${file%://*}
+ if [ "$tmp" != "$file" ]
+ then
+ echo "$file"
+ fi
+
+ # Otherwise, TFTP using an appropriate host. Start with the
+ # DHCP 'tftp' option:
+ host=${tftp}
+
+ # next, try the DHCP next-server-address
+ [ -z "$host" ] && host=${siaddr}
+
+ # finally, use the DHCP server we got this lease from:
+ [ -z "$host" ] && host=${serverid}
+
+ echo "tftp://$host/$file"
+}
+
+do_pxe() {
+ basedir=$1
+
+ params="conf@/net/${interface} method=dhcp"
+
+ # first, try by MAC
+ mac=$(tr ':' '-' < /sys/class/net/$interface/address)
+ pb-event $params url=$basedir/01-$mac
+
+ # try decreasing fragments of IP lease
+ ip_hex=$(printf '%02X%02X%02X%02X' $(echo $ip | tr '.' ' '))
+ for i in $(seq 8 -1 1)
+ do
+ frag=${ip_hex:0:$i}
+ pb-event $params url=$basedir/$frag
+ done
+
+ # last, use default
+ pb-event $params url=$basedir/default
+}
+