Skip to content

Commit e666155

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 e666155

File tree

1 file changed

+49
-40
lines changed

1 file changed

+49
-40
lines changed

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

+49-40
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,43 +285,56 @@ 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
288+
scanning=0
289+
broken=1
290+
while [[ ${scanning} -lt 3 ]]; do
291+
sleep 0.5
292+
scanning=$(( scanning + 1 ))
293+
ARRAY=($(sudo 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
295+
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"
302301
while [[ 1 ]] ; do
303-
SSID=$(echo ${ARRAY[$input-1]} | cut -d"," -f2)
304-
read -r -p "Enter a password for ${SSID}: " password
305-
break
302+
while [[ 1 ]] ; do
303+
for str in ${ARRAY[@]}; do echo $str | sed "s/,/ \t /g"; done
304+
read -r -p "Enter a number of SSID: " input
305+
if [[ "$input" =~ ^[0-9]{,2}$ ]] ; then break; fi
306+
done
307+
echo ""
308+
# get password
309+
while [[ 1 ]] ; do
310+
SSID=$(echo ${ARRAY[$input-1]} | cut -d"," -f2)
311+
echo ""
312+
read -r -p "Enter a password for ${SSID}: " password
313+
break
314+
done
315+
316+
# generate config
317+
cat <<- EOF > "${SDCARD}"/etc/netplan/30-wifis-dhcp.yaml
318+
# Created by Armbian firstlogin script
319+
network:
320+
wifis:
321+
${WIFI_DEVICE}:
322+
dhcp4: yes
323+
dhcp6: yes
324+
access-points:
325+
"$SSID":
326+
password: "${password}"
327+
EOF
328+
329+
# apply to netplan
330+
systemctl daemon-reload
331+
netplan apply --timeout 0 2>/dev/null
332+
sleep 5
333+
334+
# exit if connection is suffesful
335+
if [[ -n $(sudo iw ${WIFI_DEVICE} link | grep "$SSID") ]]; then break; fi
306336
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
328-
done
337+
fi # detected or not detected wireless network
329338
fi
330339
echo ""
331340
fi

0 commit comments

Comments
 (0)