Magellan Linux

Diff of /trunk/magellan-initscripts/etc/rc.d/init.d/network

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

revision 71 by niro, Tue Mar 15 19:07:56 2005 UTC revision 268 by niro, Mon Oct 10 18:43:03 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.3 2005-03-15 19:07:56 niro Exp $  # $Header: /home/cvsd/magellan-cvs/magellan-src/magellan-initscripts/etc/rc.d/init.d/network,v 1.9 2005-10-10 18:43:03 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 13  Line 13 
13  source /etc/sysconfig/rc  source /etc/sysconfig/rc
14  source ${rc_functions}  source ${rc_functions}
15    
16  checkconfig() {  # read values from files
17    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}" ]   if [ -z "${NETWORKING}" ]
72   then   then
73   echo "NETWORKING missing in net.${interface}, aborted"   echo "NETWORKING missing in net.${interface}, aborted"
# Line 53  checkconfig() { Line 107  checkconfig() {
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.//)" ;;
  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]"  
  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   if [ -n "${GATEWAY}" -a -n "${GATEWAY_IF}" ]  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     iwconfig "${iface}" enc on
145     [[ -n ${WIRELESS_KEY_LENGTH} ]] && iwconfig "${iface}" enc "${WIRELESS_KEY_LENGTH}"
146     [[ -n ${WIRELESS_KEY} ]] && iwconfig "${iface}" key "${WIRELESS_KEY}"
147     [[ -n ${WIRELESS_KEY_ASCII} ]] && iwconfig "${iface}" key s:"${WIRELESS_KEY_ASCII}"
148    }
149    
150    config_wireless_wpa()
151    {
152     local iface="$1"
153    
154     if [[ -z ${iface} ]]
155     then
156     echo "WPA: no \$iface given. Aborting setup."
157     return 1
158     fi
159    
160     if [ ! -x /sbin/wpa_supplicant ]
161     then
162     echo "WPA: wpa_supplicant not installed. Aborting setup."
163     return 1
164     fi
165    
166     # get default settings
167     [[ -f /etc/conf.d/wpa_supplicant ]] && source /etc/conf.d/wpa_supplicant
168    
169     # check the configuration
170     [[ -z ${WIRELESS_WPA_CONFIG} ]] && WIRELESS_WPA_CONFIG=/etc/wpa_supplicant.auto
171     [[ -z ${WIRELESS_WPA_SKEL} ]] && WIRELESS_WPA_SKEL=/etc/conf.d/wpa_supplicant.skel
172     if [[ -z ${WIRELESS_WPA_DRIVER} ]]
173     then
174     echo "WPA: WIRELESS_WPA_DRIVER given. Aborting setup."
175     return 1
176     fi
177    
178     # write a config with the settings from net.${iface}
179     # only wpa-psk ! all other needs manual setup
180     if [[ ${WIRELESS_WPA_AUTOCONF} = true ]]
181     then
182     # write default cfg from skeleton
183     cat ${WIRELESS_WPA_SKEL} > ${WIRELESS_WPA_CONFIG}
184    
185     # setup the network entry
186     sed -i -e "s:@WIRELESS_ESSID@:${WIRELESS_ESSID}:g" \
187     -e "s:@WIRELESS_KEY@:${WIRELESS_KEY}:g" \
188     ${WIRELESS_WPA_CONFIG}
189     fi
190    
191     # now run the wpa_supplicant dameon
192     wpa_supplicant -B \
193     -D"${WIRELESS_WPA_DRIVER}" \
194     -c"${WIRELESS_WPA_CONFIG}" \
195     -i"${iface}" \
196     ${WIRELESS_WPA_OPTS}
197    }
198    
199    setup_wireless_extensions()
200    {
201     local iface="$1"
202    
203     if [[ -z ${iface} ]]
204     then
205     echo "WIRELESS_EXTENSIONS: no \$iface given. Aborting setup."
206     return 1
207     fi
208    
209     [[ -n ${WIRELESS_BITRATE} ]] && iwconfig "${iface}" rate "${WIRELESS_BITRATE}"
210     [[ -n ${WIRELESS_CHANNEL} ]] && iwconfig "${iface}" channel "${WIRELESS_CHANNEL}"
211     [[ -n ${WIRELESS_ESSID} ]] && iwconfig "${iface}" essid "${WIRELESS_ESSID}"
212     [[ -n ${WIRELESS_FREQUENCY} ]] && iwconfig "${iface}" freq "${WIRELESS_FREQUENCY}"
213     [[ -n ${WIRELESS_MODE} ]] && iwconfig "${iface}" mode "${WIRELESS_MODE}"
214     [[ -n ${WIRELESS_NICK} ]] && iwconfig "${iface}" nick "${WIRELESS_NICK}"
215    
216     case "${WIRELESS_AUTH_MODE}" in
217     wpa) config_wireless_wpa "${iface}" ;;
218     wep|on) config_wireless_wep "${iface}" ;;
219     off) iwconfig "${iface}" enc off ;;
220     esac
221    }
222    
223    networking_start()
224    {
225     local iface dns
226    
227     # get list of all devices
228     for iface in $(onboot_interface_list ${network_settings}/net.*)
229     do
230     # checkconfig
231     source ${network_settings}/net.${iface} || exit 1
232     checkconfig
233    
234     echo -e ${COLOREDSTAR}"Bringing up interface ${COLBLUE}${iface}${COLDEFAULT} ..."
235    
236     # setup mac
237     [ -n "${FORCE_MAC_TO}" ] && ifconfig ${iface} hw ether "${FORCE_MAC_TO}"
238    
239     # setup static or dhcp
240     case ${NETWORKING} in
241     dhcp|DHCP)
242     ${CURS_UP}
243     ${SET_WWCOL}
244     echo "[DHCP]"
245     loadproc ${DHCP_PROG} ${DHCP_START}
246     ;;
247     static|STATIC)
248     ${CURS_UP}
249     ${SET_WWCOL}
250     echo "[STATIC]"
251     ifconfig "${iface}" "${IP}" netmask "${NETMASK}" broadcast "${BROADCAST}"
252     evaluate_retval
253     ;;
254     esac
255    
256     # setup def gw
257     if [[ -n ${GATEWAY} ]]
258   then   then
259   echo -e ${COLOREDSTAR}"Setting up default gateway ..."   echo -e ${COLOREDSTAR}"Setting up default gateway for ${COLBLUE}${iface}${COLDEFAULT} ..."
260   route add default gateway ${GATEWAY} metric 1 \   route add default gateway ${GATEWAY} metric 1 dev ${iface}
  dev ${GATEWAY_IF}  
261   evaluate_retval   evaluate_retval
262   fi   fi
263    
264   update_svcstatus $1   # setup /etc/resolv.conf
265   splash svc_started "$(basename $0)" 0   if [[ -n ${NAMESERVER} ]]
266   ;;   then
267     echo -e ${COLOREDSTAR}"Setting up all nameserver for ${COLBLUE}${iface}${COLDEFAULT} ..."
268    
269     # whipe out the old one
270     echo "# Generated by the magellan-initscripts for ${iface}" > /etc/resolv.conf
271     for dns in ${NAMESERVER}
272     do
273     echo "nameserver ${dns}" >> /etc/resolv.conf
274     done
275     fi
276    
277   stop)   # setup wlan extensions
278   if [ -n "${GATEWAY}" ]   if [ -x /usr/sbin/iwconfig ]
279     then
280     setup_wireless_extensions "${iface}"
281     fi
282     done
283    }
284    
285    networking_stop()
286    {
287     # get list of all devices
288     for iface in $(onboot_interface_list ${network_settings}/net.*)
289     do
290     source ${network_settings}/net.${iface} || exit 1
291     checkconfig
292    
293     if [[ -n ${GATEWAY} ]]
294   then   then
295   echo -e ${COLOREDSTAR}"Removing default gateway ..."   echo -e ${COLOREDSTAR}"Removing default gateway ..."
296   route del -net default   route del -net default
297   evaluate_retval   evaluate_retval
298   fi   fi
299    
300   for file in $(grep -il "ONBOOT=\"yes\"" ${network_settings}/net.*)   echo -e ${COLOREDSTAR}"Bringing down interface ${COLBLUE}${iface}${COLDEFAULT} ..."
301   do   ifconfig ${iface} down
302   interface=$(basename ${file} | sed s/net.//)   evaluate_retval
  case "${interface}" in  
  *~) ;;  
  *)  
  #$network_devices/ifdown $interface  
  source ${network_settings}/net.${interface} || exit 1  
  checkconfig  
  echo -e ${COLOREDSTAR}"Bringing down interface ${COLBLUE}${interface}${COLDEFAULT} ..."  
  ifconfig ${interface} down  
  evaluate_retval  
   
  #shutdown dhcp-daemon  
  if [ "${NETWORKING}" == dhcp ]  
  then  
  my_runlevel="`runlevel | cut -d ' ' -f2`"  
  if [ -n "$(pidof ${DHCP_PROG})" ]  
  then  
  echo -e ${COLOREDSTAR}"Stopping the dhcp-daemon ..."  
  ${CURS_UP}  
  ${SET_WWCOL}  
  echo "[$(basename ${DHCP_PROG})]"  
  ${DHCP_PROG} ${DHCP_STOP}  
  evaluate_retval  
  fi  
  fi  
  ;;  
  esac  
  done  
303    
304     # shutdown dhcp-daemon
305     if [[ ${NETWORKING} = dhcp ]] && [[ -n $(pidof ${DHCP_PROG}) ]]
306     then
307     echo -e ${COLOREDSTAR}"Stopping the dhcp-daemon ..."
308     ${CURS_UP}
309     ${SET_WWCOL}
310     echo "[$(basename ${DHCP_PROG})]"
311     ${DHCP_PROG} ${DHCP_STOP}
312     evaluate_retval
313     fi
314    
315     # shutdown wpa_supplicant daemon
316     if [[ -n $(pidof wpa_supplicant) ]]
317     then
318     killall wpa_supplicant
319     fi
320     done
321    }
322    
323    case $1 in
324     start)
325     networking_start
326     update_svcstatus $1
327     splash svc_started "$(basename $0)" 0
328     ;;
329    
330     stop)
331     networking_stop
332   update_svcstatus $1   update_svcstatus $1
333   splash svc_stopped "$(basename $0)" 0   splash svc_stopped "$(basename $0)" 0
334   ;;   ;;

Legend:
Removed from v.71  
changed lines
  Added in v.268