Merge remote-tracking branch 'origin/github/pr/45'
[grml.org.git] / scripts / 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: Mon Apr 17 21:48:36 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 [ -f /etc/sysconfig/i18n ] && . /etc/sysconfig/i18n
435
436 # Default all strings to English
437 NET_DEVICE_NAME="Network_device"
438 NET_DEVICE_NAME_W="Wireless_device"
439 NET_DEVICE_NAME_FW="Firewire_device"
440 NET_DEVICE_NAME_AUTO="Auto"
441 MESSAGE0="No supported network cards found."
442 MESSAGE1="Please select network device"
443 MESSAGE2="Use DHCP broadcast?"
444 MESSAGE3="Sending DHCP broadcast from device"
445 MESSAGE4="Failed."
446 MESSAGE5="Hit return to exit."
447 MESSAGE6="Please enter IP Address for "
448 MESSAGE7="Please enter Network Mask for "
449 MESSAGE8="Please enter Broadcast Address for "
450 MESSAGE9="Please enter Default Gateway"
451 MESSAGE10="Please enter Nameserver(s)"
452 MESSAGE11="Setting Nameserver in /etc/resolv.conf to"
453 MESSAGE12="Adding Nameserver to /etc/resolv.conf:"
454 MESSAGE13="Setup wireless options?"
455 MESSAGE14="Failed to bring up the interface, would you like to reconfigure it?"
456 MESSAGE15="Interface enabled, do you want it auto enabled at boot?"
457 MESSAGEW0="No wireless network card found."
458 MESSAGEW1="Configuration of wireless parameters for"
459 MESSAGEW3="Please configure IP parameters of the interface first"
460 MESSAGEW4="Enter the ESSID for"
461 MESSAGEW5="\n\n\n(empty for 'any', not recommended !)\n"
462 MESSAGEW6="Enter the NWID (cell identifier)\nfor"
463 MESSAGEW7=", if needed\n\n\n"
464 MESSAGEW8="Enter the mode for"
465 MESSAGEW9="\n\n(Managed(=default), Ad-Hoc, Master,\nRepeater, Secondary, auto)\n"
466 MESSAGEW10="Enter channel number for"
467 MESSAGEW11="\n\n(0 bis 16, empty for auto or if you want to\n enter the frequency next)\n"
468 MESSAGEW12="Enter the frequency for"
469 MESSAGEW13="\n\n(e.g 2.412G, empty for auto)"
470 MESSAGEW14="Enter the encryption key\nfor"
471 MESSAGEW15="\n\n(empty for cleartext, not recommended !!)"
472 MESSAGEW16="Enter additional parameters for\n'iwconfig"
473 MESSAGEW17="' if needed, e.g.\n\n\nsens -80  rts 512  frag 512  rate 5.5M"
474 MESSAGEW18="Enter additional parameters for\n'iwspy"
475 MESSAGEW19="' if needed\n\n\n"
476 MESSAGEW20="Enter additional parameters for\n'iwpriv"
477 MESSAGEW21="' if needed\n\n\n"
478 MESSAGEW22="Enable WPA support?"
479 MESSAGEW23="Enter the WPA passphrase (passphrase must be 8..63 characters) for"
480 MESSAGEW25="Would you like to store your wep key in it's own private file ("
481 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"
482 MESSAGEW27="Is SSID broadcast enabled?"
483
484 case "$LANGUAGE" in
485   de|at|ch)
486     NET_DEVICE_NAME="Netzwerkkarte"
487     MESSAGE0="Keine unterstützten Netzwerkkarte(n) gefunden."
488     MESSAGE1="Bitte Netzwerkkarte auswählen"
489     MESSAGE2="DHCP Broadcast zur Konfiguration benutzen? (Nein=manuell)"
490     MESSAGE3="Sende DHCP Broadcast von Netzwerkkarte"
491     MESSAGE4="Fehlgeschlagen."
492     MESSAGE5="Eingabetaste zum Beenden."
493     MESSAGE6="Bitte geben Sie die IP-Adresse ein für "
494     MESSAGE7="Bitte geben Sie die Netzwerk-Maske ein für "
495     MESSAGE8="Bitte geben Sie die Broadcast-Adresse ein für "
496     MESSAGE9="Bitte geben Sie das Default-Gateway ein"
497     MESSAGE10="Bitte geben Sie den/die Nameserver ein"
498     MESSAGE11="Setze Nameserver in /etc/resolv.conf auf "
499     MESSAGE12="Füge Nameserver in /etc/resolv.conf hinzu:"
500     MESSAGE13="WLAN-Einstellungen konfigurieren?"
501     MESSAGE14="Fehler beim Aktivieren des Interface, wollen Sie es neu konfigurieren?"
502     MESSAGE15="Interface aktiviert, beim Systemstart automatisch aktivieren?"
503     MESSAGEW0="Keine Wireless-Netzwerkkarte gefunden."
504     MESSAGEW1="Konfiguration der Wireless-Parameter von"
505     MESSAGEW2="Bitte Wireless-Netzwerkkarte auswählen"
506     MESSAGEW3="Bitte konfigurieren Sie vorher die IP-Parameter der Karte !"
507     MESSAGEW4="Geben Sie die ESSID für"
508     MESSAGEW5="ein\n\n\n(leer für 'any', nicht zu empfehlen !!)\n"
509     MESSAGEW6="Geben Sie ggf. die NWID (Cell Identifier)\nfür"
510     MESSAGEW7="ein, falls es eine gibt\n\n\n"
511     MESSAGEW8="Geben Sie den Modus für"
512     MESSAGEW9="ein\n\n(Managed(=default), Ad-Hoc, Master,\nRepeater, Secondary, auto)\n"
513     MESSAGEW10="Geben Sie den Kanal für"
514     MESSAGEW11="ein\n\n(0 bis 16, leer für auto oder Frequenz-\neingabe im nächsten Fenster)\n"
515     MESSAGEW12="Geben Sie die Frequenz für"
516     MESSAGEW13="ein\n\n(z.B. 2.412G, leer für auto)"
517     MESSAGEW14="Geben Sie den Verschlüsselungs-Key\nfür"
518     MESSAGEW15="ein\n\n(leer für Klartext, nicht zu empfehlen !!)"
519     MESSAGEW16="Geben Sie ggf. zusätzliche Parameter für\n'iwconfig"
520     MESSAGEW17="' ein, z.B.\n\n\nsens -80  rts 512  frag 512  rate 5.5M"
521     MESSAGEW18="Geben Sie ggf. zusätzliche Parameter für\n'iwspy"
522     MESSAGEW19="' ein\n\n\n"
523     MESSAGEW20="Geben Sie ggf. zusätzliche Parameter für\n'iwpriv"
524     MESSAGEW21="' ein\n\n\n"
525     MESSAGEW22="WPA-Unterstützung aktivieren?"
526     MESSAGEW23="WPA-Passwort eingeben für"
527     MESSAGEW25="WEP-Schlüssel in privater Datei abspeichern ("
528     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."
529     MESSAGEW27="Ist SSID Broadcast aktiviert?"
530     ;;
531   es)
532     NET_DEVICE_NAME="Dispositivo_de_la_red"
533     MESSAGE0="Se han encontrado tarjetas de red no soportadas."
534     MESSAGE1="Por favor, seleccione el dispositivo fisico  de red"
535     MESSAGE2="¿Utilizar broadcast DHCP?"
536     MESSAGE3="Enviando broadcast DHCP desde el dispositivo"
537     MESSAGE4="Fallado."
538     MESSAGE5="Pulse enter para salir."
539     MESSAGE6="Por favor, inserte la dirección IP para "
540     MESSAGE7="Por favor, inserte la máscara de red para "
541     MESSAGE8="Por favor, inserte la dirección de Broadcast para "
542     MESSAGE9="Por favor, inserte la puerta de enlace por defecto"
543     MESSAGE10="Por favor, inserte los servidores DNS"
544     MESSAGE11="Poniendo los servidores de nombres de /etc/resolv.conf a "
545     MESSAGE12="Adicionando servidor DNS a /etc/resolv.conf:"
546     MESSAGEW0="No se ha encontrado una tarjeta inalámbrica."
547     MESSAGEW1="Configuración de los parámetros inalámbricos para"
548     MESSAGEW2="Por favor, seleccione un dispositivo de red inalámbrico"
549     MESSAGEW3="Por favor, configure primero los parámetros de la IP para la interfaz"
550     MESSAGEW4="Teclee el ESSID para"
551     MESSAGEW5="\n\n\n(vacío para 'cualquiera', ¡no recomendado!)\n"
552     MESSAGEW6="Teclee el NWID (identificador de celda)\npara"
553     MESSAGEW7=", si es necesario\n\n\n"
554     MESSAGEW8="Teclee el modo para"
555     MESSAGEW9="\n\n(Managed(=por_defecto), Ad-Hoc, Master,\nRepeater, Secondary, auto)\n"
556     MESSAGEW10="Teclee el número del canal para"
557     MESSAGEW11="\n\n(0 bis 16, vacío para auto o si lo prefiere\n teclee la frecuencia seguidamente)\n"
558     MESSAGEW12="Teclee la frecuencia para"
559     MESSAGEW13="\n\n(ej. 2.412G, vacío para auto)"
560     MESSAGEW14="Teclee la clave de encriptación\npara"
561     MESSAGEW15="\n\n(vacío para texto plano, ¡¡no recomendado!!)"
562     MESSAGEW16="Teclee los parámetros adicionales para\n'iwconfig"
563     MESSAGEW17="' Si es necesario, ej.\n\n\nsens -80  rts 512  frag 512  rate 5.5M"
564     MESSAGEW18="Teclee los parámetros adicionales para\n'iwspy"
565     MESSAGEW19="' si es necesario\n\n\n"
566     MESSAGEW20="Teclee los parámetros adicionales para\n'iwpriv"
567     MESSAGEW21="' si es necesario\n\n\n"
568     ;;
569   it)
570     NET_DEVICE_NAME="Periferica_di_rete"
571     NET_DEVICE_NAME_W="Periferica_Wireless"
572     NET_DEVICE_NAME_FW="Periferica_Firewire"
573     NET_DEVICE_NAME_AUTO="Automatico"
574     MESSAGE0="Non ho trovato schede di rete supportate."
575     MESSAGE1="Per favore seleziona la periferica di rete"
576     MESSAGE2="Devo utilizzare il broadcast DHCP?"
577     MESSAGE3="Sto inviando il broadcast DHCP dalla periferica"
578     MESSAGE4="Fallito."
579     MESSAGE5="Premi invio per uscire."
580     MESSAGE6="Inserisci l'indirizzo IP per "
581     MESSAGE7="Inserisci la maschera di rete per "
582     MESSAGE8="Inserisci l'indirizzo di broadcast per "
583     MESSAGE9="Inserisci il Gateway di default"
584     MESSAGE10="Inserisci i Nameserver"
585     MESSAGE11="Sto settando i Nameserver in /etc/resolv.conf a"
586     MESSAGE12="Aggiungo i Nameserver in /etc/resolv.conf:"
587     MESSAGE13="Configuro le opzioni del wireless?"
588     MESSAGE14="Non riesco ad attivare l'interfaccia, vuoi riconfigurarla?"
589     MESSAGE15="Interfaccia attiva, vuoi abilitarla automaticamente all'avvio?"
590     MESSAGEW0="Nessuna scheda di rete wireless trovata."
591     MESSAGEW1="Configurazione dei parametri wireless per"
592     MESSAGEW3="Configura i parametri IP dell'interfaccia per prima cosa!"
593     MESSAGEW4="Inserisci l'ESSID per"
594     MESSAGEW5="\n\n\n(vuoto per 'tutti', non raccomandato!)\n"
595     MESSAGEW6="Inserisci il NWID (cell identifier)\nper"
596     MESSAGEW7=", se necessario\n\n\n"
597     MESSAGEW8="Inserisci la modalità per"
598     MESSAGEW9="\n\n(Managed(=default), Ad-Hoc, Master,\nRepeater, Secondary, auto)\n"
599     MESSAGEW10="Inserisci il numero di canale per"
600     MESSAGEW11="\n\n(da 0 a 16, vuoto per automatico o se vuoi\n inserire la frequnza dopo)\n"
601     MESSAGEW12="Inserisci la frequenza per"
602     MESSAGEW13="\n\n(es. 2.412G, vuoto per automatico)"
603     MESSAGEW14="Inserisci la chiave crittografica\nper"
604     MESSAGEW15="\n\n(vuoto per trasmissione in chiaro, non raccomandato!)"
605     MESSAGEW16="Inserisci i parametri aggiuntivi per\n'iwconfig"
606     MESSAGEW17="' se necessario, es.\n\n\nsens -80  rts 512  frag 512  rate 5.5M"
607     MESSAGEW18="Inserisci parametri aggiuntivi per\n'iwspy"
608     MESSAGEW19="' se necessario\n\n\n"
609     MESSAGEW20="Inserisci parametri aggiuntivi per\n'iwpriv"
610     MESSAGEW21="' se necessario\n\n\n"
611     MESSAGEW22="Abilito il supporto WPA?"
612     MESSAGEW23="Inserisci la Passphrase di WPA\nper"
613     MESSAGEW25="Vuoi memorizzare la tua chiave WEP nel suo file riservato ("
614     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"
615     MESSAGEW27="Is SSID broadcast enabled?"
616     ;;
617 fr)
618     NET_DEVICE_NAME="Carte_réseau"
619     MESSAGE0="Aucune carte réseau supportée trouvée."
620     MESSAGE1="Sélectionnez la carte réseau, svp"
621     MESSAGE2="Voulez-vous utiliser DHCP?"
622     MESSAGE3="Envoi de broadcast DHCP par la carte"
623     MESSAGE4="Echec."
624     MESSAGE5="Appuyez sur Entrée pour quitter."
625     MESSAGE6="Entrez une adresse IP pour "
626     MESSAGE7="Entrez le Masque de Sous-réseau pour "
627     MESSAGE8="Entrez l'adresse Broadcast pour "
628     MESSAGE9="Entrez l'IP de la Passerelle par Défaut"
629     MESSAGE10="Entrez Les DNS de votre FAI"
630     MESSAGE11="Réglage des DNS dans /etc/resolv.conf"
631     MESSAGE12="Ajoût des DNS dans /etc/resolv.conf:"
632     MESSAGEW0="Aucune carte Wifi trouvée."
633     MESSAGEW1="Configuration des paramètres de réseau sans fil pour "
634     MESSAGEW3="SVP, Commencez par configurer les paramètres d'IP de l'interface!"
635     MESSAGEW4="Entrez l'ESSID pour"
636     MESSAGEW5="\n\n\n(ne rien mettre pour 'peu importe' n'est pas recommandé !)\n"
637     MESSAGEW6="Entrez le NWID (cell identifier)\npour"
638     MESSAGEW7=", si nécessaire\n\n\n"
639     MESSAGEW8="Entrez le mode pour "
640     MESSAGEW9="\n\n(Managed(=default), Ad-Hoc, Master,\nRepeater, Secondary, auto)\n"
641     MESSAGEW10="Entrez numéro de canal pour"
642     MESSAGEW11="\n\n(0 à 16, vide pour auto ou si vous voulez\n entrer la fréquence ensuite)\n"
643     MESSAGEW12="Entrez la fréquence pour"
644     MESSAGEW13="\n\n(ex: 2.412G, vide pour auto)"
645     MESSAGEW14="Entrez la clé de cryptage\npour"
646     MESSAGEW15="\n\n(vide pour texte en clair, non recommandé !!)"
647     MESSAGEW16="Entrez des paramètres additionnels pour\n'iwconfig"
648     MESSAGEW17="' si nécessaire, comme \n\n\nsens -80  rts 512  frag 512  rate 5.5M"
649     MESSAGEW18="Entrer des paramètres additionnels pour\n'iwspy"
650     MESSAGEW19="' si nécessaire\n\n\n"
651     MESSAGEW20="Entrer des paramètres additionnels pour\n'iwpriv"
652     MESSAGEW21="' si nécessaire\n\n\n"
653     MESSAGEW22="Activer la protection WPA?"
654     MESSAGEW23="Entrez le mot-de-passe WPA pour"
655     MESSAGEW25="Clé WEP sauvée dans un fichier privé ("
656     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'"
657     MESSAGEW27="Is SSID broadcast enabled?"
658     ;;
659 esac
660
661 NETDEVICESCOUNT=0
662 LAN=$(tail +3 /proc/net/dev|awk -F: '{print $1}'|sed "s/\s*//"|grep -v -e ^lo -e ^vmnet|sort)
663 [ -n "$WLAN" ] || WLAN=$(tail +3 /proc/net/wireless|awk -F: '{print $1}'|sort)
664 unset LAN_DEVICES WLAN_DEVICES FIREWIRE_DEVICES NETDEVICES
665 while read dev mac; do
666 #echo "Making NETDEVICES $NETDEVICESCOUNT $dev"
667   iswlan=$(echo $dev $WLAN|tr ' ' '\n'|sort|uniq -d)
668   isauto="0"
669   grep auto /etc/network/interfaces | grep -q $dev && isauto="1"
670   driver=$(ethtool -i $dev 2>/dev/null|awk '/^driver:/{print $2}')
671   if [ "$driver" ]; then
672     if [ "$iswlan" ]; then
673       NETDEVICES[$NETDEVICESCOUNT]="$dev A::$isauto M::$mac D::$driver W::1 F::0"
674     else
675       NETDEVICES[$NETDEVICESCOUNT]="$dev A::$isauto M::$mac D::$driver W::0 F::0"
676     fi
677   else
678     if [ "$iswlan" ]; then
679       NETDEVICES[$NETDEVICESCOUNT]="$dev A::$isauto M::$mac W::1 F::0"
680     else
681       NETDEVICES[$NETDEVICESCOUNT]="$dev A::$isauto M::$mac W::0 F::0"
682     fi
683   fi
684 #echo "Made to ${NETDEVICES[$NETDEVICESCOUNT]}"
685   ((NETDEVICESCOUNT++))
686 done < <(ifconfig -a|grep Ethernet|grep -v ^vmnet|awk '! /^\s/{print $1" "$5}')
687 for dev in $LAN; do
688   if [ "$(ethtool -i $dev 2>/dev/null|awk '/^bus-info:/{print $2}')" == "ieee1394" ]; then
689     isauto="0"
690     grep auto /etc/network/interfaces | grep -q $dev && isauto="1"
691     NETDEVICES[$NETDEVICESCOUNT]="$dev A::$isauto D::$(ethtool -i $dev 2>/dev/null|awk '/^driver:/{print $2}') W::0 F::1"
692     ((NETDEVICESCOUNT++))
693   fi
694 done
695
696 #NETDEVICES="$(cat /proc/net/dev | awk -F: '/eth.:|lan.:|tr.:|wlan.:|ath.:|ra.:/{print $1}')"
697
698 if [ -z "$NETDEVICES" ]; then
699   $DIALOG --msgbox "$MESSAGE0" 15 45
700   bailout
701 fi
702
703 count="$NETDEVICESCOUNT"
704
705 if [ "$count" -gt 1 ]; then
706   DEVICELIST=""
707   mycount=0
708   while [ $mycount -lt $count ]; do
709     DEVICE=${NETDEVICES[$mycount]}
710 #echo "$mycount is $DEVICE"
711     device2props
712 #echo "name: $DEVICENAME auto: $isauto fw: $isfirewire mac: $mac driver: $driver"
713     props2string
714     DEVICELIST="$DEVICELIST $mycount $MY_DEVICE_NAME"
715     ((mycount++))
716   done
717 fi
718
719 # To translate
720 EXITKEY="E"
721 EXITMENU="$EXITKEY Exit"
722
723 # main program loop until they bailout
724 while (true); do
725   # first get the device
726   if [ "$count" -gt 1 ]; then
727     rm -f "$TMP"
728     $DIALOG --menu "$MESSAGE1" 18 60 12 $DEVICELIST $EXITMENU 2>"$TMP" || bailout
729     read DV <"$TMP" ; rm -f "$TMP"
730     [ "$DV" = "$EXITKEY" ] && bailout
731   else
732     # Only one device
733     DV=0
734     # they have asked to stop configuring the interface so exit
735     [ -z "$IFACEDONE" ] || bailout
736   fi
737   # device config loop
738   IFACEDONE=""
739   while [ -n "$DV" -a -z "$IFACEDONE" ]; do
740     configiface
741     ifdown $DV
742     sleep 3
743     if ! ifup $DV; then
744       $DIALOG --yesno "$MESSAGE14" 15 50 || IFACEDONE="DONE"
745     else
746       $DIALOG --yesno "$MESSAGE15" 15 50 && addauto || remauto
747       IFACEDONE="DONE"
748     fi
749   done
750 done
751
752 ## END OF FILE #################################################################