/
netcardconfig
executable file
·604 lines (530 loc) · 20.3 KB
/
netcardconfig
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
#!/bin/bash
# Filename: grml-network
# Purpose: configuration script for network
# Authors: Michael Prokop <mika@grml.org>, Marcel Wichern 2006, Klaus Knopper 2002, Niall Walsh + Stefan Lippers-Hollmann 2004-2007
# Bug-Reports: see http://grml.org/bugs/
# License: This file is licensed under the GPL v2.
################################################################################
# Changes have been merged from Kanotix's and Sidux's netcardconfig:
# http://kanotix.com/files/debian/pool/main/n/netcardconfig-kanotix/
# http://svn.berlios.de/wsvn/fullstory/configure-networkcard/trunk/
################################################################################
PATH="/bin:/sbin:/usr/bin:/usr/sbin"
LANGUAGE=C LANG=C
export PATH LANGUAGE LANG
. /etc/grml/script-functions
check4root || exit 1
TMP=$(mktemp)
bailout() {
rm -f "$TMP"
exit $1
}
# This function produces the IWOURLINE for interfaces
writeiwline() {
IWOURLINE=""
if [ -n "$NWID" ]; then
IWOURLINE="$IWOURLINE wireless-nwid $NWID\n"
fi
if [ -n "$MODE" ]; then
IWOURLINE="$IWOURLINE wireless-mode $MODE\n"
fi
if [ -n "$CHANNEL" ]; then
IWOURLINE="$IWOURLINE wireless-channel $CHANNEL\n"
fi
if [ -n "$FREQ" ]; then
IWOURLINE="$IWOURLINE wireless-freq $FREQ\n"
fi
if [ -n "$KEY" ]; then
if [ "$PUBKEY" -eq 1 ]; then
# Store the key in interfaces in wireless-key
IWOURLINE="$IWOURLINE wireless-key $KEY\n"
else
# Store the key in /etc/network/wep.$DV which is root readable only
# Use pre-up in interfaces to read and set it
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"
fi
fi
[ -d /sys/module/rt2??0/ ] && IWPREUPLINE="$IWPREUPLINE pre-up /sbin/ifconfig $DV up\n"
if [ -n "$IWCONFIG" ]; then
IWPREUPLINE="$IWPREUPLINE iwconfig $IWCONFIG\n"
fi
if [ -n "$IWSPY" ]; then
IWPREUPLINE="$IWPREUPLINE iwspy $IWSPY\n"
fi
if [ -n "$IWPRIV" ]; then
IWPREUPLINE="$IWPREUPLINE iwpriv $IWPRIV\n"
fi
# execute ESSID last, but make sure that it is written as first option
if [ -n "$ESSID" ]; then
IWOURLINE="$IWOURLINE wireless-essid $ESSID\n"
fi
if [ "$WPAON" -gt 0 ]; then
IWOURLINE="$IWOURLINE wpa-ssid $ESSID\n wpa-psk $WPASECRET\n"
fi
IWOURLINE="$IWOURLINE $IWPREUPLINE"
#echo "DEBUG: for interfaces $IWOURLINE"
}
generate_udev_entry() {
interface=''
mkdir -p /etc/udev/scripts
echo "# Auto generated script from netcardconfig on $(date)
# Executing this script generates an entry in /etc/udev/rules.d/z25_persistent-net.rules
# for you, please check z25_persistent-net.rules for existing entries before
# running this script (once more)." > /etc/udev/scripts/netcardconfig
for interface in `ifconfig | awk '/^[a-z]/ &&!/^lo/{ print $1} '` ; do
echo -n "INTERFACE=$interface /lib/udev/write_net_rules " >> /etc/udev/scripts/netcardconfig && \
if which udevadm >/dev/null 2>&1; then
udevadm info -a -p /sys/class/net/$interface | awk -F'==' '/address/ {print $2}' >> /etc/udev/scripts/netcardconfig
else
udevinfo -a -p /sys/class/net/$interface | awk -F'==' '/address/ {print $2}' >> /etc/udev/scripts/netcardconfig
fi
done
# send errors to /dev/null as well because the sed line inside the /lib/udev/write_net_rules
# script outputs a sed warning which might unsettle users
chmod +x /etc/udev/scripts/netcardconfig && /etc/udev/scripts/netcardconfig 1>/dev/null 2>&1
}
disable_config_dhcp() {
if grep -q CONFIG_DHCP /etc/grml/autoconfig ; then
sed -i "s|^CONFIG_DHCP.*|CONFIG_DHCP='no'|" /etc/grml/autoconfig
fi
}
device2props() {
PARTCOUNT=0
isauto=0
isfirewire=0
iswireless=0
driver=""
mac=""
for PART in $DEVICE; do
if [ $PARTCOUNT -eq 0 ]; then
DEVICENAME=$PART
else
echo $PART | grep -q A::1 && isauto=1
echo $PART | grep -q F::1 && isfirewire=1
echo $PART | grep -q W::1 && iswireless=1
[ -z "$driver" ] && driver=$(echo $PART|awk 'BEGIN {FS="::"} /^D:/{print $2}')
[ -z "$mac" ] && mac=$(echo $PART|awk 'BEGIN {FS="::"} /^M:/{print $2}')
fi
((PARTCOUNT++))
done
}
props2string() {
MY_DEVICE_NAME=""
[ $isfirewire -gt 0 ] && MY_DEVICE_NAME="$NET_DEVICE_NAME_FW"
[ -z "$MY_DEVICE_NAME" -a $iswireless -gt 0 ] && MY_DEVICE_NAME="$NET_DEVICE_NAME_W"
[ -z "$MY_DEVICE_NAME" ] && MY_DEVICE_NAME="$NET_DEVICE_NAME"
MY_DEVICE_NAME="$DEVICENAME $MY_DEVICE_NAME $mac $driver"
[ $isauto -gt 0 ] && MY_DEVICE_NAME="$MY_DEVICE_NAME $NET_DEVICE_NAME_AUTO"
MY_DEVICE_NAME=$(echo $MY_DEVICE_NAME | sed 's/\ /__/g')
}
addauto() {
if ! egrep -e "^auto[ ]+.*$DV" /etc/network/interfaces >/dev/null; then
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"
cat "$TMP" > /etc/network/interfaces
fi
}
remauto(){
if egrep -e "^auto[ ]+.*$DV" /etc/network/interfaces >/dev/null; then
perl -pi -e 's/^(auto.*)'$DV'(.*)$/$1$2/;' /etc/network/interfaces
fi
}
configiface() {
[ ! -r /etc/network/interfaces ] && touch /etc/network/interfaces
DEVICE=${NETDEVICES[$DV]}
device2props
DV=$DEVICENAME
ifdown $DV
sleep 3
# wireless config
WLDEVICE="$(LANG=C LC_MESSAGEWS=C iwconfig $DV 2>/dev/null | awk '/802\.11|READY|ESSID/{print $1}')"
WLDEVICECOUNT="$(LANG=C LC_MESSAGEWS=C iwconfig $DV 2>/dev/null | wc -l)"
if [ $iswireless -gt 0 ] && $DIALOG --yesno "$MESSAGE13" 8 45; then
ESSID=""
NWID=""
MODE=""
CHANNEL=""
FREQ=""
SENS=""
RATE=""
KEY=""
RTS=""
FRAG=""
IWCONFIG=""
IWSPY=""
IWPRIV=""
if [ -f /etc/network/interfaces ]; then
awk '/iface/{if(/'"$DV"'/){found=1}else{found=0}}
/essid/{if(found){for(i=NF;i>=2;i--)essid=$i "~" essid}}
/nwid/{if(found){nwid=$NF}}
/mode/{if(found){mode=$NF}}
/channel/{if(found){channel=$NF}}
/freq/{if(found){freq=$NF}}
/sens/{if(found){sens=$NF}}
/rate/{if(found){rate=$NF}}
/rts/{if(found){rts=$NF}}
/frag/{if(found){frag=$NF}}
/iwconfig/{if(!/KEY/){if(found){iwconfig=$NF}}}
/iwspy/{if(found){iwspy=$NF}}
/iwpriv/{if(found){iwpriv=$NF}}
/wireless[-_]key/{if(found){gsub(/^\W*wireless[-_]key\W*/,"");key=$0}}
END{
if (!(length(essid))){essid="~~~"}
if (!(length(nwid))){nwid="~~~"}
if (!(length(mode))){mode="~~~"}
if (!(length(channel))){channel="~~~"}
if (!(length(freq))){freq="~~~"}
if (!(length(sens))){sens="~~~"}
if (!(length(rate))){rate="~~~"}
if (!(length(rts))){rts="~~~"}
if (!(length(frag))){frag="~~~"}
if (!(length(iwconfig))){iwconfig="~~~"}
if (!(length(iwspy))){iwspy="~~~"}
if (!(length(iwpriv))){iwpriv="~~~"}
if (!(length(key))){key="~~~"}
print essid" "nwid" "mode" "channel" "freq" "sens" "rate" "rts" "frag" "iwconfig" "iwspy" "iwpriv" "key
}' /etc/network/interfaces >"$TMP"
read ESSID NWID MODE CHANNEL FREQ SENS RATE RTS FRAG IWCONFIG IWSPY IWPRIV KEY<"$TMP"
[ "$ESSID" = "~~~" ] && ESSID=""
[ "$NWID" = "~~~" ] && NWID=""
[ "$MODE" = "~~~" ] && MODE=""
[ "$CHANNEL" = "~~~" ] && CHANNEL=""
[ "$FREQ" = "~~~" ] && FREQ=""
[ "$SENS" = "~~~" ] && SENS=""
[ "$RATE" = "~~~" ] && RATE=""
[ "$RTS" = "~~~" ] && RTS=""
[ "$FRAG" = "~~~" ] && FRAG=""
[ "$IWCONFIG" = "~~~" ] && IWCONFIG=""
[ "$IWSPY" = "~~~" ] && IWSPY=""
[ "$IWPRIV" = "~~~" ] && IWPRIV=""
[ "$KEY" = "~~~" ] && KEY=""
ESSID=$(echo $ESSID | tr "~" " " | sed 's/ *$//')
if [ -z "$KEY" ]; then
KEY=$(cat /etc/network/wep.$DV 2>/dev/null)
if [ -z "$KEY" ]; then
PUBKEY=0
else
PUBKEY=-1
fi
else
PUBKEY=1
fi
#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"
rm -f "$TMP"
fi
$DIALOG --inputbox "$MESSAGEW4 $DEVICENAME $MESSAGEW5" 15 50 "$ESSID" 2>"$TMP" || bailout 1
read ESSID <"$TMP" ; rm -f "$TMP"
[ -z "$ESSID" ] && ESSID="any"
$DIALOG --inputbox "$MESSAGEW6 $DEVICENAME $MESSAGEW7" 15 50 "$NWID" 2>"$TMP" || bailout 1
read NWID <"$TMP" ; rm -f "$TMP"
$DIALOG --inputbox "$MESSAGEW8 $DEVICENAME $MESSAGEW9" 15 50 "$MODE" 2>"$TMP" || bailout 1
read MODE <"$TMP" ; rm -f "$TMP"
[ -z "$MODE" ] && MODE="Managed"
$DIALOG --inputbox "$MESSAGEW10 $DEVICENAME $MESSAGEW11" 15 50 "$CHANNEL" 2>"$TMP" || bailout 1
read CHANNEL <"$TMP" ; rm -f "$TMP"
if [ -z "$CHANNEL" ]; then
$DIALOG --inputbox "$MESSAGEW12 $DEVICENAME $MESSAGEW13" 15 50 "$FREQ" 2>"$TMP" || bailout 1
read FREQ <"$TMP" ; rm -f "$TMP"
fi
WPAON=0
IWDRIVER=$driver
case $IWDRIVER in
ath_pci)
WPA_DEV="madwifi"
;;
ipw2200|ipw2100|ipw3945)
WPA_DEV="wext"
;;
hostap)
WPA_DEV="hostap"
;;
*)
WPA_DEV="wext"
;;
esac
if [ -z "$WPA_DEV" ]; then
if [ -d /proc/net/ndiswrapper/$DV ]; then
WPA_DEV=ndiswrapper
elif [ -d /proc/net/hostap/$DV ]; then
WPA_DEV=hostap
elif [ $WLDEVICECOUNT -eq 1 ]; then
if [ -e /proc/driver/atmel ]; then
WPA_DEV=atmel
fi
fi
fi
WPAON=-1
if [ -n "$WPA_DEV" ]; then
if $DIALOG --yesno "$MESSAGEW22" 15 50; then
# Other wpa options
# scan_ssid [0]|1
# bssid 00:11:22:33:44:55
# priority [0]|Integer
# proto [WPA RSN] WPA|RSN
# key_mgmt [WPA-PSK WPA-EAP]|NONE|WPA-PSK|WPA-EAP|IEEE8021X
# pairwise [CCMP TKIP]|CCMP|TKIP|NONE
# group [CCMP TKIP WEP105 WEP40]|CCMP|TKIP|WEP105|WEP40
# eapol_flags [3]|1|2
WPAON=1
KEY=""
WPASECRET=$(awk '
/iface/{
if(found){
found=0
}
else if (/'"$DV"'/){
found=1
}
}
/wpa-psk/{
if(found){
gsub(/\W*#.*$/,"");
if (gsub(/^\W*wpa-psk\W*/,"")){
gsub(/\W.*$/,"");
print;
exit;
}
}
}
' /etc/network/interfaces)
while [ -z "$WPASECRET" ] ; do
$DIALOG --inputbox "$MESSAGEW23 $ESSID" 15 50 "$WPASECRET" 2>"$TMP" || bailout 1
read WPASECRET <"$TMP"
if [ -z "$WPASECRET" ] ; then
$DIALOG --msgbox "Sorry, empty password not allowed, please retry." 0 0 || bailout 1
fi
done
# make sure backslashes inside passphrase are handled correct
WPASECRET=$(sed -e 's/\\/\\/g' "$TMP") && rm -r "$TMP"
case $WPA_DEV in
hostap)
MODE="Managed"
;;
esac
else
WPASECRET=""
fi
else
WPASECRET=""
fi
# No need for a wep key if we are using wpa
if [ ! $WPAON -eq 1 ]; then
$DIALOG --inputbox "$MESSAGEW14 $DEVICENAME $MESSAGEW15" 15 50 "$KEY" 2>"$TMP" || bailout 1
read KEY <"$TMP" ; rm -f "$TMP"
if [ -n "$KEY" -a "$PUBKEY" -eq 0 ]; then
if ! $DIALOG --yesno "$MESSAGEW25 $DEVICENAME $MESSAGEW26" 15 50; then
PUBKEY=1
fi
fi
fi
$DIALOG --inputbox "$MESSAGEW16 $DEVICENAME $MESSAGEW17" 15 50 "$IWCONFIG" 2>"$TMP" || bailout 1
read IWCONFIG <"$TMP" ; rm -f "$TMP"
$DIALOG --inputbox "$MESSAGEW18 $DEVICENAME $MESSAGEW19" 15 50 "$IWSPY" 2>"$TMP" || bailout 1
read IWSPY <"$TMP" ; rm -f "$TMP"
$DIALOG --inputbox "$MESSAGEW20 $DEVICENAME $MESSAGEW21" 15 50 "$IWPRIV" 2>"$TMP" || bailout 1
read IWPRIV <"$TMP" ; rm -f "$TMP"
writeiwline
fi
if $DIALOG --yesno "$MESSAGE2" 8 45; then
if [ -w /etc/network/interfaces ]; then
rm -f "$TMP"
awk '/iface/{if(/'"$DV"'/){found=1}else{found=0}}
/^\W$/{if(blank==0){lastblank=1}else{lastblank=0}{blank=1}}
/\w/{blank=0;lastblank=0}
{if(!(found+lastblank)){print}}
END{print "iface '"$DV"' inet dhcp"}' \
/etc/network/interfaces >"$TMP"
echo -e "$IWOURLINE" >> $TMP
#echo -e "\n\n" >> $TMP
cat "$TMP" >/etc/network/interfaces
rm -f "$TMP"
# Add an "auto" entry
#addauto
fi
else
if [ -f /etc/network/interfaces ]; then
awk '/iface/{if(/'"$DV"'/){found=1}else{found=0}}
/address/{if(found){address=$NF}}
/netmask/{if(found){netmask=$NF}}
/broadcast/{if(found){broadcast=$NF}}
/gateway/{if(found){gateway=$NF}}
/dns-nameservers/{if(found){dnsnameservers=$NF}}
END{print address" "netmask" "broadcast" "gateway" "dnsnameservers}' /etc/network/interfaces >"$TMP"
read IP NM BC DG <"$TMP"
rm -f "$TMP"
fi
$DIALOG --inputbox "$MESSAGE6 $DV" 10 45 "${IP:-192.168.0.1}" 2>"$TMP" || bailout 1
read IP <"$TMP" ; rm -f "$TMP"
$DIALOG --inputbox "$MESSAGE7 $DV" 10 45 "${NM:-255.255.255.0}" 2>"$TMP" || bailout 1
read NM <"$TMP" ; rm -f "$TMP"
$DIALOG --inputbox "$MESSAGE8 $DV" 10 45 "${BC:-${IP%.*}.255}" 2>"$TMP" || bailout 1
read BC <"$TMP" ; rm -f "$TMP"
$DIALOG --inputbox "$MESSAGE9" 10 45 "${DG:-${IP%.*}.1}" 2>"$TMP"
read DG <"$TMP" ; rm -f "$TMP"
if [ -f "/etc/resolv.conf" ]; then
NS="$(awk '/^nameserver/{printf "%s ",$2}' /etc/resolv.conf)"
fi
$DIALOG --inputbox "$MESSAGE10" 10 45 "${NS:-$DG}" 2>"$TMP"
read NS <"$TMP" ; rm -f "$TMP"
if [ -w /etc/network/interfaces ]; then
awk '/iface/{if(/'"$DV"'/){found=1}else{found=0}}
{if(!found){print}}
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"}' \
/etc/network/interfaces >"$TMP"
cat "$TMP" >/etc/network/interfaces
rm -f "$TMP"
# Add an "auto" entry
#addauto
fi
fi
echo "Done."
}
DIALOG="dialog"
NET_DEVICE_NAME="Network_device"
NET_DEVICE_NAME_W="Wireless_device"
NET_DEVICE_NAME_FW="Firewire_device"
NET_DEVICE_NAME_AUTO="Auto"
MESSAGE0="No supported network cards found."
MESSAGE1="Please select network device"
MESSAGE2="Use DHCP broadcast?"
MESSAGE3="Sending DHCP broadcast from device"
MESSAGE4="Failed."
MESSAGE5="Hit return to exit."
MESSAGE6="Please enter IP Address for"
MESSAGE7="Please enter Network Mask for"
MESSAGE8="Please enter Broadcast Address for"
MESSAGE9="Please enter Default Gateway"
MESSAGE10="Please enter Nameserver(s)"
MESSAGE11="Setting Nameserver in /etc/resolv.conf to"
MESSAGE12="Adding Nameserver to /etc/resolv.conf:"
MESSAGE13="Setup wireless options?"
MESSAGE14="Failed to bring up the interface, would you like to reconfigure it?"
MESSAGE15="Interface enabled, do you want it auto enabled at boot?"
MESSAGEW0="No wireless network card found."
MESSAGEW1="Configuration of wireless parameters for"
MESSAGEW3="Please configure IP parameters of the interface first"
MESSAGEW4="Enter the ESSID for"
MESSAGEW5="\n\n\n(empty for 'any', not recommended !)\n"
MESSAGEW6="Enter the NWID (cell identifier)\nfor"
MESSAGEW7=", if needed\n\n\n"
MESSAGEW8="Enter the mode for"
MESSAGEW9="\n\n(Managed(=default), Ad-Hoc, Master,\nRepeater, Secondary, auto)\n"
MESSAGEW10="Enter channel number for"
MESSAGEW11="\n\n(0 bis 16, empty for auto or if you want to\n enter the frequency next)\n"
MESSAGEW12="Enter the frequency for"
MESSAGEW13="\n\n(e.g 2.412G, empty for auto)"
MESSAGEW14="Enter the encryption key\nfor"
MESSAGEW15="\n\n(empty for cleartext, not recommended !!)"
MESSAGEW16="Enter additional parameters for\n'iwconfig"
MESSAGEW17="' if needed, e.g.\n\n\nsens -80 rts 512 frag 512 rate 5.5M"
MESSAGEW18="Enter additional parameters for\n'iwspy"
MESSAGEW19="' if needed\n\n\n"
MESSAGEW20="Enter additional parameters for\n'iwpriv"
MESSAGEW21="' if needed\n\n\n"
MESSAGEW22="Enable WPA support?"
MESSAGEW23="Enter the WPA passphrase (passphrase must be 8..63 characters) for"
MESSAGEW25="Would you like to store your wep key in it's own private file ("
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"
NETDEVICESCOUNT=0
if [ -r /proc/net/dev ] ; then
LAN=$(tail -n +3 /proc/net/dev | awk -F: '{print $1}'| sed "s/\s*//" | grep -v -e ^lo -e ^vmnet | sort)
else
LAN=""
fi
if [ -z "$WLAN" ] ; then
WLAN_OLD=$(tail -n +3 /proc/net/wireless 2>/dev/null|awk -F: '{print $1}')
# /proc/net/wireless does not work e.g. with iwl3945 on kernel 2.6.33 anymore
WLAN_NEW=$(for i in /sys/class/net/* ; do ( [ -d $i/wireless ] || [ -d $i/phy80211 ] ) && basename $i ; done)
set -a WLAN_IWCONFIG
for DEV in $LAN ; do
iwconfig $DEV 2>/dev/null 1>&2 && WLAN_IWCONFIG+=($DEV)
done
WLAN=$(echo $WLAN_OLD $WLAN_NEW ${WLAN_IWCONFIG[@]} | tr ' ' '\n' | sort -u)
fi
unset LAN_DEVICES WLAN_DEVICES FIREWIRE_DEVICES NETDEVICES WLAN_IWCONFIG
while read dev mac; do
#echo "Making NETDEVICES $NETDEVICESCOUNT $dev"
iswlan=$(echo $dev $WLAN|tr ' ' '\n'|sort|uniq -d)
isauto="0"
grep auto /etc/network/interfaces | grep -q $dev && isauto="1"
driver=$(ethtool -i $dev 2>/dev/null|awk '/^driver:/{print $2}')
if [ "$driver" ]; then
if [ "$iswlan" ]; then
NETDEVICES[$NETDEVICESCOUNT]="$dev A::$isauto M::$mac D::$driver W::1 F::0"
else
NETDEVICES[$NETDEVICESCOUNT]="$dev A::$isauto M::$mac D::$driver W::0 F::0"
fi
else
if [ "$iswlan" ]; then
NETDEVICES[$NETDEVICESCOUNT]="$dev A::$isauto M::$mac W::1 F::0"
else
NETDEVICES[$NETDEVICESCOUNT]="$dev A::$isauto M::$mac W::0 F::0"
fi
fi
#echo "Made to ${NETDEVICES[$NETDEVICESCOUNT]}"
((NETDEVICESCOUNT++))
done < <(ifconfig -a|grep Ethernet|grep -v ^vmnet|awk '! /^\s/{print $1" "$5}')
for dev in $LAN; do
if [ "$(ethtool -i $dev 2>/dev/null|awk '/^bus-info:/{print $2}')" == "ieee1394" ]; then
isauto="0"
grep auto /etc/network/interfaces | grep -q $dev && isauto="1"
NETDEVICES[$NETDEVICESCOUNT]="$dev A::$isauto D::$(ethtool -i $dev 2>/dev/null|awk '/^driver:/{print $2}') W::0 F::1"
((NETDEVICESCOUNT++))
fi
done
#NETDEVICES="$(cat /proc/net/dev | awk -F: '/eth.:|lan.:|tr.:|wlan.:|ath.:|ra.:/{print $1}')"
if [ -z "$NETDEVICES" ]; then
$DIALOG --msgbox "$MESSAGE0" 15 45
bailout
fi
count="$NETDEVICESCOUNT"
if [ "$count" -gt 1 ]; then
DEVICELIST=""
mycount=0
while [ $mycount -lt $count ]; do
DEVICE=${NETDEVICES[$mycount]}
#echo "$mycount is $DEVICE"
device2props
#echo "name: $DEVICENAME auto: $isauto fw: $isfirewire mac: $mac driver: $driver"
props2string
DEVICELIST="$DEVICELIST $mycount $MY_DEVICE_NAME"
((mycount++))
done
fi
# To translate
EXITKEY="E"
EXITMENU="$EXITKEY Exit"
# main program loop until they bailout
while (true); do
# first get the device
if [ "$count" -gt 1 ]; then
rm -f "$TMP"
$DIALOG --menu "$MESSAGE1" 18 60 12 $DEVICELIST $EXITMENU 2>"$TMP" || bailout
read DV <"$TMP" ; rm -f "$TMP"
[ "$DV" = "$EXITKEY" ] && bailout
else
# Only one device
DV=0
# they have asked to stop configuring the interface so exit
[ -z "$IFACEDONE" ] || bailout
fi
# device config loop
IFACEDONE=""
while [ -n "$DV" -a -z "$IFACEDONE" ]; do
configiface
if ! ifup $DV; then
$DIALOG --yesno "$MESSAGE14" 15 50 || IFACEDONE="DONE"
else
if $DIALOG --yesno "$MESSAGE15" 12 50 ; then
addauto
# get persistent interface names across reboots
generate_udev_entry
# make sure we don't run the dhcp stuff when using /etc/network/interfaces
disable_config_dhcp
else
remauto
fi
IFACEDONE="DONE"
fi
done
done
## END OF FILE #################################################################