Magellan Linux

Diff of /trunk/initscripts/sysvinit/rc/network

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

trunk/magellan-initscripts/etc/rc.d/init.d/network revision 1165 by niro, Sun Sep 26 18:53:37 2010 UTC trunk/initscripts/sysvinit/rc/network revision 1665 by niro, Fri Jan 20 23:01:04 2012 UTC
# Line 12  Line 12 
12    
13  source /etc/conf.d/rc  source /etc/conf.d/rc
14  source ${rc_functions}  source ${rc_functions}
15    source /etc/conf.d/network
16    
17  # read values from files  # read values from files
18  read_value()  read_value()
# Line 81  checkconfig() Line 82  checkconfig()
82  {  {
83   if [[ -z ${NETWORKING} ]]   if [[ -z ${NETWORKING} ]]
84   then   then
85   echo "NETWORKING missing in net.${iface}, aborted"   rc_echo "NETWORKING missing in net.${iface}, aborted"
86   exit 1   exit 1
87   fi   fi
88    
# Line 89  checkconfig() Line 90  checkconfig()
90   static)   static)
91   if [[ -z ${IP} ]]   if [[ -z ${IP} ]]
92   then   then
93   echo "IP missing in net.${iface}, aborted"   rc_echo "IP missing in net.${iface}, aborted"
94   exit 1   exit 1
95   fi   fi
96    
97   if [[ -z ${NETMASK} ]]   if [[ -z ${NETMASK} ]]
98   then   then
99   echo -n "NETMASK missing in net.${iface}, "   rc_echo -n "NETMASK missing in net.${iface}, "
100   echo "using 255.255.255.0"   rc_echo "using ${DEFAULT_NETMASK}"
101   NETMASK=255.255.255.0   NETMASK="${DEFAULT_NETMASK}"
102   fi   fi
103    
104   if [[ -z ${BROADCAST} ]]   if [[ -z ${BROADCAST} ]]
105   then   then
106   echo -n "BROADCAST missing in net.${iface}, "   rc_echo -n "BROADCAST missing in net.${iface}, "
107   echo "using default address"   rc_echo "using default address"
108   fi   fi
109   ;;   ;;
110    
111   dhcp)   dhcp)
112   if [[ -z ${DHCP_PROG} ]]   if [[ -z ${DHCP_PROG} ]]
113   then   then
114   echo -n "DHCP_PROG missing in net.${iface},"   rc_echo -n "DHCP_PROG missing in net.${iface},"
115   echo "using default programm /sbin/dhcpcd"   rc_echo "using default programm ${DEFAULT_DHCP_PROG}"
116   DHCP_PROG="/sbin/dhcpcd"   DHCP_PROG="${DEFAULT_DHCP_PROG}"
117   fi   fi
118   [[ -z ${DHCP_START} ]] && DHCP_START="-t 10"   [[ -z ${DHCP_START} ]] && DHCP_START="${DEFAULT_DHCP_START}"
119   [[ -z ${DHCP_STOP} ]] && DHCP_STOP="-k"   [[ -z ${DHCP_STOP} ]] && DHCP_STOP="${DEFAULT_DHCP_STOP}"
120   ;;   ;;
121    
122   esac   esac
# Line 131  onboot_interface_list() Line 132  onboot_interface_list()
132   # get list of all devices   # get list of all devices
133   for file in $@   for file in $@
134   do   do
135     iface="$(basename ${file} | sed s/net.//)"
136    
137     # exclude backup files and exclude net.routes and net.sample too
138     case "${iface}" in
139     *~) continue ;;
140     routes) continue ;;
141     sample) continue ;;
142     esac
143    
144   if [[ $(read_value ONBOOT ${file}) = yes ]]   if [[ $(read_value ONBOOT ${file}) = yes ]]
145   then   then
146   iface="$(basename ${file} | sed s/net.//)"   devices="${devices} ${iface}"
  # exclude backup files and exclude net.routes too  
  case "${iface}" in  
  *~) ;;  
  */net.routes) ;;  
  *) devices="${devices} $(basename ${file} | sed s/net.//)" ;;  
  esac  
147   fi   fi
148   done   done
149    
# Line 152  config_wireless_wep() Line 156  config_wireless_wep()
156    
157   if [[ -z ${iface} ]]   if [[ -z ${iface} ]]
158   then   then
159   echo "WEP: no \$iface given. Aborting setup."   rc_echo "WEP: no \$iface given. Aborting setup."
160   return 1   return 1
161   fi   fi
162    
163   ${CURS_UP}   ${CURS_UP}
164   ${SET_WWCOL}   ${SET_WWCOL}
165   echo "[AUTH: WEP]"   rc_echo "[AUTH: WEP]"
166    
167   iwconfig "${iface}" enc on   iwconfig "${iface}" enc on
168   [[ -n ${WIRELESS_KEY_LENGTH} ]] && iwconfig "${iface}" enc "${WIRELESS_KEY_LENGTH}"   [[ -n ${WIRELESS_KEY_LENGTH} ]] && iwconfig "${iface}" enc "${WIRELESS_KEY_LENGTH}"
# Line 172  config_wireless_wpa() Line 176  config_wireless_wpa()
176    
177   if [[ -z ${iface} ]]   if [[ -z ${iface} ]]
178   then   then
179   echo "WPA: no \$iface given. Aborting setup."   rc_echo "WPA: no \$iface given. Aborting setup."
180   return 1   return 1
181   fi   fi
182    
183   if [ ! -x /sbin/wpa_supplicant ]   if [ ! -x /sbin/wpa_supplicant ]
184   then   then
185   echo "WPA: wpa_supplicant not installed. Aborting setup."   rc_echo "WPA: wpa_supplicant not installed. Aborting setup."
186   return 1   return 1
187   fi   fi
188    
189   ${CURS_UP}   ${CURS_UP}
190   ${SET_WWCOL}   ${SET_WWCOL}
191   echo "[AUTH: WPA]"   rc_echo "[AUTH: WPA]"
192    
193   # get default settings   # get default settings
194   [[ -f /etc/conf.d/wpa_supplicant ]] && source /etc/conf.d/wpa_supplicant   [[ -f /etc/conf.d/wpa_supplicant ]] && source /etc/conf.d/wpa_supplicant
# Line 217  config_wireless_wpa() Line 221  config_wireless_wpa()
221   fi   fi
222    
223   # remove old state dir   # remove old state dir
224   [ -d /var/run/wpa_supplicant ] && rm -rf /var/run/wpa_supplicant   [ -d /run/wpa_supplicant ] && rm -rf /run/wpa_supplicant
225    
226   # now run the wpa_supplicant dameon   # now run the wpa_supplicant dameon
227   wpa_supplicant -B \   wpa_supplicant -B \
# Line 227  config_wireless_wpa() Line 231  config_wireless_wpa()
231   ${WIRELESS_WPA_OPTS}   ${WIRELESS_WPA_OPTS}
232    
233   # echo wait 5 seconds   # echo wait 5 seconds
234   echo "    Waiting 5 seconds to retrieve authentification reply ... "   rc_echo "    Waiting 5 seconds to retrieve authentification reply ... "
235   sleep 5   sleep 5
236  }  }
237    
# Line 237  setup_wireless_extensions() Line 241  setup_wireless_extensions()
241    
242   if [[ -z ${iface} ]]   if [[ -z ${iface} ]]
243   then   then
244   echo "WIRELESS_EXTENSIONS: no \$iface given. Aborting setup."   rc_echo "WIRELESS_EXTENSIONS: no \$iface given. Aborting setup."
245   return 1   return 1
246   fi   fi
247    
# Line 249  setup_wireless_extensions() Line 253  setup_wireless_extensions()
253   [[ -n ${WIRELESS_NICK} ]] ||   [[ -n ${WIRELESS_NICK} ]] ||
254   [[ -n ${WIRELESS_AUTH_MODE} ]]   [[ -n ${WIRELESS_AUTH_MODE} ]]
255   then   then
256   echo -e ${COLOREDSTAR}"Setting up wlan-ext for ${COLBLUE}${iface}${COLDEFAULT} ... "   rc_print "Setting up wlan-ext for ${COLBLUE}${iface}${COLDEFAULT} ... "
257   fi   fi
258    
259   [[ -n ${WIRELESS_BITRATE} ]] && iwconfig "${iface}" rate "${WIRELESS_BITRATE}"   [[ -n ${WIRELESS_BITRATE} ]] && iwconfig "${iface}" rate "${WIRELESS_BITRATE}"
# Line 277  config_bridge_options() Line 281  config_bridge_options()
281   # enable spanning-tree protocol   # enable spanning-tree protocol
282   case ${BRIDGE_STP} in   case ${BRIDGE_STP} in
283   on|off) brctl stp "${iface}" "${BRIDGE_STP}" ;;   on|off) brctl stp "${iface}" "${BRIDGE_STP}" ;;
284   *) echo "BRIDGE: unkown value \$BRIDGE_STP='$BRIDGE_STP'."; return 1 ;;   *) rc_echo "BRIDGE: unkown value \$BRIDGE_STP='$BRIDGE_STP'."; return 1 ;;
285   esac   esac
286    
287   # configure ageing time   # configure ageing time
# Line 341  config_bridge_devices() Line 345  config_bridge_devices()
345    
346   if [[ -z ${iface} ]]   if [[ -z ${iface} ]]
347   then   then
348   echo "BRIDGE: no \$iface given. Aborting setup."   rc_echo "BRIDGE: no \$iface given. Aborting setup."
349   return 1   return 1
350   fi   fi
351    
352   if [[ -z ${method} ]]   if [[ -z ${method} ]]
353   then   then
354   echo "BRIDGE: no \$method given. Aborting setup."   rc_echo "BRIDGE: no \$method given. Aborting setup."
355   return 1   return 1
356   fi   fi
357    
358   # first check for brctl   # first check for brctl
359   if [[ -z $(which brctl) ]]   if [[ -z $(which brctl) ]]
360   then   then
361   echo "brctl not found! Please install 'net-misc/bridge-utils'."   rc_echo "brctl not found! Please install 'net-misc/bridge-utils'."
362   return 1   return 1
363   fi   fi
364    
365   # check the config   # check the config
366   if [[ -z ${BRIDGE_INTERFACES} ]]   if [[ -z ${BRIDGE_INTERFACES} ]]
367   then   then
368   echo "BRIDGE: no \$BRIDGE_INTERFACES given. Aborting setup."   rc_echo "BRIDGE: no \$BRIDGE_INTERFACES given. Aborting setup."
369   return 1   return 1
370   fi   fi
371    
# Line 405  config_routes() Line 409  config_routes()
409    
410   # only add and del are allowed   # only add and del are allowed
411   case ${method} in   case ${method} in
412   add) message="Adding route ${COLBLUE}${route}${COLDEFAULT} ..." ;;   add) message="Adding" ;;
413   del) message="Removing route ${COLBLUE}${route}${COLDEFAULT} ..." ;;   del) message="Removing" ;;
414   *)   *)
415   echo "config_routes: unsupported \$method '${method}'."   rc_echo "config_routes: unsupported \$method '${method}'."
416   exit 1   exit 1
417   ;;   ;;
418   esac   esac
# Line 422  config_routes() Line 426  config_routes()
426   case "${route}" in   case "${route}" in
427   \#*|"") continue ;;   \#*|"") continue ;;
428   esac   esac
429   echo -e ${COLOREDSTAR}"${message}"   rc_print "${message} route ${COLBLUE}${route}${COLDEFAULT} ..."
430   route "${method}" "${route}"   # do not esacpe ${route} or it breaks!
431     route "${method}" ${route}
432   evaluate_retval   evaluate_retval
433   done   done
434   fi   fi
# Line 442  networking_start() Line 447  networking_start()
447   ALL_INTERFACES="$1"   ALL_INTERFACES="$1"
448   else   else
449   ${FAILURE}   ${FAILURE}
450   echo "Interface $1 does not exist. Aborting"   rc_echo "Interface $1 does not exist. Aborting"
451   ${NORMAL}   ${NORMAL}
452   exit 1   exit 1
453   fi   fi
# Line 458  networking_start() Line 463  networking_start()
463   # setup mac   # setup mac
464   if [[ -n ${FORCE_MAC_TO} ]]   if [[ -n ${FORCE_MAC_TO} ]]
465   then   then
466   echo -e ${COLOREDSTAR}"Faking MAC to ${FORCE_MAC_TO} for ${COLBLUE}${iface}${COLDEFAULT} ... "   rc_print "Faking MAC to ${FORCE_MAC_TO} for ${COLBLUE}${iface}${COLDEFAULT} ... "
467   ifconfig "${iface}" hw ether "${FORCE_MAC_TO}"   ifconfig "${iface}" hw ether "${FORCE_MAC_TO}"
468   evaluate_retval   evaluate_retval
469   fi   fi
# Line 472  networking_start() Line 477  networking_start()
477   # now configure wireless_extensions   # now configure wireless_extensions
478   [ -x /usr/sbin/iwconfig ] && setup_wireless_extensions "${iface}"   [ -x /usr/sbin/iwconfig ] && setup_wireless_extensions "${iface}"
479    
480   echo -e ${COLOREDSTAR}"Bringing up interface ${COLBLUE}${iface}${COLDEFAULT} ..."   rc_print "Bringing up interface ${COLBLUE}${iface}${COLDEFAULT} ..."
481    
482   # activate the interface   # activate the interface
483   ifconfig "${iface}" up   ifconfig "${iface}" up
# Line 482  networking_start() Line 487  networking_start()
487   dhcp|DHCP)   dhcp|DHCP)
488   ${CURS_UP}   ${CURS_UP}
489   ${SET_WWCOL}   ${SET_WWCOL}
490   echo "[DHCP]"   rc_echo "[DHCP]"
491   loadproc "${DHCP_PROG}" "${DHCP_START}" "${iface}"   loadproc ${DHCP_PROG} ${DHCP_START} "${iface}"
492   ;;   ;;
493   static|STATIC)   static|STATIC)
494   ${CURS_UP}   ${CURS_UP}
495   ${SET_WWCOL}   ${SET_WWCOL}
496   echo "[STATIC]"   rc_echo "[STATIC]"
497   ifconfig "${iface}" "${IP}" netmask "${NETMASK}" broadcast "${BROADCAST}"   ifconfig "${iface}" "${IP}" netmask "${NETMASK}" broadcast "${BROADCAST}"
498   evaluate_retval   evaluate_retval
499   ;;   ;;
# Line 497  networking_start() Line 502  networking_start()
502   # setup def gw   # setup def gw
503   if [[ -n ${GATEWAY} ]]   if [[ -n ${GATEWAY} ]]
504   then   then
505   echo -e ${COLOREDSTAR}"Setting up default gateway for ${COLBLUE}${iface}${COLDEFAULT} ..."   rc_print "Setting up default gateway for ${COLBLUE}${iface}${COLDEFAULT} ..."
506   route add default gateway "${GATEWAY}" metric 1 dev "${iface}"   route add default gateway "${GATEWAY}" metric 1 dev "${iface}"
507   evaluate_retval   evaluate_retval
508    
# Line 508  networking_start() Line 513  networking_start()
513   # add given nameserver   # add given nameserver
514   if [[ -n ${NAMESERVER} ]]   if [[ -n ${NAMESERVER} ]]
515   then   then
516   echo -e ${COLOREDSTAR}"Setting up all nameserver for ${COLBLUE}${iface}${COLDEFAULT} ..."   rc_print "Setting up all nameserver for ${COLBLUE}${iface}${COLDEFAULT} ..."
517    
518   # whipe out the old one   # whipe out the old one
519   echo "# Generated by the magellan-initscripts for ${iface}" > /etc/resolv.conf   echo "# Generated by the magellan-initscripts for ${iface}" > /etc/resolv.conf
# Line 552  networking_stop() Line 557  networking_stop()
557   ALL_INTERFACES="$1"   ALL_INTERFACES="$1"
558   else   else
559   ${FAILURE}   ${FAILURE}
560   echo "Interface $1 does not exist. Aborting"   rc_echo "Interface $1 does not exist. Aborting"
561   ${NORMAL}   ${NORMAL}
562   exit 1   exit 1
563   fi   fi
# Line 566  networking_stop() Line 571  networking_stop()
571    
572   if [[ -n ${GATEWAY} ]]   if [[ -n ${GATEWAY} ]]
573   then   then
574   echo -e ${COLOREDSTAR}"Removing default gateway ..."   rc_print "Removing default gateway ..."
575   route del -net default   route del -net default
576   evaluate_retval   evaluate_retval
577   fi   fi
578    
579   echo -e ${COLOREDSTAR}"Bringing down interface ${COLBLUE}${iface}${COLDEFAULT} ..."   rc_print "Bringing down interface ${COLBLUE}${iface}${COLDEFAULT} ..."
580   ifconfig ${iface} down   ifconfig "${iface}" down
581   evaluate_retval   evaluate_retval
582    
583   # remove bridges   # remove bridges
# Line 582  networking_stop() Line 587  networking_stop()
587   fi   fi
588    
589   # shutdown dhcp-daemon   # shutdown dhcp-daemon
590   if [[ ${NETWORKING} = dhcp ]] && [[ -n $(pidof ${DHCP_PROG}) ]]   if [[ ${NETWORKING} = dhcp ]] && [[ -n $(pidof $(basename ${DHCP_PROG})) ]]
591   then   then
592   echo -e ${COLOREDSTAR}"Stopping the dhcp-daemon ..."   rc_print "Stopping the dhcp-daemon ..."
593   ${CURS_UP}   ${CURS_UP}
594   ${SET_WWCOL}   ${SET_WWCOL}
595   echo "[$(basename ${DHCP_PROG})]"   rc_echo "[$(basename ${DHCP_PROG})]"
596   ${DHCP_PROG} ${DHCP_STOP} "${iface}"   if [[ -z ${DHCP_STOP} ]]
597   evaluate_retval   then
598     killproc ${DHCP_PROG}
599     evaluate_retval
600     else
601     ${DHCP_PROG} ${DHCP_STOP} "${iface}"
602     evaluate_retval
603     fi
604   fi   fi
605    
606   # shutdown wpa_supplicant daemon   # shutdown wpa_supplicant daemon
# Line 600  networking_stop() Line 611  networking_stop()
611   done   done
612    
613   # remove state dir   # remove state dir
614   if [ -d /var/run/wpa_supplicant ]   if [ -d /run/wpa_supplicant ]
615   then   then
616   rm -rf /var/run/wpa_supplicant   rm -rf /run/wpa_supplicant
617   fi   fi
618    
619   # delete user routes   # delete user routes
# Line 629  case $1 in Line 640  case $1 in
640   ;;   ;;
641    
642   *)   *)
643   echo "Usage: $0 {start|stop|restart} [interface]"   rc_echo "Usage: $0 {start|stop|restart} [interface]"
644   exit 1   exit 1
645   ;;   ;;
646  esac  esac

Legend:
Removed from v.1165  
changed lines
  Added in v.1665