71 lines
2.0 KiB
Bash
Executable File
71 lines
2.0 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
#
|
|
# It's simple script to control a wirelless network connection
|
|
# using iwd and dhcpcd
|
|
#
|
|
|
|
interface='wlo1'
|
|
m() { ${DMENU:-dmenu} "$@"; }
|
|
|
|
add() {
|
|
list_all=$(iwctl station "$interface" get-networks | awk 'NR > 4 && $0 !~ /^$/ && $0 !~ />/ { print $1}')
|
|
list_known=$(iwctl known-networks list | awk 'NR>4 && $0 !~ /^$/ { print $1 }')
|
|
list=$(comm -23 <(sort -u <<<"$list_all") <(sort -u <<<"$list_known"))
|
|
ssid=$(printf "%s" "$list" | m -i -p "Add") || return
|
|
pass=$(m -P -p " ") || return
|
|
|
|
if iwctl --passphrase "$pass" station $interface connect "$ssid"; then
|
|
notify-send "Agregué $ssid"
|
|
exit
|
|
else
|
|
notify-send "$ssid: Contraseña incorrecta"
|
|
return
|
|
fi
|
|
}
|
|
|
|
switch() {
|
|
list_known=$(iwctl known-networks list | awk 'NR>4 && $0 !~ /^$/ { print $1 }')
|
|
connected=$(iwctl station "$interface" show | awk 'NR>4 && /Connected/ { print $3 }')
|
|
list=$(comm -23 <(sort -u <<<"$list_known") <(sort -u <<<"$connected"))
|
|
|
|
[ -z "$list" ] && {
|
|
notify-send "No hay redes disponibles"
|
|
return
|
|
}
|
|
|
|
ssid=$(printf "%s" "$list" | m -p "switch") || return
|
|
if iwctl station $interface connect "$ssid"; then
|
|
notify-send "Conectado a $ssid"
|
|
exit
|
|
else
|
|
notify-send "No se pudo conectar a $ssid"
|
|
return
|
|
fi
|
|
}
|
|
|
|
forget() {
|
|
list=$(iwctl known-networks list | awk 'NR>4 && $0 !~ /^$/ { print $1 }')
|
|
[ -z "$list" ] && {
|
|
notify-send "No hay redes para olvidar."
|
|
return
|
|
}
|
|
ssid=$(printf "%s" "$list" | m -p "forget") || return
|
|
iwctl known-networks "$ssid" forget && notify-send "Olvidé $ssid" && exit
|
|
}
|
|
|
|
scan() {
|
|
iwctl station $interface scan
|
|
notify-send "Scaneando..."
|
|
}
|
|
|
|
while true; do
|
|
options="Scanear\nAgregar\nCambiar\nOlvidar"
|
|
choice=$(printf "%b" "$options" | m -i -p " ") || exit
|
|
case $choice in
|
|
"Scanear") scan ;;
|
|
"Agregar") add ;;
|
|
"Cambiar") switch ;;
|
|
"Olvidar") forget ;;
|
|
esac
|
|
done
|