#!/bin/sh 

# This script is installed into /etc/NetworkManager/dispatcher.d
# for starting/stopping of PowerPathPost.

export LC_ALL=C

if [ -f /etc/init.d/PowerPathPost ]; then
    if [ "$2" = "down" ]; then
        /sbin/ip route ls | grep -q ^default || {
            [ -f /var/lock/subsys/PowerPathPost ] && /etc/init.d/PowerPathPost stop || :
        } && { :; }
    fi

    if [ "$2" = "up" ]; then
        /sbin/ip -o route show dev "$1" | grep -q '^default' && {
            /sbin/chkconfig PowerPathPost && /etc/init.d/PowerPathPost start || :
        } || { :; }
    fi
else
    if [ "$2" = "down" ]; then
        /sbin/ip route ls | grep -q ^default || {
            [ -f /var/lock/subsys/PowerPathPost ] && /usr/lib/PowerPath/PowerPathPost stop || :
        } && { :; }
    fi

    if [ "$2" = "up" ]; then
        /sbin/ip -o route show dev "$1" | grep -q '^default' && {
            /usr/lib/PowerPath/PowerPathPost start || :
        } || { :; }
    fi
fi

