#!/bin/sh # speedwm-netctrl # dmenu/other run launcher GUI for iwd # Licensed under the GNU GPLv3 free software license. case "$RUNLAUNCHER" in "") RUNLAUNCHER=dmenu ;; esac BINDIR=$(cat /usr/share/speedwm-bindir) HAVE_GRID="true" HAVE_PASSWORD="false" if [ -e "$HOME/.config/speedwm-de/global/config" ]; then . $HOME/.config/speedwm-de/global/config grep -q HAVE_PASSWORD $HOME/.config/speedwm-de/global/config || printf "\nHAVE_PASSWORD=$HAVE_PASSWORD # Whether or not to use the Password argument if a script requests it. If you do not have the dmenu password patch, set this to false. Doing so will disable password prompts." >> $HOME/.config/speedwm-de/global/config else mkdir -p $HOME/.config/speedwm-de/global printf "HAVE_GRID=$HAVE_GRID # Whether or not to use the Grid argument. If you do not have the dmenu grid patch, set this to false. Doing so will disable grid." > $HOME/.config/speedwm-de/global/config printf "\nHAVE_PASSWORD=$HAVE_PASSWORD # Whether or not to use the Password argument if a script requests it. If you do not have the dmenu password patch, set this to false. Doing so will disable password prompts." >> $HOME/.config/speedwm-de/global/config fi if [ "$HAVE_GRID" = "true" ]; then GRIDNUM="1" fi if [ "$HAVE_GRID" = "true" ]; then GRIDARG="-g" fi SHOW_PASSWORD="true" test ${BINDIR}iwctl || exit 0 if [ -e "$HOME/.config/speedwm-de/netctrl/config" ]; then . $HOME/.config/speedwm-de/netctrl/config else mkdir -p $HOME/.config/speedwm-de/netctrl printf "SHOW_PASSWORD=$SHOW_PASSWORD # Show password when entering it or not? Requires the 'password' dmenu patch. If you do not have it, you can get my build. You also need to enable it in $HOME/.config/speedwm-de/global/config. (true/false)" > $HOME/.config/speedwm-de/netctrl/config fi if [ "$SHOW_PASSWORD" = "false" ]; then if [ "$HAVE_PASSWORD" = "true" ]; then PASS_ARG="-P" fi fi # Get the device used to connect. getdevice() { seldevice=$1 if [ -e "$HOME/.local/share/seldevice" ]; then seldevice=$(cat $HOME/.local/share/seldevice) else case "$1" in "") devices="$(printf "\n$(ip link)" | awk '{ print $2 }' | awk 'NR%2==0' | sed "s/://g")" seldevice=$(echo $devices | sed 's/ /\n/g' | $RUNLAUNCHER -p "What device do you want to connect with?" -l 10 $GRIDARG $GRIDNUM) && echo $seldevice > $HOME/.local/share/seldevice ;; esac fi case "$seldevice" in "") exit 0 ;; esac } connectwifi() { iwctl station $seldevice scan network="$(printf "$(iwctl station $seldevice get-networks | sed -n 6,20p | sed "s|>||g" | awk '{ print $1 }')\n------\nExit" | sed "s| |No networks found|g" | $RUNLAUNCHER -l 10 $GRIDARG $GRIDNUM -p "Select a network to connect to" | sed "s|------||g" | sed "s|No networks found| |g")" case "$network" in "") $0 && exit 0 ;; "Exit") exit 0 ;; esac iwctl station $seldevice get-networks | grep "$network" > /dev/null || exit 1 connect_pass() { PASSPHRASE=$(printf "\n" | $RUNLAUNCHER -p "This network is protected. Enter the passphrase." -l 1 $GRIDARG $GRIDNUM $PASS_ARG) case "$PASSPHRASE" in "") exit 0 ;; esac printf "$network\n" >> $HOME/.local/share/networks iwctl station $seldevice connect $network -P $PASSPHRASE || connect_pass if [ -e "${BINDIR}notify-send" ]; then notify-send " Connected to $network!" fi exit 0 } connect_no_pass() { iwctl station $seldevice connect $network || exit 0 if [ -e "${BINDIR}notify-send" ]; then notify-send " Connected to $network!" fi exit 0 } grep $network $HOME/.local/share/networks && connect_no_pass && exit 0 iwctl station $seldevice get-networks | grep psk && connect_pass && exit 0 } getdevice && connectwifi pkill status && status &