Debian Codegraph @

executor-scripts/linux/dhcp

raw
1 #!/bin/sh
2 # some users provide a shell fragment for the hostname property.
3 [ -n "$IF_DHCP_HOSTNAME" ] && IF_DHCP_HOSTNAME=$(eval echo $IF_DHCP_HOSTNAME)
4
5 determine_implementation() {
6 [ -n "$IF_DHCP_PROGRAM" ] && echo "$IF_DHCP_PROGRAM" && return
7 [ -x /sbin/dhcpcd ] && echo "dhcpcd" && return
8 [ -x /usr/sbin/dhclient ] && echo "dhclient" && return
9 [ -x /sbin/udhcpc ] && echo "udhcpc" && return
10 echo "could not find a supported DHCP implementation"
11 exit 1
12 }
13
14 start() {
15 case "$1" in
16 dhcpcd)
17 [ -n "$IF_DHCP_HOSTNAME" ] && optargs="$optargs -h $IF_DHCP_HOSTNAME"
18 [ -n "$IF_DHCP_VENDOR" ] && optargs="$optargs -i $IF_DHCP_VENDOR"
19 [ -n "$IF_DHCP_CLIENT_ID" ] && optargs="$optargs -i $IF_DHCP_CLIENT_ID"
20 [ -n "$IF_DHCP_LEASETIME" ] && optargs="$optargs -l $IF_DHCP_LEASETIME"
21 ${MOCK} /sbin/dhcpcd $optargs $IFACE
22 ;;
23 dhclient)
24 # Specific config file given?
25 if [ -n "$IF_DHCP_CONFIG" ]; then
26 optargs="$optargs -cf $IF_DHCP_CONFIG"
27 fi
28
29 ${MOCK} /usr/sbin/dhclient -pf /var/run/dhclient.$IFACE.pid $optargs $IFACE
30 ;;
31 udhcpc)
32 optargs=$(eval echo $IF_UDHCPC_OPTS)
33 [ -n "$IF_DHCP_HOSTNAME" ] && optargs="$optargs -x hostname:$IF_DHCP_HOSTNAME"
34 [ -n "$IF_DHCP_CLIENT_ID" ] && optargs="$optargs -c $IF_DHCP_CLIENT_ID"
35 [ -n "$IF_DHCP_SCRIPT" ] && optargs="$optargs -s $IF_DHCP_SCRIPT"
36 ${MOCK} /sbin/udhcpc -b -R -p /var/run/udhcpc.$IFACE.pid -i $IFACE $optargs
37 ;;
38 *)
39 ;;
40 esac
41 }
42
43 stop() {
44 case "$1" in
45 dhcpcd)
46 ${MOCK} /sbin/dhcpcd -k $IFACE
47 ;;
48 dhclient)
49 ${MOCK} kill -9 $(cat /var/run/dhclient.$IFACE.pid) 2>/dev/null
50 ;;
51 udhcpc)
52 ${MOCK} kill $(cat /var/run/udhcpc.$IFACE.pid)
53 ;;
54 *)
55 ;;
56 esac
57 }
58
59 impl=$(determine_implementation)
60
61 [ -z "$VERBOSE" ] || set -x
62
63 case "$PHASE" in
64 up) start $impl ;;
65 down) stop $impl || true ;;
66 *) ;;
67 esac