commit a509902bb680cc62eeb371361a7fac7bddc9611e Author: Valerie Date: Fri Sep 13 11:59:35 2024 -0400 initial commit diff --git a/README.md b/README.md new file mode 100644 index 0000000..de1c61d --- /dev/null +++ b/README.md @@ -0,0 +1,14 @@ + +# wpa_supplement + +Supplementary helper commands for wpa_supplicant. + +## `wpa_add` + +A helper command to add a network to the default wpa_supplicant configuration +and restart the daemon. + +## `wpa_tmp` + +A helper command to connect to a network using a temporary configuration. + diff --git a/wpa_add b/wpa_add new file mode 100755 index 0000000..2f31d0c --- /dev/null +++ b/wpa_add @@ -0,0 +1,11 @@ +#!/usr/bin/bash + +if [ "$#" -eq 2 ]; then + PSK="$2" +else + read -p 'password: ' PSK +fi + +wpa_passphrase "$1" "$PSK" | sudo tee -a /etc/wpa_supplicant/wpa_supplicant.conf +sudo sv restart wpa_supplicant + diff --git a/wpa_tmp b/wpa_tmp new file mode 100755 index 0000000..5fe7c5c --- /dev/null +++ b/wpa_tmp @@ -0,0 +1,38 @@ +#!/usr/bin/bash + +# protect existing connection +if [ -f /tmp/wpa.conf ]; then + read -p "delete existing temp config? (y/N) " choice + case "$choice" in + y|Y ) rm /tmp/wpa.conf;; + * ) exit 1;; + esac +fi + +# get passphrase if not provided by $2 +if [[ "$2" -eq "NONE" ]]; then + PSK="" +elif [[ "$2" -ne "" ]]; then + PSK="$2" +else + read -p "enter passphrase: " PSK +fi + +# make tmp config +echo -e "# temp configuration file for wpa_supplicant\nctrl_interface=/run/wpa_supplicant\nctrl_interface_group=wheel\neapol_version=1\nap_scan=1\nfast_reauth=1\nupdate_config=1\n" > /tmp/wpa.conf +if [[ "$PSK" -ne "" ]]; then + wpa_passphrase "$1" "$PSK" >> /tmp/wpa.conf +else + echo -e "network={\n\tssid=\"$1\"\n\tkey_mgmt=NONE\n}" >> /tmp/wpa.conf +fi + +# protect existing wpa_supplicant +if [ -f /run/wpa_supplicant/wlp3s0 ]; then + read -p "stop existing wpa_supplicant? (y/N) " choice + case "$choice" in + y|Y ) sudo sv stop wpa_supplicant;; + * ) rm /tmp/wpa.conf; exit 1;; + esac +fi +sudo wpa_supplicant -B -i wlp3s0 -c /tmp/wpa.conf +