Created
January 13, 2015 06:54
-
-
Save alecthegeek/d9adea0df786f47b70f8 to your computer and use it in GitHub Desktop.
Add a network to the wpa_supplicant.conf
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/dash | |
ssid=$1 ;shift | |
psk=$1; shift | |
# Is this network already defined? | |
network_id=$(wpa_cli list_networks | tail -n +3 | grep $ssid |cut -f 1) | |
if [ -z $network_id ] ; then | |
maxNetworkId=$(wpa_cli list_networks | tail -n +3 | tail -n 1 | cut -f 1)] | |
if [ -z $maxNetworkId ] ; then | |
network_id=0 | |
else | |
network_id=$((maxNetworkID + 1 )) | |
fi | |
else | |
wpa_cli remove_network $network_id # Don't care if it fails | |
fi | |
cat <<EOF | wpa_cli | |
add_network $network_id | |
set_network $network_id ssid "$ssid" | |
set_network $network_id id_str "$ssid" | |
set_network $network_id psk "$psk" | |
enable_network $network_id | |
save_config | |
quit | |
EOF | |
# Alternatively | |
# | |
# This little fragment will add an id_str to a network stanza. Makes it | |
# possible to refer to network by name | |
#wpa_passphrase SSID passphrase | sed -Ee '/^(.+)ssid=(.+)/s//\1id_str=\2\ | |
#\1ssid=\2/' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment