#!/bin/bash
#
# Copyright (c) Ensim Corporation 2000, 2001   All Rights Reserved.
#
# This software is furnished under a license and may be used and copied
# only  in  accordance  with  the  terms  of such  license and with the
# inclusion of the above copyright notice. This software or any other
# copies thereof may not be provided or otherwise made available to any
# other person. No title to and ownership of the software is hereby
# transferred.
#
# The information in this software is subject to change without notice
# and  should  not be  construed  as  a commitment by Ensim Corporation.
# Ensim assumes no responsibility for the use or  reliability  of its
# software on equipment which is not supplied by Ensim.
#
# $Id: applifconfig,v 1.2 2001/10/09 00:31:37 dturco Exp $
#
# Special wrapper for handling alias in the bsd ifconfig stuff
#
# Usage: aifconfig alias IPADDRESS
#        aifconfig delete IPADDRESS
#

cmd=$1
alias_addr=$2

#Default to eth0 if an interface wasn't specified
alias_intf=${3:-eth0}

CONFIG=/etc/sysconfig/network-scripts/ifcfg-$alias_intf
IPCMD=/sbin/ip
# Here is the real stuff

case "$1" in
  delete )
    #We do not want to accidentally delete the main IP address
    [ -f "$CONFIG" ] || {
      echo "Missing config file - $CONFIG"
      exit 1
    }
    . $CONFIG
    [ "$IPADDR" = "$alias_addr" ] && {
      echo "aifconfig can not be used to delete the main IP address"
      exit 1
    }
    ${IPCMD} addr del $alias_addr/32 dev $alias_intf >>/var/log/ensim_appliance.log 2>&1
  ;;
  alias )
	
    ${IPCMD} addr add $alias_addr/32 dev $alias_intf >>/var/log/ensim_appliance.log 2>&1
  ;;
  *)
  echo "Usage applifconfig alias|delete IPADDRESS [ INTERFACE ]"
  exit 1
esac
