Because snaps are installed as root, it's impossible to do exactly as you ask at install time, as $SNAP_USER_DATA
is user-specific, so it'll always be root's. However, you can do this at install-time using a system-wide directory, such as $SNAP_DATA
, using the install
hook:
$ snapcraft init
Created snap/snapcraft.yaml.
Edit the file to your liking or run `snapcraft` to get started
Create the hook. In our case we'll just create a new file in $SNAP_DATA
, but you could do whatever you wanted.
$ mkdir -p snap/hooks
$ echo "touch \$SNAP_DATA/foo" >> snap/hooks/install
$ chmod a+x snap/hooks/install
Build the snap.
$ snapcraft
Preparing to pull my-part
Pulling my-part
Preparing to build my-part
Building my-part
Staging my-part
Priming my-part
Snapping 'my-snap-name' |
Snapped my-snap-name_0.1_amd64.snap
Install the snap. This will run the install
hook.
$ sudo snap install my-snap-name_0.1_amd64.snap --devmode --dangerous
my-snap-name 0.1 installed
Notice a file was created in $SNAP_DATA.
$ ls /var/snap/my-snap-name/current
foo
The only way to get similar functionality for $SNAP_USER_DATA
would be to wrap your real command in a script that creates the config. This command is then run by the user, which means you get the $SNAP_USER_DATA
you intend. Of course, this isn't at install-time.