functionalize wifi and cleanup

This commit is contained in:
Tobias Powalowski 2022-12-08 11:35:46 +01:00
parent da3634cb5c
commit beb862a063

View file

@ -18,6 +18,71 @@ essid_scan() {
done
}
do_wireless() {
WLAN_HIDDEN=""
WLAN_ESSID=""
WLAN_SECURITY=""
WLAN_KEY=""
# iwd renames wireless devices to wlanX
if [[ "${CONNECTION}" == "wireless" ]]; then
# bring interface up for essid scan
ip link set dev "${INTERFACE}" up
DIALOG --infobox "Scanning for ESSIDs ..." 3 40
#shellcheck disable=SC2086,SC2046
DIALOG --menu "Choose your ESSID:" 14 55 7 \
$(essid_scan _) \
"Hidden" "_" 2>"${ANSWER}" || return 1
WLAN_ESSID=$(cat "${ANSWER}")
if [[ "${WLAN_ESSID}" = "Hidden" ]]; then
DIALOG --inputbox "Enter the hidden ESSID:" 8 65 \
"secret" 2>"${ANSWER}" || return 1
WLAN_ESSID=$(cat "${ANSWER}")
WLAN_HIDDEN="yes"
fi
# readd spaces
#shellcheck disable=SC2001,SC2086
WLAN_ESSID="$(echo ${WLAN_ESSID} | sed -e 's|#|\ |g')"
while [[ ${WPA_AUTH} = "" ]]; do
DIALOG --inputbox "Enter your KEY (clear/empty for open network):" 8 50 "SecretWirelessKey" 2>"${ANSWER}" || return 1
WLAN_KEY=$(cat "${ANSWER}")
WLAN_SECURITY="WPA-PSK"
[[ -z "${WLAN_KEY}" ]] && WLAN_SECURITY="NONE"
# setup wpa_supplicant
WPA_PROFILE="/etc/wpa_supplicant/wpa_supplicant-${INTERFACE}.conf"
echo "#$NETWORK_PROFILE generated by archboot setup" > "${WPA_PROFILE}"
echo "network={" >> "${WPA_PROFILE}"
[[ "${WLAN_HIDDEN}" == "yes" ]] && echo "scan_ssid=1" >> "${WPA_PROFILE}"
echo "key_mgmt=${WLAN_SECURITY}" >> "${WPA_PROFILE}"
echo "ssid=\"${WLAN_ESSID}\"" >> "${WPA_PROFILE}"
[[ -z "${WLAN_KEY}" ]] || echo "psk=\"${WLAN_KEY}\"" >> "${WPA_PROFILE}"
echo "}" >> "${WPA_PROFILE}"
echo "wpa_supplicant config saved to ${WPA_PROFILE}." > "${LOG}"
echo "Starting wpa_supplicant@${INTERFACE} ..." > "${LOG}"
#shellcheck disable=2086
systemctl restart wpa_supplicant@${INTERFACE}.service
AUTH_COUNT="0"
DIALOG --infobox "Waiting 30 seconds for authentification ..." 3 60
#shellcheck disable=2086
while ! systemctl status wpa_supplicant@${INTERFACE} | grep -qw "CTRL-EVENT-CONNECTED"; do
sleep 1
AUTH_COUNT="$((AUTH_COUNT+1))"
systemctl status wpa_supplicant@${INTERFACE} | grep -qw "CTRL-EVENT-DISCONNECTED" && break
[[ "${AUTH_COUNT}" == "30" ]] && break
done
#shellcheck disable=2086
if systemctl status wpa_supplicant@${INTERFACE} | grep -qw "CTRL-EVENT-CONNECTED"; then
WPA_AUTH="1"
echo "wpa_supplicant@${INTERFACE}" > /tmp/.wpa_supplicant
DIALOG --infobox "Authentification successfull. Continuing in 3 seconds ..." 3 70
sleep 3
else
DIALOG --msgbox "Error:\nAuthentification failed. Please configure again!" 6 60
WPA_AUTH=""
fi
done
fi
}
# donetwork()
# Hand-hold through setting up networking
#
@ -47,69 +112,8 @@ donetwork() {
NETWORK_PROFILE=""
DIALOG --inputbox "Enter your network profile name:" 7 40 "${INTERFACE}-${CONNECTION}" 2>"${ANSWER}" || return 1
NETWORK_PROFILE=/etc/systemd/network/$(cat "${ANSWER}").network
# wireless switch
WLAN_HIDDEN=""
WLAN_ESSID=""
WLAN_SECURITY=""
WLAN_KEY=""
# iwd renames wireless devices to wlanX
if [[ "${CONNECTION}" == "wireless" ]]; then
# bring interface up for essid scan
ip link set dev "${INTERFACE}" up
DIALOG --infobox "Scanning for ESSIDs ..." 3 40
#shellcheck disable=SC2086,SC2046
DIALOG --menu "Choose your ESSID:" 14 55 7 \
$(essid_scan _) \
"Hidden" "_" 2>"${ANSWER}" || return 1
WLAN_ESSID=$(cat "${ANSWER}")
if [[ "${WLAN_ESSID}" = "Hidden" ]]; then
DIALOG --inputbox "Enter the hidden ESSID:" 8 65 \
"secret" 2>"${ANSWER}" || return 1
WLAN_ESSID=$(cat "${ANSWER}")
WLAN_HIDDEN="yes"
fi
# readd spaces
#shellcheck disable=SC2001,SC2086
WLAN_ESSID="$(echo ${WLAN_ESSID} | sed -e 's|#|\ |g')"
while [[ ${WPA_AUTH} = "" ]]; do
DIALOG --inputbox "Enter your KEY (clear/empty for open network):" 8 50 "SecretWirelessKey" 2>"${ANSWER}" || return 1
WLAN_KEY=$(cat "${ANSWER}")
WLAN_SECURITY="WPA-PSK"
[[ -z "${WLAN_KEY}" ]] && WLAN_SECURITY="NONE"
# setup wpa_supplicant
WPA_PROFILE="/etc/wpa_supplicant/wpa_supplicant-${INTERFACE}.conf"
echo "#$NETWORK_PROFILE generated by archboot setup" > "${WPA_PROFILE}"
echo "network={" >> "${WPA_PROFILE}"
[[ "${WLAN_HIDDEN}" == "yes" ]] && echo "scan_ssid=1" >> "${WPA_PROFILE}"
echo "key_mgmt=${WLAN_SECURITY}" >> "${WPA_PROFILE}"
echo "ssid=\"${WLAN_ESSID}\"" >> "${WPA_PROFILE}"
[[ -z "${WLAN_KEY}" ]] || echo "psk=\"${WLAN_KEY}\"" >> "${WPA_PROFILE}"
echo "}" >> "${WPA_PROFILE}"
echo "wpa_supplicant config saved to ${WPA_PROFILE}." > "${LOG}"
echo "Starting wpa_supplicant@${INTERFACE}.service ..." > "${LOG}"
#shellcheck disable=2086
systemctl restart wpa_supplicant@${INTERFACE}.service
AUTH_COUNT="0"
DIALOG --infobox "Waiting 30 seconds for authentification ..." 3 60
#shellcheck disable=2086
while ! systemctl status wpa_supplicant@${INTERFACE}.service | grep -qw CTRL-EVENT-CONNECTED > /dev/null 2>&1; do
sleep 1
AUTH_COUNT="$((AUTH_COUNT+1))"
systemctl status wpa_supplicant@${INTERFACE}.service | grep -qw CTRL-EVENT-DISCONNECTED > /dev/null 2&>1 && break
[[ "${AUTH_COUNT}" == "30" ]] && break
done
#shellcheck disable=2086
if systemctl status wpa_supplicant@${INTERFACE}.service | grep -qw CTRL-EVENT-CONNECTED ; then
WPA_AUTH="1"
echo "wpa_supplicant@${INTERFACE}.service" > /tmp/.wpa_supplicant
DIALOG --infobox "Authentification successfull. Continuing in 3 seconds ..." 3 70
sleep 3
else
DIALOG --msgbox "Error:\nAuthentification failed. Please configure again!" 6 60
WPA_AUTH=""
fi
done
fi
# wifi setup first
do_wireless
# dhcp switch
IP=""
DIALOG --yesno "Do you want to use DHCP?" 5 40