2020-07-25 08:36:11 +00:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
|
|
|
determine_implementation() {
|
2020-07-25 09:04:02 +00:00
|
|
|
[ -x /sbin/dhcpcd ] && echo "dhcpcd" && return
|
2020-07-25 09:06:47 +00:00
|
|
|
[ -x /usr/sbin/dhclient ] && echo "dhclient" && return
|
2020-07-25 08:36:11 +00:00
|
|
|
[ -x /sbin/udhcpc ] && echo "udhcpc" && return
|
|
|
|
echo "???"
|
|
|
|
}
|
|
|
|
|
|
|
|
start() {
|
|
|
|
case "$1" in
|
2020-07-25 09:04:02 +00:00
|
|
|
dhcpcd)
|
|
|
|
[ -z "$IF_HOSTNAME" ] && optargs="$optargs -h $IF_HOSTNAME"
|
|
|
|
[ -z "$IF_VENDOR" ] && optargs="$optargs -i $IF_VENDOR"
|
|
|
|
[ -z "$IF_CLIENT" ] && optargs="$optargs -i $IF_CLIENT"
|
|
|
|
[ -z "$IF_LEASETIME" ] && optargs="$optargs -l $IF_LEASETIME"
|
|
|
|
/sbin/dhcpcd $optargs $IFACE
|
2020-07-25 09:06:47 +00:00
|
|
|
dhclient)
|
|
|
|
/usr/sbin/dhclient -pf /var/run/dhclient.$IFACE.pid $IFACE
|
|
|
|
;;
|
2020-07-25 08:36:11 +00:00
|
|
|
udhcpc)
|
|
|
|
/sbin/udhcpc -b -R -p /var/run/udhcpc.$IFACE.pid -i $IFACE
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "implementation $1 not supported"
|
|
|
|
exit 1
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
|
|
|
stop() {
|
|
|
|
case "$1" in
|
2020-07-25 09:04:02 +00:00
|
|
|
dhcpcd)
|
|
|
|
/sbin/dhcpcd -k $IFACE
|
|
|
|
;;
|
2020-07-25 09:06:47 +00:00
|
|
|
dhclient)
|
|
|
|
kill -9 $(cat /var/run/dhclient.$IFACE.pid) 2>/dev/null
|
|
|
|
;;
|
2020-07-25 08:36:11 +00:00
|
|
|
udhcpc)
|
2020-07-25 09:06:47 +00:00
|
|
|
kill $(cat /var/run/udhcpc.$IFACE.pid)
|
2020-07-25 08:36:11 +00:00
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "implementation $1 not supported"
|
|
|
|
exit 1
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
|
|
|
impl=$(determine_implementation)
|
|
|
|
|
|
|
|
[ -z "$VERBOSE" ] || set -x
|
|
|
|
|
|
|
|
case "$MODE" in
|
|
|
|
start) start $impl ;;
|
|
|
|
stop) stop $impl ;;
|
|
|
|
*) echo "unknown mode $MODE" ;;
|
|
|
|
esac
|