#!/bin/bash

[ "x$1" = "xprereqs" ] && exit

[ "x$debug" = "xy" ] && set -x

# fix for SIO1545037: [T730][u-kit] [T6X52107][reg] image can't get IP if it is deployed by the latest version U-kit.
# bring up all interfaces even if we don't use them, this prevent nic lockup upon reboot
for i in `ls /sys/class/net/`; do 
  ifconfig $i up
done

# only do this if we boot via network
[ "x$MODE" != "xpxe" ] && exit 0

ifup() {
  echo "Bring up $netif"
  dhclient $netif
  sleep 1
  netip=`ip addr list $netif | grep -w inet | awk '{print $2}'`

  # cmdline option may supersedes dhcp options
  [ "x$netimgurl" = "x" ] && netimgurl=`grep -w auto-update-image /var/lib/dhcp/dhclient.leases | tail -1 | awk '{print $3}' | sed -e 's/"//g' -e 's/;//'`
  [ "x$netscript" = "x" ] && netscript=`grep -w auto-update-script /var/lib/dhcp/dhclient.leases | tail -1 | awk '{print $3}' | sed -e 's/"//g' -e 's/;//'`
}

[ "x$netif" = "x" ] && netif=`ifconfig -a | grep Ethernet| head -1|awk '{print $1}'`
netmac=`ifconfig -a | grep Ethernet| head -1| sed "s/.*HWaddr //"`

ifup

echo "NETIF=${netif:-none}" >> /conf/param.conf
echo "NETMAC=${netmac:-none}" >> /conf/param.conf
echo "NETIP=${netip:-none}" >> /conf/param.conf
echo "NETIMGURL=${netimgurl:-none}" >> /conf/param.conf
echo "NETSCRIPT=${netscript:-none}" >> /conf/param.conf

