#!/bin/bash
# ifup.local - called from ifup-post, except that the script
# is designed to call /sbin/ifup-local, so that is a link to this
# script in /etc/sysconfig/network-scripts.
#
# originally duplicated from ifup, to automatically pull in ifcfg-$IF
#
PATH=/sbin:/usr/sbin:/bin:/usr/bin

cd /etc/sysconfig/network-scripts
. network-functions

need_hostname

CONFIG=$1

[ -z "$CONFIG" ] && {
    echo "usage: ifup.local <device name>" >&2
    exit 1
}

[ -f "$CONFIG" ] || CONFIG=ifcfg-$CONFIG
[ -f "$CONFIG" ] || {
    echo "usage: ifup.local <device name>" >&2
    exit 1
}

if [ $UID != 0 ]; then
    if [ -x /usr/sbin/usernetctl ]; then
	if /usr/sbin/usernetctl $CONFIG report ; then
	    exec /usr/sbin/usernetctl $CONFIG up
	fi
    fi
    echo "Users cannot control this device." >&2
    exit 1
fi

source_config

# this usage is 'ifup.local $IF boot', and
# the ifcfg-$IF says ONBOOT=no
if [ "foo$2" = "fooboot" -a "${ONBOOT}" = "no" ] ; then
    exit
fi

IPSETUP=no

DEVICETYPE=`echo $DEVICE | sed "s/[0-9]*$//"`
REALDEVICE=`echo $DEVICE | sed 's/:.*//g'`
if echo $DEVICE | grep -q ':' ; then
    ISALIAS=yes
else
    ISALIAS=no
fi

if [ "$SECURITY" = yes ] ; then
	LOCALADDR=`ifconfig $DEVICE | grep 'inet addr' | sed -e 's/^.*inet addr:\([0-9.]*\) .*$/\1/'`
	/usr/local/etc/ipchains_config up $SECURITY_TYPE $DEVICE $LOCALADDR
	fi
