philipp / rpms / dhcp

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