Fix wpa_supplicant stuffs

Now it checks if the service exists and if it's running or not
This commit is contained in:
Le0xFF 2022-07-06 08:56:36 +02:00
parent 5f5fb2b19b
commit 10001b9a08

View File

@ -28,19 +28,23 @@ function set_keyboard_layout () {
echo -e "\nTo set a keyboard layout, write its name, without \".map.gz\" (i.e. us.map.gz -> us).\n"
while true ; do
read -p "Choose the keyboard layout you want to set and press [ENTER] or press [ENTER] to keep the one currently set: " user_keyboard_layout
if [[ -z "${user_keyboard_layout}" ]]; then
echo -e "\nNo keyboard layout selected, keeping the previous one."
break
else
if loadkeys ${user_keyboard_layout} 2>/dev/null ; then
echo -e "\nKeyboad layout set to \"${user_keyboard_layout}\"."
break
else
echo -e "\nNot a valid keyboard layout, please try again.\n"
fi
fi
done
}
@ -62,45 +66,47 @@ function connect_to_wifi () {
if [[ "${yn}" == "y" ]] || [[ "${yn}" == "Y" ]] ; then
if [[ -e /var/service/NetworkManager ]] ; then
while true; do
echo
read -n 1 -r -p "Is your ESSID hidden? (y/n): " yn
if [[ "${yn}" == "y" ]] || [[ "${yn}" == "Y" ]] ; then
echo
echo
nmcli device wifi
echo
nmcli --ask device wifi connect ${wifi_essid} hidden yes
nmcli --ask device wifi connect hidden yes
break
elif [[ "${yn}" == "n" ]] || [[ "${yn}" == "N" ]] ; then
echo
echo
nmcli device wifi
echo
nmcli --ask device wifi connect ${wifi_essid}
nmcli --ask device wifi connect
break
fi
done
else
### UNTESTED ###
echo
ip a
echo
while true; do
echo -e -n "\nEnter the wifi interface and press [ENTER]: "
read wifi_interface
if [[ ! -z "${wifi_interface}" ]]; then
echo -e -n "\nEnter your ESSID and press [ENTER]: "
read wifi_essid
if [[ -d /etc/wpa_supplicant/ ]]; then
continue
else
mkdir -p /etc/wpa_supplicant/
fi
echo -e "\nGenerating configuration files..."
wpa_passphrase "${wifi_essid}" | tee /etc/wpa_supplicant/wpa_supplicant.conf
wpa_supplicant -B -c /etc/wpa_supplicant/wpa_supplicant.conf -i "${wifi_interface}"
echo -e "\nEnabling wpa_supplicant service..."
if [[ -e /var/service/wpa_supplicant ]]; then
echo -e "\nService already enabled, restarting..."
sv restart {dhcpcd,wpa_supplicant}
@ -109,6 +115,20 @@ function connect_to_wifi () {
ln -s /etc/sv/wpa_supplicant /var/service/
sv restart {dhcpcd,wpa_supplicant}
fi
echo -e -n "\nEnter your ESSID and press [ENTER]: "
read wifi_essid
if [[ -d /etc/wpa_supplicant/ ]]; then
continue
else
mkdir -p /etc/wpa_supplicant/
fi
echo -e "\nGenerating configuration files..."
wpa_passphrase "${wifi_essid}" | tee /etc/wpa_supplicant/wpa_supplicant.conf
wpa_supplicant -B -c /etc/wpa_supplicant/wpa_supplicant.conf -i "${wifi_interface}"
break
else
@ -116,6 +136,7 @@ function connect_to_wifi () {
fi
done
fi
if ping -c2 8.8.8.8 &> /dev/null ; then