2020-07-25 08:36:11 +00:00
|
|
|
#!/bin/sh
|
2020-09-11 08:33:54 +00:00
|
|
|
# some users provide a shell fragment for the hostname property.
|
2020-11-30 21:36:28 +00:00
|
|
|
[ -n "$IF_DHCP_HOSTNAME" ] && IF_DHCP_HOSTNAME=$(eval echo $IF_DHCP_HOSTNAME)
|
2020-09-11 08:33:54 +00:00
|
|
|
|
2020-07-25 08:36:11 +00:00
|
|
|
determine_implementation() {
|
2020-07-26 09:26:11 +00:00
|
|
|
[ -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
|
2020-07-25 08:36:11 +00:00
|
|
|
[ -x /sbin/udhcpc ] && echo "udhcpc" && return
|
2020-07-25 09:09:41 +00:00
|
|
|
echo "could not find a supported DHCP implementation"
|
|
|
|
exit 1
|
2020-07-25 08:36:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
start() {
|
|
|
|
case "$1" in
|
2020-07-25 09:04:02 +00:00
|
|
|
dhcpcd)
|
2020-11-30 21:36:28 +00:00
|
|
|
[ -n "$IF_DHCP_HOSTNAME" ] && optargs="$optargs -h $IF_DHCP_HOSTNAME"
|
|
|
|
[ -n "$IF_DHCP_VENDOR" ] && optargs="$optargs -i $IF_DHCP_VENDOR"
|
|
|
|
[ -n "$IF_DHCP_CLIENT_ID" ] && optargs="$optargs -i $IF_DHCP_CLIENT_ID"
|
|
|
|
[ -n "$IF_DHCP_LEASETIME" ] && optargs="$optargs -l $IF_DHCP_LEASETIME"
|
2020-07-26 09:26:11 +00:00
|
|
|
${MOCK} /sbin/dhcpcd $optargs $IFACE
|
|
|
|
;;
|
2020-07-25 09:06:47 +00:00
|
|
|
dhclient)
|
2020-11-30 21:38:32 +00:00
|
|
|
# Specific config file given?
|
|
|
|
if [ -n "$IF_DHCP_CONFIG" ]; then
|
|
|
|
optargs="$optargs -cf $IF_DHCP_CONFIG"
|
|
|
|
fi
|
|
|
|
|
|
|
|
${MOCK} /usr/sbin/dhclient -pf /var/run/dhclient.$IFACE.pid $optarts $IFACE
|
2020-07-25 09:06:47 +00:00
|
|
|
;;
|
2020-07-25 08:36:11 +00:00
|
|
|
udhcpc)
|
2020-09-11 08:31:22 +00:00
|
|
|
optargs=$(eval echo $IF_UDHCPC_OPTS)
|
2020-11-30 21:36:28 +00:00
|
|
|
[ -n "$IF_DHCP_HOSTNAME" ] && optargs="$optargs -x hostname:$IF_DHCP_HOSTNAME"
|
|
|
|
[ -n "$IF_DHCP_CLIENT_ID" ] && optargs="$optargs -c $IF_DHCP_CLIENT_ID"
|
|
|
|
[ -n "$IF_DHCP_SCRIPT" ] && optargs="$optargs -s $IF_DHCP_SCRIPT"
|
2020-09-11 08:31:22 +00:00
|
|
|
${MOCK} /sbin/udhcpc -b -R -p /var/run/udhcpc.$IFACE.pid -i $IFACE $optargs
|
2020-07-25 08:36:11 +00:00
|
|
|
;;
|
|
|
|
*)
|
2020-07-25 09:09:41 +00:00
|
|
|
;;
|
2020-07-25 08:36:11 +00:00
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
|
|
|
stop() {
|
|
|
|
case "$1" in
|
2020-07-25 09:04:02 +00:00
|
|
|
dhcpcd)
|
2020-07-26 09:26:11 +00:00
|
|
|
${MOCK} /sbin/dhcpcd -k $IFACE
|
2020-07-25 09:04:02 +00:00
|
|
|
;;
|
2020-07-25 09:06:47 +00:00
|
|
|
dhclient)
|
2020-07-26 09:26:11 +00:00
|
|
|
${MOCK} kill -9 $(cat /var/run/dhclient.$IFACE.pid) 2>/dev/null
|
2020-07-25 09:06:47 +00:00
|
|
|
;;
|
2020-07-25 08:36:11 +00:00
|
|
|
udhcpc)
|
2020-07-26 09:26:11 +00:00
|
|
|
${MOCK} kill $(cat /var/run/udhcpc.$IFACE.pid)
|
2020-07-25 08:36:11 +00:00
|
|
|
;;
|
|
|
|
*)
|
2020-07-25 09:09:41 +00:00
|
|
|
;;
|
2020-07-25 08:36:11 +00:00
|
|
|
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 ;;
|
|
|
|
*) ;;
|
2020-07-25 08:36:11 +00:00
|
|
|
esac
|