Magellan Linux

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

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

branches/unlabeled-1.1.1/magellan-initscripts/etc/rc.d/init.d/network revision 2 by niro, Mon Dec 13 22:52:07 2004 UTC trunk/magellan-initscripts/etc/rc.d/init.d/network revision 270 by niro, Tue Oct 11 11:19:58 2005 UTC
# Line 1  Line 1 
1  #!/bin/bash  #!/bin/bash
2    # $Header: /home/cvsd/magellan-cvs/magellan-src/magellan-initscripts/etc/rc.d/init.d/network,v 1.10 2005-10-11 11:19:58 niro Exp $
3    
4  #%rlevels: 0:k 1:k 2:k 3:s 4:s 5:s 6:k  #%rlevels: 0:k 1:k 2:k 3:s 4:s 5:s 6:k
5  #%start: 20  #%start: 20
# Line 10  Line 11 
11  #%after:  #%after:
12    
13  source /etc/sysconfig/rc  source /etc/sysconfig/rc
14  source $rc_functions  source ${rc_functions}
15    
16  checkconfig() {  # read values from files
17   if [ -z $NETWORKING ]  read_value()
18    {
19     local var="$1"
20     local file="$2"
21     local value
22    
23     # local all possible vars
24     # global
25     local ONBOOT
26     local NETWORKING
27    
28     # static
29     local IP
30     local NETMASK
31     local BROADCAST
32     local NETWORKING
33     local FORCE_MAC_TO
34    
35     # dhcp
36     local DHCP_PROG
37     local DHCP_START
38     local DHCP_STOP
39    
40     # default gw
41     local GATEWAY
42     local GATEWAY_IF
43    
44     # wireless extensions
45     local WIRELESS_AP
46     local WIRELESS_AUTH_MODE
47     local WIRELESS_BITRATE
48     local WIRELESS_CHANNEL
49     local WIRELESS_DEFAULT_KEY
50     local WIRELESS_ESSID
51     local WIRELESS_FREQUENCY
52     local WIRELESS_KEY
53     local WIRELESS_KEY_ASCII
54     local WIRELESS_KEY_0
55     local WIRELESS_KEY_1
56     local WIRELESS_KEY_2
57     local WIRELESS_KEY_3
58     local WIRELESS_KEY_LENGTH
59     local WIRELESS_MODE
60     local WIRELESS_NICK
61     local WIRELESS_NWID
62     local WIRELESS_POWER
63    
64     source ${file}
65     eval value=\$$(echo ${var})
66     echo "${value}"
67    }
68    
69    checkconfig()
70    {
71     if [ -z "${NETWORKING}" ]
72   then   then
73   echo "NETWORKING missing in net.${interface}, aborted"   echo "NETWORKING missing in net.${interface}, aborted"
74   exit 1   exit 1
75   fi   fi
76    
77   case $NETWORKING in   case "${NETWORKING}" in
78   static)   static)
79   if [ -z $IP ]   if [ -z "${IP}" ]
80   then   then
81   echo "IP missing in net.${interface}, aborted"   echo "IP missing in net.${interface}, aborted"
82   exit 1   exit 1
83   fi   fi
84    
85   if [ -z $NETMASK ]   if [ -z "${NETMASK}" ]
86   then   then
87   echo -n "NETMASK missing in net.${interface}, "   echo -n "NETMASK missing in net.${interface}, "
88   echo "using 255.255.255.0"   echo "using 255.255.255.0"
89   NETMASK=255.255.255.0   NETMASK=255.255.255.0
90   fi   fi
91    
92   if [ -z $BROADCAST ]   if [ -z "${BROADCAST}" ]
93   then   then
94   echo -n "BROADCAST missing in net.${interface}, "   echo -n "BROADCAST missing in net.${interface}, "
95   echo "using default address"   echo "using default address"
96   fi   fi
97   ;;   ;;
98    
99   dhcp)   dhcp)
100   if [ -z $DHCP_PROG ]   if [ -z "${DHCP_PROG}" ]
101   then   then
102   echo "DHCP_PROG missing in net.${interface}, aborted"   echo "DHCP_PROG missing in net.${interface}, aborted"
103   exit 1   exit 1
104   fi   fi
105   ;;   ;;
106    
107   esac   esac
108  }  }
109    
110    # onboot_interface_list /path/to/files*
111  case "$1" in  onboot_interface_list()
112   start)  {
113   for file in $(grep -il "ONBOOT=\"yes\"" $network_settings/net.*)   local file
114   do   local devices
115   interface=$(basename $file | sed s/net.//)   local iface
116   case "$interface" in  
117     # get list of all devices
118     for file in $@
119     do
120     if [[ $(read_value ONBOOT ${file}) = yes ]]
121     then
122     iface="$(basename ${file} | sed s/net.//)"
123     # exclude backup files
124     case "${iface}" in
125   *~) ;;   *~) ;;
126   *)   *) devices="${devices} $(basename ${file} | sed s/net.//)" ;;
  #$network_devices/ifup $interface  
  source $network_settings/net.${interface} || exit 1  
  checkconfig  
  case $NETWORKING in  
  dhcp)  
  echo -e ${COLOREDSTAR}"Bringing up interface ${COLBLUE}${interface}${COLDEFAULT} ..."  
  $CURS_UP  
  $SET_WWCOL  
  echo "[DHCP]"  
  #modprobe $interface  
  loadproc $DHCP_PROG $DHCP_START  
  ;;  
  static)  
  echo -e ${COLOREDSTAR}"Bringing up interface ${COLBLUE}${interface}${COLDEFAULT} ..."  
  $CURS_UP  
  $SET_WWCOL  
  echo "[STATIC]"  
  ifconfig $interface $IP netmask $NETMASK broadcast $BROADCAST  
  evaluate_retval  
  ;;  
  esac  
  ;;  
127   esac   esac
128   done   fi
129     done
130    
131     echo "${devices}"
132    }
133    
134    config_wireless_wep()
135    {
136     local iface="$1"
137    
138     if [[ -z ${iface} ]]
139     then
140     echo "WEP: no \$iface given. Aborting setup."
141     return 1
142     fi
143    
144     ${CURS_UP}
145     ${SET_WWCOL}
146     echo "[AUTH: WEP]"
147    
148     iwconfig "${iface}" enc on
149     [[ -n ${WIRELESS_KEY_LENGTH} ]] && iwconfig "${iface}" enc "${WIRELESS_KEY_LENGTH}"
150     [[ -n ${WIRELESS_KEY} ]] && iwconfig "${iface}" key "${WIRELESS_KEY}"
151     [[ -n ${WIRELESS_KEY_ASCII} ]] && iwconfig "${iface}" key s:"${WIRELESS_KEY_ASCII}"
152    }
153    
154    config_wireless_wpa()
155    {
156     local iface="$1"
157    
158     if [[ -z ${iface} ]]
159     then
160     echo "WPA: no \$iface given. Aborting setup."
161     return 1
162     fi
163    
164     if [ ! -x /sbin/wpa_supplicant ]
165     then
166     echo "WPA: wpa_supplicant not installed. Aborting setup."
167     return 1
168     fi
169    
170     ${CURS_UP}
171     ${SET_WWCOL}
172     echo "[AUTH: WPA]"
173    
174     # get default settings
175     [[ -f /etc/conf.d/wpa_supplicant ]] && source /etc/conf.d/wpa_supplicant
176    
177     # check the configuration
178     [[ -z ${WIRELESS_WPA_CONFIG} ]] && WIRELESS_WPA_CONFIG=/etc/wpa_supplicant.auto
179     [[ -z ${WIRELESS_WPA_SKEL} ]] && WIRELESS_WPA_SKEL=/etc/conf.d/wpa_supplicant.skel
180     if [[ -z ${WIRELESS_WPA_DRIVER} ]]
181     then
182     echo "WPA: WIRELESS_WPA_DRIVER given. Aborting setup."
183     return 1
184     fi
185    
186     # write a config with the settings from net.${iface}
187     # only wpa-psk ! all other needs manual setup
188     if [[ ${WIRELESS_WPA_AUTOCONF} = true ]]
189     then
190     # write default cfg from skeleton
191     cat ${WIRELESS_WPA_SKEL} > ${WIRELESS_WPA_CONFIG}
192    
193     # setup the network entry
194     sed -i -e "s:@WIRELESS_ESSID@:${WIRELESS_ESSID}:g" \
195     -e "s:@WIRELESS_KEY@:${WIRELESS_KEY}:g" \
196     ${WIRELESS_WPA_CONFIG}
197     fi
198    
199     # now run the wpa_supplicant dameon
200     wpa_supplicant -B \
201     -D"${WIRELESS_WPA_DRIVER}" \
202     -c"${WIRELESS_WPA_CONFIG}" \
203     -i"${iface}" \
204     ${WIRELESS_WPA_OPTS}
205    
206     # echo wait 5 seconds
207     echo "    Waiting 5 seconds to retrieve authentification reply ... "
208     sleep 5
209    }
210    
211    setup_wireless_extensions()
212    {
213     local iface="$1"
214    
215     if [[ -z ${iface} ]]
216     then
217     echo "WIRELESS_EXTENSIONS: no \$iface given. Aborting setup."
218     return 1
219     fi
220    
221     echo -e ${COLOREDSTAR}"Setting up wlan-ext for ${COLBLUE}${iface}${COLDEFAULT} ... "
222    
223   if [ "$GATEWAY" != "" ]   [[ -n ${WIRELESS_BITRATE} ]] && iwconfig "${iface}" rate "${WIRELESS_BITRATE}"
224     [[ -n ${WIRELESS_CHANNEL} ]] && iwconfig "${iface}" channel "${WIRELESS_CHANNEL}"
225     [[ -n ${WIRELESS_ESSID} ]] && iwconfig "${iface}" essid "${WIRELESS_ESSID}"
226     [[ -n ${WIRELESS_FREQUENCY} ]] && iwconfig "${iface}" freq "${WIRELESS_FREQUENCY}"
227     [[ -n ${WIRELESS_MODE} ]] && iwconfig "${iface}" mode "${WIRELESS_MODE}"
228     [[ -n ${WIRELESS_NICK} ]] && iwconfig "${iface}" nick "${WIRELESS_NICK}"
229    
230     case "${WIRELESS_AUTH_MODE}" in
231     wpa) config_wireless_wpa "${iface}" ;;
232     wep|on) config_wireless_wep "${iface}" ;;
233     off) iwconfig "${iface}" enc off ;;
234     esac
235    }
236    
237    networking_start()
238    {
239     local iface dns
240    
241     # get list of all devices
242     for iface in $(onboot_interface_list ${network_settings}/net.*)
243     do
244     # checkconfig
245     source ${network_settings}/net.${iface} || exit 1
246     checkconfig
247    
248     # setup mac
249     if [ -n "${FORCE_MAC_TO}" ]
250   then   then
251   echo -e ${COLOREDSTAR}"Setting up default gateway ..."   echo -e ${COLOREDSTAR}"Faking MAC to ${FORCE_MAC_TO} for ${COLBLUE}${iface}${COLDEFAULT} ... "
252   route add default gateway $GATEWAY metric 1 \   ifconfig "${iface}" hw ether "${FORCE_MAC_TO}"
  dev $GATEWAY_IF  
253   evaluate_retval   evaluate_retval
254   fi   fi
255    
256   update_svcstatus $1   # activate the interface
257   splash svc_started "$(basename $0)" 0   ifconfig "${iface}" up
258   ;;  
259     # now configure wireless_extensions
260     [ -x /usr/sbin/iwconfig ] && setup_wireless_extensions "${iface}"
261    
262     echo -e ${COLOREDSTAR}"Bringing up interface ${COLBLUE}${iface}${COLDEFAULT} ..."
263    
264     # setup static or dhcp
265     case ${NETWORKING} in
266     dhcp|DHCP)
267     ${CURS_UP}
268     ${SET_WWCOL}
269     echo "[DHCP]"
270     loadproc ${DHCP_PROG} ${DHCP_START}
271     ;;
272     static|STATIC)
273     ${CURS_UP}
274     ${SET_WWCOL}
275     echo "[STATIC]"
276     ifconfig "${iface}" "${IP}" netmask "${NETMASK}" broadcast "${BROADCAST}"
277     evaluate_retval
278     ;;
279     esac
280    
281   stop)   # setup def gw
282   if [ "$GATEWAY" != "" ]   if [[ -n ${GATEWAY} ]]
283     then
284     echo -e ${COLOREDSTAR}"Setting up default gateway for ${COLBLUE}${iface}${COLDEFAULT} ..."
285     route add default gateway ${GATEWAY} metric 1 dev ${iface}
286     evaluate_retval
287     fi
288    
289     # setup /etc/resolv.conf
290     if [[ -n ${NAMESERVER} ]]
291     then
292     echo -e ${COLOREDSTAR}"Setting up all nameserver for ${COLBLUE}${iface}${COLDEFAULT} ..."
293    
294     # whipe out the old one
295     echo "# Generated by the magellan-initscripts for ${iface}" > /etc/resolv.conf
296     for dns in ${NAMESERVER}
297     do
298     echo "nameserver ${dns}" >> /etc/resolv.conf
299     done
300     fi
301     done
302    }
303    
304    networking_stop()
305    {
306     # get list of all devices
307     for iface in $(onboot_interface_list ${network_settings}/net.*)
308     do
309     source ${network_settings}/net.${iface} || exit 1
310     checkconfig
311    
312     if [[ -n ${GATEWAY} ]]
313   then   then
314   echo -e ${COLOREDSTAR}"Removing default gateway ..."   echo -e ${COLOREDSTAR}"Removing default gateway ..."
315   route del -net default   route del -net default
316   evaluate_retval   evaluate_retval
317   fi   fi
318    
319   for file in $(grep -il "ONBOOT=\"yes\"" $network_settings/net.*)   echo -e ${COLOREDSTAR}"Bringing down interface ${COLBLUE}${iface}${COLDEFAULT} ..."
320   do   ifconfig ${iface} down
321   interface=$(basename $file | sed s/net.//)   evaluate_retval
322   case "$interface" in  
323   *~) ;;   # shutdown dhcp-daemon
324   *)   if [[ ${NETWORKING} = dhcp ]] && [[ -n $(pidof ${DHCP_PROG}) ]]
325   #$network_devices/ifdown $interface   then
326   source $network_settings/net.${interface} || exit 1   echo -e ${COLOREDSTAR}"Stopping the dhcp-daemon ..."
327   checkconfig   ${CURS_UP}
328   echo -e ${COLOREDSTAR}"Bringing down interface ${COLBLUE}${interface}${COLDEFAULT} ..."   ${SET_WWCOL}
329   ifconfig eth0 down   echo "[$(basename ${DHCP_PROG})]"
330   evaluate_retval   ${DHCP_PROG} ${DHCP_STOP} "${iface}"
331     evaluate_retval
332   #shutdown dhcp-daemon   fi
333   if [ $NETWORKING == dhcp ]  
334   then   # shutdown wpa_supplicant daemon
335   my_runlevel="`runlevel | cut -d ' ' -f2`"   if [[ -n $(pidof wpa_supplicant) ]]
336   if [ "$my_runlevel" -ne "0" -a "$my_runlevel" -ne "6" ]   then
337   then   killall wpa_supplicant
338   echo -e ${COLOREDSTAR}"Stopping the dhcp-daemon ..."   fi
339   $CURS_UP   done
340   $SET_WWCOL  
341   echo "[${DHCP_PROG}]"   # remove state dir
342   $DHCP_PROG $DHCP_STOP   if [ -d /var/run/wpa_supplicant ]
343   evaluate_retval   then
344   fi   rm -rf /var/run/wpa_supplicant
345   fi   fi
346   ;;  }
  esac  
  done  
347    
348    case $1 in
349     start)
350     networking_start
351     update_svcstatus $1
352     splash svc_started "$(basename $0)" 0
353     ;;
354    
355     stop)
356     networking_stop
357   update_svcstatus $1   update_svcstatus $1
358   splash svc_stopped "$(basename $0)" 0   splash svc_stopped "$(basename $0)" 0
359   ;;   ;;

Legend:
Removed from v.2  
changed lines
  Added in v.270