copy data to active configuration while snap installation

Best reply by CodeShepherd

Sorry for the late reply, busy days...

Yes, this plug is "auto" connected by the deviceadmin snap.

I extended the datalayer.registernode example from the SDK version 1.12 and added a hook that copies files when the necessary plug (active-solution) is connected.

See documentation of snapcraft:
https://snapcraft.io/docs/interface-hooks
https://snapcraft.io/docs/supported-snap-hooks

  1. Add a folder "db_config" including a test file and a folder "hooks" including the hook executable "connect-plug-active-solution" to the project:


    1. Make file "connect-plug-active-solution" executable
      chmod +x connect-plug-active-solution​

       

  2. Add changes to "snacraft.yaml"
    1. Add plug to the application, to be able to read/write test file in the program later on

      apps:
        registerNode:
          command: registerNode
          # interfaces to connect to https://snapcraft.io/docs/supported-interfaces
          plugs:
            - network
            - datalayer
            - active-solution
    2. Add new part to the snap to get the test file into the snap
      parts:
        test:
          plugin: dump
          source: ./db_config
          organize: 
            '*': ./db_config/
    3. Add plug to the snap to get general access to the active configuration
      plugs:
        active-solution:
          interface: content
          content: solutions
          target: $SNAP_COMMON/solutions​
    4. Add plug to the hook so active configuration can be manipulated in there
      hooks:
        connect-plug-active-solution:
          plugs: [active-solution]​

       

  3. Add command line code in the executable "connect-plug-active-solution" to create a folder and copy test file to the active configuration
    #!/bin/bash
    mkdir -p $SNAP_COMMON/solutions/activeConfiguration/db_config/
    cp $SNAP/db_config/test $SNAP_COMMON/solutions/activeConfiguration/db_config/​

 

After installation the folder "db_config" is added to the active configuration including file "test"

 

 

View original
7 replies