#!/bin/sh
#
# bondctl-ifenslave -- bondctl-ifenslave wrapper for the bondctl program
#
# (c) 2009, Arthur Corliss <corliss@digitalmages.com>
#
# $Id: ifenslave.in,v 1.0 2011/02/22 02:43:32 acorliss Exp $
#
#    This program is free software; you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation; either version 2 of the License, or
#    any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program; if not, write to the Free Software
#    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#

BONDCTL=/sbin/bondctl

help () {
    cat << "EOF"
Usage: bondctl-ifenslave [-f] <master-if> <slave-if> [<slave-if>...]
       bondctl-ifenslave -d   <master-if> <slave-if> [<slave-if>...]
       bondctl-ifenslave -c   <master-if> <slave-if>

WARNING:  This isn't the real ifenslave from the Linux kernel source, but
          a wrapper for the bondctl script which is functionally equivalent.
          If you find any behavior that fails to produce the desired 
          results please report them to the bondctl developer.

          You may also want to use bondctl directly instead since it provides 
          many more capabilities.

EOF
}

case $1 in
    -a)
        $BONDCTL detail all
        ;;
    -f)
        shift
        $BONDCTL attach $@
        ;;
    -d)
        shift
        $BONDCTL detach $@
        ;;
    -c)
        $BONDCTL set $2 active_slave $3
        ;;
    *)
        if [ ${#@} == 0 ]; then
            help
        elif [ ${#@} == 1 ]; then
            $BONDCTL detail $1
        else
            $BONDCTL attach $@
        fi
        ;;
esac

exit $?
