Преглед на файлове

wifi utils static analysis

Bob Mottram преди 7 години
родител
ревизия
c44d07bd2f
променени са 2 файла, в които са добавени 128 реда и са изтрити 132 реда
  1. 0
    1
      src/freedombone-app-syncthing
  2. 128
    131
      src/freedombone-utils-wifi

+ 0
- 1
src/freedombone-app-syncthing Целия файл

112
     syncthing_create_ids_file
112
     syncthing_create_ids_file
113
 
113
 
114
     data=$(mktemp 2>/dev/null)
114
     data=$(mktemp 2>/dev/null)
115
-    trap "rm -f $data" 0 1 2 5 15
116
     dialog --backtitle $"Freedombone User Control Panel" \
115
     dialog --backtitle $"Freedombone User Control Panel" \
117
            --title $"Add a Syncthing device ID" \
116
            --title $"Add a Syncthing device ID" \
118
            --form $"Paste the device ID for your laptop/desktop/netbook/phone/tablet below" 9 80 2 \
117
            --form $"Paste the device ID for your laptop/desktop/netbook/phone/tablet below" 9 80 2 \

+ 128
- 131
src/freedombone-utils-wifi Целия файл

74
     else
74
     else
75
         read_config_param "LOCAL_NETWORK_STATIC_IP_ADDRESS"
75
         read_config_param "LOCAL_NETWORK_STATIC_IP_ADDRESS"
76
         read_config_param "ROUTER_IP_ADDRESS"
76
         read_config_param "ROUTER_IP_ADDRESS"
77
-        echo 'iface default inet static' > /etc/network/interfaces.d/static
78
-        echo "    address ${LOCAL_NETWORK_STATIC_IP_ADDRESS}" >> /etc/network/interfaces.d/static
79
-        echo '    netmask 255.255.255.0' >> /etc/network/interfaces.d/static
80
-        echo "    gateway ${ROUTER_IP_ADDRESS}" >> /etc/network/interfaces.d/static
77
+        { echo 'iface default inet static';
78
+          echo "    address ${LOCAL_NETWORK_STATIC_IP_ADDRESS}";
79
+          echo '    netmask 255.255.255.0';
80
+          echo "    gateway ${ROUTER_IP_ADDRESS}"; } > /etc/network/interfaces.d/static
81
     fi
81
     fi
82
 }
82
 }
83
 
83
 
98
     else
98
     else
99
         atheros_drivers_file=$(pwd)/$atheros_drivers_file
99
         atheros_drivers_file=$(pwd)/$atheros_drivers_file
100
     fi
100
     fi
101
-    dpkg -i $atheros_drivers_file
101
+    dpkg -i "$atheros_drivers_file"
102
     reset_usb_devices
102
     reset_usb_devices
103
     update_wifi_adaptors
103
     update_wifi_adaptors
104
-    if [ $IFACE ]; then
105
-        wpa_action ${IFACE} stop
106
-        wpa_cli -i ${IFACE} terminate
104
+    if [ "$IFACE" ]; then
105
+        wpa_action "${IFACE}" stop
106
+        wpa_cli -i "${IFACE}" terminate
107
         #ifconfig $IFACE up
107
         #ifconfig $IFACE up
108
-        ifup $IFACE
108
+        ifup "$IFACE"
109
     fi
109
     fi
110
 }
110
 }
111
 
111
 
129
         HOTSPOT='yes'
129
         HOTSPOT='yes'
130
     fi
130
     fi
131
 
131
 
132
-    if [ -f $WIFI_NETWORKS_FILE ]; then
133
-        ${PROJECT_NAME}-wifi --networks $WIFI_NETWORKS_FILE
132
+    if [ -f "$WIFI_NETWORKS_FILE" ]; then
133
+        "${PROJECT_NAME}-wifi" --networks "$WIFI_NETWORKS_FILE"
134
         mark_complete "${FUNCNAME[0]}"
134
         mark_complete "${FUNCNAME[0]}"
135
         return
135
         return
136
     fi
136
     fi
144
             echo $'Wifi passphrase was too short'
144
             echo $'Wifi passphrase was too short'
145
             return
145
             return
146
         fi
146
         fi
147
-        ${PROJECT_NAME}-wifi -s $WIFI_SSID -t $WIFI_TYPE -p $WIFI_PASSPHRASE --hotspot $HOTSPOT --networks $WIFI_NETWORKS_FILE
147
+        "${PROJECT_NAME}-wifi" -s "$WIFI_SSID" -t "$WIFI_TYPE" -p "$WIFI_PASSPHRASE" --hotspot "$HOTSPOT" --networks "$WIFI_NETWORKS_FILE"
148
     else
148
     else
149
-        ${PROJECT_NAME}-wifi -s $WIFI_SSID -t $WIFI_TYPE --hotspot $HOTSPOT --networks $WIFI_NETWORKS_FILE
149
+        "${PROJECT_NAME}-wifi" -s "$WIFI_SSID" -t "$WIFI_TYPE" --hotspot "$HOTSPOT" --networks "$WIFI_NETWORKS_FILE"
150
     fi
150
     fi
151
     mark_completed "${FUNCNAME[0]}"
151
     mark_completed "${FUNCNAME[0]}"
152
 }
152
 }
156
     if [[ $(is_completed "${FUNCNAME[0]}") == "1" ]]; then
156
     if [[ $(is_completed "${FUNCNAME[0]}") == "1" ]]; then
157
         return
157
         return
158
     fi
158
     fi
159
-    if [ $INSTALLING_ON_BBB != "yes" ]; then
159
+    if [ "$INSTALLING_ON_BBB" != "yes" ]; then
160
         return
160
         return
161
     fi
161
     fi
162
     if [[ $ENABLE_BATMAN != "yes" ]]; then
162
     if [[ $ENABLE_BATMAN != "yes" ]]; then
163
         return
163
         return
164
     fi
164
     fi
165
-    if [ -d $INSTALL_DIR/open-ath9k-htc-firmware ]; then
165
+    if [ -d "$INSTALL_DIR/open-ath9k-htc-firmware" ]; then
166
         return
166
         return
167
     fi
167
     fi
168
     # have drivers already been installed ?
168
     # have drivers already been installed ?
170
         return
170
         return
171
     fi
171
     fi
172
     apt-get -yq install build-essential cmake git m4 texinfo
172
     apt-get -yq install build-essential cmake git m4 texinfo
173
-    if [ ! -d $INSTALL_DIR ]; then
174
-        mkdir -p $INSTALL_DIR
173
+    if [ ! -d "$INSTALL_DIR" ]; then
174
+        mkdir -p "$INSTALL_DIR"
175
     fi
175
     fi
176
-    cd $INSTALL_DIR
177
-    if [ ! -d $INSTALL_DIR/open-ath9k-htc-firmware ]; then
176
+    cd "$INSTALL_DIR" || exit 24678246
177
+    if [ ! -d "$INSTALL_DIR/open-ath9k-htc-firmware" ]; then
178
         function_check git_clone
178
         function_check git_clone
179
-        git_clone $ATHEROS_WIFI_REPO $INSTALL_DIR/open-ath9k-htc-firmware
180
-        if [ ! "$?" = "0" ]; then
181
-            rm -rf $INSTALL_DIR/open-ath9k-htc-firmware
179
+        if ! git_clone "$ATHEROS_WIFI_REPO" "$INSTALL_DIR/open-ath9k-htc-firmware"; then
180
+            rm -rf "$INSTALL_DIR/open-ath9k-htc-firmware"
182
             exit 74283
181
             exit 74283
183
         fi
182
         fi
184
     fi
183
     fi
185
-    cd $INSTALL_DIR/open-ath9k-htc-firmware
184
+    cd "$INSTALL_DIR/open-ath9k-htc-firmware" || exit 24682468
186
     git checkout 1.4.0
185
     git checkout 1.4.0
187
-    make toolchain
188
-    if [ ! "$?" = "0" ]; then
189
-        rm -rf $INSTALL_DIR/open-ath9k-htc-firmware
186
+    if ! make toolchain; then
187
+        rm -rf "$INSTALL_DIR/open-ath9k-htc-firmware"
190
         exit 24820
188
         exit 24820
191
     fi
189
     fi
192
-    make firmware
193
-    if [ ! "$?" = "0" ]; then
194
-        rm -rf $INSTALL_DIR/open-ath9k-htc-firmware
190
+    if ! make firmware; then
191
+        rm -rf "$INSTALL_DIR/open-ath9k-htc-firmware"
195
         exit 63412
192
         exit 63412
196
     fi
193
     fi
197
-    cp target_firmware/*.fw /lib/firmware/
198
-    if [ ! "$?" = "0" ]; then
194
+    if ! cp target_firmware/*.fw /lib/firmware/; then
199
         exit 74681
195
         exit 74681
200
     fi
196
     fi
201
     mark_completed "${FUNCNAME[0]}"
197
     mark_completed "${FUNCNAME[0]}"
206
     IFACE_SECONDARY=
202
     IFACE_SECONDARY=
207
 
203
 
208
     for i in $(seq 10 -1 0); do
204
     for i in $(seq 10 -1 0); do
209
-        ifdown --force wlan${i} 2> /dev/null
205
+        ifdown --force "wlan${i}" 2> /dev/null
210
     done
206
     done
211
 
207
 
212
     for i in $(seq 10 -1 0); do
208
     for i in $(seq 10 -1 0); do
226
     passphrase=$2
222
     passphrase=$2
227
 
223
 
228
     psk=$(wpa_passphrase "$ssid" "$passphrase" | grep 'psk=' | sed -n 2p | awk -F '=' '{print $2}')
224
     psk=$(wpa_passphrase "$ssid" "$passphrase" | grep 'psk=' | sed -n 2p | awk -F '=' '{print $2}')
229
-    echo $psk
225
+    echo "$psk"
230
 }
226
 }
231
 
227
 
232
 function hotspot_off {
228
 function hotspot_off {
274
 
270
 
275
     sed -i 's|#DAEMON_CONF=.*|DAEMON_CONF="/etc/hostapd/hostapd.conf"|g' /etc/default/hostapd
271
     sed -i 's|#DAEMON_CONF=.*|DAEMON_CONF="/etc/hostapd/hostapd.conf"|g' /etc/default/hostapd
276
 
272
 
277
-    echo '### Wireless network name ###' > /etc/hostapd/hostapd.conf
278
-    echo "interface=$WIFI_INTERFACE" >> /etc/hostapd/hostapd.conf
279
-    echo '' >> /etc/hostapd/hostapd.conf
280
-    echo '### Set your bridge name ###' >> /etc/hostapd/hostapd.conf
281
-    echo 'bridge=br0' >> /etc/hostapd/hostapd.conf
282
-    echo '' >> /etc/hostapd/hostapd.conf
283
-    echo 'driver=nl80211' >> /etc/hostapd/hostapd.conf
284
-    echo "country_code=UK" >> /etc/hostapd/hostapd.conf
285
-    echo "ssid=$WIFI_SSID" >> /etc/hostapd/hostapd.conf
286
-    echo 'hw_mode=g' >> /etc/hostapd/hostapd.conf
287
-    echo 'channel=6' >> /etc/hostapd/hostapd.conf
288
-    echo 'wpa=2' >> /etc/hostapd/hostapd.conf
289
-    echo "wpa_passphrase=$WIFI_PASSPHRASE" >> /etc/hostapd/hostapd.conf
290
-    echo '' >> /etc/hostapd/hostapd.conf
291
-    echo '## Key management algorithms ##' >> /etc/hostapd/hostapd.conf
292
-    echo 'wpa_key_mgmt=WPA-PSK' >> /etc/hostapd/hostapd.conf
293
-    echo '' >> /etc/hostapd/hostapd.conf
294
-    echo '## Set cipher suites (encryption algorithms) ##' >> /etc/hostapd/hostapd.conf
295
-    echo '## TKIP = Temporal Key Integrity Protocol' >> /etc/hostapd/hostapd.conf
296
-    echo '## CCMP = AES in Counter mode with CBC-MAC' >> /etc/hostapd/hostapd.conf
297
-    echo 'wpa_pairwise=TKIP' >> /etc/hostapd/hostapd.conf
298
-    echo 'rsn_pairwise=CCMP' >> /etc/hostapd/hostapd.conf
299
-    echo '' >> /etc/hostapd/hostapd.conf
300
-    echo '## Shared Key Authentication ##'
301
-    echo 'auth_algs=1' >> /etc/hostapd/hostapd.conf
302
-    echo '' >> /etc/hostapd/hostapd.conf
303
-    echo '## Accept all MAC address ###' >> /etc/hostapd/hostapd.conf
304
-    echo 'macaddr_acl=0' >> /etc/hostapd/hostapd.conf
273
+    { echo '### Wireless network name ###';
274
+      echo "interface=$WIFI_INTERFACE";
275
+      echo '';
276
+      echo '### Set your bridge name ###';
277
+      echo 'bridge=br0';
278
+      echo '';
279
+      echo 'driver=nl80211';
280
+      echo "country_code=UK";
281
+      echo "ssid=$WIFI_SSID";
282
+      echo 'hw_mode=g';
283
+      echo 'channel=6';
284
+      echo 'wpa=2';
285
+      echo "wpa_passphrase=$WIFI_PASSPHRASE";
286
+      echo '';
287
+      echo '## Key management algorithms ##';
288
+      echo 'wpa_key_mgmt=WPA-PSK';
289
+      echo '';
290
+      echo '## Set cipher suites (encryption algorithms) ##';
291
+      echo '## TKIP = Temporal Key Integrity Protocol';
292
+      echo '## CCMP = AES in Counter mode with CBC-MAC';
293
+      echo 'wpa_pairwise=TKIP';
294
+      echo 'rsn_pairwise=CCMP';
295
+      echo '';
296
+      echo '## Shared Key Authentication ##'
297
+      echo 'auth_algs=1';
298
+      echo '';
299
+      echo '## Accept all MAC address ###';
300
+      echo 'macaddr_acl=0'; } > /etc/hostapd/hostapd.conf
305
 
301
 
306
     if [ ! -f /etc/network/interfaces_original_static ]; then
302
     if [ ! -f /etc/network/interfaces_original_static ]; then
307
         if [ -f /etc/network/interfaces.d/static ]; then
303
         if [ -f /etc/network/interfaces.d/static ]; then
365
     echo "  wpa-roam $WIFI_CONFIG" >> /etc/network/interfaces.d/wifi
361
     echo "  wpa-roam $WIFI_CONFIG" >> /etc/network/interfaces.d/wifi
366
     wifi_static_network_interface
362
     wifi_static_network_interface
367
 
363
 
368
-    wpa_passphrase "$ssid" "$passphrase" > $WIFI_CONFIG
364
+    wpa_passphrase "$ssid" "$passphrase" > "$WIFI_CONFIG"
369
 
365
 
370
     systemctl restart network-manager
366
     systemctl restart network-manager
371
     ifup $WIFI_INTERFACE
367
     ifup $WIFI_INTERFACE
385
 
381
 
386
     wifi_static_network_interface
382
     wifi_static_network_interface
387
 
383
 
388
-    echo 'ctrl_interface=/run/wpa_supplicant' > $WIFI_CONFIG
389
-    echo 'update_config=1' >> $WIFI_CONFIG
390
-    echo 'eapol_version=1' >> $WIFI_CONFIG
391
-    echo '' >> $WIFI_CONFIG
392
-
393
-    echo 'network={' >> $WIFI_CONFIG
384
+    { echo 'ctrl_interface=/run/wpa_supplicant';
385
+      echo 'update_config=1';
386
+      echo 'eapol_version=1';
387
+      echo '';
388
+      echo 'network={'; } > "$WIFI_CONFIG"
394
     if [[ "${ssid}" != $'any' && "${ssid}" != $'all' && "${ssid}" != $'open' ]]; then
389
     if [[ "${ssid}" != $'any' && "${ssid}" != $'all' && "${ssid}" != $'open' ]]; then
395
-        echo "  ssid=\"${ssid}\"" >> $WIFI_CONFIG
390
+        echo "  ssid=\"${ssid}\"" >> "$WIFI_CONFIG"
396
     fi
391
     fi
397
-    echo '  key_mgmt=NONE' >> $WIFI_CONFIG
398
-    echo '}' >> $WIFI_CONFIG
392
+    echo '  key_mgmt=NONE' >> "$WIFI_CONFIG"
393
+    echo '}' >> "$WIFI_CONFIG"
399
 
394
 
400
     systemctl restart network-manager
395
     systemctl restart network-manager
401
     ifup $WIFI_INTERFACE
396
     ifup $WIFI_INTERFACE
402
 }
397
 }
403
 
398
 
404
 function networks_from_file {
399
 function networks_from_file {
405
-    if [ ! -f $WIFI_NETWORKS_FILE ]; then
400
+    if [ ! -f "$WIFI_NETWORKS_FILE" ]; then
406
         exit 4
401
         exit 4
407
     fi
402
     fi
408
 
403
 
416
     echo 'allow-hotplug eth0' > /etc/network/interfaces.d/static
411
     echo 'allow-hotplug eth0' > /etc/network/interfaces.d/static
417
     echo 'iface eth0 inet dhcp' >> /etc/network/interfaces.d/static
412
     echo 'iface eth0 inet dhcp' >> /etc/network/interfaces.d/static
418
 
413
 
419
-    echo "allow-hotplug ${WIFI_INTERFACE}" >> /etc/network/interfaces.d/wifi
420
-    echo "iface ${WIFI_INTERFACE} inet manual" >> /etc/network/interfaces.d/wifi
421
-    echo "  wpa-roam $WIFI_CONFIG" >> /etc/network/interfaces.d/wifi
414
+    { echo "allow-hotplug ${WIFI_INTERFACE}";
415
+      echo "iface ${WIFI_INTERFACE} inet manual";
416
+      echo "  wpa-roam $WIFI_CONFIG"; } > /etc/network/interfaces.d/wifi
422
 
417
 
423
     wifi_static_network_interface
418
     wifi_static_network_interface
424
 
419
 
425
     # remove wpa_supplicant.conf if it exists
420
     # remove wpa_supplicant.conf if it exists
426
-    if [ -f $WIFI_CONFIG ]; then
427
-        rm -f $WIFI_CONFIG
421
+    if [ -f "$WIFI_CONFIG" ]; then
422
+        rm -f "$WIFI_CONFIG"
428
     fi
423
     fi
429
 
424
 
430
-    echo 'ctrl_interface=/run/wpa_supplicant' > $WIFI_CONFIG
431
-    echo 'update_config=1' >> $WIFI_CONFIG
432
-    echo 'eapol_version=1' >> $WIFI_CONFIG
433
-    echo '' >> $WIFI_CONFIG
425
+    { echo 'ctrl_interface=/run/wpa_supplicant';
426
+      echo 'update_config=1';
427
+      echo 'eapol_version=1';
428
+      echo ''; } > "$WIFI_CONFIG"
434
 
429
 
435
     ctr=0
430
     ctr=0
436
     while read -r line
431
     while read -r line
443
                 if [ $ctr -eq 1 ]; then
438
                 if [ $ctr -eq 1 ]; then
444
                     WIFI_TYPE="$line"
439
                     WIFI_TYPE="$line"
445
                     if [[ $WIFI_TYPE == $'none' || $WIFI_TYPE == $'open' ]]; then
440
                     if [[ $WIFI_TYPE == $'none' || $WIFI_TYPE == $'open' ]]; then
446
-                        echo 'network={' >> $WIFI_CONFIG
441
+                        echo 'network={' >> "$WIFI_CONFIG"
447
                         if [[ "${WIFI_SSID}" != $'any' && "${WIFI_SSID}" != $'all' && "${WIFI_SSID}" != $'open' ]]; then
442
                         if [[ "${WIFI_SSID}" != $'any' && "${WIFI_SSID}" != $'all' && "${WIFI_SSID}" != $'open' ]]; then
448
-                            echo "  ssid=\"${WIFI_SSID}\"" >> $WIFI_CONFIG
443
+                            echo "  ssid=\"${WIFI_SSID}\"" >> "$WIFI_CONFIG"
449
                         fi
444
                         fi
450
-                        echo '  key_mgmt=NONE' >> $WIFI_CONFIG
451
-                        echo '}' >> $WIFI_CONFIG
445
+                        echo '  key_mgmt=NONE' >> "$WIFI_CONFIG"
446
+                        echo '}' >> "$WIFI_CONFIG"
452
                         ctr=0
447
                         ctr=0
453
                         continue
448
                         continue
454
                     fi
449
                     fi
455
                 fi
450
                 fi
456
                 if [ $ctr -eq 2 ]; then
451
                 if [ $ctr -eq 2 ]; then
457
                     WIFI_PASSPHRASE="$line"
452
                     WIFI_PASSPHRASE="$line"
458
-                    wpa_passphrase "$WIFI_SSID" "$WIFI_PASSPHRASE" >> $WIFI_CONFIG
453
+                    wpa_passphrase "$WIFI_SSID" "$WIFI_PASSPHRASE" >> "$WIFI_CONFIG"
459
                     ctr=0
454
                     ctr=0
460
                     continue
455
                     continue
461
                 fi
456
                 fi
463
                 ctr=$((ctr + 1))
458
                 ctr=$((ctr + 1))
464
             fi
459
             fi
465
         fi
460
         fi
466
-    done < $WIFI_NETWORKS_FILE
461
+    done < "$WIFI_NETWORKS_FILE"
467
 
462
 
468
     systemctl restart network-manager
463
     systemctl restart network-manager
469
     #ifconfig ${WIFI_INTERFACE} up
464
     #ifconfig ${WIFI_INTERFACE} up
471
 }
466
 }
472
 
467
 
473
 function wifi_networks_file_header {
468
 function wifi_networks_file_header {
474
-    echo $'# Add wifi networks as follows:' > $WIFI_NETWORKS_FILE
475
-    echo '#' >> $WIFI_NETWORKS_FILE
476
-    echo $'# MySSID' >> $WIFI_NETWORKS_FILE
477
-    echo $'# wpa2-psk' >> $WIFI_NETWORKS_FILE
478
-    echo $'# myWifiPassphrase' >> $WIFI_NETWORKS_FILE
479
-    echo '#' >> $WIFI_NETWORKS_FILE
480
-    echo $'# AnotherSSID' >> $WIFI_NETWORKS_FILE
481
-    echo $'# none' >> $WIFI_NETWORKS_FILE
482
-    echo '#' >> $WIFI_NETWORKS_FILE
469
+    { echo $'# Add wifi networks as follows:';
470
+      echo '#';
471
+      echo $'# MySSID';
472
+      echo $'# wpa2-psk';
473
+      echo $'# myWifiPassphrase';
474
+      echo '#';
475
+      echo $'# AnotherSSID';
476
+      echo $'# none';
477
+      echo '#'; } > "$WIFI_NETWORKS_FILE"
483
 }
478
 }
484
 
479
 
485
 function create_networks_interactive {
480
 function create_networks_interactive {
486
     remove_config_param "WIFI_INTERFACE"
481
     remove_config_param "WIFI_INTERFACE"
487
     update_wifi_adaptors
482
     update_wifi_adaptors
488
-    if [ ! $IFACE ]; then
483
+    if [ ! "$IFACE" ]; then
489
         # Don't try to configure wifi if there are no adaptors
484
         # Don't try to configure wifi if there are no adaptors
490
         return
485
         return
491
     fi
486
     fi
492
 
487
 
493
-    if [ -f $WIFI_NETWORKS_FILE ]; then
494
-        rm $WIFI_NETWORKS_FILE
488
+    if [ -f "$WIFI_NETWORKS_FILE" ]; then
489
+        rm "$WIFI_NETWORKS_FILE"
495
     fi
490
     fi
496
 
491
 
497
     # By default connect to any open wifi
492
     # By default connect to any open wifi
503
     wifi_settings_defined=
498
     wifi_settings_defined=
504
     while [ ! $wifi_networks_done ]
499
     while [ ! $wifi_networks_done ]
505
     do
500
     do
506
-        data=$(tempfile 2>/dev/null)
507
-        trap "rm -f $data" 0 1 2 5 15
508
-        wifistr=$"\nTo use this system via wifi (eg. USB dongle) enter the details below, otherwise just select Ok:"
501
+        data=$(mktemp 2>/dev/null)
502
+        wifistr=$"\\nTo use this system via wifi (eg. USB dongle) enter the details below, otherwise just select Ok:"
509
         if [ -f /root/.wifi-only ]; then
503
         if [ -f /root/.wifi-only ]; then
510
-            wifistr=$"\nEnter your wifi login details below."
504
+            wifistr=$"\\nEnter your wifi login details below."
511
         fi
505
         fi
512
         dialog --backtitle $"Freedombone Configuration" \
506
         dialog --backtitle $"Freedombone Configuration" \
513
                --title $"Wifi Settings ${wifi_ctr}" \
507
                --title $"Wifi Settings ${wifi_ctr}" \
515
                $"SSID (can be 'any'):" 1 1 "$WIFI_SSID" 1 24 30 30 \
509
                $"SSID (can be 'any'):" 1 1 "$WIFI_SSID" 1 24 30 30 \
516
                $"Type (open/wpa2-psk):" 2 1 "$WIFI_TYPE" 2 24 10 10 \
510
                $"Type (open/wpa2-psk):" 2 1 "$WIFI_TYPE" 2 24 10 10 \
517
                $"Passphrase:" 3 1 "$WIFI_PASSPHRASE" 3 24 50 50 \
511
                $"Passphrase:" 3 1 "$WIFI_PASSPHRASE" 3 24 50 50 \
518
-               2> $data
512
+               2> "$data"
519
         sel=$?
513
         sel=$?
520
         case $sel in
514
         case $sel in
521
-            1) return;;
522
-            255) return;;
515
+            1) rm -f "$data"
516
+               return;;
517
+            255) rm -f "$data"
518
+                 return;;
523
         esac
519
         esac
524
-        WIFI_SSID=$(cat $data | sed -n 1p)
525
-        WIFI_TYPE=$(cat $data | sed -n 2p)
526
-        WIFI_PASSPHRASE=$(cat $data | sed -n 3p)
520
+        WIFI_SSID=$(sed -n 1p < "$data")
521
+        WIFI_TYPE=$(sed -n 2p < "$data")
522
+        WIFI_PASSPHRASE=$(sed -n 3p < "$data")
523
+        rm -f "$data"
527
 
524
 
528
         # If the wifi-only indicator is present then wifi details must
525
         # If the wifi-only indicator is present then wifi details must
529
         # be specified, otherwise they're optional
526
         # be specified, otherwise they're optional
539
             fi
536
             fi
540
         fi
537
         fi
541
 
538
 
542
-        if [ ! -f $WIFI_NETWORKS_FILE ]; then
539
+        if [ ! -f "$WIFI_NETWORKS_FILE" ]; then
543
             wifi_networks_file_header
540
             wifi_networks_file_header
544
         fi
541
         fi
545
 
542
 
546
         # update the wifi networks file
543
         # update the wifi networks file
547
-        echo '' >> $WIFI_NETWORKS_FILE
548
-        echo "$WIFI_SSID" >> $WIFI_NETWORKS_FILE
549
-        echo "$WIFI_TYPE" >> $WIFI_NETWORKS_FILE
544
+        { echo '';
545
+          echo "$WIFI_SSID";
546
+          echo "$WIFI_TYPE"; } >> "$WIFI_NETWORKS_FILE"
550
         if [ ${#WIFI_PASSPHRASE} -gt 1 ]; then
547
         if [ ${#WIFI_PASSPHRASE} -gt 1 ]; then
551
-            echo "$WIFI_PASSPHRASE" >> $WIFI_NETWORKS_FILE
548
+            echo "$WIFI_PASSPHRASE" >> "$WIFI_NETWORKS_FILE"
552
         fi
549
         fi
553
 
550
 
554
         if [ ${#WIFI_SSID} -gt 1 ]; then
551
         if [ ${#WIFI_SSID} -gt 1 ]; then
626
         systemctl disable wifistart
623
         systemctl disable wifistart
627
         rm $systemd_file
624
         rm $systemd_file
628
     fi
625
     fi
629
-    if [ -f $HOME/${PROJECT_NAME}-wifi.cfg ]; then
630
-        rm $HOME/${PROJECT_NAME}-wifi.cfg
626
+    if [ -f "$HOME/${PROJECT_NAME}-wifi.cfg" ]; then
627
+        rm "$HOME/${PROJECT_NAME}-wifi.cfg"
631
     fi
628
     fi
632
 }
629
 }
633
 
630
 
634
 function create_wifi_startup_script {
631
 function create_wifi_startup_script {
635
     systemd_file=/etc/systemd/system/wifistart.service
632
     systemd_file=/etc/systemd/system/wifistart.service
636
-    echo '[Unit]' > $systemd_file
637
-    echo 'Description=WifiStartup (Start wifi networking)' >> $systemd_file
638
-    echo 'After=syslog.target' >> $systemd_file
639
-    echo 'After=network.target' >> $systemd_file
640
-    echo 'After=remote-fs.target' >> $systemd_file
641
-    echo '' >> $systemd_file
642
-    echo '[Service]' >> $systemd_file
643
-    echo 'Type=simple' >> $systemd_file
644
-    echo 'User=root' >> $systemd_file
645
-    echo 'Group=root' >> $systemd_file
646
-    echo 'WorkingDirectory=/root' >> $systemd_file
647
-    echo "ExecStart=/usr/local/bin/${PROJECT_NAME}-wifi --wait 5 2> /dev/null" >> $systemd_file
648
-    echo '' >> $systemd_file
649
-    echo '[Install]' >> $systemd_file
650
-    echo 'WantedBy=multi-user.target' >> $systemd_file
633
+    { echo '[Unit]';
634
+      echo 'Description=WifiStartup (Start wifi networking)';
635
+      echo 'After=syslog.target';
636
+      echo 'After=network.target';
637
+      echo 'After=remote-fs.target';
638
+      echo '';
639
+      echo '[Service]';
640
+      echo 'Type=simple';
641
+      echo 'User=root';
642
+      echo 'Group=root';
643
+      echo 'WorkingDirectory=/root';
644
+      echo "ExecStart=/usr/local/bin/${PROJECT_NAME}-wifi --wait 5 2> /dev/null";
645
+      echo '';
646
+      echo '[Install]';
647
+      echo 'WantedBy=multi-user.target'; } > $systemd_file
651
 
648
 
652
     systemctl enable wifistart
649
     systemctl enable wifistart
653
     systemctl daemon-reload
650
     systemctl daemon-reload