#!/bin/sh
# udhcpc (BusyBox) script of the Vetro initramfs: configures the interface
# with the address obtained via DHCP, the default route and the DNS.
# Prints a single line with the lease values: it must be the same with QEMU's
# user network and with the Vetro stack (crates/vetro-net).
case "$1" in
  deconfig)
    ifconfig "$interface" 0.0.0.0 up
    ;;
  bound|renew)
    ifconfig "$interface" "$ip" netmask "$subnet" up
    while route del default dev "$interface" 2>/dev/null; do :; done
    for r in $router; do
      route add default gw "$r" dev "$interface"
    done
    : > /etc/resolv.conf
    for d in $dns; do
      echo "nameserver $d" >> /etc/resolv.conf
    done
    echo "udhcpc: $1 $interface $ip/$subnet router $router dns $dns lease $lease"
    ;;
esac
exit 0
