From 942bd4188d442e9ad56fd585b716205fdbb96a87 Mon Sep 17 00:00:00 2001 From: Igor Pecovnik Date: Thu, 20 Jun 2024 19:07:21 +0200 Subject: [PATCH] Replace Network manager nmtui-connect with own method --- .../common/usr/lib/armbian/armbian-firstlogin | 42 +++++++++++++++++-- 1 file changed, 39 insertions(+), 3 deletions(-) diff --git a/packages/bsp/common/usr/lib/armbian/armbian-firstlogin b/packages/bsp/common/usr/lib/armbian/armbian-firstlogin index 47cdf52cf..625958dba 100755 --- a/packages/bsp/common/usr/lib/armbian/armbian-firstlogin +++ b/packages/bsp/common/usr/lib/armbian/armbian-firstlogin @@ -285,10 +285,47 @@ set_timezone_and_locales() { else response=n fi - echo "$response" done if [[ "${response}" =~ ^(Y|y)$ ]]; then - nmtui-connect + + # 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 + while [[ 1 ]] ; do + SSID=$(echo ${ARRAY[$input-1]} | cut -d"," -f2) + 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 fi echo "" fi @@ -319,7 +356,6 @@ set_timezone_and_locales() { else response=$SET_LANG_BASED_ON_LOCATION fi - echo "$response" done # change it only if we have a match and if we agree if [[ "${response}" =~ ^(N|n)$ ]]; then