2019-08-30 03:43:39 +00:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
# TODO: rid ourselves of plaintext configs which can have sensitive network keys
|
|
|
|
|
2019-12-03 07:53:46 +00:00
|
|
|
export cfg_loc="/home/shockrah/.config/wifi-configs/"
|
|
|
|
export usb_iface='enx9cebe828e98a'
|
|
|
|
export default_iface='wlp1s0'
|
|
|
|
export iface=$default_iface
|
2019-08-30 23:30:58 +00:00
|
|
|
debug_kill=
|
2019-08-30 03:43:39 +00:00
|
|
|
|
2019-08-30 19:52:43 +00:00
|
|
|
# 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
|
|
|
|
|
|
|
|
__write_config_personal() {
|
2019-08-30 03:43:39 +00:00
|
|
|
printf "network={
|
|
|
|
ssid=\"$2\"
|
|
|
|
psk=\"$3\"
|
2019-08-30 19:52:43 +00:00
|
|
|
}\n" > "$cfg_loc/$1"
|
2019-08-30 03:43:39 +00:00
|
|
|
}
|
|
|
|
|
2019-08-30 19:52:43 +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() {
|
2019-08-30 19:52:43 +00:00
|
|
|
if [ -z "$debug_kill" ]
|
2019-08-30 03:43:39 +00:00
|
|
|
then
|
2019-08-30 20:14:00 +00:00
|
|
|
kill "`pgrep wpa_supplicant`"
|
2019-08-30 03:43:39 +00:00
|
|
|
dhclient -r
|
|
|
|
else
|
|
|
|
echo 'Not killing anything'
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2019-08-30 19:52:43 +00:00
|
|
|
__connect_config() {
|
|
|
|
if [ -z "$debug_kill" ]
|
2019-08-30 03:43:39 +00:00
|
|
|
then
|
2019-09-24 00:48:53 +00:00
|
|
|
if [ ! -f "$1" ]; then
|
|
|
|
echo Config not found
|
2019-12-03 07:53:46 +00:00
|
|
|
exit 1
|
2019-09-24 00:48:53 +00:00
|
|
|
fi
|
2019-08-30 03:43:39 +00:00
|
|
|
__kill_old
|
2019-09-24 00:48:53 +00:00
|
|
|
wpa_supplicant -B -i $iface -c "$1"
|
|
|
|
dhclient $iface
|
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
|
|
|
|
}
|
|
|
|
|
2019-12-03 07:53:46 +00:00
|
|
|
select_interface() {
|
|
|
|
_iface="`ip a \
|
|
|
|
| awk '{print $2}' \
|
|
|
|
| grep -E '^[a-z0-9]+:$' \
|
|
|
|
| sed 's/://g' \
|
|
|
|
| dmenu -i -p 'Select interface to connect on'`"
|
|
|
|
if [ -z "$_iface" ];then
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
iface=$_iface
|
|
|
|
}
|
|
|
|
|
2019-08-30 03:43:39 +00:00
|
|
|
remove_old_config() {
|
2019-09-04 19:05:03 +00:00
|
|
|
name="`ls $cfg_loc | dmenu -i -p 'Name of config to remove'`"
|
2019-08-30 03:43:39 +00:00
|
|
|
rm -f "$cfg_loc/$name"
|
2019-08-30 19:52:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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"
|
2019-08-30 19:52:43 +00:00
|
|
|
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'`"
|
2019-08-30 19:52:43 +00:00
|
|
|
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'`"
|
2019-08-30 23:30:58 +00:00
|
|
|
__write_config_personal "$name" "$ssid" "$psk"
|
2019-08-30 03:43:39 +00:00
|
|
|
;;
|
|
|
|
*Enterprise)
|
2019-08-30 19:52:43 +00:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-12-13 00:56:52 +00:00
|
|
|
option=`printf "Remove\nConnect\nNew\nDisconnect\n" | dmenu -i -p 'Options:'`
|
2019-08-30 03:43:39 +00:00
|
|
|
case $option in
|
|
|
|
New) create_new_config;;
|
|
|
|
Remove) remove_old_config;;
|
2019-12-03 07:53:46 +00:00
|
|
|
Connect)
|
|
|
|
select_interface; echo 'yes'; reconnect_old_config
|
|
|
|
;;
|
2019-08-30 19:52:43 +00:00
|
|
|
Disconnect) __kill_old;;
|
2019-08-30 03:43:39 +00:00
|
|
|
esac
|