evenet/lib/dhcp.bash

25 lines
590 B
Bash

start_dhclient() {
local interface=$1
if [[ "$OSTYPE" == "linux-gnu" ]]; then
dhclient -x
dhclient -nw "$interface"
elif [[ "$OSTYPE" == "freebsd"* ]]; then
dhclient -b "$interface"
else
nohup setsid dhclient "$interface" >/dev/null 2>&1
fi
}
start_dhcp() {
local interface=$1
if has dhcpcd; then
dhcpcd -b -n "$interface"
elif has dhclient; then
start_dhclient "$interface"
elif [[ "$OSTYPE" == "darwin"* ]]; then # TODO untested
ipconfig set "$interface" DHCP
else
die "no suitable dhcp program found, need dhcpcd or dhclient"
fi
}