Hi all, I’ve seen this mentioned before but years ago, and myself and chatgpt have had a falling out over this, I cannot figure this out.
Quick question…
Is there any way to set the wifi settings from within a snap after ubuntu core has been setup?
Background.
I want to offer a raspberry pi ubuntu core image, that users can download and write with a preinstalled snap I’ve made, however if its not a wired connection, I want to offer wifi connection settings first. (I understand this will probably be a separate app, chained in snapcraft before the main app)
I don’t want the user to ssh in and use nmcli (its got to be dummy proof). I’d prefer for my customers not to dig out a mouse/keyboard to setup the pi. My idea would be to show some QR code on screen, the user connects to (ideally Bluetooth) on their phone in which I make an app to set the wifi settings on the Pi and away they go. However, I’ve created a very simple bash script as a snap using something similar to this below to no avail
Using ‘/snap/network-manager/current/usr/bin/nmcli’ is a no no as its confined away.
Using a local install of nmcli inside my snap gives access denied
Using ‘snap run network-manager.nmcli’ allows me to list WiFi networks, but setting anything gives ‘Error: Failed to add/activate new connection: failure adding connection: keyfile writer produces an invalid connection: cannot access file: No such file or directory’
What is the proper way of doing this?
Can it even be done?
I was thinking maybe I configure network-manager in some way to use some shared folder which my snap can write to and that reads from? There are old posts about using dbus which link to 404s.
Any light on how you’d tackle this would be appreciated.
Using ChatGPT for such stuff is generally a very bad idea… The model gets trained with answers from the web which usually are really outdated info so ChatGPT will give suggestions that are usually outdated… Just asking in a forum like you are now doing is usually the safe way to get decent information
Yeah it is rather trivial but depends on how you created the image and what you included…
If you are using the default setup the image just comes with netplan, so you can use the network-setup-control interface… That will give you full write access to /etc/netplan so you can modify the yaml file in there or replace it with one with your changes… The interface also gives you access to the netplan generate and netplan apply commands to make the changes active without a reboot …
If you instead included network manager in the image you need to use the network-manager-control interface and either ship the nmcli tool in your snap or craft the network manager dbus calls programmatically to control network manager…
In general I’d not use network manager if you don’t have to, managing netplan is way simpler…
To make your snap auto connect the respective interfaces you need to set up a declaration in your IoT app store (formerly called Brand Store) or you can use an entry in your gadget.yaml when building your gadget and use the connections: block to define the automatic connections applied on first boot …
Thanks for this, I tried it both ways and got it working in each case. My problem was I wasn’t bundling it when I created the image, and therefore my snap although had nmcli installed couldn’t talk to the host, as you say it needs to be bundled in from the start. (I was installing network-manager after)
I think I am going with the network-manager route as I can pull out the ‘search for WiFi’ output straight onto the screen.
Done a few snaps in the past but not needed to use a gadget.yml yet.
You’re correct on ChatGPT, I would guess I wasted a good few hours being led down different routes and it also contradicted its self hugely. It seemed to answer based on generic snaps rather than Ubuntu Cores confinement.
Again cheers for your response (it was me asking on IRC too so thanks there as well)