9ba8b65
#!/bin/bash
9ba8b65
export LC_ALL=C
9ba8b65
9ba8b65
[ -f /etc/sysconfig/dhcpd ] && . /etc/sysconfig/dhcpd
9ba8b65
9ba8b65
# restart dhcpd whenever $1 interface is brought up by NM (rhbz #565921)
9ba8b65
if [ "$2" = "up" ]; then
cc2eb94
    # exit if the service is not configured to be started in the current runlevel
cc2eb94
    /bin/systemctl is-enabled dhcpd.service || exit 0
9ba8b65
cc2eb94
    ifaces=""                # interfaces defined in DHCPDARGS
cc2eb94
    net=$(ls /sys/class/net) # all interfaces on system
9ba8b65
cc2eb94
    if [ -n "${DHCPDARGS}" ]; then
cc2eb94
        for iface in ${net}; do
cc2eb94
            for arg in ${DHCPDARGS}; do
cc2eb94
                [ $arg == $iface ] && ifaces="$ifaces $iface"
cc2eb94
            done
cc2eb94
        done
cc2eb94
    fi
cc2eb94
cc2eb94
    # exit if dhcpd is not defined to listen on $1
cc2eb94
    # i.e. if there are interfaces defined in DHCPDARGS and $1 is not among them
cc2eb94
    if [ -n "${ifaces}" ] &&
cc2eb94
       [[ "${ifaces}" != *$1* ]]; then
cc2eb94
          exit 0
cc2eb94
    fi
cc2eb94
cc2eb94
    # restart service
cc2eb94
    /bin/systemctl restart dhcpd.service || :
9ba8b65
fi