From 2444adfe7afba6bed2608bfcd6cccc79eccf39f3 Mon Sep 17 00:00:00 2001 From: Philip Wittamore Date: Sun, 21 Dec 2025 12:05:53 +0100 Subject: update --- wifi_connect | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100755 wifi_connect (limited to 'wifi_connect') diff --git a/wifi_connect b/wifi_connect new file mode 100755 index 0000000..a92a07d --- /dev/null +++ b/wifi_connect @@ -0,0 +1,73 @@ +#!/usr/bin/env bash + +# wpa_supplicant script to discover and add access points +# or connect to known access points + +set -e + +W_IF="wlan0" # change with your right interface +WPA_CONF="/etc/wpa_supplicant/wpa_supplicant.conf" + +# bogus call of doas to force auth so as to not be bothered by fzf blocking +# the prompt later on. +# assumes that you're not being prompt for passwd at every single call :) +doas echo -n + +# with a little help from my friends +get_essid () +{ + ESSID=$(doas iw ${W_IF} scan | rg "\tSSID" | \ + sed -e 's/^.*SSID: //g' | sort | uniq | fzf ) +} + +known_essid () +{ + ID=$(doas wpa_cli list_networks | rg -F "${ESSID}") +} + +connect_essid () +{ + echo "${ESSID} found, connecting..." + echo + doas wpa_cli enable_network "${ID}" + # uncomment following if using with wpa-conf + #echo + #doas dhclient -v ${W_IF} +} + +add_essid () +{ + while true; do + echo "ESSID PASSWORD: " + read -r ESSID_PASSWD + while true; do + echo "Is \"${ESSID_PASSWD}\" correct? (y/n)" + read -r ANSWER_PASSWD + if [ "${ANSWER_PASSWD}" = "y" ]; then + ENTRY="$(wpa_passphrase "$ESSID" "$ESSID_PASSWD")" + echo "$ENTRY" | doas tee -a $WPA_CONF + break + fi + done + break + done + echo "${ESSID} added, connecting..." +} + +get_essid +if known_essid; then + connect_essid + exit +else + while true; do + echo "Add this access point? (y/n)" + read -r ANSWER_ADD + if [ "${ANSWER_ADD}" = "y" ]; then + add_essid + wpa_cli reconfigure + known_essid + connect_essid + exit + fi + done +fi -- cgit v1.2.3