Last active
August 29, 2015 14:13
-
-
Save alecthegeek/6f4335d2e1b8a45c6420 to your computer and use it in GitHub Desktop.
Setup up a wifi interface
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/sh | |
ssid=$1; shift | |
psk=$1; shift | |
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 | |
fi | |
wpa_cli remove_network $network_id # Don't care if it fails | |
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment