--- trunk/magellan-initscripts/etc/rc.d/init.d/network 2007/08/18 18:44:15 522 +++ trunk/magellan-initscripts/etc/rc.d/init.d/network 2010/07/14 07:29:53 1091 @@ -1,5 +1,5 @@ #!/bin/bash -# $Header: /home/cvsd/magellan-cvs/magellan-src/magellan-initscripts/etc/rc.d/init.d/network,v 1.13 2007-08-18 18:44:15 niro Exp $ +# $Id$ #%rlevels: 0:k 1:k 2:k 3:s 4:s 5:s 6:k #%start: 20 @@ -10,7 +10,7 @@ #%before: #%after: -source /etc/sysconfig/rc +source /etc/conf.d/rc source ${rc_functions} # read values from files @@ -24,7 +24,7 @@ # global local ONBOOT local NETWORKING - + # static local IP local NETMASK @@ -60,6 +60,10 @@ local WIRELESS_NICK local WIRELESS_NWID local WIRELESS_POWER + local WIRELESS_WPA_DRIVER + + local BRIDGE_INTERFACES + local BRIDGE_STP source ${file} eval value=\$$(echo ${var}) @@ -68,7 +72,7 @@ checkconfig() { - if [ -z "${NETWORKING}" ] + if [[ -z ${NETWORKING} ]] then echo "NETWORKING missing in net.${interface}, aborted" exit 1 @@ -76,20 +80,20 @@ case "${NETWORKING}" in static) - if [ -z "${IP}" ] + if [[ -z ${IP} ]] then echo "IP missing in net.${interface}, aborted" exit 1 fi - if [ -z "${NETMASK}" ] + if [[ -z ${NETMASK} ]] then echo -n "NETMASK missing in net.${interface}, " echo "using 255.255.255.0" NETMASK=255.255.255.0 fi - if [ -z "${BROADCAST}" ] + if [[ -z ${BROADCAST} ]] then echo -n "BROADCAST missing in net.${interface}, " echo "using default address" @@ -97,11 +101,14 @@ ;; dhcp) - if [ -z "${DHCP_PROG}" ] + if [[ -z ${DHCP_PROG} ]] then - echo "DHCP_PROG missing in net.${interface}, aborted" - exit 1 + echo -n "DHCP_PROG missing in net.${interface}," + echo "using default programm" + DHCP_PROG="/sbin/dhcpcd" fi + [[ -z ${DHCP_START} ]] && DHCP_START="-t 10" + [[ -z ${DHCP_STOP} ]] && DHCP_STOP="-k" ;; esac @@ -178,11 +185,9 @@ # check the configuration [[ -z ${WIRELESS_WPA_CONFIG} ]] && WIRELESS_WPA_CONFIG=/etc/wpa_supplicant.auto [[ -z ${WIRELESS_WPA_SKEL} ]] && WIRELESS_WPA_SKEL=/etc/conf.d/wpa_supplicant.skel - if [[ -z ${WIRELESS_WPA_DRIVER} ]] - then - echo "WPA: WIRELESS_WPA_DRIVER given. Aborting setup." - return 1 - fi + + # use wext as default driver, do not abort here anymore + [[ -z ${WIRELESS_WPA_DRIVER} ]] && WIRELESS_WPA_DRIVER=wext # write a config with the settings from net.${iface} # only wpa-psk ! all other needs manual setup @@ -191,9 +196,16 @@ # write default cfg from skeleton cat ${WIRELESS_WPA_SKEL} > ${WIRELESS_WPA_CONFIG} + local wpa_proto + case ${WIRELESS_AUTH_MODE} in + wpa) wpa_proto="WPA" ;; + wpa2) wpa_proto="WPA2" ;; + esac + # setup the network entry sed -i -e "s:@WIRELESS_ESSID@:${WIRELESS_ESSID}:g" \ - -e "s:@WIRELESS_KEY@:${WIRELESS_KEY}:g" \ + -e "s:@WIRELESS_KEY@:${WIRELESS_KEY_ASCII}:g" \ + -e "s:@WIRELESS_AUTH_MODE@:${wpa_proto}:g" \ ${WIRELESS_WPA_CONFIG} fi @@ -241,9 +253,9 @@ [[ -n ${WIRELESS_NICK} ]] && iwconfig "${iface}" nick "${WIRELESS_NICK}" case "${WIRELESS_AUTH_MODE}" in - wpa) config_wireless_wpa "${iface}" ;; - wep|on) config_wireless_wep "${iface}" ;; - off) iwconfig "${iface}" enc off ;; + wpa|wpa2) config_wireless_wpa "${iface}" ;; + wep|on) config_wireless_wep "${iface}" ;; + off) iwconfig "${iface}" enc off ;; esac } @@ -251,6 +263,7 @@ { local iface="$1" local method="$2" + local bport if [[ -z ${iface} ]] then @@ -272,9 +285,9 @@ fi # check the config - if [[ -z ${BRIDGE_INTERFACE} ]] + if [[ -z ${BRIDGE_INTERFACES} ]] then - echo "BRIDGE: no \$BRIDGE_INTERFACE given. Aborting setup." + echo "BRIDGE: no \$BRIDGE_INTERFACES given. Aborting setup." return 1 fi @@ -282,23 +295,35 @@ add) # setup the bridge device brctl addbr ${iface} - # enter promiscous mode - ifconfig ${BRIDGE_INTERFACE} 0.0.0.0 promisc - # now setup the bridge - brctl addif ${iface} ${BRIDGE_INTERFACE} + for bport in ${BRIDGE_INTERFACES} + do + # enter promiscous mode + ifconfig ${bport} 0.0.0.0 promisc + # now setup the bridge + brctl addif ${iface} ${bport} + done + # enable spanning-tree protocol + case ${BRIDGE_STP} in + on|off) brctl stp ${iface} ${BRIDGE_STP} ;; + *) echo "BRIDGE: unkown value \$BRIDGE_STP='$BRIDGE_STP'."; return 1 ;; + esac ;; + remove) - # bring the interface down - ifconfig ${BRIDGE_INTERFACE} down - # remove the interface from the bridge - brctl delif ${iface} ${BRIDGE_INTERFACE} + for bport in ${BRIDGE_INTERFACE} + do + # bring the interface down + ifconfig ${bport} down + # remove the interface from the bridge + brctl delif ${iface} ${bport} + done # bring the bridge down brctl delbr ${iface} ;; esac - + # unset the bridge variable to be safe - unset BRIDGE_INTERFACE + unset BRIDGE_INTERFACES # continue to setup generic networking } @@ -339,9 +364,9 @@ if [[ -z $1 ]] then - ALL_INTERFACES=$(onboot_interface_list ${network_settings}/net.*) + ALL_INTERFACES=$(onboot_interface_list ${rc_network_settings}/net.*) else - if [[ -e ${network_settings}/net.$1 ]] + if [[ -e ${rc_network_settings}/net.$1 ]] then ALL_INTERFACES="$1" else @@ -356,11 +381,11 @@ for iface in ${ALL_INTERFACES} do # checkconfig - source ${network_settings}/net.${iface} || exit 1 + source ${rc_network_settings}/net.${iface} || exit 1 checkconfig # setup mac - if [ -n "${FORCE_MAC_TO}" ] + if [[ -n ${FORCE_MAC_TO} ]] then echo -e ${COLOREDSTAR}"Faking MAC to ${FORCE_MAC_TO} for ${COLBLUE}${iface}${COLDEFAULT} ... " ifconfig "${iface}" hw ether "${FORCE_MAC_TO}" @@ -373,21 +398,21 @@ config_bridge_devices ${iface} add fi - # activate the interface - ifconfig "${iface}" up - # now configure wireless_extensions [ -x /usr/sbin/iwconfig ] && setup_wireless_extensions "${iface}" echo -e ${COLOREDSTAR}"Bringing up interface ${COLBLUE}${iface}${COLDEFAULT} ..." + # activate the interface + ifconfig "${iface}" up + # setup static or dhcp case ${NETWORKING} in dhcp|DHCP) ${CURS_UP} ${SET_WWCOL} echo "[DHCP]" - loadproc ${DHCP_PROG} ${DHCP_START} "${iface}" + loadproc "${DHCP_PROG}" "${DHCP_START}" "${iface}" ;; static|STATIC) ${CURS_UP} @@ -404,19 +429,38 @@ echo -e ${COLOREDSTAR}"Setting up default gateway for ${COLBLUE}${iface}${COLDEFAULT} ..." route add default gateway ${GATEWAY} metric 1 dev ${iface} evaluate_retval + + unset GATEWAY fi # setup /etc/resolv.conf + # whipe out the old one + echo "# Generated by the magellan-initscripts for ${iface}" > /etc/resolv.conf + # include head + if [ -f /etc/resolv.conf.head ] + then + cat /etc/resolv.conf.head >> /etc/resolv.conf + else + echo "# /etc/resolv.conf.head can replace this line" >> /etc/resolv.conf + fi + # add given nameserver if [[ -n ${NAMESERVER} ]] then echo -e ${COLOREDSTAR}"Setting up all nameserver for ${COLBLUE}${iface}${COLDEFAULT} ..." - - # whipe out the old one - echo "# Generated by the magellan-initscripts for ${iface}" > /etc/resolv.conf + for dns in ${NAMESERVER} do echo "nameserver ${dns}" >> /etc/resolv.conf done + + unset NAMESERVER + fi + # include tail + if [ -f /etc/resolv.conf.tail ] + then + cat /etc/resolv.conf.tail >> /etc/resolv.conf + else + echo "# /etc/resolv.conf.tail can replace this line" >> /etc/resolv.conf fi done @@ -428,9 +472,9 @@ { if [[ -z $1 ]] then - ALL_INTERFACES=$(onboot_interface_list ${network_settings}/net.*) + ALL_INTERFACES=$(onboot_interface_list ${rc_network_settings}/net.*) else - if [[ -e ${network_settings}/net.$1 ]] + if [[ -e ${rc_network_settings}/net.$1 ]] then ALL_INTERFACES="$1" else @@ -444,7 +488,7 @@ # get list of all devices for iface in ${ALL_INTERFACES} do - source ${network_settings}/net.${iface} || exit 1 + source ${rc_network_settings}/net.${iface} || exit 1 checkconfig if [[ -n ${GATEWAY} ]]