Replace Network manager nmtui-connect with own method

This commit is contained in:
Igor Pecovnik
2024-06-20 19:07:21 +02:00
committed by Igor
parent ce16e75642
commit 942bd4188d

View File

@@ -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