cancel
Showing results for 
Search instead for 
Did you mean: 
SOLVED

copy data to active configuration while snap installation

copy data to active configuration while snap installation

CodeShepherd
Community Moderator
Community Moderator
7 REPLIES 7

SebastianUVA
New Poster

Resurecting an old topic here, I'm dealing with sort of the same thing. I need to copy over a db config.

Is it possible to copy over the file to th defult configuration during install of the snap?

Could you specify what you want to do? As I understood you created an own app with a db inside. This db needs it settings in the active configuration so you'd like to put it there while installing it.

For that case I would suggest to simply copy it there while booting up the process.

Correct, I'm snapping an app with db, and to be able to create users I need to change the db config and restart the app.

The way I have done it now is that I'm uploading the config before installing the snap, but I want a more streamline install.

I have tried to copy over the file during install but havnt succeded. I have used the install hook to try and copy but nothing shows up in the folder.

I have tried this

cp "myfile.." /var/snap/rexroth-solutions/common/solutions/activeConfiguration/

cp "myfile.." $SNAP_COMMON/solutions/activeConfiguration/

Do you now the exact path?

You can try to use hooks (see online documentation) but you will have to check if the content interface is connected via snapctl. Otherwise your snap is not allowed to access the path you I and also you mentioned above.

plugs:
  active-solution:
    interface: content
    content: solutions
    target: $SNAP_COMMON/solutions

Shouldnt that interface be auto connected?
I cant really check snapctl as I'm not able to access SSH on this ctrlx as it has been disabled. I was told that SSH was going to be disabled going forward?

Either way, I have been able to write a file to that location with a sandbox app so I know that I have access. What I cant figure out is how to put a file there during the install of the snap. Could you please provide an example on how you do that?

Any update?

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. CodeShepherd_0-1637582112608.png

    2. 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"

CodeShepherd_0-1637586565568.png

 

 

Icon--AD-black-48x48Icon--address-consumer-data-black-48x48Icon--appointment-black-48x48Icon--back-left-black-48x48Icon--calendar-black-48x48Icon--center-alignedIcon--Checkbox-checkIcon--clock-black-48x48Icon--close-black-48x48Icon--compare-black-48x48Icon--confirmation-black-48x48Icon--dealer-details-black-48x48Icon--delete-black-48x48Icon--delivery-black-48x48Icon--down-black-48x48Icon--download-black-48x48Ic-OverlayAlertIcon--externallink-black-48x48Icon-Filledforward-right_adjustedIcon--grid-view-black-48x48IC_gd_Check-Circle170821_Icons_Community170823_Bosch_Icons170823_Bosch_Icons170821_Icons_CommunityIC-logout170821_Icons_Community170825_Bosch_Icons170821_Icons_CommunityIC-shopping-cart2170821_Icons_CommunityIC-upIC_UserIcon--imageIcon--info-i-black-48x48Icon--left-alignedIcon--Less-minimize-black-48x48Icon-FilledIcon--List-Check-grennIcon--List-Check-blackIcon--List-Cross-blackIcon--list-view-mobile-black-48x48Icon--list-view-black-48x48Icon--More-Maximize-black-48x48Icon--my-product-black-48x48Icon--newsletter-black-48x48Icon--payment-black-48x48Icon--print-black-48x48Icon--promotion-black-48x48Icon--registration-black-48x48Icon--Reset-black-48x48Icon--right-alignedshare-circle1Icon--share-black-48x48Icon--shopping-bag-black-48x48Icon-shopping-cartIcon--start-play-black-48x48Icon--store-locator-black-48x48Ic-OverlayAlertIcon--summary-black-48x48tumblrIcon-FilledvineIc-OverlayAlertwhishlist