philipp / rpms / dhcp

Forked from rpms/dhcp 4 years ago
Clone

Blame SOURCES/56dhclient

c8bb8f
#!/bin/sh
c8bb8f
# If we are running dhclient, shutdown running instances cleanly and
c8bb8f
# bring them back up on resume.
c8bb8f
c8bb8f
. "${PM_FUNCTIONS}"
c8bb8f
c8bb8f
PM_DHCLIENT_RUNDIR="${PM_UTILS_RUNDIR}/network"
c8bb8f
PM_DHCLIENT_SUSPEND="${PM_DHCLIENT_RUNDIR}/dhclient.suspend"
c8bb8f
c8bb8f
suspend_dhclient() {
c8bb8f
    [ ! -d /etc/sysconfig/network-scripts ] && return
c8bb8f
    [ ! -x /sbin/ifdown ] && return
c8bb8f
c8bb8f
    [ ! -d ${PM_DHCLIENT_RUNDIR} ] && /bin/mkdir -p ${PM_DHCLIENT_RUNDIR}
c8bb8f
    [ -f ${PM_DHCLIENT_SUSPEND} ] && /bin/rm -f ${PM_DHCLIENT_SUSPEND}
c8bb8f
c8bb8f
    cd /etc/sysconfig/network-scripts
c8bb8f
    for ifcfg in ifcfg-* ; do
c8bb8f
        # Clear relevant parameters set by previous interface
c8bb8f
        # (lo doesn't set them)
c8bb8f
        NM_CONTROLLED=
c8bb8f
        BOOTPROTO=
c8bb8f
c8bb8f
        . ./"${ifcfg}"
c8bb8f
c8bb8f
        if [ "${NM_CONTROLLED}" = "no" ] || [ "${NM_CONTROLLED}" = "n" ] || [ "${NM_CONTROLLED}" = "false" ]; then
c8bb8f
            if [ "${BOOTPROTO}" = "bootp" ] || [ "${BOOTPROTO}" = "dhcp" ] || [ -z "${BOOTPROTO}" ]; then
c8bb8f
                # device is not NetworkManager controlled and uses dhcp,
c8bb8f
                # now see if it's actually up at the moment
c8bb8f
                /sbin/ip link show ${DEVICE} | /bin/grep -qE "state (UP|UNKNOWN)" >/dev/null 2>&1
c8bb8f
                if [ $? -eq 0 ]; then
c8bb8f
                    echo "${DEVICE}" >> ${PM_DHCLIENT_SUSPEND}
c8bb8f
                    /sbin/ifdown ${DEVICE}
c8bb8f
                fi
c8bb8f
            fi
c8bb8f
        fi
c8bb8f
    done
c8bb8f
}
c8bb8f
c8bb8f
resume_dhclient() {
c8bb8f
    [ ! -f ${PM_DHCLIENT_SUSPEND} ] && return
c8bb8f
    [ ! -x /sbin/ifup ] && return
c8bb8f
c8bb8f
    cd /etc/sysconfig/network-scripts
c8bb8f
    while read device ; do
c8bb8f
        /sbin/ifup ${device}
c8bb8f
    done < ${PM_DHCLIENT_SUSPEND}
c8bb8f
c8bb8f
    /bin/rm -f ${PM_DHCLIENT_SUSPEND}
c8bb8f
}
c8bb8f
c8bb8f
case "$1" in
c8bb8f
    hibernate|suspend)
c8bb8f
        suspend_dhclient
c8bb8f
        ;;
c8bb8f
    thaw|resume)
c8bb8f
        resume_dhclient
c8bb8f
        ;;
c8bb8f
    *) exit $NA
c8bb8f
        ;;
c8bb8f
esac