fixed some """"issues"""", really just made behavior follow expectations

This commit is contained in:
shockrahwow 2019-08-30 12:52:43 -07:00
parent c000ee9ef7
commit 4547825e03

74
wifi
View File

@ -5,16 +5,38 @@
cfg_loc="$HOME/.config/wifi-configs/" cfg_loc="$HOME/.config/wifi-configs/"
iface="wlp1s0" iface="wlp1s0"
debug_kill='on' # wpa_supplicant and dhclient are only exposed to root by default
__write_config() { 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() {
printf "network={ printf "network={
ssid=\"$2\" ssid=\"$2\"
psk=\"$3\" psk=\"$3\"
}\n" # > "$cfg_loc/$1" }\n" > "$cfg_loc/$1"
} }
__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"
}
__kill_old() { __kill_old() {
if [ ! -z "$debug_kill" ] if [ -z "$debug_kill" ]
then then
kill `pgrep wpa` kill `pgrep wpa`
dhclient -r dhclient -r
@ -23,56 +45,56 @@ __kill_old() {
fi fi
} }
_reconnect_config() { __connect_config() {
__kill_old if [ -z "$debug_kill" ]
if [ ! -z "$debug_kill" ]
then then
__kill_old __kill_old
wpa_supplicant -B -i wlp1s0 -c /etc/wpa_supplicant.conf -D wext
dhclient wlp1s0
else else
echo 'No restart' echo 'No restart'
fi fi
} }
remove_old_config() { remove_old_config() {
name="`echo '' | dmenu -i -p 'Name of config to remove(This will disconnect you)'`" name="`echo '' | dmenu -i -p 'Name of config to remove'`"
rm -f "$cfg_loc/$name" rm -f "$cfg_loc/$name"
}
reconnect_old_config() {
name="`ls $cfg_loc | dmenu -i -p 'Choose config to connect with'`"
if [ ! -z "$name" ]
then
__kill_old __kill_old
__connect_config
fi
} }
create_new_config() { create_new_config() {
name="`echo '' | dmenu -i -p 'Name of new config'`" name="`echo '' | dmenu -i -p 'Name of new config'`"
type="`printf "WPA2 Personal\nWPA2 Enterprise" | dmenu -i -p 'Connection Type'`" type="`printf "WPA2 Personal\nWPA2 Enterprise" | dmenu -i -p 'Connection Type'`"
mkdir -p $cfg_loc
case $type in case $type in
*Personal) *Personal)
ssid="`echo '' | dmenu -p 'SSID'`" ssid="`echo '' | dmenu -p 'SSID'`"
psk="`echo '' | dmenu -p 'Passkey'`" psk="`echo '' | dmenu -p 'Passkey'`"
__write_config "$HOME/.config//$name" "$ssid" "$psk" __write_config_personal "$cfg_loc/$name" "$ssid" "$psk"
con="`printf "Yes\nNo" | dmenu -i -p 'Connect with new config?'`"
if [ "$con" = "Yes" ]
then
_reconnect_config $con
fi
;; ;;
*Enterprise) *Enterprise)
echo 'Not yet implemented' | dmenu -p 'SSID' ssid="`echo '' | dmenu -p 'SSID'`"
exit identity="`echo '' | dmenu -p 'Identity'`"
psk="`echo '' | dmenu -p 'Passkey'`"
__write_config_enterprise $ssid $identity $psk $name
;; ;;
esac 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` option=`printf "Remove\nConnect\nNew\nDiconnect\n" | dmenu -i`
case $option in case $option in
New) create_new_config;; New) create_new_config;;
Remove) remove_old_config;; Remove) remove_old_config;;
Reconnect) reconnect_old_config;; Connect) reconnect_old_config;;
Disconnect) __kill_old;;
esac esac