rice/wifi

105 lines
2.1 KiB
Plaintext
Raw Normal View History

2019-08-30 03:43:39 +00:00
#!/bin/sh
# TODO: rid ourselves of plaintext configs which can have sensitive network keys
2019-08-30 20:14:00 +00:00
cfg_loc="/home/shockrah/.config/wifi-configs/"
2019-08-30 03:43:39 +00:00
iface="wlp1s0"
# wpa_supplicant and dhclient are only exposed to root by default
if [ "`id -u`" -ne 0 ]
then
echo 'Must be ran as root'
exit 1
fi
# Only activating this for testing the menu tbh
debug_kill=
__write_config_personal() {
2019-08-30 03:43:39 +00:00
printf "network={
ssid=\"$2\"
psk=\"$3\"
}\n" > "$cfg_loc/$1"
2019-08-30 03:43:39 +00:00
}
__write_config_enterprise() {
printf "network={
ssid=\"$1\"
scan_ssid=1
key_mgmt=WPA-EAP
identity=\"$2\"
password=\"$3\"
eap=PEAP
phase1=\"peaplabel=0\"
phase2=\"auth=MSCHAPV2\"
}" > "$cfg_loc/$4"
}
2019-08-30 03:43:39 +00:00
__kill_old() {
if [ -z "$debug_kill" ]
2019-08-30 03:43:39 +00:00
then
2019-08-30 20:14:00 +00:00
echo killing old process
kill "`pgrep wpa_supplicant`"
echo releasing leases
2019-08-30 03:43:39 +00:00
dhclient -r
else
echo 'Not killing anything'
fi
}
__connect_config() {
if [ -z "$debug_kill" ]
2019-08-30 03:43:39 +00:00
then
__kill_old
2019-08-30 20:14:00 +00:00
echo Seriously this is going to take a minute
echo Setting up wpa_supplicant
wpa_supplicant -B -i wlp1s0 -c "$1"
echo Attempting dhclient
dhclient wlp1s0
2019-08-30 03:43:39 +00:00
else
2019-08-30 20:14:00 +00:00
echo Not connecting to anything
2019-08-30 03:43:39 +00:00
fi
}
remove_old_config() {
name="`echo '' | dmenu -i -p 'Name of config to remove'`"
2019-08-30 03:43:39 +00:00
rm -f "$cfg_loc/$name"
}
reconnect_old_config() {
name="`ls $cfg_loc | dmenu -i -p 'Choose config to connect with'`"
if [ ! -z "$name" ]
then
2019-08-30 20:14:00 +00:00
__connect_config "$cfg_loc/$name"
fi
2019-08-30 03:43:39 +00:00
}
create_new_config() {
name="`echo '' | dmenu -i -p 'Name of new config'`"
type="`printf "WPA2 Personal\nWPA2 Enterprise" | dmenu -i -p 'Connection Type'`"
mkdir -p $cfg_loc
2019-08-30 03:43:39 +00:00
case $type in
*Personal)
ssid="`echo '' | dmenu -p 'SSID'`"
psk="`echo '' | dmenu -p 'Passkey'`"
__write_config_personal "$cfg_loc/$name" "$ssid" "$psk"
2019-08-30 03:43:39 +00:00
;;
*Enterprise)
ssid="`echo '' | dmenu -p 'SSID'`"
identity="`echo '' | dmenu -p 'Identity'`"
psk="`echo '' | dmenu -p 'Passkey'`"
__write_config_enterprise $ssid $identity $psk $name
2019-08-30 03:43:39 +00:00
;;
esac
}
option=`printf "Remove\nConnect\nNew\nDiconnect\n" | dmenu -i`
2019-08-30 03:43:39 +00:00
case $option in
New) create_new_config;;
Remove) remove_old_config;;
Connect) reconnect_old_config;;
Disconnect) __kill_old;;
2019-08-30 03:43:39 +00:00
esac