2022-09-13 01:06:55 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
# ***This script was made by Clay Gomera (Drake)***
|
2022-12-20 00:15:21 +00:00
|
|
|
# - Description: A simple wifi dmenu script
|
|
|
|
# - Dependencies: dmenu, NetworkManager
|
2022-09-13 01:06:55 +00:00
|
|
|
|
|
|
|
## MAIN OPTIONS ##
|
2022-12-20 00:15:21 +00:00
|
|
|
option1="turn on wifi"
|
|
|
|
option2="turn off wifi"
|
|
|
|
option3="disconnect wifi"
|
|
|
|
option4="connect wifi"
|
|
|
|
option5="setup captive portal"
|
|
|
|
option6="exit"
|
2022-09-13 01:06:55 +00:00
|
|
|
options="$option1\n$option2\n$option3\n$option4\n$option5\n$option6"
|
|
|
|
|
|
|
|
wlan=$(nmcli dev | grep wifi | sed 's/ \{2,\}/|/g' | cut -d '|' -f1 | head -1)
|
|
|
|
## TURN OFF WIFI FUNCTION ##
|
|
|
|
turnoff() {
|
|
|
|
nmcli radio wifi off
|
|
|
|
notify-send "WiFi has been turned off"
|
|
|
|
}
|
|
|
|
|
|
|
|
## TURN ON WIFI FUNCTION ##
|
|
|
|
turnon() {
|
|
|
|
nmcli radio wifi on
|
|
|
|
notify-send "WiFi has been turned on"
|
|
|
|
}
|
|
|
|
|
|
|
|
## DISCONNECT WIFI FUNCTION ##
|
|
|
|
disconnect() {
|
|
|
|
nmcli device disconnect "$wlan"
|
|
|
|
sleep 1
|
|
|
|
constate=$(nmcli dev | grep wifi | sed 's/ \{2,\}/|/g' | cut -d '|' -f3 | head -1)
|
|
|
|
if [ "$constate" = "disconnected" ]; then
|
|
|
|
notify-send "WiFi has been disconnected"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
## CONNECT FUNCTION ##
|
|
|
|
connect() {
|
|
|
|
notify-send "Scannig networks, please wait"
|
|
|
|
sleep 1
|
2023-05-26 06:52:32 +00:00
|
|
|
bssid=$(nmcli device wifi list | sed -n '1!p' | cut -b 9- | dmenu -i -l 10 -nb \#1d2021 -nf \#fbf1c7 -sb \#cc241d -sf \#fbf1c7 -p "select wifi:" | cut -d' ' -f1)
|
2023-05-26 06:32:03 +00:00
|
|
|
}
|
2022-09-13 01:06:55 +00:00
|
|
|
|
|
|
|
## SELECT PASSWORD FUNCTION ##
|
|
|
|
password() {
|
2023-05-26 06:52:32 +00:00
|
|
|
pass=$(echo " " | dmenu -P -i -nb \#1d2021 -nf \#fbf1c7 -sb \#cc241d -sf \#fbf1c7 -p "enter password:")
|
2023-05-26 06:32:03 +00:00
|
|
|
}
|
2022-09-13 01:06:55 +00:00
|
|
|
|
|
|
|
## MAIN CONNECTION COMMAND ##
|
|
|
|
action() {
|
|
|
|
nmcli device wifi connect "$bssid" password "$pass" || nmcli device wifi connect "$bssid"
|
2023-05-26 06:32:03 +00:00
|
|
|
}
|
2022-09-13 01:06:55 +00:00
|
|
|
|
|
|
|
## CHECKING IF WIFI IS WORKING
|
|
|
|
check() {
|
|
|
|
notify-send "Checking if connection was successful"
|
|
|
|
sleep 1
|
|
|
|
currentwfi=$(nmcli dev | grep wifi | sed 's/ \{2,\}/|/g' | cut -d '|' -f4 | head -1)
|
|
|
|
if ping -q -c 2 -W 2 google.com >/dev/null; then
|
|
|
|
notify-send "You are now connected to $currentwfi and internet is working properly"
|
|
|
|
else
|
|
|
|
notify-send "Your internet is not working :("
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
## MAIN ACTION COMMANDS ##
|
2023-05-26 06:52:32 +00:00
|
|
|
cases=$(echo -e "$options" | dmenu -i -nb \#1d2021 -nf \#fbf1c7 -sb \#cc241d -sf \#fbf1c7 -p "wifi options:" )
|
2022-09-13 01:06:55 +00:00
|
|
|
case "$cases" in
|
|
|
|
$option1*)
|
|
|
|
turnon;;
|
|
|
|
$option2*)
|
|
|
|
turnoff;;
|
|
|
|
$option3*)
|
|
|
|
disconnect;;
|
|
|
|
$option4*)
|
|
|
|
connect;
|
|
|
|
password;
|
|
|
|
action;
|
|
|
|
check;;
|
|
|
|
$option5*)
|
2023-05-27 04:52:32 +00:00
|
|
|
$BROWSER http://networkcheck.kde.org;;
|
2022-09-13 01:06:55 +00:00
|
|
|
$option6*)
|
|
|
|
exit 0
|
|
|
|
esac
|