25 lines
480 B
Plaintext
25 lines
480 B
Plaintext
|
#!/usr/bin/env bash
|
||
|
has() {
|
||
|
command -v "$1" >/dev/null 2>&1
|
||
|
}
|
||
|
|
||
|
stop_dhclient() {
|
||
|
local interface="$1"
|
||
|
local pid_file="/var/run/dhclient.${interface}.pid"
|
||
|
if [[ "$OSTYPE" == "linux-gnu" ]]; then
|
||
|
dhclient -r -x
|
||
|
elif [[ -f "$pid_file" ]
|
||
|
kill "$(< $pid_file)"
|
||
|
fi
|
||
|
}
|
||
|
|
||
|
if has dhcpcd; then
|
||
|
dhcpcd -k "$INTERFACE"
|
||
|
elif has dhclient; then
|
||
|
stop_dhcpclient "$INTERFACE"
|
||
|
elif [[ "$OSTYPE" == "darwin"* ]]; then # TODO untested
|
||
|
ipconfig set "$interface" NONE
|
||
|
fi
|
||
|
exit 0
|
||
|
|