|
@@ -131,4 +131,346 @@ function install_atheros_wifi {
|
131
|
131
|
mark_completed $FUNCNAME
|
132
|
132
|
}
|
133
|
133
|
|
|
134
|
+function update_wifi_adaptors {
|
|
135
|
+ IFACE=
|
|
136
|
+ IFACE_SECONDARY=
|
|
137
|
+
|
|
138
|
+ for i in $(seq 10 -1 0); do
|
|
139
|
+ if grep -q "wlan${i}" /proc/net/dev; then
|
|
140
|
+ if [ ! $IFACE ]; then
|
|
141
|
+ IFACE="wlan${i}"
|
|
142
|
+ else
|
|
143
|
+ IFACE_SECONDARY="wlan${i}"
|
|
144
|
+ return
|
|
145
|
+ fi
|
|
146
|
+ fi
|
|
147
|
+ done
|
|
148
|
+}
|
|
149
|
+
|
|
150
|
+function wifi_get_psk {
|
|
151
|
+ ssid=$1
|
|
152
|
+ passphrase=$2
|
|
153
|
+
|
|
154
|
+ psk=$(wpa_passphrase "$ssid" "$passphrase" | grep 'psk=' | sed -n 2p | awk -F '=' '{print $2}')
|
|
155
|
+ echo $psk
|
|
156
|
+}
|
|
157
|
+
|
|
158
|
+function hotspot_off {
|
|
159
|
+ if [ ! -f /etc/hostapd/hostapd.conf ]; then
|
|
160
|
+ return
|
|
161
|
+ fi
|
|
162
|
+ systemctl stop hostapd
|
|
163
|
+
|
|
164
|
+ rm /etc/hostapd/hostapd.conf
|
|
165
|
+
|
|
166
|
+ if [ -f /etc/network/interfaces_original ]; then
|
|
167
|
+ cp /etc/network/interfaces_original /etc/network/interfaces
|
|
168
|
+ else
|
|
169
|
+ echo '# interfaces(5) file used by ifup(8) and ifdown(8)' > /etc/network/interfaces
|
|
170
|
+ echo '# Include files from /etc/network/interfaces.d:' >> /etc/network/interfaces
|
|
171
|
+ echo 'source-directory /etc/network/interfaces.d' >> /etc/network/interfaces
|
|
172
|
+ fi
|
|
173
|
+
|
|
174
|
+ systemctl restart network-manager
|
|
175
|
+ ifdown $WIFI_INTERFACE
|
|
176
|
+}
|
|
177
|
+
|
|
178
|
+function hotspot_on {
|
|
179
|
+ if [ ! -f /etc/default/hostapd ]; then
|
|
180
|
+ echo $'/etc/default/hostapd was not found'
|
|
181
|
+ exit 67241
|
|
182
|
+ fi
|
|
183
|
+ if [ ${#WIFI_PASSPHRASE} -lt 8 ]; then
|
|
184
|
+ echo $'Wifi hotspot passphrase is too short'
|
|
185
|
+ exit 25719
|
|
186
|
+ fi
|
|
187
|
+
|
|
188
|
+ sed -i 's|#DAEMON_CONF=.*|DAEMON_CONF="/etc/hostapd/hostapd.conf"|g' /etc/default/hostapd
|
|
189
|
+
|
|
190
|
+ echo '### Wireless network name ###' > /etc/hostapd/hostapd.conf
|
|
191
|
+ echo "interface=$WIFI_INTERFACE" >> /etc/hostapd/hostapd.conf
|
|
192
|
+ echo '' >> /etc/hostapd/hostapd.conf
|
|
193
|
+ echo '### Set your bridge name ###' >> /etc/hostapd/hostapd.conf
|
|
194
|
+ echo 'bridge=br0' >> /etc/hostapd/hostapd.conf
|
|
195
|
+ echo '' >> /etc/hostapd/hostapd.conf
|
|
196
|
+ echo 'driver=nl80211' >> /etc/hostapd/hostapd.conf
|
|
197
|
+ echo "country_code=UK" >> /etc/hostapd/hostapd.conf
|
|
198
|
+ echo "ssid=$WIFI_SSID" >> /etc/hostapd/hostapd.conf
|
|
199
|
+ echo 'hw_mode=g' >> /etc/hostapd/hostapd.conf
|
|
200
|
+ echo 'channel=6' >> /etc/hostapd/hostapd.conf
|
|
201
|
+ echo 'wpa=2' >> /etc/hostapd/hostapd.conf
|
|
202
|
+ echo "wpa_passphrase=$WIFI_PASSPHRASE" >> /etc/hostapd/hostapd.conf
|
|
203
|
+ echo '' >> /etc/hostapd/hostapd.conf
|
|
204
|
+ echo '## Key management algorithms ##' >> /etc/hostapd/hostapd.conf
|
|
205
|
+ echo 'wpa_key_mgmt=WPA-PSK' >> /etc/hostapd/hostapd.conf
|
|
206
|
+ echo '' >> /etc/hostapd/hostapd.conf
|
|
207
|
+ echo '## Set cipher suites (encryption algorithms) ##' >> /etc/hostapd/hostapd.conf
|
|
208
|
+ echo '## TKIP = Temporal Key Integrity Protocol' >> /etc/hostapd/hostapd.conf
|
|
209
|
+ echo '## CCMP = AES in Counter mode with CBC-MAC' >> /etc/hostapd/hostapd.conf
|
|
210
|
+ echo 'wpa_pairwise=TKIP' >> /etc/hostapd/hostapd.conf
|
|
211
|
+ echo 'rsn_pairwise=CCMP' >> /etc/hostapd/hostapd.conf
|
|
212
|
+ echo '' >> /etc/hostapd/hostapd.conf
|
|
213
|
+ echo '## Shared Key Authentication ##'
|
|
214
|
+ echo 'auth_algs=1' >> /etc/hostapd/hostapd.conf
|
|
215
|
+ echo '' >> /etc/hostapd/hostapd.conf
|
|
216
|
+ echo '## Accept all MAC address ###' >> /etc/hostapd/hostapd.conf
|
|
217
|
+ echo 'macaddr_acl=0' >> /etc/hostapd/hostapd.conf
|
|
218
|
+
|
|
219
|
+ if [ ! -f /etc/network/interfaces_original ]; then
|
|
220
|
+ if ! grep -q "# wifi enabled" /etc/network/interfaces; then
|
|
221
|
+ cp /etc/network/interfaces /etc/network/interfaces_original
|
|
222
|
+ fi
|
|
223
|
+ fi
|
|
224
|
+
|
|
225
|
+ echo '# wifi enabled' > /etc/network/interfaces
|
|
226
|
+ echo 'auto lo br0' >> /etc/network/interfaces
|
|
227
|
+ echo 'iface lo inet loopback' >> /etc/network/interfaces
|
|
228
|
+ echo '' >> /etc/network/interfaces
|
|
229
|
+ echo "# wireless $WIFI_INTERFACE" >> /etc/network/interfaces
|
|
230
|
+ echo "allow-hotplug $WIFI_INTERFACE" >> /etc/network/interfaces
|
|
231
|
+ echo "iface $WIFI_INTERFACE inet manual" >> /etc/network/interfaces
|
|
232
|
+ echo '' >> /etc/network/interfaces
|
|
233
|
+ echo '# eth0 connected to the ISP router' >> /etc/network/interfaces
|
|
234
|
+ echo 'allow-hotplug eth0' >> /etc/network/interfaces
|
|
235
|
+ echo 'iface eth0 inet manual' >> /etc/network/interfaces
|
|
236
|
+ echo '' >> /etc/network/interfaces
|
|
237
|
+ echo '# Setup bridge' >> /etc/network/interfaces
|
|
238
|
+ echo 'iface br0 inet static' >> /etc/network/interfaces
|
|
239
|
+ echo " bridge_ports $WIFI_INTERFACE eth0" >> /etc/network/interfaces
|
|
240
|
+
|
|
241
|
+ systemctl restart network-manager
|
|
242
|
+ ifup $WIFI_INTERFACE
|
|
243
|
+ systemctl restart hostapd
|
|
244
|
+}
|
|
245
|
+
|
|
246
|
+function wifi_wpa2_psk {
|
|
247
|
+ ssid=$1
|
|
248
|
+ passphrase=$2
|
|
249
|
+
|
|
250
|
+ if [ ! -f /etc/network/interfaces_original ]; then
|
|
251
|
+ if ! grep -q "# wifi enabled" /etc/network/interfaces; then
|
|
252
|
+ cp /etc/network/interfaces /etc/network/interfaces_original
|
|
253
|
+ fi
|
|
254
|
+ fi
|
|
255
|
+
|
|
256
|
+ echo '# wifi enabled' > /etc/network/interfaces
|
|
257
|
+ echo 'auto lo' >> /etc/network/interfaces
|
|
258
|
+ echo 'iface lo inet loopback' >> /etc/network/interfaces
|
|
259
|
+ echo '' >> /etc/network/interfaces
|
|
260
|
+ echo 'allow-hotplug eth0' >> /etc/network/interfaces
|
|
261
|
+ echo 'iface eth0 inet dhcp' >> /etc/network/interfaces
|
|
262
|
+ echo '' >> /etc/network/interfaces
|
|
263
|
+ echo "allow-hotplug ${WIFI_INTERFACE}" >> /etc/network/interfaces
|
|
264
|
+ echo "iface ${WIFI_INTERFACE} inet manual" >> /etc/network/interfaces
|
|
265
|
+ echo " wpa-roam $WIFI_CONFIG" >> /etc/network/interfaces
|
|
266
|
+ echo '' >> /etc/network/interfaces
|
|
267
|
+ echo 'iface default inet dhcp' >> /etc/network/interfaces
|
|
268
|
+
|
|
269
|
+ wpa_passphrase "$ssid" "$passphrase" > $WIFI_CONFIG
|
|
270
|
+
|
|
271
|
+ systemctl restart network-manager
|
|
272
|
+ ifup ${WIFI_INTERFACE}
|
|
273
|
+}
|
|
274
|
+
|
|
275
|
+function wifi_none {
|
|
276
|
+ ssid=$1
|
|
277
|
+
|
|
278
|
+ if [ ! -f /etc/network/interfaces_original ]; then
|
|
279
|
+ if ! grep -q "# wifi enabled" /etc/network/interfaces; then
|
|
280
|
+ cp /etc/network/interfaces /etc/network/interfaces_original
|
|
281
|
+ fi
|
|
282
|
+ fi
|
|
283
|
+
|
|
284
|
+ echo '# wifi enabled' > /etc/network/interfaces
|
|
285
|
+ echo 'auto lo' >> /etc/network/interfaces
|
|
286
|
+ echo 'iface lo inet loopback' >> /etc/network/interfaces
|
|
287
|
+ echo '' >> /etc/network/interfaces
|
|
288
|
+ echo 'allow-hotplug eth0' >> /etc/network/interfaces
|
|
289
|
+ echo 'iface eth0 inet dhcp' >> /etc/network/interfaces
|
|
290
|
+ echo '' >> /etc/network/interfaces
|
|
291
|
+ echo "allow-hotplug ${WIFI_INTERFACE}" >> /etc/network/interfaces
|
|
292
|
+ echo "iface ${WIFI_INTERFACE} inet manual" >> /etc/network/interfaces
|
|
293
|
+ echo " wpa-roam $WIFI_CONFIG" >> /etc/network/interfaces
|
|
294
|
+ echo '' >> /etc/network/interfaces
|
|
295
|
+ echo 'iface default inet dhcp' >> /etc/network/interfaces
|
|
296
|
+
|
|
297
|
+ echo 'network={' > $WIFI_CONFIG
|
|
298
|
+ echo " ssid=\"${ssid}\"" >> $WIFI_CONFIG
|
|
299
|
+ echo ' key_mgmt=NONE' >> $WIFI_CONFIG
|
|
300
|
+ echo '}' >> $WIFI_CONFIG
|
|
301
|
+
|
|
302
|
+ systemctl restart network-manager
|
|
303
|
+ ifup ${WIFI_INTERFACE}
|
|
304
|
+}
|
|
305
|
+
|
|
306
|
+function networks_from_file {
|
|
307
|
+ if [ ! -f $WIFI_NETWORKS_FILE ]; then
|
|
308
|
+ exit 4
|
|
309
|
+ fi
|
|
310
|
+
|
|
311
|
+ if [ ! -f /etc/network/interfaces_original ]; then
|
|
312
|
+ if ! grep -q "# wifi enabled" /etc/network/interfaces; then
|
|
313
|
+ cp /etc/network/interfaces /etc/network/interfaces_original
|
|
314
|
+ fi
|
|
315
|
+ fi
|
|
316
|
+
|
|
317
|
+ echo '# wifi enabled' > /etc/network/interfaces
|
|
318
|
+ echo 'auto lo' >> /etc/network/interfaces
|
|
319
|
+ echo 'iface lo inet loopback' >> /etc/network/interfaces
|
|
320
|
+ echo '' >> /etc/network/interfaces
|
|
321
|
+ echo 'allow-hotplug eth0' >> /etc/network/interfaces
|
|
322
|
+ echo 'iface eth0 inet dhcp' >> /etc/network/interfaces
|
|
323
|
+ echo '' >> /etc/network/interfaces
|
|
324
|
+ echo "allow-hotplug ${WIFI_INTERFACE}" >> /etc/network/interfaces
|
|
325
|
+ echo "iface ${WIFI_INTERFACE} inet manual" >> /etc/network/interfaces
|
|
326
|
+ echo " wpa-roam $WIFI_CONFIG" >> /etc/network/interfaces
|
|
327
|
+ echo '' >> /etc/network/interfaces
|
|
328
|
+ echo 'iface default inet dhcp' >> /etc/network/interfaces
|
|
329
|
+
|
|
330
|
+ # remove wpa_supplicant.conf if it exists
|
|
331
|
+ if [ -f $WIFI_CONFIG ]; then
|
|
332
|
+ rm -f $WIFI_CONFIG
|
|
333
|
+ fi
|
|
334
|
+
|
|
335
|
+ ctr=0
|
|
336
|
+ while read -r line
|
|
337
|
+ do
|
|
338
|
+ if [ ${#line} -gt 1 ]; then
|
|
339
|
+ if [[ "$line" != '#'* ]]; then
|
|
340
|
+ if [ $ctr -eq 0 ]; then
|
|
341
|
+ WIFI_SSID="$line"
|
|
342
|
+ fi
|
|
343
|
+ if [ $ctr -eq 1 ]; then
|
|
344
|
+ WIFI_TYPE="$line"
|
|
345
|
+ if [[ $WIFI_TYPE == $'none' || $WIFI_TYPE == $'open' ]]; then
|
|
346
|
+ echo 'network={' >> $WIFI_CONFIG
|
|
347
|
+ echo " ssid=\"${WIFI_SSID}\"" >> $WIFI_CONFIG
|
|
348
|
+ echo ' key_mgmt=NONE' >> $WIFI_CONFIG
|
|
349
|
+ echo '}' >> $WIFI_CONFIG
|
|
350
|
+ ctr=0
|
|
351
|
+ continue
|
|
352
|
+ fi
|
|
353
|
+ fi
|
|
354
|
+ if [ $ctr -eq 2 ]; then
|
|
355
|
+ WIFI_PASSPHRASE="$line"
|
|
356
|
+ wpa_passphrase "$WIFI_SSID" "$WIFI_PASSPHRASE" >> $WIFI_CONFIG
|
|
357
|
+ ctr=0
|
|
358
|
+ continue
|
|
359
|
+ fi
|
|
360
|
+
|
|
361
|
+ ctr=$((ctr + 1))
|
|
362
|
+ fi
|
|
363
|
+ fi
|
|
364
|
+ done < $WIFI_NETWORKS_FILE
|
|
365
|
+
|
|
366
|
+ systemctl restart network-manager
|
|
367
|
+ ifup ${WIFI_INTERFACE}
|
|
368
|
+}
|
|
369
|
+
|
|
370
|
+function create_networks_interactive {
|
|
371
|
+ update_wifi_adaptors
|
|
372
|
+ if [ ! $IFACE ]; then
|
|
373
|
+ # Don't try to configure wifi if there are no adaptors
|
|
374
|
+ return
|
|
375
|
+ fi
|
|
376
|
+
|
|
377
|
+ if [ -f $WIFI_NETWORKS_FILE ]; then
|
|
378
|
+ rm $WIFI_NETWORKS_FILE
|
|
379
|
+ fi
|
|
380
|
+
|
|
381
|
+ echo $'# Add wifi networks as follows:' > $WIFI_NETWORKS_FILE
|
|
382
|
+ echo '#' >> $WIFI_NETWORKS_FILE
|
|
383
|
+ echo $'# MySSID' >> $WIFI_NETWORKS_FILE
|
|
384
|
+ echo $'# wpa2-psk' >> $WIFI_NETWORKS_FILE
|
|
385
|
+ echo $'# myWifiPassphrase' >> $WIFI_NETWORKS_FILE
|
|
386
|
+ echo '#' >> $WIFI_NETWORKS_FILE
|
|
387
|
+ echo $'# AnotherSSID' >> $WIFI_NETWORKS_FILE
|
|
388
|
+ echo $'# none' >> $WIFI_NETWORKS_FILE
|
|
389
|
+ echo '#' >> $WIFI_NETWORKS_FILE
|
|
390
|
+
|
|
391
|
+ wifi_ctr=0
|
|
392
|
+ wifi_networks_done=
|
|
393
|
+ while [ ! $wifi_networks_done ]
|
|
394
|
+ do
|
|
395
|
+ data=$(tempfile 2>/dev/null)
|
|
396
|
+ trap "rm -f $data" 0 1 2 5 15
|
|
397
|
+ dialog --backtitle $"Freedombone Configuration" \
|
|
398
|
+ --title $"Wifi Settings ${wifi_ctr}" \
|
|
399
|
+ --form $"\nIf you wish to use wifi and have a Free Software compatible adapter (eg. Atheros) rather than wired ethernet then enter the details below, otherwise just select Ok:" 15 55 4 \
|
|
400
|
+ $"SSID:" 1 1 "$WIFI_SSID" 1 16 30 30 \
|
|
401
|
+ $"Type:" 2 1 "$WIFI_TYPE" 2 16 10 10 \
|
|
402
|
+ $"Passphrase:" 3 1 "$WIFI_PASSPHRASE" 3 16 30 30 \
|
|
403
|
+ 2> $data
|
|
404
|
+ sel=$?
|
|
405
|
+ case $sel in
|
|
406
|
+ 1) return;;
|
|
407
|
+ 255) return;;
|
|
408
|
+ esac
|
|
409
|
+ WIFI_SSID=$(cat $data | sed -n 1p)
|
|
410
|
+ WIFI_TYPE=$(cat $data | sed -n 2p)
|
|
411
|
+ WIFI_PASSPHRASE=$(cat $data | sed -n 3p)
|
|
412
|
+
|
|
413
|
+ # if these fields are empty then there are no more wifi networks
|
|
414
|
+ if [ ${#WIFI_SSID} -lt 2 ]; then
|
|
415
|
+ wifi_networks_done='yes'
|
|
416
|
+ continue
|
|
417
|
+ fi
|
|
418
|
+ if [ ${#WIFI_TYPE} -lt 2 ]; then
|
|
419
|
+ wifi_networks_done='yes'
|
|
420
|
+ continue
|
|
421
|
+ fi
|
|
422
|
+
|
|
423
|
+ # update the wifi networks file
|
|
424
|
+ echo '' >> $WIFI_NETWORKS_FILE
|
|
425
|
+ echo "$WIFI_SSID" >> $WIFI_NETWORKS_FILE
|
|
426
|
+ echo "$WIFI_TYPE" >> $WIFI_NETWORKS_FILE
|
|
427
|
+ if [ ${#WIFI_PASSPHRASE} -gt 1 ]; then
|
|
428
|
+ echo "$WIFI_PASSPHRASE" >> $WIFI_NETWORKS_FILE
|
|
429
|
+ fi
|
|
430
|
+
|
|
431
|
+ if [ ${#WIFI_SSID} -gt 1 ]; then
|
|
432
|
+ if [ ${#WIFI_TYPE} -gt 1 ]; then
|
|
433
|
+ if [[ "${WIFI_TYPE}" == $'none' || "${WIFI_TYPE}" == $'open' ]]; then
|
|
434
|
+ return
|
|
435
|
+ else
|
|
436
|
+ if [ ${#WIFI_PASSPHRASE} -gt 1 ]; then
|
|
437
|
+ return
|
|
438
|
+ fi
|
|
439
|
+ fi
|
|
440
|
+ fi
|
|
441
|
+ fi
|
|
442
|
+
|
|
443
|
+ # clear values
|
|
444
|
+ WIFI_SSID=
|
|
445
|
+ WIFI_PASSPHRASE=
|
|
446
|
+
|
|
447
|
+ wifi_ctr=$((wifi_ctr + 1))
|
|
448
|
+ done
|
|
449
|
+}
|
|
450
|
+
|
|
451
|
+function disable_wifi {
|
|
452
|
+ if [[ ${1} == 'yes' || ${1} == 'y' ]]; then
|
|
453
|
+ hotspot_off
|
|
454
|
+ echo '# interfaces(5) file used by ifup(8) and ifdown(8)' > /etc/network/interfaces
|
|
455
|
+ echo '# Include files from /etc/network/interfaces.d:' >> /etc/network/interfaces
|
|
456
|
+ echo 'source-directory /etc/network/interfaces.d' >> /etc/network/interfaces
|
|
457
|
+ systemctl restart network-manager
|
|
458
|
+ ifdown ${WIFI_INTERFACE}
|
|
459
|
+ else
|
|
460
|
+ networks_from_file
|
|
461
|
+ fi
|
|
462
|
+}
|
|
463
|
+
|
|
464
|
+function count_wlan {
|
|
465
|
+ # counts the number of wlan devices
|
|
466
|
+ ctr=0
|
|
467
|
+
|
|
468
|
+ for i in $(seq 0 1 10); do
|
|
469
|
+ if grep -q "wlan${i}" /proc/net/dev; then
|
|
470
|
+ ctr=$((ctr + 1))
|
|
471
|
+ fi
|
|
472
|
+ done
|
|
473
|
+ echo $ctr
|
|
474
|
+}
|
|
475
|
+
|
134
|
476
|
# NOTE: deliberately no exit 0
|