9ba8b65
#!/bin/bash
9ba8b65
export LC_ALL=C
9ba8b65
8187e8f
[ -f /etc/sysconfig/dhcpd ] && . /etc/sysconfig/dhcpd
8187e8f
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
8187e8f
    ifaces=""                # interfaces defined in DHCPDARGS
8187e8f
    net=$(ls /sys/class/net) # all interfaces on system
8187e8f
8187e8f
    if [ -n "${DHCPDARGS}" ]; then
8187e8f
        for iface in ${net}; do
8187e8f
            for arg in ${DHCPDARGS}; do
8187e8f
                [ $arg == $iface ] && ifaces="$ifaces $iface"
8187e8f
            done
8187e8f
        done
8187e8f
    fi
8187e8f
8187e8f
    # exit if dhcpd is not defined to listen on $1
8187e8f
    # i.e. if there are interfaces defined in DHCPDARGS and $1 is not among them
8187e8f
    if [ -n "${ifaces}" ] &&
8187e8f
       [[ "${ifaces}" != *$1* ]]; then
8187e8f
          exit 0
8187e8f
    fi
8187e8f
cc2eb94
    # restart service
cc2eb94
    /bin/systemctl restart dhcpd.service || :
9ba8b65
fi