45d60a
#!/bin/bash
45d60a
# run dhclient.d scripts in an emulated environment
45d60a
45d60a
PATH=/bin:/usr/bin:/sbin
45d60a
SAVEDIR=/var/lib/dhclient
45d60a
ETCDIR=/etc/dhcp
45d60a
interface=$1
45d60a
45d60a
eval "$(
45d60a
declare | LC_ALL=C grep '^DHCP4_[A-Z_]*=' | while read -r opt; do
45d60a
    optname=${opt%%=*}
45d60a
    optname=${optname,,}
45d60a
    optname=new_${optname#dhcp4_}
45d60a
    optvalue=${opt#*=}
45d60a
    echo "export $optname=$optvalue"
45d60a
done
45d60a
)"
45d60a
45d60a
[ -f /etc/sysconfig/network ] && . /etc/sysconfig/network
45d60a
45d60a
[ -f /etc/sysconfig/network-scripts/ifcfg-$interface ] && \
45d60a
    . /etc/sysconfig/network-scripts/ifcfg-$interface
45d60a
45d60a
if [ -d $ETCDIR/dhclient.d ]; then
45d60a
    for f in $ETCDIR/dhclient.d/*.sh; do
45d60a
        if [ -x $f ]; then
45d60a
            subsystem="${f%.sh}"
45d60a
            subsystem="${subsystem##*/}"
45d60a
            . ${f}
45d60a
            if [ "$2" = "up" ]; then
45d60a
                "${subsystem}_config"
45d60a
            elif [ "$2" = "dhcp4-change" ]; then
45d60a
                if [ "$subsystem" = "chrony" -o "$subsystem" = "ntp" ]; then
45d60a
                    "${subsystem}_config"
45d60a
                fi
45d60a
            elif [ "$2" = "down" ]; then
45d60a
                "${subsystem}_restore"
45d60a
            fi
45d60a
        fi
45d60a
    done
45d60a
fi