Connect to wireless network from command line, for wicd

In my personal life, I’m endeavoring to use less and less systemd and its derivatives and relatives and any other *ives (and I’m not even being figurative!).

So, for my devuan installs on my laptop fleet, I’m trying to automate all my installs and configs, because I automate things for work. And part of my documented workflow is to “Add to the wicd interface settings screen device ‘wlan0’ for the wireless nic.” So I wanted to learn how to connect to my wireless network from the command line.

After some research, I discovered a brief way to do it. I hope this helps somebody.

MYNETWORK=myssidname
MYPASSPHRASE="mypassphrase"
nid="$( wicd-cli -ySl | awk -v "n=${MYNETWORK}" '$NF==n {print $1}' )"
wicd-cli -y -n"${nid}" -p apsk -s "${MYPASSPHRASE}"
wicd-cli -y -n"${nid}" -c

I will explain a few parts briefly, but for more details you should check out the references below.
-y use wireless connection.
-S scan
-l list cached results, so what we just learned from the scan
-n use this network id, which is a number internal to wicd to keep track of the networks it has seen.
-p display a property
-s value, so with a -p SOMETHING and -s VALUE combo, it will set the property for you instead of display it.
-c connect.

In my tests, I discovered that I was unable to implement the saved password with the connect command. So it takes multiple invocations of wicd-cli, but I can live with that.
This for some reason took me way less time to research how to connect with wicd, than with nmcli in the past.

References

Weblinks

  1. Helped me minimally Wicd tutorial [www.gadgetdaily.xyz]
  2. what enlightened me about -p SOMETHING -s VALUE as opposed to -s ‘SOMETHING=VALUE’ like I tried at first README.cli [github.com]
  3. how I found wicd-cli in the first place: Linux: Can I get the wicd daemon to disconnect my wireless network from the command line? [superuser.com]

Web searches used

  1. wicd-cli connect example [google]
  2. wicd set wireless network from command line

man pages

  1. wicd-cli(8)
  2. wicd(1)

Alternatives and other reading

  1. How to connect and disconnect to a network manually in terminal? [askubuntu.com]
Advertisements