#!/bin/sh

# The execution of this script takes the network down and restarts it.
# If this occurs during a Jenkins-driven build, this can cause problems
# where Jenkins entirely loses track of the connection. Even for a
# make sysinstall, this can be quite annoying. If you want to override
# this entirely, you can touch the "/etc/barracuda/no_ip_reconf" file,
# and this will just abort.
if [ -e /etc/barracuda/no_ip_reconf ]; then
    echo Aborting ip_reconf due to /etc/barracuda/no_ip_reconf
    exit 0;
fi

# interface is first arg
INTERFACE=$1

# sentinel file--when existant, ip_reconf is running or was killed.
SENTINEL=/var/run/ip_reconf
touch $SENTINEL

# autodetect
if [ "a$INTERFACE" == "a" ]; then
  if /bin/grep -q br0 /proc/net/dev; then
    INTERFACE='br0'
  else
    INTERFACE='eth0'
  fi
fi

# load config info
. /etc/sysconfig/network-scripts/ifcfg-$INTERFACE

if [ $INTERFACE == "mgmt" ]; then
    $INTERFACE = `/bin/cat /home/bws/code/config/mgmt_if`
fi

# Toggle the individual interface so the settings take effect
# If you only want to add/remove an IP, use Linux::IPRoute2 or iproute2 instead
/sbin/ifdown $INTERFACE

if [ "$ONBOOT" != "no" ]; then
    /sbin/ifup $INTERFACE
fi

# Implement options that aren't supported by older ifup.
sys_dir=/sys/class/net/$INTERFACE
if [ -n "$DELAY" -a -w ${sys_dir}/bridge/forward_delay ]; then
  echo $DELAY > ${sys_dir}/bridge/forward_delay
fi

# cleanup
rm -f $SENTINEL
