#!/bin/sh

# This script loads a wrboot script from the TFTP server and runs it.
if [ "x$eth0.ipaddr" = "x" ] || [ "$eth0.ipaddr" = "0.0.0.0" ]; then
    dhcp 5;
fi

# fetch wrboot-<MAC> script, or <IP>/wrboot or wrboot
tftp wrboot-$eth0.ethaddr wrboot
ret=$?
if [ "$ret" -ne "0" ]; then
    sleep 1
    tftp $eth0.ipaddr/wrboot wrboot
    ret=$?
fi
if [ "$ret" -ne "0" ]; then
    sleep 1
    tftp wrboot wrboot
    ret=$?
fi
if [ "$ret" -eq "0" ]; then
    ./wrboot
fi

# If the script doesn't boot return to menu after some time to read output
echo "Script exited: re-running menu in 2 seconds"
sleep 2
menu -s boot
