Skip to content

Commit de97455

Browse files
committed
Bugifx: addressing two problems at firstlogin script
- removing network manager dependancy - errors when wireless networking is still not detected
1 parent 8ca4068 commit de97455

File tree

1 file changed

+62
-46
lines changed

1 file changed

+62
-46
lines changed

packages/bsp/common/usr/lib/armbian/armbian-firstlogin

+62-46
Original file line numberDiff line numberDiff line change
@@ -265,11 +265,7 @@ set_timezone_and_locales() {
265265
PUBLIC_IP=$(curl --max-time 5 -s https://ipinfo.io/ip)
266266

267267
# Check if we have wireless adaptor
268-
if command -v nmcli > /dev/null 2>&1; then
269-
WIFI_DEVICE=$(LC_ALL=C nmcli dev status | grep " wifi " 2> /dev/null)
270-
elif command -v iw > /dev/null 2>&1; then
271-
WIFI_DEVICE=$(LC_ALL=C iw dev | awk '$1=="Interface"{print $2}' 2> /dev/null)
272-
fi
268+
WIFI_DEVICE=$(LC_ALL=C iw dev | awk '$1=="Interface"{print $2}' 2> /dev/null)
273269

274270
if [ -z "$PUBLIC_IP" ]; then
275271

@@ -289,49 +285,69 @@ set_timezone_and_locales() {
289285
if [[ "${response}" =~ ^(Y|y)$ ]]; then
290286

291287
# get list of wireless networks
292-
echo -e "\nDetected wireless networks:\n"
293-
ARRAY=($(sudo iwlist ${WIFI_DEVICE} scanning | egrep 'ESSID' | sed 's/^[ \t]*//' | sed 's/"//g' | sed 's/ESSID://' | awk 'BEGIN{FS=OFS=","} {$NF=++count OFS $NF} 1'))
294-
while [[ 1 ]] ; do
295-
while [[ 1 ]] ; do
296-
for str in ${ARRAY[@]}; do echo $str | sed "s/,/ \t /g"; done
297-
read -r -p "Enter a number of SSID: " input
298-
if [[ "$input" =~ ^[0-9]{,2}$ ]] ; then break; fi
299-
done
300-
echo ""
301-
# get password
302-
while [[ 1 ]] ; do
303-
SSID=$(echo ${ARRAY[$input-1]} | cut -d"," -f2)
304-
read -r -p "Enter a password for ${SSID}: " password
305-
break
306-
done
307-
308-
# generate config
309-
cat <<- EOF > "${SDCARD}"/etc/netplan/30-wifis-dhcp.yaml
310-
# Created by Armbian firstlogin script
311-
network:
312-
wifis:
313-
${WIFI_DEVICE}:
314-
dhcp4: yes
315-
dhcp6: yes
316-
access-points:
317-
"$SSID":
318-
password: "${password}"
319-
EOF
320-
321-
# apply to netplan
322-
systemctl daemon-reload
323-
netplan apply --timeout 0 2>/dev/null
324-
sleep 5
325-
326-
# exit if connection is suffesful
327-
if [[ -n $(sudo iw ${WIFI_DEVICE} link | grep "$SSID") ]]; then break; fi
288+
scanning=0
289+
broken=1
290+
while [[ ${scanning} -lt 3 ]]; do
291+
sleep 0.5
292+
scanning=$(( scanning + 1 ))
293+
ARRAY=($(iwlist ${WIFI_DEVICE} scanning 2> /dev/null | egrep 'ESSID' | sed 's/^[ \t]*//' | sed 's/"//g' | sed 's/ESSID://' | awk 'BEGIN{FS=OFS=","} {$NF=++count OFS $NF} 1'))
294+
if [[ $? == 0 ]]; then broken=0; break; fi
328295
done
296+
# wifi can also fail
297+
if [[ ${broken} == 1 ]]; then
298+
echo -e "\nWireless connection was \x1B[91mnot detected\x1B[0m.\n"
299+
else
300+
echo -e "\nDetected wireless networks:\n"
301+
scanning=0
302+
broken=1
303+
while [[ ${scanning} -lt 3 ]]; do
304+
scanning=$(( scanning + 1 ))
305+
while [[ 1 ]] ; do
306+
for str in ${ARRAY[@]}; do echo $str | sed "s/,/ \t /g"; done
307+
echo ""
308+
read -r -p "Enter a number of SSID: " input
309+
if [[ "$input" =~ ^[0-9]{,2}$ ]] ; then break; fi
310+
done
311+
# get password
312+
while [[ 1 ]] ; do
313+
SSID=$(echo ${ARRAY[$input-1]} | cut -d"," -f2)
314+
echo ""
315+
read -r -p "Enter a password for ${SSID}: " password
316+
break
317+
done
318+
319+
# generate config
320+
cat <<- EOF > "${SDCARD}"/etc/netplan/30-wifis-dhcp.yaml
321+
# Created by Armbian firstlogin script
322+
network:
323+
wifis:
324+
${WIFI_DEVICE}:
325+
dhcp4: yes
326+
dhcp6: yes
327+
access-points:
328+
"$SSID":
329+
password: "${password}"
330+
EOF
331+
332+
# apply to netplan
333+
systemctl daemon-reload
334+
netplan apply --timeout 0 2>/dev/null
335+
sleep 5
336+
337+
# exit if connection is suffesful
338+
if [[ -n $(iw "${WIFI_DEVICE}" link 2> /dev/null | grep "$SSID") ]]; then broken=0; break; fi
339+
done
340+
if [[ ${broken} == 1 ]]; then
341+
echo -e "\n\x1B[91mUnable to connect to Access Point\x1B[0m.\n"
342+
fi
343+
fi # detected or not detected wireless network
329344
fi
330345
echo ""
331346
fi
332347
fi
333348

334349
# Grab IP once again if not found
350+
sleep 3
335351
[[ -z "$PUBLIC_IP" && -n "$WIFI_DEVICE" ]] && PUBLIC_IP=$(curl --max-time 5 -s https://ipinfo.io/ip)
336352

337353
# Call the geolocation API and capture the output
@@ -346,15 +362,17 @@ set_timezone_and_locales() {
346362

347363
TZDATA=$(echo "${RES}" | cut -d"," -f1)
348364
CCODE=$(echo "${RES}" | cut -d"," -f3 | xargs)
349-
echo -e "Detected timezone: \x1B[92m$TZDATA\x1B[0m"
350-
echo ""
365+
351366
unset response
352367
while [[ ! "${response}" =~ ^(Y|y|N|n)$ ]]; do
353-
if [ -z $SET_LANG_BASED_ON_LOCATION ];then
368+
if [ -z "${SET_LANG_BASED_ON_LOCATION}" ] && [ -n "${TZDATA}" ];then
369+
echo -e "Detected timezone: \x1B[92m$TZDATA\x1B[0m"
370+
echo ""
354371
read -r -p "Set user language based on your location? [Y/n] " response
355372
response=${response:-Y}
356373
else
357374
response=$SET_LANG_BASED_ON_LOCATION
375+
break
358376
fi
359377
done
360378
# change it only if we have a match and if we agree
@@ -367,13 +385,11 @@ set_timezone_and_locales() {
367385
# UTF8 is not present everywhere so check again in case it returns empty value
368386
[[ -z "$LOCALES" ]] && LOCALES=$(grep territory /usr/share/i18n/locales/* | grep _"$CCODE" | cut -d ":" -f 1 | cut -d "/" -f 6 |
369387
xargs -I{} grep {} /usr/share/i18n/SUPPORTED | cut -d " " -f 1)
370-
371388
readarray -t options <<< "${LOCALES}"
372389

373390
if [ -z $PRESET_LOCALE ];then
374391
# when having more locales, prompt for choosing one
375392
if [[ "${#options[@]}" -gt 1 ]]; then
376-
377393
options+=("Skip generating locales")
378394
echo -e "\nAt your location, more locales are possible:\n"
379395
PS3='Please enter your choice:'

0 commit comments

Comments
 (0)