philipp / rpms / dhcp

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