How to best add default config to a snap without rebuilding?

I am building a simple kiosk based on mir-kiosk and wpe-webkit-mir-kiosk and need to set the config variable “url” for the wpe-webkit-mir-kiosk to “https://mysite?id=CPUID”.

I have successfully combined core18 + mir-kiosk + wpe-webkit-mir-kiosk into a custom image, but I still have to run this command interactively to set the URL after install:

id=$(cat /proc/cpuinfo|egrep "Serial.*: "|awk ‘{print $3}’);snap set url=https://mysite/?id=$id

Being a snap amateur I tried to do this in the install/configure hooks before I realized that this goes against the idea of containment and “snapctl” only has access to the context of my mysite-wpe-webkit–mir-kiosk snap.

Failed install hook:
id=$(cat /proc/cpuinfo|egrep "Serial.*: "|awk ‘{print $3}’)
snapclt set wpe-webkit-mir-kiosk url=$id

  1. What would be the most correct way to do this (beside rebuilding wpe-webkit-mir-kiosk with a hardcoded default), and
  2. what would be the quickest and ugliest hack to do this?

A snap declaration via a brand store or a default setting for wpe-webkit-mir-kiosk in a gadget snap … here is some write-up where I create an UbuntuCore kiosk with various defaults set via the gadget snap:

Quickest: manually create a script (not as snap) that calls snap set ... and manually create a systemd unit that calls the script on boot (checking with snap get ... if the value needs changing) …

Ugliest: create a static visial-basic binary that you wrap in a wine snap to call snap set and install it in --devmode, then create a pyhon script that provides a REST API outside of the snap with a systemd unit that runs it as a deamon, hook that REST API up to an excel sheet on your desktop and set the URL from there via an unportable microsoft office macro… :stuck_out_tongue_winking_eye:


Absolutely LOVE the ugliest hack. :slight_smile:

Not entirely what I was aiming for, but a highly entertaining read…

The other options look good. Will read and test!

1 Like

(wpe-webkit-mir-kiosk maintainer here :wave:)
As @ogra pointed out, a gadget snap would be the most straightforward option if you intend to build a custom device. We’re using this for our own gadget as well.

If you need to change the URL during runtime from another snap, I’ve implemented the D-Bus interface for com.igalia.Cog which lets you remote-control the browser with some basic commands. Check the snap craft docs on how to add the corresponding plug to your snap. I’ll update the wpe-webkit-mir-kiosk README to reflect that. But please note that the D-Bus interface is not auto connected, so you need to run snap connect my-snap:dbus-cogctl wpe-webkit-mir-kiosk:dbus-cogctl after you have implemented the interface in your snap.

1 Like

Great. I actually managed to set URL and do some initial stuff by using ogra’s “quickest” fix in the post above, but it would be so much cleaner to do this from my own snap using a wpe-webkit-mir-kiosk connection. Mounted the finished image and placed a coupe of scripts in /user-data on the writable partition, created .service files in /etc/systemd/system and linked them in manually from /etc/systemd/system/

I tried to rebuild the gadget (wpe-webkit-mir-kiosk) to put my changes directly into a local fork of the wpe-webkit-gadget, but ran out of time before I was successful. Trying again this week after upgrading build env from Ubuntu 18.04 to 19.10. Would be awesome if I could manage to put all the small tweaks in a snap and not have to rebuild the gadget.

Maybe I didn’t fully grasp your second paragraph, but the gadget.yaml link was only meant as an example on how to configure the wpe-webkit-mir-kiosk URL from your own gadget snap :wink: Rebuilding our gadget would produce a lot of configuration for snaps you probably don’t want to include (like our mirros-one snap). I’d go with the D-Bus route so you can set the browser URL to whatever you require from within your own snap. Just add this to your snapcraft.yaml above the apps part:

    interface: dbus
    bus: system
    name: com.igalia.Cog

Once your snap is built and installed, run snap connect my-snap:dbus-cogctl wpe-webkit-mir-kiosk:dbus-cogctl. Afterwards, you can issue D-Bus commands from within your snap to control WPE. Check out D-Feet to experiment with D-Bus (helped me a lot to get into this topic).

FYI, snapcraft uses multipass Ubuntu VMs to build snaps since v3 (at least if you don’t explicitly disable it), so your host OS version shouldn’t have an impact on the snap build. Should not keep you from updating to the latest and greatest, though :smile:

1 Like

Ref the “second paragraph”, I checked out the source from and tried to build that. It stated somewhere that the build environment was Ubuntu 19.10 so when I got a few file references that pointed to the wrong places in the build, I decided to wait and retry under 19.10. I most likely did something wrong or failed to set necessary env vars.

With regard to getting my CA into the image, I successfully added my new CA to existing ca-certificates by unsquaching -d snap wpe.snap, “cat myca >> snap/etc/ssl/ca-certificates.crt” and then mksquashfs from the snap directory again. The new snap was 20% larger so I guess I might have repackaged a debug environment, but it works. When I booted the image with my new snap the browser accepted our local web server certificate, so all is well. (Thanks tobias)

This leaves me with two remaining issues to make this “pretty”. My ultimate goal is to use ubuntu-image to produce a finished image that I can drop onto an SD-card for my RPI and not need any further tricks. Assuming I use the wpe-webkit dbus-connection to set the URL, I still need to mount the image to add the CA cert and create the connection between my “config-snap” and the “wpe-webkit-mir-kiosk” dbus slot.

As my immediate problems have been dealt with, I will probably take my own sweet time to solve this in a more correct and efficient way as I learn more about snaps. :slight_smile: