initscripts/sbin/ifup
Davide Madrisan 83dce52968 ifup: minor code refactoring
Signed-off-by: Davide Madrisan <davide.madrisan@gmail.com>
2013-02-21 21:20:19 +01:00

85 lines
2.2 KiB
Bash

#!/bin/bash
# Copyright (c) 2003-2012 by Silvan Calarco <silvan.calarco@mambasoft.it>
# Copyright (c) 2003-2009,2013 by Davide Madrisan <davide.madrisan@gmail.com>
. /etc/sysconfig/rc
. $rc_functions
. $rc_networkfunctions
DEVICE=${1}
[ "${DEVICE}" ] || exit 1
[ -r /etc/sysconfig/network ] && . /etc/sysconfig/network
[ -r $network_devices/ifcfg-${DEVICE} ] && . $network_devices/ifcfg-${DEVICE}
[ "$NM_CONTROLLED" = "no" ] || exit 0
if [ "$2" = "--udev" ]; then
case "$ONBOOT" in
yes|true|1)
# udev boot: exit if root filesystem is read only
[ -w /var/run ] || exit 0
;;
*) exit 0
;;
esac
fi
if [ -x $network_devices/ifup-${DEVICE} ]; then
$network_devices/ifup-${DEVICE}
exit 0
fi
[ -r $network_devices/ifup-wireless ] && . $network_devices/ifup-wireless
if [ "$BOOTPROTO" = "dhcp" ]; then
if [ ! -r /var/run/dhclient.${DEVICE}.pid ]; then
echo -n "Bringing up the ${DEVICE} interface: "
/sbin/ifconfig ${DEVICE} up
dhclient -q ${DEVICE} -nw -pf /var/run/dhclient.${DEVICE}.pid >/dev/null
evaluate_retval
echo
else
echo -n "Error: dhclient is already running for the interface"
fi
else
[ "$IPADDR" ] || IPADDR=$IP
if [ "$IPADDR" ]; then
if [ -z "$NETMASK" ]; then
echo "\
NETMASK variable missing in ifcfg-${DEVICE}, echo using 255.255.255.0"
NETMASK=255.255.255.0
fi
[ "$BROADCAST" ] || eval `/bin/ipcalc --broadcast ${IPADDR} ${NETMASK}`
echo -n "Bringing up the ${DEVICE} interface: "
/sbin/ifconfig ${DEVICE} $IPADDR netmask $NETMASK broadcast $BROADCAST
evaluate_retval
echo
else
# if IPADDR is missing interface is brought up anyway without address
echo -n "Bringing up the ${DEVICE} interface with no address: "
/sbin/ifconfig ${DEVICE} up
evaluate_retval
echo
fi
if [ -n "$ETHTOOL_OPTS" ] ; then
/usr/sbin/ethtool -s ${DEVICE} $ETHTOOL_OPTS
fi
if [[ "$GATEWAY_IF" = "${DEVICE}" && -n "$GATEWAY" ]]; then
echo -n "Setting up default gateway: "
route add default gateway $GATEWAY metric 1 dev $GATEWAY_IF
evaluate_retval
echo
fi
fi
[ -r $network_devices/ifup-routes ] && . $network_devices/ifup-routes ${DEVICE}
exit 0