rice/wifi
2019-08-29 20:43:39 -07:00

79 lines
1.5 KiB
Bash
Executable File

#!/bin/sh
# TODO: rid ourselves of plaintext configs which can have sensitive network keys
cfg_loc="$HOME/.config/wifi-configs/"
iface="wlp1s0"
debug_kill='on'
__write_config() {
printf "network={
ssid=\"$2\"
psk=\"$3\"
}\n" # > "$cfg_loc/$1"
}
__kill_old() {
if [ ! -z "$debug_kill" ]
then
kill `pgrep wpa`
dhclient -r
else
echo 'Not killing anything'
fi
}
_reconnect_config() {
__kill_old
if [ ! -z "$debug_kill" ]
then
__kill_old
else
echo 'No restart'
fi
}
remove_old_config() {
name="`echo '' | dmenu -i -p 'Name of config to remove(This will disconnect you)'`"
rm -f "$cfg_loc/$name"
__kill_old
}
create_new_config() {
name="`echo '' | dmenu -i -p 'Name of new config'`"
type="`printf "WPA2 Personal\nWPA2 Enterprise" | dmenu -i -p 'Connection Type'`"
case $type in
*Personal)
ssid="`echo '' | dmenu -p 'SSID'`"
psk="`echo '' | dmenu -p 'Passkey'`"
__write_config "$HOME/.config//$name" "$ssid" "$psk"
con="`printf "Yes\nNo" | dmenu -i -p 'Connect with new config?'`"
if [ "$con" = "Yes" ]
then
_reconnect_config $con
fi
;;
*Enterprise)
echo 'Not yet implemented' | dmenu -p 'SSID'
exit
;;
esac
}
reconnect_old_config() {
name="`ls $cfg_loc | dmenu -i -p 'Choose config to connect with'`"
if [ -f $name ]
then
rm -f "$cfg_loc/$name"
__kill_old
fi
}
option=`printf "Remove\nReconnect\nNew\n" | dmenu -i`
case $option in
New) create_new_config;;
Remove) remove_old_config;;
Reconnect) reconnect_old_config;;
esac