13 Commits

Author SHA1 Message Date
Maciej Borzecki
bd629832e2 data/env: cosmetic tweak for fish
@faho pointed out in https://github.com/snapcore/snapd/pull/11416 this can be
done in a single set call

Signed-off-by: Maciej Borzecki <maciej.zenon.borzecki@canonical.com>
2022-02-23 11:48:48 +01:00
Maciej Borzecki
b6126cf4ee data/env: more workarounds for even older fish shells, provide reasonable defaults (#11416)
Tweak snapd.fish to be compatible with even older releases of fish, going back to 2.7, which was shipped with Ubuntu 18.04.

* data/env: make fish setup compatible with fish 2.7

Make the environment setup script compatible with fish 2.7 which was shipped
with Ubuntu 18.04.

Thanks to @faho for the review.

Signed-off-by: Maciej Borzecki <maciej.zenon.borzecki@canonical.com>

* tests/main/user-session-env: verify env in fish shell

Signed-off-by: Maciej Borzecki <maciej.zenon.borzecki@canonical.com>

* tests/main/user-session-env: tweak comments

Signed-off-by: Maciej Borzecki <maciej.zenon.borzecki@canonical.com>

* data/env: provide reasonable default if XDG_DATA_DIRS is unset in fish shell

Fixes: https://bugs.launchpad.net/ubuntu/+source/snapd/+bug/1960702

Signed-off-by: Maciej Borzecki <maciej.zenon.borzecki@canonical.com>

* tests/main/user-session-env: verify that XDG_DATA_DIRS contains reasonable defaults

Signed-off-by: Maciej Borzecki <maciej.zenon.borzecki@canonical.com>
2022-02-23 11:42:13 +01:00
Maciej Borzecki
2a94f057cf data/env: fix fish env for all versions of fish, unexport local vars, export XDG_DATA_DIRS
Make the fish env setup script compatible with old versions of fish 3.0.x which
was released back in 2019, but is still shipped by recent releases of distros
eg. Ubuntu 21.10.

While doing so, make sure that helper variables used in the script stay local.

Since only newer versions of fish (3.1+) are aware of XDG_DATA_DIRS make sure
that it's exported.

Fixes:
https://bugs.launchpad.net/ubuntu/+source/snapd/+bug/1958022
https://bugs.launchpad.net/ubuntu/+source/snapd/+bug/1957948
https://bugs.launchpad.net/ubuntu/+source/snapd/+bug/1960492

Signed-off-by: Maciej Borzecki <maciej.zenon.borzecki@canonical.com>
2022-02-10 12:22:25 +01:00
Jakub Duchateau
77cb1707f8 Threat XDG_DATA_DIRS like PATH
Tell fish to treat XDG_DATA_DIRS as a column separated list and not space separated (default).
Otherwise, get corrupted list with mixed separators:
XDG_DATA_DIRS=/var/lib/flatpak/exports/share:/usr/local/share/:/usr/share/:/var/lib/snapd/desktop /var/lib/snapd/desktop /var/lib/snapd/desktop
2022-01-08 11:07:36 +01:00
Maciej Borzecki
f9dd306a07 data/env: improve fish shell env setup
Based on comments in https://github.com/snapcore/snapd/pull/11071 the way to add
$SNAP_MOUNT_DIR/bin to fish PATH can be simplified.

Thanks to @Karrq for the suggestion.

Signed-off-by: Maciej Borzecki <maciej.zenon.borzecki@canonical.com>
2021-12-02 12:49:46 +01:00
Maciej Borzecki
73f39f4996 data/env: provide profile setup for fish shell
Profile profile setup for fish shell, which does not load /etc/profile.d.

Fixes: https://bugs.launchpad.net/snapd/+bug/1951145

Signed-off-by: Maciej Borzecki <maciej.zenon.borzecki@canonical.com>
2021-11-17 12:08:33 +01:00
Maciej Borzecki
ae84b651f4 data/env/snapd: use quoting in case PATH contains spaces
When PATH contain spaces, which is a really bad idea anyway, the export will
most likely set it to a value up to the first space. Use quoting to prevent
that.

Note, shellcheck does not complain about that, but try this:

sh-5.1$ export foo=foo bar baz
sh-5.1$ echo $foo
foo
sh-5.1$ export foo="foo bar baz"
sh-5.1$ echo $foo
foo bar baz
sh-5.1$

Signed-off-by: Maciej Borzecki <maciej.zenon.borzecki@canonical.com>
2021-02-02 09:56:48 +01:00
Vladimir Jelovac
7db04cf54b Fixing shellcheck warnings. 2020-04-18 11:25:30 +02:00
Zygmunt Krynicki
8f769b04ca data/env: use "# shellcheck shell=sh" instead of shebang
This has the same properties we were after but is much easier than the
original approach. Shellcheck and rpmlint are both happy now.

Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
2018-06-20 12:24:12 +02:00
Zygmunt Krynicki
e2044ec5da data: remove /bin/sh from snapd.sh
The snapd.sh file is meant to be sourced so the shebang line is just
some meta-data that shellcheck is using. This meta-data is, however,
also picked up by rpmlint, resulting in the following warning:

[   73s] snapd.x86_64: W: sourced-script-with-shebang /etc/profile.d/snapd.sh /bin/sh --this-shebang-is-just-here-to-inform-shellcheck--
[   73s] This text file contains a shebang, but is meant to be sourced, not executed.

This patch keeps the shebang for validation but drops it for
installation.

Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
2018-06-20 09:31:29 +02:00
Didier Roche
526b770852 snap/env: fix env duplication logic (#5075)
* snap/env: fix env duplication logic

The snap insertion inside environment variables like PATH and XDG_DATA_DIRS
expects that the snap element is always the latest of the path, which isn't
necessarily the case.
Ensure we do substring detection following POSIX.

* Handle subdirectories not matching exact path

Ensure that subdirectory of wanted path doesn't match accidently the wanted
exact path.
As now the syntax is a little bit more complex, factor out wanted path.
2018-05-18 08:44:56 +02:00
John R. Lenton
67b6ba2483 Fix 14.04 (thank you spread), address review feedback (thank you mvo)
Also do some work to keep the diffs between 14.04 and 16.04 small.
2017-08-29 18:32:47 +01:00
John R. Lenton
2f55619677 packaging: unify PATH and XDG_DATA_DIRS handling cross-distro
All distributions need to add the snappy bin directory (/snap/bin or
/var/lib/snapd/snap/bin, depending) to the user's PATH, and to add
/var/lib/snapd/desktop to XDG_DATA_DIRS (which might be unset, meaning
it needs adding to the defaults).

Up to now all distros were doing this separately, so we had a bunch of
duplication. Also, as things move to Wayland, on debian-based distros
XDG_DATA_DIRS was only being set in X sessions which mean that
switching to wayland lost you your snappy desktop files.

This tries to fix all that, hopefully in a sane way.
2017-08-29 13:32:03 +01:00