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 Answers
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
- 7,502