@@ -55,7 +55,8 @@ country_set()
5555 " $WLAN_IFACE " " $ifconfig_args "
5656 error_str=" ${error_str# ifconfig: } "
5757 # Restart wpa_supplicant(8) (should not fail).
58- [ " $iface_up " ] && f_eval_catch -d wlanconfig wpa_supplicant \
58+ [ " $iface_up " ] && ifconfig " $WLAN_IFACE " up && \
59+ f_eval_catch -d wlanconfig wpa_supplicant \
5960 ' wpa_supplicant -B -i "%s" -c "%s/wpa_supplicant.conf"' \
6061 " $WLAN_IFACE " " $BSDINSTALL_TMPETC "
6162 if [ " $error_str " ]; then
@@ -91,7 +92,7 @@ dialog_country_select()
9192 sub(/.*domains:/, ""), /[^[:alnum:][[:space:]]/ {
9293 n = split($0, domains)
9394 for (i = 1; i <= n; i++)
94- printf "' \' ' %s' \' ' ' \'\' ' ", domains[i]
95+ printf "' \' ' %s' \' ' ' \'\' ' \n ", domains[i]
9596 }
9697 ' | sort )
9798 countries=$( echo " $input " | awk '
@@ -146,6 +147,34 @@ dialog_country_select()
146147 country_set " $regdomain " " $country "
147148}
148149
150+ dialog_network_select ()
151+ {
152+ local ssid flags height width rows prompt
153+
154+ # Avoid using eval on untrusted data.
155+ set --
156+ while IFS=$' \t ' read -r ssid flags; do
157+ [ -n " $ssid " ] || continue
158+ set -- " $@ " " $ssid " " $flags "
159+ done << EOF
160+ $NETWORKS
161+ EOF
162+
163+ f_dialog_title " Network Selection"
164+ prompt=" Select a wireless network to connect to."
165+ f_dialog_menu_size height width rows \
166+ " $DIALOG_TITLE " " $DIALOG_BACKTITLE " " $prompt " " " " $@ "
167+ $DIALOG \
168+ --title " $DIALOG_TITLE " \
169+ --backtitle " $DIALOG_BACKTITLE " \
170+ --extra-button \
171+ --extra-label " Rescan" \
172+ --menu " $prompt " \
173+ $height $width $rows \
174+ " $@ " \
175+ 2>&1 >& $DIALOG_TERMINAL_PASSTHRU_FD
176+ }
177+
149178# ########################################################### MAIN
150179
151180: > " $BSDINSTALL_TMPETC /wpa_supplicant.conf"
199228
200229while : ; do
201230 SCANSSID=0
231+ # While wpa_supplicant may IFF_UP the interface, we do not want to rely
232+ # in this. In case the script is run manually (outside the installer,
233+ # e.g., for testing) wpa_supplicant may be running and the wlanN
234+ # interface may be down (especially if dialog_country_select is not
235+ # run successfully either) and scanning will not work.
236+ f_eval_catch -d wlanconfig ifconfig " ifconfig $WLAN_IFACE up"
202237 f_eval_catch -d wlanconfig wpa_cli " wpa_cli scan"
203238 f_dialog_title " Scanning"
204239 f_dialog_pause " Waiting 5 seconds to scan for wireless networks..." 5 ||
205240 exit 1
206241
207242 f_eval_catch -dk SCAN_RESULTS wlanconfig wpa_cli " wpa_cli scan_results"
208243 NETWORKS=$( echo " $SCAN_RESULTS " | awk -F ' \t' '
209- /..:..:..:..:..:../ && $5 { printf "\"%s\"\t\"%s\"\n", $5, $4 }
244+ /..:..:..:..:..:../ && $5 { print $5 "\t" $4 }
210245 ' | sort | uniq )
211246
212247 if [ ! " $NETWORKS " ]; then
213248 f_dialog_title " $msg_error "
214249 f_yesno " No wireless networks were found. Rescan?" && continue
215- exit 1
250+ else
251+ NETWORK=$( dialog_network_select )
216252 fi
217-
218- f_dialog_title " Network Selection"
219- prompt=" Select a wireless network to connect to."
220- f_dialog_menu_size height width rows " $DIALOG_TITLE " \
221- " $DIALOG_BACKTITLE " " $prompt " " " $menu_list
222- NETWORK=$( eval $DIALOG \
223- --title \"\$ DIALOG_TITLE\" \
224- --backtitle \"\$ DIALOG_BACKTITLE\" \
225- --extra-button \
226- --extra-label \" Rescan\" \
227- --menu \"\$ prompt\" \
228- $height $width $rows \
229- $NETWORKS \
230- 2>&1 >& $DIALOG_TERMINAL_PASSTHRU_FD
231- )
232253 retval=$?
233254 f_dialog_data_sanitize NETWORK
234255 case $retval in
@@ -264,7 +285,7 @@ while :; do
264285done
265286
266287[ " $ENCRYPTION " ] || ENCRYPTION=$( echo " $NETWORKS " |
267- awk -F ' \t' " /^\" $NETWORK \" \t/ { print \$ 2 }" )
288+ awk -F ' \t' " /^$NETWORK \t/ { print \$ 2 }" )
268289
269290if echo " $ENCRYPTION " | grep -q PSK; then
270291 PASS=$( $DIALOG \
0 commit comments