Skip to content

Commit

Permalink
Bugifx: addressing two problems at firstlogin script
Browse files Browse the repository at this point in the history
- removing network manager dependancy
- errors when wireless networking is still not detected
  • Loading branch information
igorpecovnik committed Jun 28, 2024
1 parent 8ca4068 commit e666155
Showing 1 changed file with 49 additions and 40 deletions.
89 changes: 49 additions & 40 deletions packages/bsp/common/usr/lib/armbian/armbian-firstlogin
Original file line number Diff line number Diff line change
Expand Up @@ -265,11 +265,7 @@ set_timezone_and_locales() {
PUBLIC_IP=$(curl --max-time 5 -s https://ipinfo.io/ip)

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

if [ -z "$PUBLIC_IP" ]; then

Expand All @@ -289,43 +285,56 @@ set_timezone_and_locales() {
if [[ "${response}" =~ ^(Y|y)$ ]]; then

# get list of wireless networks
echo -e "\nDetected wireless networks:\n"
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'))
while [[ 1 ]] ; do
while [[ 1 ]] ; do
for str in ${ARRAY[@]}; do echo $str | sed "s/,/ \t /g"; done
read -r -p "Enter a number of SSID: " input
if [[ "$input" =~ ^[0-9]{,2}$ ]] ; then break; fi
done
echo ""
# get password
scanning=0
broken=1
while [[ ${scanning} -lt 3 ]]; do
sleep 0.5
scanning=$(( scanning + 1 ))
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'))
if [[ $? == 0 ]]; then broken=0; break; fi
done
# wifi can also fail
if [[ ${broken} == 1 ]]; then
echo -e "\nWireless connection was \x1B[91mnot detected\x1B[0m.\n"
else
echo -e "\nDetected wireless networks:\n"
while [[ 1 ]] ; do
SSID=$(echo ${ARRAY[$input-1]} | cut -d"," -f2)
read -r -p "Enter a password for ${SSID}: " password
break
while [[ 1 ]] ; do
for str in ${ARRAY[@]}; do echo $str | sed "s/,/ \t /g"; done
read -r -p "Enter a number of SSID: " input
if [[ "$input" =~ ^[0-9]{,2}$ ]] ; then break; fi
done
echo ""
# get password
while [[ 1 ]] ; do
SSID=$(echo ${ARRAY[$input-1]} | cut -d"," -f2)
echo ""
read -r -p "Enter a password for ${SSID}: " password
break
done

# generate config
cat <<- EOF > "${SDCARD}"/etc/netplan/30-wifis-dhcp.yaml
# Created by Armbian firstlogin script
network:
wifis:
${WIFI_DEVICE}:
dhcp4: yes
dhcp6: yes
access-points:
"$SSID":
password: "${password}"
EOF

# apply to netplan
systemctl daemon-reload
netplan apply --timeout 0 2>/dev/null
sleep 5

# exit if connection is suffesful
if [[ -n $(sudo iw ${WIFI_DEVICE} link | grep "$SSID") ]]; then break; fi
done

# generate config
cat <<- EOF > "${SDCARD}"/etc/netplan/30-wifis-dhcp.yaml
# Created by Armbian firstlogin script
network:
wifis:
${WIFI_DEVICE}:
dhcp4: yes
dhcp6: yes
access-points:
"$SSID":
password: "${password}"
EOF

# apply to netplan
systemctl daemon-reload
netplan apply --timeout 0 2>/dev/null
sleep 5

# exit if connection is suffesful
if [[ -n $(sudo iw ${WIFI_DEVICE} link | grep "$SSID") ]]; then break; fi
done
fi # detected or not detected wireless network
fi
echo ""
fi
Expand Down

0 comments on commit e666155

Please sign in to comment.