Programmatically determine snap's channel

I’d like my app to visually tell users whether it is on Edge or Beta or Stable in my custom GUI. Could there be an environment variable that identifies what channel the snap is on? Or is there another way to do this?

Right off the bat, the easiest thing that I would suggest is to use a configure in your snap package. This hook is executed after your snap package is installed and every time it is refreshed.

You could use a combination of grep, awk, snap list, and snap info in this hook to pull which channel the user is running on and then set the value in a .conf file that can be queried by your program.

Not sure how complicated this is to implement in practice, but I would definitely agree that an environment variable like $SNAP_CHANNEL should be wishlisted for future releases of snapcraft and/or snapd.

1 Like

It may seem innocuous to “visually tell users whether it is on Edge or Beta or Stable” but that’s another feature to be tested.

And more generally, is it really a good software engineering to enable a program’s behavior depending on the active channel? Once it is possible, all sorts of changes can be made. E.g. "we’ll use the test database for beta

At the far end of the slope is: "It works on candidate, let’s promote and test to see if it works the same on stable". And that sound slightly mad.

1 Like

you sadly wont be able to actually call the snap command from within a snap at all … not even from any of the hooks …

… unless you give the snap full access to the snapd socket via the snapd-control interface which is generally not granted for snaps in the global store since it gives your snap root access to the host.

i fear the only valid solution is a wishlist bug for the above mentioned env variable or for some extension of the snapctl command to be able to list your current channel …

1 Like