simplify wifi

This commit is contained in:
Tobias Powalowski 2023-07-14 21:05:47 +02:00
parent 756af5779b
commit 0c604a70d2

View file

@ -49,12 +49,11 @@ _essid_list() {
done done
} }
_do_wireless() { _wireless() {
_WLAN_HIDDEN="" _WLAN_HIDDEN=""
_WLAN_SSID="" _WLAN_SSID=""
_WLAN_KEY="" _WLAN_KEY=""
_WLAN_AUTH="" _WLAN_AUTH=""
if [[ "${_CONNECTION}" == "wireless" ]]; then
# disconnect the interface first! # disconnect the interface first!
iwctl station "${_INTERFACE}" disconnect &>"${_NO_LOG}" iwctl station "${_INTERFACE}" disconnect &>"${_NO_LOG}"
# clean old keys first! # clean old keys first!
@ -68,7 +67,7 @@ _do_wireless() {
#shellcheck disable=SC2086,SC2046 #shellcheck disable=SC2086,SC2046
if _dialog --title " SSID Scan Result " --menu "Empty spaces in your SSID are replaced by '+' char" 13 60 6 \ if _dialog --title " SSID Scan Result " --menu "Empty spaces in your SSID are replaced by '+' char" 13 60 6 \
$(_essid_list _) \ $(_essid_list _) \
"Hidden" "_" "RESCAN" "_" 2>"${_ANSWER}"; then "HIDDEN" "SSID" "RESCAN" "SSIDs" 2>"${_ANSWER}"; then
_WLAN_SSID=$(cat "${_ANSWER}") _WLAN_SSID=$(cat "${_ANSWER}")
_CONTINUE=1 _CONTINUE=1
if grep -q 'RESCAN' "${_ANSWER}"; then if grep -q 'RESCAN' "${_ANSWER}"; then
@ -79,37 +78,21 @@ _do_wireless() {
fi fi
done done
_WLAN_CONNECT="connect" _WLAN_CONNECT="connect"
if [[ "${_WLAN_SSID}" == "Hidden" ]]; then if [[ "${_WLAN_SSID}" == "HIDDEN" ]]; then
_CONTINUE="" _dialog --no-cancel --title " HIDDEN SSID " --inputbox "" 7 65 "secret" 2>"${_ANSWER}"
while [[ -z "${_CONTINUE}" ]]; do
if _dialog --title " Hidden SSID " --inputbox "" 7 65 \
"secret" 2>"${_ANSWER}"; then
_WLAN_SSID=$(cat "${_ANSWER}") _WLAN_SSID=$(cat "${_ANSWER}")
_WLAN_CONNECT="connect-hidden" _WLAN_CONNECT="connect-hidden"
_WLAN_HIDDEN=1 _WLAN_HIDDEN=1
_CONTINUE=1
else
_abort
fi
done
fi fi
# replace # with spaces again # replace # with spaces again
#shellcheck disable=SC2001,SC2086 #shellcheck disable=SC2001,SC2086
_WLAN_SSID="$(echo ${_WLAN_SSID} | sed -e 's|\+|\ |g')" _WLAN_SSID="$(echo ${_WLAN_SSID} | sed -e 's|\+|\ |g')"
#shellcheck disable=SC2001,SC2086
# expect hidden network has a WLAN_KEY # expect hidden network has a WLAN_KEY
#shellcheck disable=SC2143 #shellcheck disable=SC2143
if ! [[ "$(iwctl station "${_INTERFACE}" get-networks | grep -w "${_WLAN_SSID}" | cut -c 42-49 | grep -q 'open')" ]] \ if ! [[ "$(iwctl station "${_INTERFACE}" get-networks | grep -w "${_WLAN_SSID}" | cut -c 42-49 | grep -q 'open')" ]] \
|| [[ "${_WLAN_CONNECT}" == "connect-hidden" ]]; then || [[ "${_WLAN_CONNECT}" == "connect-hidden" ]]; then
_CONTINUE="" _dialog --no-cancel --title " Connection Key " --inputbox "" 7 50 "Secret-WirelessKey" 2>"${_ANSWER}"
while [[ -z "${_CONTINUE}" ]]; do
if _dialog --no-cancel --title " Connection Key " --inputbox "" 7 50 "Secret-WirelessKey" 2>"${_ANSWER}"; then
_WLAN_KEY=$(cat "${_ANSWER}") _WLAN_KEY=$(cat "${_ANSWER}")
_CONTINUE=1
else
_abort
fi
done
fi fi
# time to connect # time to connect
_dialog --infobox "Connecting to SSID='${_WLAN_SSID}' with interface ${_INTERFACE}..." 3 70 _dialog --infobox "Connecting to SSID='${_WLAN_SSID}' with interface ${_INTERFACE}..." 3 70
@ -124,12 +107,12 @@ _do_wireless() {
if [[ -n "${_WLAN_AUTH}" ]]; then if [[ -n "${_WLAN_AUTH}" ]]; then
_dialog --infobox "Authentification was successful." 3 70 _dialog --infobox "Authentification was successful." 3 70
sleep 3 sleep 3
return 0
else else
_dialog --infobox "Error:\nAuthentification failed. Please configure again!" 6 60 _dialog --infobox "Error:\nAuthentification failed. Please configure again!" 6 60
sleep 5 sleep 5
return 1 return 1
fi fi
fi
} }
_network() { _network() {
@ -160,7 +143,7 @@ _network() {
# wifi setup first # wifi setup first
_CONTINUE="" _CONTINUE=""
while [[ -z "${_CONTINUE}" && "${_CONNECTION}" == "wireless" ]]; do while [[ -z "${_CONTINUE}" && "${_CONNECTION}" == "wireless" ]]; do
if _do_wireless; then if _wireless; then
_CONTINUE=1 _CONTINUE=1
else else
_CONTINUE="" _CONTINUE=""