92 lines
2.2 KiB
Text
92 lines
2.2 KiB
Text
|
#!/usr/bin/env bash
|
||
|
|
||
|
# ***This script was made by Clay Gomera (Drake)***
|
||
|
# - Description: A simple wifi rofi script
|
||
|
# - Dependencies: rofi, NetworkManager
|
||
|
|
||
|
## ROFI VARIABLES ##
|
||
|
ROFI1="rofi -dmenu -l 10 -b -i -p"
|
||
|
ROFI2="rofi -dmenu -b -p"
|
||
|
ROFI3="rofi -dmenu -l 5 -b -i -p"
|
||
|
|
||
|
## MAIN OPTIONS ##
|
||
|
option1="(O) Turn on WiFi"
|
||
|
option2="(F) Turn off WiFi"
|
||
|
option3="(D) Disconnect WiFi"
|
||
|
option4="(C) Connect WiFi"
|
||
|
option5="(S) Setup captive portal"
|
||
|
option6="(X) Exit"
|
||
|
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
|
||
|
bssid=$(nmcli device wifi list | sed -n '1!p' | cut -b 9- | $ROFI1 "Select Wifi :" | cut -d' ' -f1)
|
||
|
}
|
||
|
|
||
|
## SELECT PASSWORD FUNCTION ##
|
||
|
password() {
|
||
|
pass=$(echo " " | $ROFI2 "Enter Password :")
|
||
|
}
|
||
|
|
||
|
## MAIN CONNECTION COMMAND ##
|
||
|
action() {
|
||
|
nmcli device wifi connect "$bssid" password "$pass" || nmcli device wifi connect "$bssid"
|
||
|
}
|
||
|
|
||
|
## 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 ##
|
||
|
cases=$(echo -e "$options" | $ROFI3 "What do you want to do?" )
|
||
|
case "$cases" in
|
||
|
$option1*)
|
||
|
turnon;;
|
||
|
$option2*)
|
||
|
turnoff;;
|
||
|
$option3*)
|
||
|
disconnect;;
|
||
|
$option4*)
|
||
|
connect;
|
||
|
password;
|
||
|
action;
|
||
|
check;;
|
||
|
$option5*)
|
||
|
io.elementary.capnet-assist;;
|
||
|
$option6*)
|
||
|
exit 0
|
||
|
esac
|