Mechanism to run a script before any connections?

Hello, I am looking for a mechanism to run a script on install before any connection happens.

I have a setup with three snaps. Two applications and one configuration snap. The configuration snap shares data located in SNAP_COMMON over a content interface.

At installation the configuration snap has to copy data into the SNAP_COMMON.

The data has to be in SNAP_COMMON since it can be modified manually by the user.

The problem is that the install hook is called after the connection is established for the content interface (by auto-connection). This is a problem because the application snap tries to read data that don’t exist.

Is there a possibility to place data in $SNAP_COMMON at installation before an interface is connected? (I tried install and default-configure hook)

Thank you.

1 Like


1 Like

Who is this @Regan ? :face_with_monocle:

The problem with interface hook is that they are triggered multiple time if the interface gets connected/disconnected. In my case, when the second application snap connects, the connect-slot hook is called again.

So the only solution is to have a “smart” connect-slot hook that checks if it was already called once?

Just add a check with snapctl is-connected to the top that makes your code a no-op when it has already run…