#!/bin/bash

set -e

export LANG=C

IFACE="$1"
echo $IFACE

if [ ! -f "/proc/net/bonding/$IFACE" ]
then
  BOND=`ls -1 /proc/net/bonding/bond* 2> /dev/null | sed -e 's#/proc/net/bonding/##' | head -n 1`
  if [ ! -f "/proc/net/bonding/$BOND" ]
  then
    exit 1
  fi
  ip link set dev $BOND down
  ip link set dev $BOND name $IFACE
fi

exit 0
