22 lines
561 B
Bash
22 lines
561 B
Bash
#!/bin/bash
|
|
|
|
sudo ip addr flush dev wlan0
|
|
sudo killall wpa_supplicant
|
|
sudo truncate -s 0 /tmp/wifi_connection_status.txt
|
|
sudo wpa_supplicant -B -i wlan0 -f /tmp/wifi_connection_status.txt -c /etc/wpa_supplicant/wpa_supplicant.conf
|
|
|
|
declare -i i=0
|
|
declare -i timeout=10
|
|
while [ $i -le $timeout ]; do
|
|
if grep -iq 'CTRL-EVENT-CONNECTED' /tmp/wifi_connection_status.txt; then
|
|
sudo dhclient wlan0
|
|
exit 2
|
|
elif grep -iq '4-Way Handshake failed' /tmp/wifi_connection_status.txt; then
|
|
exit 2
|
|
fi
|
|
|
|
(( i++ ))
|
|
sleep 1
|
|
done
|
|
|
|
exit 0 |