[feature] Import existing networks from wpa_supplicant
Hi,
Please add a way to (automaticly) import existing wifi network from wpa_supplicant (when installing)
I installed this a month ago on my pi zero which had already internet, but it didn't use the networks that were already in /etc/wpa_supplicant.conf (or how it is called).
If you would add this, then that would be nice. I know like nearly everyone installs this on a new pi, but I didn't and I saw this missed chance.
Btw I love this project. It is a very helpful utility if you don't have a screen and/or HDMI cable available.
Kind regards,
- Miniontoby
Comitup uses NetworkManager, which obsoletes wpa_supplicant.conf (and the interfaces file).
Comitup will use any predefined NetworkManager WiFi connections.
Wait,
But that is NOT my question!
I know it makes wpa_supplicant.conf useless, but you should read out that file (at installation) for any predefined networks!
wpa_supplicant.conf has the networkname and password saved in plaintext
I have no plans to do that, but I endeavor to review patches promptly.
What command is ran to connect to a new network in this thing? Cause I can find dbus controlled, but I cannot find the code of the comitup dbus
comitup-cli
The Comitup class in statemgr.py.
... and look at the man pages.
Here is a script to import from wpa_supplicant:
(it needs the comitup python lib to work, but it could be added in the apt install script after the lib has been installed)
#!/usr/bin/env python3
from re import finditer
try:
from comitup.nm import make_connection_for
except:
print ("[ERROR] Comitup python lib missing!")
quit()
try:
f = open("/etc/wpa_supplicant/wpa_supplicant.conf", "r")
except FileNotFoundError:
print ("[WARNING] No wpa_supplicant file, skipping import")
quit()
wpa_conf = f.read()
f.close()
matches = finditer(r"network=\{\n([\s\t]+(ssid=\"([^\"]+)\"|psk=\"([^\"]+)\"|[\w\=\"-_]+)\n)+\}( |)", wpa_conf)
for match in matches:
ssid = match.group(3)
psk = match.group(4)
print ("[INFO] Adding {ssid} {psk}".format(ssid=ssid, psk="without psk" if psk is None else "with psk"))
make_connection_for(ssid, psk)
Thanks. It's not quite ready for inclusion in the package, but I've linked it from the Install Page. That should be on the path for those who would need it.