initial checkin
[grml-scripts.git] / usr_sbin / netcardconfig
1 #!/bin/bash
2 # Filename:      grml-network
3 # Purpose:       configuration script for network
4 # Authors:       Klaus Knopper 2002, Niall Walsh + Stefan Lippers-Hollmann 2005, Michael Prokop <mika@grml.org>, Marcel Wichern <marcel@grml.org>
5 # Bug-Reports:   see http://grml.org/bugs/
6 # License:       This file is licensed under the GPL v2.
7 # Latest change: Mit Okt 04 11:52:26 CEST 2006 [mika]
8 ################################################################################
9 # Changes have been merged from Kanotix's netcardconfig taken from
10 # http://kanotix.com/files/debian/pool/main/n/netcardconfig-kanotix/
11 ################################################################################
12
13 PATH="/bin:/sbin:/usr/bin:/usr/sbin"
14 export PATH
15
16 # get root
17 if [ $UID != 0 ]; then
18  echo Error: become root before starting $0 >&2
19  exit 100
20 fi
21
22 TMP=$(mktemp)
23 WPATMP=$(mktemp)
24
25 bailout() {
26   rm -f "$TMP"
27   rm -f "$WPATMP"
28   exit $1
29 }
30
31 # This function produces the IWOURLINE for interfaces
32 writeiwline() {
33   IWOURLINE=""
34   if [ -n "$NWID" ]; then
35     IWOURLINE="$IWOURLINE wireless-nwid $NWID\n"
36   fi
37
38   if [ -n "$MODE" ]; then
39     IWOURLINE="$IWOURLINE wireless-mode $MODE\n"
40   fi
41
42   if [ -n "$CHANNEL" ]; then
43     IWOURLINE="$IWOURLINE wireless-channel $CHANNEL\n"
44   fi
45
46   if [ -n "$FREQ" ]; then
47     IWOURLINE="$IWOURLINE wireless-freq $FREQ\n"
48   fi
49
50   if [ -n "$KEY" ]; then
51     if [ "$PUBKEY" -eq 1 ]; then
52       # Store the key in interfaces in wireless-key
53       IWOURLINE="$IWOURLINE wireless-key $KEY\n"
54     else
55       # Store the key in /etc/network/wep.$DV which is root readable only
56       # Use pre-up in interfaces to read and set it
57       echo "$KEY" > /etc/network/wep.$DV && chmod 600 /etc/network/wep.$DV && IWOURLINE="$IWOURLINE pre-up KEY=\$(cat /etc/network/wep.$DV) && iwconfig $DV key \$KEY\n"
58     fi
59   fi
60
61   [ -d /sys/module/rt2??0/ ] && IWPREUPLINE="$IWPREUPLINE pre-up /sbin/ifconfig $DV up\n"
62
63   if [ -n "$IWCONFIG" ]; then
64     IWPREUPLINE="$IWPREUPLINE iwconfig $IWCONFIG\n"
65   fi
66
67   if [ -n "$IWSPY" ]; then
68     IWPREUPLINE="$IWPREUPLINE iwspy $IWSPY\n"
69   fi
70
71   if [ -n "$IWPRIV" ]; then
72     IWPREUPLINE="$IWPREUPLINE iwpriv $IWPRIV\n"
73   fi
74
75   # execute ESSID last, but make sure that it is written as first option
76   if [ -n "$ESSID" ]; then
77     IWOURLINE="$IWOURLINE wireless-essid $ESSID\n"
78   fi
79
80   if [ $WPAON -gt 0 ]; then
81     # Using wpa requires a wpa_supplicant entry
82     IWPREUPLINE="${IWPREUPLINE}pre-up wpa_supplicant -D$WPA_DEV -i$WLDEVICE -c/etc/wpa_supplicant.conf -B\n"
83     touch /etc/wpa_supplicant.conf
84     awk '/^network={/{if(found){found=0}else{found=1;hold=$0}}/ssid={/{if(/ssid='"$ESSID"'/){found=1}else{found=0;print hold}}{if(!found){print}}' /etc/wpa_supplicant.conf >> "$TMP"
85     wpa_passphrase "$ESSID" "$WPASECRET" 2>/dev/null >> "$TMP"
86     mv -f /etc/wpa_supplicant.conf /etc/wpa_supplicant.conf.$(date +%Y%m%d_%H%M)
87     if ! grep -q "For more information take a look at" /etc/wpa_supplicant.conf ; then
88       cat >$WPATMP <<EOF
89 # /etc/wpa_supplicant.conf
90 # For more information take a look at /usr/share/doc/wpasupplicant/
91 #
92 # Other WPA options:
93 #  scan_ssid [0]|1
94 #  bssid 00:11:22:33:44:55
95 #  priority [0]|Integer
96 #  proto [WPA RSN] WPA|RSN
97 #  key_mgmt [WPA-PSK WPA-EAP]|NONE|WPA-PSK|WPA-EAP|IEEE8021X
98 #  pairwise [CCMP TKIP]|CCMP|TKIP|NONE
99 #  group [CCMP TKIP WEP105 WEP40]|CCMP|TKIP|WEP105|WEP40
100 #  eapol_flags [3]|1|2
101
102 EOF
103     fi
104     [ -n "$APSCAN" ] && echo "$APSCAN" >> "$WPATMP"
105     cat "$WPATMP" "$TMP" > /etc/wpa_supplicant.conf
106     rm -f $WPATMP 2>/dev/null
107     IWDOWNLINE="${IWDOWNLINE}down killall wpa_supplicant\n"
108   fi
109
110   IWOURLINE="$IWOURLINE $IWPREUPLINE $IWDOWNLINE"
111   #echo "DEBUG: for interfaces $IWOURLINE"
112 }
113
114 device2props() {
115   PARTCOUNT=0
116   isauto=0
117   isfirewire=0
118   iswireless=0
119   driver=""
120   mac=""
121   for PART in $DEVICE; do
122     if [ $PARTCOUNT -eq 0 ]; then
123       DEVICENAME=$PART
124     else
125       echo $PART | grep -q A::1 && isauto=1
126       echo $PART | grep -q F::1 && isfirewire=1
127       echo $PART | grep -q W::1 && iswireless=1
128       [ -z "$driver" ] && driver=$(echo $PART|awk 'BEGIN {FS="::"} /^D:/{print $2}')
129       [ -z "$mac" ] && mac=$(echo $PART|awk 'BEGIN {FS="::"} /^M:/{print $2}')
130     fi
131     ((PARTCOUNT++))
132   done
133 }
134
135 props2string() {
136   MY_DEVICE_NAME=""
137   [ $isfirewire -gt 0 ] && MY_DEVICE_NAME="$NET_DEVICE_NAME_FW"
138   [ -z "$MY_DEVICE_NAME" -a $iswireless -gt 0 ] && MY_DEVICE_NAME="$NET_DEVICE_NAME_W"
139   [ -z "$MY_DEVICE_NAME" ] && MY_DEVICE_NAME="$NET_DEVICE_NAME"
140   MY_DEVICE_NAME="$DEVICENAME $MY_DEVICE_NAME $mac $driver"
141   [ $isauto -gt 0 ] && MY_DEVICE_NAME="$MY_DEVICE_NAME $NET_DEVICE_NAME_AUTO"
142   MY_DEVICE_NAME=$(echo $MY_DEVICE_NAME | sed 's/\ /__/g')
143 }
144
145 addauto() {
146   if ! egrep -e "^auto[  ]+.*$DV" /etc/network/interfaces >/dev/null; then
147     awk '{if(/^auto/){if(done==0){print $0 " '"$DV"'";done=1}else{print}}else{print}}END{if(done==0){print "auto '$DV'"}}' "/etc/network/interfaces" > "$TMP"
148     cat "$TMP" > /etc/network/interfaces
149   fi
150 }
151
152 remauto(){
153   if egrep -e "^auto[  ]+.*$DV" /etc/network/interfaces >/dev/null; then
154     perl -pi -e 's/^(auto.*)'$DV'(.*)$/$1$2/;' /etc/network/interfaces
155   fi
156 }
157
158 configiface() {
159   [ ! -r /etc/network/interfaces ] && touch /etc/network/interfaces
160   DEVICE=${NETDEVICES[$DV]}
161   device2props
162   DV=$DEVICENAME
163   # wireless config
164   WLDEVICE="$(LANG=C LC_MESSAGEWS=C iwconfig $DV 2>/dev/null | awk '/802\.11|READY|ESSID/{print $1}')"
165   WLDEVICECOUNT="$(LANG=C LC_MESSAGEWS=C iwconfig $DV 2>/dev/null | wc -l)"
166   if [ $iswireless -gt 0 ] && $DIALOG --yesno "$MESSAGE13" 8 45; then
167     ESSID=""
168     NWID=""
169     MODE=""
170     CHANNEL=""
171     FREQ=""
172     SENS=""
173     RATE=""
174     KEY=""
175     RTS=""
176     FRAG=""
177     IWCONFIG=""
178     IWSPY=""
179     IWPRIV=""
180
181     if [ -f /etc/network/interfaces ]; then
182       awk '/iface/{if(/'"$DV"'/){found=1}else{found=0}}
183         /essid/{if(found){for(i=NF;i>=2;i--)essid=$i "~" essid}}
184         /nwid/{if(found){nwid=$NF}}
185         /mode/{if(found){mode=$NF}}
186         /channel/{if(found){channel=$NF}}
187         /freq/{if(found){freq=$NF}}
188         /sens/{if(found){sens=$NF}}
189         /rate/{if(found){rate=$NF}}
190         /rts/{if(found){rts=$NF}}
191         /frag/{if(found){frag=$NF}}
192         /iwconfig/{if(!/KEY/){if(found){iwconfig=$NF}}}
193         /iwspy/{if(found){iwspy=$NF}}
194         /iwpriv/{if(found){iwpriv=$NF}}
195         /wireless[-_]key/{if(found){gsub(/^\W*wireless[-_]key\W*/,"");key=$0}}
196         END{
197           if (!(length(essid))){essid="~~~"}
198           if (!(length(nwid))){nwid="~~~"}
199           if (!(length(mode))){mode="~~~"}
200           if (!(length(channel))){channel="~~~"}
201           if (!(length(freq))){freq="~~~"}
202           if (!(length(sens))){sens="~~~"}
203           if (!(length(rate))){rate="~~~"}
204           if (!(length(rts))){rts="~~~"}
205           if (!(length(frag))){frag="~~~"}
206           if (!(length(iwconfig))){iwconfig="~~~"}
207           if (!(length(iwspy))){iwspy="~~~"}
208           if (!(length(iwpriv))){iwpriv="~~~"}
209           if (!(length(key))){key="~~~"}
210           print essid" "nwid" "mode" "channel" "freq" "sens" "rate" "rts" "frag" "iwconfig" "iwspy" "iwpriv" "key
211         }' /etc/network/interfaces >"$TMP"
212
213       read ESSID NWID MODE CHANNEL FREQ SENS RATE RTS FRAG IWCONFIG IWSPY IWPRIV KEY<"$TMP"
214
215       if [ "$ESSID" = "~~~" ]; then  ESSID=""; fi
216       if [ "$NWID" = "~~~" ]; then  NWID=""; fi
217       if [ "$MODE" = "~~~" ]; then  MODE=""; fi
218       if [ "$CHANNEL" = "~~~" ]; then  CHANNEL=""; fi
219       if [ "$FREQ" = "~~~" ]; then  FREQ=""; fi
220       if [ "$SENS" = "~~~" ]; then  SENS=""; fi
221       if [ "$RATE" = "~~~" ]; then  RATE=""; fi
222       if [ "$RTS" = "~~~" ]; then  RTS=""; fi
223       if [ "$FRAG" = "~~~" ]; then  FRAG=""; fi
224       if [ "$IWCONFIG" = "~~~" ]; then IWCONFIG=""; fi
225       if [ "$IWSPY" = "~~~" ]; then  IWSPY=""; fi
226       if [ "$IWPRIV" = "~~~" ]; then  IWPRIV=""; fi
227       if [ "$KEY" = "~~~" ]; then  KEY=""; fi
228
229       ESSID=$(echo $ESSID | tr "~" " " | sed 's/ *$//')
230
231       if [ -z "$KEY" ]; then
232         KEY=$(cat /etc/network/wep.$DV 2>/dev/null)
233
234         if [ -z "$KEY" ]; then
235           PUBKEY=0
236         else
237           PUBKEY=-1
238         fi
239       else
240         PUBKEY=1
241       fi
242
243       #echo "DEBUG:E:$ESSID N:$NWID M:$MODE C:$CHANNEL F:$FREQ S:$SENS R:$RATE K:$KEY R:$RTS F:$FRAG I:$IWCONFIG I:$IWSPY I:$IWPRIV"
244       rm -f "$TMP"
245     fi
246
247     $DIALOG --inputbox "$MESSAGEW4 $DEVICENAME $MESSAGEW5" 15 50 "$ESSID" 2>"$TMP" || bailout 1
248     read ESSID <"$TMP" ; rm -f "$TMP"
249     [ -z "$ESSID" ] && ESSID="any"
250
251     $DIALOG --inputbox "$MESSAGEW6 $DEVICENAME $MESSAGEW7" 15 50 "$NWID" 2>"$TMP" || bailout 1
252     read NWID <"$TMP" ; rm -f "$TMP"
253
254     $DIALOG --inputbox "$MESSAGEW8 $DEVICENAME $MESSAGEW9" 15 50 "$MODE" 2>"$TMP" || bailout 1
255     read MODE <"$TMP" ; rm -f "$TMP"
256     [ -z "$MODE" ] && MODE="Managed"
257
258     $DIALOG --inputbox "$MESSAGEW10 $DEVICENAME $MESSAGEW11" 15 50 "$CHANNEL" 2>"$TMP" || bailout 1
259     read CHANNEL <"$TMP" ; rm -f "$TMP"
260
261     if [ -z "$CHANNEL" ]; then
262       $DIALOG --inputbox "$MESSAGEW12 $DEVICENAME $MESSAGEW13" 15 50 "$FREQ" 2>"$TMP" || bailout 1
263       read FREQ <"$TMP" ; rm -f "$TMP"
264     fi
265
266     WPAON=0
267     IWDRIVER=$driver
268
269     case $IWDRIVER in
270       ath_pci)
271         WPA_DEV="madwifi"
272         ;;
273       ipw2200|ipw2100)
274         WPA_DEV="wext"
275         ;;
276       hostap)
277         WPA_DEV="hostap"
278         ;;
279     esac
280
281     if [ -z "$WPA_DEV" ]; then
282       if [ -d /proc/net/ndiswrapper/$DV ]; then
283         WPA_DEV=ndiswrapper
284       elif [ -d /proc/net/hostap/$DV ]; then
285         WPA_DEV=hostap
286       elif [ $WLDEVICECOUNT -eq 1 ]; then
287         if [ -e /proc/driver/atmel ]; then
288           WPA_DEV=atmel
289         fi
290       fi
291     fi
292
293     WPAON=-1
294
295     if [ -n "$WPA_DEV" ]; then
296       if $DIALOG --yesno "$MESSAGEW22" 15 50; then
297         # Other wpa options
298         # scan_ssid [0]|1
299         # bssid 00:11:22:33:44:55
300         # priority [0]|Integer
301         # proto [WPA RSN] WPA|RSN
302         # key_mgmt [WPA-PSK WPA-EAP]|NONE|WPA-PSK|WPA-EAP|IEEE8021X
303         # pairwise [CCMP TKIP]|CCMP|TKIP|NONE
304         # group [CCMP TKIP WEP105 WEP40]|CCMP|TKIP|WEP105|WEP40
305         # eapol_flags [3]|1|2
306
307       if ! $DIALOG --yesno "Is SSID broadcast enabled?" 15 50; then
308         APSCAN="ap_scan=2"
309       fi
310         WPAON=1
311         KEY=""
312         WPASECRET=$(awk '/network/{if(found){found=0}else{found=1}}/ssid/{if(/ssid="'"$ESSID"'"/){found=1}else{found=0}}/#scan_ssid=1/#psk=/{if(found){gsub(/^\W*#psk="/,"");gsub(/"\W*$/,"");print}}' /etc/wpa_supplicant.conf)
313
314         $DIALOG --inputbox "$MESSAGEW23 $ESSID" 15 50 "$WPASECRET" 2>"$TMP" || bailout 1
315         WPASECRET=$(sed -e 's/\\/\\/g' "$TMP") && rm -r "$TMP"
316
317         case $WPA_DEV in
318           hostap)
319             MODE="Managed"
320             ;;
321         esac
322       else
323         WPASECRET=""
324       fi
325     else
326       WPASECRET=""
327     fi
328
329     # No need for a wep key if we are using wpa
330     if [ ! $WPAON -eq 1 ]; then
331       $DIALOG --inputbox "$MESSAGEW14 $DEVICENAME $MESSAGEW15" 15 50 "$KEY" 2>"$TMP" || bailout 1
332       read KEY <"$TMP" ; rm -f "$TMP"
333
334       if [ -n "$KEY" -a "$PUBKEY" -eq 0 ]; then
335         if ! $DIALOG --yesno "$MESSAGEW25 $DEVICENAME $MESSAGEW26" 15 50; then
336           PUBKEY=1
337         fi
338       fi
339     fi
340
341     $DIALOG --inputbox "$MESSAGEW16 $DEVICENAME $MESSAGEW17" 15 50 "$IWCONFIG" 2>"$TMP" || bailout 1
342     read IWCONFIG <"$TMP" ; rm -f "$TMP"
343
344     $DIALOG --inputbox "$MESSAGEW18 $DEVICENAME $MESSAGEW19" 15 50 "$IWSPY" 2>"$TMP" || bailout 1
345     read IWSPY <"$TMP" ; rm -f "$TMP"
346
347     $DIALOG --inputbox "$MESSAGEW20 $DEVICENAME $MESSAGEW21" 15 50 "$IWPRIV" 2>"$TMP" || bailout 1
348     read IWPRIV <"$TMP" ; rm -f "$TMP"
349
350     writeiwline
351   fi
352
353   if $DIALOG --yesno "$MESSAGE2" 8 45; then
354     if [ -w /etc/network/interfaces ]; then
355       rm -f "$TMP"
356       awk '/iface/{if(/'"$DV"'/){found=1}else{found=0}}
357         /^\W$/{if(blank==0){lastblank=1}else{lastblank=0}{blank=1}}
358         /\w/{blank=0;lastblank=0}
359         {if(!(found+lastblank)){print}}
360         END{print "iface '"$DV"' inet dhcp"}' \
361         /etc/network/interfaces >"$TMP"
362       echo -e "$IWOURLINE" >> $TMP
363       #echo -e "\n\n" >> $TMP
364       cat "$TMP" >/etc/network/interfaces
365       rm -f "$TMP"
366       # Add an "auto" entry
367       #addauto
368     fi
369   else
370     if [ -f /etc/network/interfaces ]; then
371       awk '/iface/{if(/'"$DV"'/){found=1}else{found=0}}
372         /address/{if(found){address=$NF}}
373         /netmask/{if(found){netmask=$NF}}
374         /broadcast/{if(found){broadcast=$NF}}
375         /gateway/{if(found){gateway=$NF}}
376         END{print address" "netmask" "broadcast" "gateway}' /etc/network/interfaces >"$TMP"
377       read IP NM BC DG <"$TMP"
378       rm -f "$TMP"
379     fi
380
381     $DIALOG --inputbox "$MESSAGE6 $DV" 10 45 "${IP:-192.168.0.1}" 2>"$TMP" || bailout 1
382     read IP <"$TMP" ; rm -f "$TMP"
383
384     $DIALOG --inputbox "$MESSAGE7 $DV" 10 45 "${NM:-255.255.255.0}" 2>"$TMP" || bailout 1
385     read NM <"$TMP" ; rm -f "$TMP"
386
387     $DIALOG --inputbox "$MESSAGE8 $DV" 10 45 "${BC:-${IP%.*}.255}" 2>"$TMP" || bailout 1
388     read BC <"$TMP" ; rm -f "$TMP"
389
390     $DIALOG --inputbox "$MESSAGE9" 10 45 "${DG:-${IP%.*}.254}" 2>"$TMP"
391     read DG <"$TMP" ; rm -f "$TMP"
392
393     if [ -f "/etc/resolv.conf" ]; then
394       NS="$(awk '/^nameserver/{printf "%s ",$2}' /etc/resolv.conf)"
395     fi
396
397     $DIALOG --inputbox "$MESSAGE10" 10 45 "${NS:-${IP%.*}.254}" 2>"$TMP"
398     read NS <"$TMP" ; rm -f "$TMP"
399
400     if [ -w /etc/network/interfaces ]; then
401       awk '/iface/{if(/'"$DV"'/){found=1}else{found=0}}
402         {if(!found){print}}
403         END{print "\niface '"$DV"' inet static\n\taddress '"$IP"'\n\tnetmask '"$NM"'\n\tnetwork '"${IP%.*}.0"'";if("'"$BC"'"!=""){print "\tbroadcast '"$BC"'"};if("'"$DG"'"!=""){print "\tgateway '"$DG"'"};if("'"$IWOURLINE"'"!=""){print "'"$IWOURLINE"'"};print "\n"}' \
404         /etc/network/interfaces >"$TMP"
405
406       cat "$TMP" >/etc/network/interfaces
407       rm -f "$TMP"
408
409       # Add an "auto" entry
410       #addauto
411     fi
412
413     if [ -n "$NS" ]; then
414       more=""
415
416       for i in $NS; do
417         if [ -z "$more" ]; then
418           more=yes
419           echo "$MESSAGE11 $i"
420           echo "nameserver $i" >/etc/resolv.conf
421         else
422           echo "$MESSAGE12 $i"
423           echo "nameserver $i" >>/etc/resolv.conf
424         fi
425       done
426     fi
427   fi
428   echo "Done."
429 }
430
431 DIALOG="dialog"
432 # export XDIALOG_HIGH_DIALOG_COMPAT=1
433 # [ -n "$DISPLAY" ] && [ -x /usr/bin/Xdialog ] && DIALOG="Xdialog"
434
435 # LANGUAGE etc.
436 [ -r /etc/default/locale ] && . /etc/default/locale
437
438 # Default all strings to English
439 NET_DEVICE_NAME="Network_device"
440 NET_DEVICE_NAME_W="Wireless_device"
441 NET_DEVICE_NAME_FW="Firewire_device"
442 NET_DEVICE_NAME_AUTO="Auto"
443 MESSAGE0="No supported network cards found."
444 MESSAGE1="Please select network device"
445 MESSAGE2="Use DHCP broadcast?"
446 MESSAGE3="Sending DHCP broadcast from device"
447 MESSAGE4="Failed."
448 MESSAGE5="Hit return to exit."
449 MESSAGE6="Please enter IP Address for "
450 MESSAGE7="Please enter Network Mask for "
451 MESSAGE8="Please enter Broadcast Address for "
452 MESSAGE9="Please enter Default Gateway"
453 MESSAGE10="Please enter Nameserver(s)"
454 MESSAGE11="Setting Nameserver in /etc/resolv.conf to"
455 MESSAGE12="Adding Nameserver to /etc/resolv.conf:"
456 MESSAGE13="Setup wireless options?"
457 MESSAGE14="Failed to bring up the interface, would you like to reconfigure it?"
458 MESSAGE15="Interface enabled, do you want it auto enabled at boot?"
459 MESSAGEW0="No wireless network card found."
460 MESSAGEW1="Configuration of wireless parameters for"
461 MESSAGEW3="Please configure IP parameters of the interface first"
462 MESSAGEW4="Enter the ESSID for"
463 MESSAGEW5="\n\n\n(empty for 'any', not recommended !)\n"
464 MESSAGEW6="Enter the NWID (cell identifier)\nfor"
465 MESSAGEW7=", if needed\n\n\n"
466 MESSAGEW8="Enter the mode for"
467 MESSAGEW9="\n\n(Managed(=default), Ad-Hoc, Master,\nRepeater, Secondary, auto)\n"
468 MESSAGEW10="Enter channel number for"
469 MESSAGEW11="\n\n(0 bis 16, empty for auto or if you want to\n enter the frequency next)\n"
470 MESSAGEW12="Enter the frequency for"
471 MESSAGEW13="\n\n(e.g 2.412G, empty for auto)"
472 MESSAGEW14="Enter the encryption key\nfor"
473 MESSAGEW15="\n\n(empty for cleartext, not recommended !!)"
474 MESSAGEW16="Enter additional parameters for\n'iwconfig"
475 MESSAGEW17="' if needed, e.g.\n\n\nsens -80  rts 512  frag 512  rate 5.5M"
476 MESSAGEW18="Enter additional parameters for\n'iwspy"
477 MESSAGEW19="' if needed\n\n\n"
478 MESSAGEW20="Enter additional parameters for\n'iwpriv"
479 MESSAGEW21="' if needed\n\n\n"
480 MESSAGEW22="Enable WPA support?"
481 MESSAGEW23="Enter the WPA passphrase (passphrase must be 8..63 characters) for"
482 MESSAGEW25="Would you like to store your wep key in it's own private file ("
483 MESSAGEW26=")?   If you say no, your wep key will be stored in /etc/network/interfaces and will be readable by any account on your system.  You may want to 'chmod 600 /etc/network/interfaces' if you answer no to this question"
484 MESSAGEW27="Is SSID broadcast enabled?"
485
486 case "$LANGUAGE" in
487   de|at|ch)
488     NET_DEVICE_NAME="Netzwerkkarte"
489     MESSAGE0="Keine unterstützten Netzwerkkarte(n) gefunden."
490     MESSAGE1="Bitte Netzwerkkarte auswählen"
491     MESSAGE2="DHCP Broadcast zur Konfiguration benutzen? (Nein=manuell)"
492     MESSAGE3="Sende DHCP Broadcast von Netzwerkkarte"
493     MESSAGE4="Fehlgeschlagen."
494     MESSAGE5="Eingabetaste zum Beenden."
495     MESSAGE6="Bitte geben Sie die IP-Adresse ein für "
496     MESSAGE7="Bitte geben Sie die Netzwerk-Maske ein für "
497     MESSAGE8="Bitte geben Sie die Broadcast-Adresse ein für "
498     MESSAGE9="Bitte geben Sie das Default-Gateway ein"
499     MESSAGE10="Bitte geben Sie den/die Nameserver ein"
500     MESSAGE11="Setze Nameserver in /etc/resolv.conf auf "
501     MESSAGE12="Füge Nameserver in /etc/resolv.conf hinzu:"
502     MESSAGE13="WLAN-Einstellungen konfigurieren?"
503     MESSAGE14="Fehler beim Aktivieren des Interface, wollen Sie es neu konfigurieren?"
504     MESSAGE15="Interface aktiviert, beim Systemstart automatisch aktivieren?"
505     MESSAGEW0="Keine Wireless-Netzwerkkarte gefunden."
506     MESSAGEW1="Konfiguration der Wireless-Parameter von"
507     MESSAGEW2="Bitte Wireless-Netzwerkkarte auswählen"
508     MESSAGEW3="Bitte konfigurieren Sie vorher die IP-Parameter der Karte !"
509     MESSAGEW4="Geben Sie die ESSID für"
510     MESSAGEW5="ein\n\n\n(leer für 'any', nicht zu empfehlen !!)\n"
511     MESSAGEW6="Geben Sie ggf. die NWID (Cell Identifier)\nfür"
512     MESSAGEW7="ein, falls es eine gibt\n\n\n"
513     MESSAGEW8="Geben Sie den Modus für"
514     MESSAGEW9="ein\n\n(Managed(=default), Ad-Hoc, Master,\nRepeater, Secondary, auto)\n"
515     MESSAGEW10="Geben Sie den Kanal für"
516     MESSAGEW11="ein\n\n(0 bis 16, leer für auto oder Frequenz-\neingabe im nächsten Fenster)\n"
517     MESSAGEW12="Geben Sie die Frequenz für"
518     MESSAGEW13="ein\n\n(z.B. 2.412G, leer für auto)"
519     MESSAGEW14="Geben Sie den Verschlüsselungs-Key\nfür"
520     MESSAGEW15="ein\n\n(leer für Klartext, nicht zu empfehlen !!)"
521     MESSAGEW16="Geben Sie ggf. zusätzliche Parameter für\n'iwconfig"
522     MESSAGEW17="' ein, z.B.\n\n\nsens -80  rts 512  frag 512  rate 5.5M"
523     MESSAGEW18="Geben Sie ggf. zusätzliche Parameter für\n'iwspy"
524     MESSAGEW19="' ein\n\n\n"
525     MESSAGEW20="Geben Sie ggf. zusätzliche Parameter für\n'iwpriv"
526     MESSAGEW21="' ein\n\n\n"
527     MESSAGEW22="WPA-Unterstützung aktivieren?"
528     MESSAGEW23="WPA-Passwort eingeben für"
529     MESSAGEW25="WEP-Schlüssel in privater Datei abspeichern ("
530     MESSAGEW26="? Wenn Sie hier Nein sagen, wird der WEP-Schlüssel in /etc/network/interfaces abgespeichert und kann von allen Accounts auf dem System gelesen werden. Wenn Sie mit Nein antworten, sollten Sie vielleicht 'chmod 600 /etc/network/interfaces' ausführen."
531     MESSAGEW27="Ist SSID Broadcast aktiviert?"
532     ;;
533   es)
534     NET_DEVICE_NAME="Dispositivo_de_la_red"
535     MESSAGE0="Se han encontrado tarjetas de red no soportadas."
536     MESSAGE1="Por favor, seleccione el dispositivo fisico  de red"
537     MESSAGE2="¿Utilizar broadcast DHCP?"
538     MESSAGE3="Enviando broadcast DHCP desde el dispositivo"
539     MESSAGE4="Fallado."
540     MESSAGE5="Pulse enter para salir."
541     MESSAGE6="Por favor, inserte la dirección IP para "
542     MESSAGE7="Por favor, inserte la máscara de red para "
543     MESSAGE8="Por favor, inserte la dirección de Broadcast para "
544     MESSAGE9="Por favor, inserte la puerta de enlace por defecto"
545     MESSAGE10="Por favor, inserte los servidores DNS"
546     MESSAGE11="Poniendo los servidores de nombres de /etc/resolv.conf a "
547     MESSAGE12="Adicionando servidor DNS a /etc/resolv.conf:"
548     MESSAGEW0="No se ha encontrado una tarjeta inalámbrica."
549     MESSAGEW1="Configuración de los parámetros inalámbricos para"
550     MESSAGEW2="Por favor, seleccione un dispositivo de red inalámbrico"
551     MESSAGEW3="Por favor, configure primero los parámetros de la IP para la interfaz"
552     MESSAGEW4="Teclee el ESSID para"
553     MESSAGEW5="\n\n\n(vacío para 'cualquiera', ¡no recomendado!)\n"
554     MESSAGEW6="Teclee el NWID (identificador de celda)\npara"
555     MESSAGEW7=", si es necesario\n\n\n"
556     MESSAGEW8="Teclee el modo para"
557     MESSAGEW9="\n\n(Managed(=por_defecto), Ad-Hoc, Master,\nRepeater, Secondary, auto)\n"
558     MESSAGEW10="Teclee el número del canal para"
559     MESSAGEW11="\n\n(0 bis 16, vacío para auto o si lo prefiere\n teclee la frecuencia seguidamente)\n"
560     MESSAGEW12="Teclee la frecuencia para"
561     MESSAGEW13="\n\n(ej. 2.412G, vacío para auto)"
562     MESSAGEW14="Teclee la clave de encriptación\npara"
563     MESSAGEW15="\n\n(vacío para texto plano, ¡¡no recomendado!!)"
564     MESSAGEW16="Teclee los parámetros adicionales para\n'iwconfig"
565     MESSAGEW17="' Si es necesario, ej.\n\n\nsens -80  rts 512  frag 512  rate 5.5M"
566     MESSAGEW18="Teclee los parámetros adicionales para\n'iwspy"
567     MESSAGEW19="' si es necesario\n\n\n"
568     MESSAGEW20="Teclee los parámetros adicionales para\n'iwpriv"
569     MESSAGEW21="' si es necesario\n\n\n"
570     ;;
571   it)
572     NET_DEVICE_NAME="Periferica_di_rete"
573     NET_DEVICE_NAME_W="Periferica_Wireless"
574     NET_DEVICE_NAME_FW="Periferica_Firewire"
575     NET_DEVICE_NAME_AUTO="Automatico"
576     MESSAGE0="Non ho trovato schede di rete supportate."
577     MESSAGE1="Per favore seleziona la periferica di rete"
578     MESSAGE2="Devo utilizzare il broadcast DHCP?"
579     MESSAGE3="Sto inviando il broadcast DHCP dalla periferica"
580     MESSAGE4="Fallito."
581     MESSAGE5="Premi invio per uscire."
582     MESSAGE6="Inserisci l'indirizzo IP per "
583     MESSAGE7="Inserisci la maschera di rete per "
584     MESSAGE8="Inserisci l'indirizzo di broadcast per "
585     MESSAGE9="Inserisci il Gateway di default"
586     MESSAGE10="Inserisci i Nameserver"
587     MESSAGE11="Sto settando i Nameserver in /etc/resolv.conf a"
588     MESSAGE12="Aggiungo i Nameserver in /etc/resolv.conf:"
589     MESSAGE13="Configuro le opzioni del wireless?"
590     MESSAGE14="Non riesco ad attivare l'interfaccia, vuoi riconfigurarla?"
591     MESSAGE15="Interfaccia attiva, vuoi abilitarla automaticamente all'avvio?"
592     MESSAGEW0="Nessuna scheda di rete wireless trovata."
593     MESSAGEW1="Configurazione dei parametri wireless per"
594     MESSAGEW3="Configura i parametri IP dell'interfaccia per prima cosa!"
595     MESSAGEW4="Inserisci l'ESSID per"
596     MESSAGEW5="\n\n\n(vuoto per 'tutti', non raccomandato!)\n"
597     MESSAGEW6="Inserisci il NWID (cell identifier)\nper"
598     MESSAGEW7=", se necessario\n\n\n"
599     MESSAGEW8="Inserisci la modalità per"
600     MESSAGEW9="\n\n(Managed(=default), Ad-Hoc, Master,\nRepeater, Secondary, auto)\n"
601     MESSAGEW10="Inserisci il numero di canale per"
602     MESSAGEW11="\n\n(da 0 a 16, vuoto per automatico o se vuoi\n inserire la frequnza dopo)\n"
603     MESSAGEW12="Inserisci la frequenza per"
604     MESSAGEW13="\n\n(es. 2.412G, vuoto per automatico)"
605     MESSAGEW14="Inserisci la chiave crittografica\nper"
606     MESSAGEW15="\n\n(vuoto per trasmissione in chiaro, non raccomandato!)"
607     MESSAGEW16="Inserisci i parametri aggiuntivi per\n'iwconfig"
608     MESSAGEW17="' se necessario, es.\n\n\nsens -80  rts 512  frag 512  rate 5.5M"
609     MESSAGEW18="Inserisci parametri aggiuntivi per\n'iwspy"
610     MESSAGEW19="' se necessario\n\n\n"
611     MESSAGEW20="Inserisci parametri aggiuntivi per\n'iwpriv"
612     MESSAGEW21="' se necessario\n\n\n"
613     MESSAGEW22="Abilito il supporto WPA?"
614     MESSAGEW23="Inserisci la Passphrase di WPA\nper"
615     MESSAGEW25="Vuoi memorizzare la tua chiave WEP nel suo file riservato ("
616     MESSAGEW26=")?   Se dici no, la tua chiave WEP sarà memorizzata nel file /etc/network/interfaces e sarà leggibile da tutti gli account del tuo sistema. Dovresti fare 'chmod 600 /etc/network/interfaces' se rispondi no a questa domanda"
617     MESSAGEW27="Is SSID broadcast enabled?"
618     ;;
619 fr)
620     NET_DEVICE_NAME="Carte_réseau"
621     MESSAGE0="Aucune carte réseau supportée trouvée."
622     MESSAGE1="Sélectionnez la carte réseau, svp"
623     MESSAGE2="Voulez-vous utiliser DHCP?"
624     MESSAGE3="Envoi de broadcast DHCP par la carte"
625     MESSAGE4="Echec."
626     MESSAGE5="Appuyez sur Entrée pour quitter."
627     MESSAGE6="Entrez une adresse IP pour "
628     MESSAGE7="Entrez le Masque de Sous-réseau pour "
629     MESSAGE8="Entrez l'adresse Broadcast pour "
630     MESSAGE9="Entrez l'IP de la Passerelle par Défaut"
631     MESSAGE10="Entrez Les DNS de votre FAI"
632     MESSAGE11="Réglage des DNS dans /etc/resolv.conf"
633     MESSAGE12="Ajoût des DNS dans /etc/resolv.conf:"
634     MESSAGEW0="Aucune carte Wifi trouvée."
635     MESSAGEW1="Configuration des paramètres de réseau sans fil pour "
636     MESSAGEW3="SVP, Commencez par configurer les paramètres d'IP de l'interface!"
637     MESSAGEW4="Entrez l'ESSID pour"
638     MESSAGEW5="\n\n\n(ne rien mettre pour 'peu importe' n'est pas recommandé !)\n"
639     MESSAGEW6="Entrez le NWID (cell identifier)\npour"
640     MESSAGEW7=", si nécessaire\n\n\n"
641     MESSAGEW8="Entrez le mode pour "
642     MESSAGEW9="\n\n(Managed(=default), Ad-Hoc, Master,\nRepeater, Secondary, auto)\n"
643     MESSAGEW10="Entrez numéro de canal pour"
644     MESSAGEW11="\n\n(0 à 16, vide pour auto ou si vous voulez\n entrer la fréquence ensuite)\n"
645     MESSAGEW12="Entrez la fréquence pour"
646     MESSAGEW13="\n\n(ex: 2.412G, vide pour auto)"
647     MESSAGEW14="Entrez la clé de cryptage\npour"
648     MESSAGEW15="\n\n(vide pour texte en clair, non recommandé !!)"
649     MESSAGEW16="Entrez des paramètres additionnels pour\n'iwconfig"
650     MESSAGEW17="' si nécessaire, comme \n\n\nsens -80  rts 512  frag 512  rate 5.5M"
651     MESSAGEW18="Entrer des paramètres additionnels pour\n'iwspy"
652     MESSAGEW19="' si nécessaire\n\n\n"
653     MESSAGEW20="Entrer des paramètres additionnels pour\n'iwpriv"
654     MESSAGEW21="' si nécessaire\n\n\n"
655     MESSAGEW22="Activer la protection WPA?"
656     MESSAGEW23="Entrez le mot-de-passe WPA pour"
657     MESSAGEW25="Clé WEP sauvée dans un fichier privé ("
658     MESSAGEW26="? Si vous répondez non ici, la clé WEP sera stockée dans /etc/network/interfaces et pourra être accessible à tous les utilisateurs de la machine. Peut-être serait-il alors judicieux de fixer ainsi les droits de 'interfaces': 'chmod 600 /etc/network/interfaces'"
659     MESSAGEW27="Is SSID broadcast enabled?"
660     ;;
661 esac
662
663 NETDEVICESCOUNT=0
664 LAN=$(tail -n +3 /proc/net/dev|awk -F: '{print $1}'|sed "s/\s*//"|grep -v -e ^lo -e ^vmnet|sort)
665 [ -n "$WLAN" ] || WLAN=$(tail -n +3 /proc/net/wireless 2>/dev/null|awk -F: '{print $1}'|sort)
666 unset LAN_DEVICES WLAN_DEVICES FIREWIRE_DEVICES NETDEVICES
667 while read dev mac; do
668 #echo "Making NETDEVICES $NETDEVICESCOUNT $dev"
669   iswlan=$(echo $dev $WLAN|tr ' ' '\n'|sort|uniq -d)
670   isauto="0"
671   grep auto /etc/network/interfaces | grep -q $dev && isauto="1"
672   driver=$(ethtool -i $dev 2>/dev/null|awk '/^driver:/{print $2}')
673   if [ "$driver" ]; then
674     if [ "$iswlan" ]; then
675       NETDEVICES[$NETDEVICESCOUNT]="$dev A::$isauto M::$mac D::$driver W::1 F::0"
676     else
677       NETDEVICES[$NETDEVICESCOUNT]="$dev A::$isauto M::$mac D::$driver W::0 F::0"
678     fi
679   else
680     if [ "$iswlan" ]; then
681       NETDEVICES[$NETDEVICESCOUNT]="$dev A::$isauto M::$mac W::1 F::0"
682     else
683       NETDEVICES[$NETDEVICESCOUNT]="$dev A::$isauto M::$mac W::0 F::0"
684     fi
685   fi
686 #echo "Made to ${NETDEVICES[$NETDEVICESCOUNT]}"
687   ((NETDEVICESCOUNT++))
688 done < <(ifconfig -a|grep Ethernet|grep -v ^vmnet|awk '! /^\s/{print $1" "$5}')
689 for dev in $LAN; do
690   if [ "$(ethtool -i $dev 2>/dev/null|awk '/^bus-info:/{print $2}')" == "ieee1394" ]; then
691     isauto="0"
692     grep auto /etc/network/interfaces | grep -q $dev && isauto="1"
693     NETDEVICES[$NETDEVICESCOUNT]="$dev A::$isauto D::$(ethtool -i $dev 2>/dev/null|awk '/^driver:/{print $2}') W::0 F::1"
694     ((NETDEVICESCOUNT++))
695   fi
696 done
697
698 #NETDEVICES="$(cat /proc/net/dev | awk -F: '/eth.:|lan.:|tr.:|wlan.:|ath.:|ra.:/{print $1}')"
699
700 if [ -z "$NETDEVICES" ]; then
701   $DIALOG --msgbox "$MESSAGE0" 15 45
702   bailout
703 fi
704
705 count="$NETDEVICESCOUNT"
706
707 if [ "$count" -gt 1 ]; then
708   DEVICELIST=""
709   mycount=0
710   while [ $mycount -lt $count ]; do
711     DEVICE=${NETDEVICES[$mycount]}
712 #echo "$mycount is $DEVICE"
713     device2props
714 #echo "name: $DEVICENAME auto: $isauto fw: $isfirewire mac: $mac driver: $driver"
715     props2string
716     DEVICELIST="$DEVICELIST $mycount $MY_DEVICE_NAME"
717     ((mycount++))
718   done
719 fi
720
721 # To translate
722 EXITKEY="E"
723 EXITMENU="$EXITKEY Exit"
724
725 # main program loop until they bailout
726 while (true); do
727   # first get the device
728   if [ "$count" -gt 1 ]; then
729     rm -f "$TMP"
730     $DIALOG --menu "$MESSAGE1" 18 60 12 $DEVICELIST $EXITMENU 2>"$TMP" || bailout
731     read DV <"$TMP" ; rm -f "$TMP"
732     [ "$DV" = "$EXITKEY" ] && bailout
733   else
734     # Only one device
735     DV=0
736     # they have asked to stop configuring the interface so exit
737     [ -z "$IFACEDONE" ] || bailout
738   fi
739   # device config loop
740   IFACEDONE=""
741   while [ -n "$DV" -a -z "$IFACEDONE" ]; do
742     configiface
743     ifdown $DV
744     sleep 3
745     if ! ifup $DV; then
746       $DIALOG --yesno "$MESSAGE14" 15 50 || IFACEDONE="DONE"
747     else
748       $DIALOG --yesno "$MESSAGE15" 15 50 && addauto || remauto
749       IFACEDONE="DONE"
750     fi
751   done
752 done
753
754 ## END OF FILE #################################################################