aboutsummaryrefslogtreecommitdiff
path: root/bin/wpa
diff options
context:
space:
mode:
authorMitchell Riedstra <mitch@riedstra.dev>2022-12-29 18:40:18 -0500
committerMitchell Riedstra <mitch@riedstra.dev>2022-12-29 18:40:18 -0500
commitcdf3d1d5acdce2b9baa8eeac8422b48fce899b50 (patch)
treeb4ed8ac47e012d4d3604f963cd8a23c71daa1939 /bin/wpa
parentd0ad22b295eae397f39de3a9542ade6320a0591b (diff)
downloaddotfiles-cdf3d1d5acdce2b9baa8eeac8422b48fce899b50.tar.gz
dotfiles-cdf3d1d5acdce2b9baa8eeac8422b48fce899b50.tar.xz
Add a script for wpa_supplicant on linux
Diffstat (limited to 'bin/wpa')
-rwxr-xr-xbin/wpa59
1 files changed, 59 insertions, 0 deletions
diff --git a/bin/wpa b/bin/wpa
new file mode 100755
index 0000000..ea79adb
--- /dev/null
+++ b/bin/wpa
@@ -0,0 +1,59 @@
+#!/bin/sh
+set -e
+session="wpa"
+t=3
+interface=
+nwid=
+wpakey=
+
+help() {
+cat <<EOF
+$0 [-i <interface>] [-n <network_name>] [-p <password>]
+EOF
+exit 1;
+}
+
+while [ $# -gt 0 ] ; do case $1 in
+ -i|if) interface="$2"; shift ; shift ;;
+ -n|nwid) nwid="$2"; shift ; shift ;;
+ -p|wpakey) wpakey="$2"; shift ; shift ;;
+ *) help ;;
+esac ; done
+
+err=0
+for _v in interface nwid wpakey ; do
+ eval v="\$$_v";
+ if [ -z "$v" ] ; then
+ echo "$_v cannot be empty"
+ err=1
+ fi
+done
+if [ $err -eq 1 ] ; then exit 1 ; fi
+
+
+wpakey="$(echo "$wpakey" | sed -e's/"/\\"/g')"
+
+conf_f="$(mktemp /dev/shm/wpa.XXXX)"
+trap 'rm -f $conf_f; exit 1;' EXIT INT
+cat > "$conf_f" <<EOF
+network={
+ ssid="$nwid"
+ scan_ssid=1
+ key_mgmt=WPA-PSK
+ psk="$wpakey"
+}
+EOF
+
+
+if tmux ls -F '#{session_name}' | grep -q "^$session\$" ; then
+ exec tmux att -t "$session"
+fi
+
+tmux new-session -s "$session" \;\
+ send-keys -t "${session}:0" "sudo wpa_supplicant -i \"$interface\" -c \"$conf_f\"" \;\
+ send-keys -t "${session}:0" Enter \;\
+ new-window -n "dhclient" -t 1 \;\
+ send-keys -t "${session}:1" "sleep $t ; sudo dhclient -d -i \"$interface\"" \;\
+ send-keys -t "${session}:1" Enter \;\
+ select-window -t "${session}:0" \;\
+