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