ifupdown-ng/executor-scripts/linux/dhcp

60 lines
1.2 KiB
Text
Raw Normal View History

#!/bin/sh
set -e
determine_implementation() {
[ -n "$IF_DHCP_PROGRAM" ] && echo "$IF_DHCP_PROGRAM" && return
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
[ -x /sbin/udhcpc ] && echo "udhcpc" && return
echo "could not find a supported DHCP implementation"
exit 1
}
start() {
case "$1" in
2020-07-25 09:04:02 +00:00
dhcpcd)
[ -n "$IF_HOSTNAME" ] && optargs="$optargs -h $IF_HOSTNAME"
[ -n "$IF_VENDOR" ] && optargs="$optargs -i $IF_VENDOR"
[ -n "$IF_CLIENT" ] && optargs="$optargs -i $IF_CLIENT"
[ -n "$IF_LEASETIME" ] && optargs="$optargs -l $IF_LEASETIME"
${MOCK} /sbin/dhcpcd $optargs $IFACE
;;
2020-07-25 09:06:47 +00:00
dhclient)
${MOCK} /usr/sbin/dhclient -pf /var/run/dhclient.$IFACE.pid $IFACE
2020-07-25 09:06:47 +00:00
;;
udhcpc)
UDHCPC_OPTS=$(eval echo $IF_UDHCPC_OPTS)
${MOCK} /sbin/udhcpc -b -R -p /var/run/udhcpc.$IFACE.pid -i $IFACE $UDHCPC_OPTS
;;
*)
;;
esac
}
stop() {
case "$1" in
2020-07-25 09:04:02 +00:00
dhcpcd)
${MOCK} /sbin/dhcpcd -k $IFACE
2020-07-25 09:04:02 +00:00
;;
2020-07-25 09:06:47 +00:00
dhclient)
${MOCK} kill -9 $(cat /var/run/dhclient.$IFACE.pid) 2>/dev/null
2020-07-25 09:06:47 +00:00
;;
udhcpc)
${MOCK} kill $(cat /var/run/udhcpc.$IFACE.pid)
;;
*)
;;
esac
}
impl=$(determine_implementation)
[ -z "$VERBOSE" ] || set -x
2020-07-25 09:08:32 +00:00
case "$PHASE" in
up) start $impl ;;
down) stop $impl ;;
*) ;;
esac