#!/bin/sh
########################################################################
#
# Program     : ifup
# Version     : 1.0
# Date        : 20 April 2005
# Author      : 
# 
# Description : Start a network interface.
#
# Usage       : ifup device
#
# Returns:    : 0 - success
#               1 - not started during boot because ONBOOT is not yes.
#               2 - not started because started by hotplug and ONHOTPLUG=no.
#               3 - failure
#
# Notes       :
#
########################################################################

. /etc/sysconfig/rc 
. $rc_functions 

scripts=/etc/sysconfig/network/scripts
interfaces=/etc/sysconfig/network/ifconfig.d

if [ $# -eq 0 ]; then
    echo "Usage:  ifup device"
    exit 3
fi

DEVICE=$1

#if [ ! -e ${network_devices}/ifconfig.$DEVICE ]; then
if [ ! -e ${interfaces}/$DEVICE ]; then
    boot_mesg "Cannot find $DEVICE"
    exit 3
fi

#. ${network_devices}/ifconfig.$DEVICE
. ${interfaces}/$DEVICE


if [ "${IN_BOOT}" = 1 -a "${ONBOOT}" != yes ]; then
    exit 1
fi

# Do not start if this service is started by hotplug and HOTPLUG is not 
# set to yes.
if [ "${IN_HOTPLUG}" = 1 -a "${ONHOTPLUG}" != yes ]; then
    exit 2
fi


if link_status=`ip link show $DEVICE` 2> /dev/null; then
    if ! echo "$link_status" | grep -q UP; then
        boot_mesg "Bringing up the $DEVICE interface..."
        ip link set $DEVICE up
        evaluate_retval
    fi
else
    boot_mesg "$DEVICE does not exist."
    exit 3
fi 

if [ "$WIRELESS" = yes ]; then
    $scripts/wireless $DEVICE up
fi

if [ "$DHCP" = yes ]; then
    $scripts/dhcpcd $DEVICE up
else
    ifconfig $DEVICE
fi
