0

Is there a way for an ubuntu snap to provide files in the FHS filesystem hierarchy, e.g. binaries in /usr/bin, package data in /usr/share/, configuration files in /etc ? If not, what is the best practice to use such resources provided by a snap? Shall one use /snap// instead of every time?

1 Answers1

1

No, a snap is self-contained. It may of course contain a bin/, usr/bin/, etc. within itself, but it cannot place things into the system's /bin/, /usr/bin/, etc.

The best practice to utilize such resources provided by the snap is to export them from the snap using the "apps" keyword in the YAML. For example, say I have an executable shell script called hello.sh, which contains the following:

#!/bin/sh
echo "hello snap guru"

And I have a snapcraft.yaml that looks like this:

name: hello
version: 1
summary: my summary
description: my description

apps:
  run:
    command: hello.sh

parts:
  hello:
    plugin: copy
    files:
      hello.sh: bin/

After you run snapcraft on this and install the resulting snap, you'll notice that hello.sh is contained within the snap's bin/ directory, which is of course not in your PATH so you can't directly call it. However, when the snap is installed, snappy creates a new script inside /snap/bin/ for each item in the "apps" keyword (run in this case), and /snap/bin/ is in your PATH. You should be able to run the hello.sh script just by using <snap name>.<app name>:

$ hello.run
hello snap guru
kyrofa
  • 7,296
  • 1
  • 31
  • 26
  • Nice, and what about things not script? Like something I normally put to /usr/share//? Is there a reference documentation fro snapcraft.yaml? – Árpád Magosányi May 27 '16 at 12:17
  • There's no real convention for that. Read-only architecture independent data (i.e. the data that would typically be placed in `/usr/share/`) can be anywhere in the snap, and the application should use it from there. So you can make a `usr/share/` directory within the snap and refer to it from the app using `$SNAP/usr/share/`, but those conventions make less sense when everything is self-contained. You could also do simply `$SNAP/data`. – kyrofa May 27 '16 at 13:01
  • My question is how to use that data from something using the package? – Árpád Magosányi May 27 '16 at 13:57