PowerShell / PowerShell-Snap

MIT License
30 stars 16 forks source link

[Ubuntu 20.04] Installing powershell snap creates incorrect icon/launcher in "Show Applications" #70

Open najeebanwer opened 4 years ago

najeebanwer commented 4 years ago

Steps to reproduce

On Ubuntu 20.04, install Powershell snap

snap install powershell --classic

click on "Show Applications" in the dock. This shows a list of all installed applications.

Expected behavior

  1. The icon for Powershell should be shown.
  2. Clicking the icon should launch Powershell.

Actual behavior

  1. The icon shown is incorrect - it is for "Powershell Preview"
  2. Clicking the icon shows an error message:
Failed to launch "PowerShell Preview"
Desktop file didn't specify Exec field

Removing the Powershell snap does remove the incorrect icon from the list of applications, but clicking on "Show Applications" causes the Gnome Shell to crash.

Environment data

Ubuntu Desktop 20.04, PowerShell 7.0.3

carlossanlop commented 4 years ago

I can reproduce this too.

I installed it via Snap in Pop!_OS, and attempting to open the app through the GNOME app menu, shows the same error dialog.

Not only it's pointing to powershell-preview, but also there are some underlying problems with Snap itself:

I took a look at the installed files, and here is where that Exec word is located:

/snap/powershell/current/meta/gui $  cat powershell-preview.desktop 

[Desktop Entry]
Name=PowerShell Preview
Exec=powershell-preview
Type=Application
Terminal=true
Categories=ConsoleOnly;System
Icon=${SNAP}/meta/gui/icon.png

I couldn't find the powershell-preview executable in the same folder, but I did find this PowerShell wrapper in a different folder, which fails if I try to execute:

/snap/powershell/current/bin $  ./powershell-wrapper

./powershell-wrapper: 9: exec: /opt/powershell/pwsh: not found

The file is a bash script, and it seems to expect an environment variable $SNAP to exist:

/snap/powershell/current $  cat bin/powershell-wrapper 

#!/bin/sh
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

# Create $XDG_RUNTIME_DIR if it doesn't exist
# || true causes bash to ignore errors
[ -n "$XDG_RUNTIME_DIR" ] && mkdir -p $XDG_RUNTIME_DIR -m 700 || true

exec "$SNAP/opt/powershell/pwsh" "$@"

The $SNAP variable is supposed to have the value /snap/, but I couldn't find it among my environment variables! So I think this is a problem with how Snap was installed in my machine.

/snap/powershell/current/meta/gui $  printenv | grep SNAP
/snap/powershell/current/meta/gui $ 

Notice no variable was found. I was expecting to also see SNAP_ARCH, SNAP_COMMON, SNAP_DATA, etc.

The $SNAP env variable is expected to exist, and is mentioned in the documentation: https://snapcraft.io/docs/environment-variables

If the variable existed, then the pwsh file is located where the script would expect it. It works well if I execute it:

carlos@tabletbox:/snap/powershell/current$ opt/powershell/pwsh
PowerShell 7.0.3
Copyright (c) Microsoft Corporation. All rights reserved.

https://aka.ms/powershell
Type 'help' to get help.

PS /snap/powershell/137> 

Conclusion

exec "$SNAP/opt/powershell/pwsh" "$@"

But it should be:

exec "$SNAP/powershell/current/opt/powershell" "$@"

I tried to edit the files but snap created the /snap/ in a read-only file system, I can't even edit even with sudo, which is frustrating.

Environment data

$PSVersionTable

Name                           Value
----                           -----
PSVersion                      7.0.3
PSEdition                      Core
GitCommitId                    7.0.3
OS                             Linux 5.4.0-7634-generic PowerShell/PowerShell#38~1596560323~20.04~7…
Platform                       Unix
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0
Snapcraft
Environment variables | Snapcraft documentation
Snaps are containerised software packages that are simple to create and install. They auto-update and are safe to run. And because they bundle their dependencies, they work on all major Linux systems without modification.
Launchpad
Bug #1890925 “In Pop!_OS 20.04, environment variables not added ...” : Bugs : snapd
This is the list of environment variables I was expecting to see: https://snapcraft.io/docs/environment-variables But after installing snapd, none of them is available. I made sure to open a new terminal window, and I even rebooted, but they did not show up: ``` /snap/powershell/137/meta/gui$ printenv | grep SNAP /snap/powershell/137/meta/gui$ ``` I found this issue in Pop!_OS 20.04, after attempting to install PowerShell, whose package expects the package to exist in $SNAP\opt\powershe...
najeebanwer commented 4 years ago

@carlossanlop, thanks for confirming that it does not work properly for you either.

I should point out that I do not have the environment variable SNAP defined either; the only environment variables that reference "snap" are shown below.

$ printenv | grep -i SNAP
XDG_DATA_DIRS=/usr/share/ubuntu:/usr/local/share/:/usr/share/:/var/lib/snapd/desktop
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin

Despite this, the other snaps I have installed (e.g., code, skype, vlc) work fine. In fact, I have installed the powershell-preview snap and that works as expected. This problem is unique to the powershell snap.

iSazonov commented 4 years ago

/cc @TravisEz13 for information.

zyga commented 4 years ago

Hello

You should not execute anything in /snap/powershell/* directly. Please use the launcher in /snap/bin instead. This can be a problem immediately after installing the snapd package. For various reasons beyond our control, you may need to restart your machine or at least log out (depending on the OS version) for the correct environment to be picked up.

Note that this is unrelated to the issue you saw directly, since running /snap/powershell/current/$anything side-steps the snap launcher which is responsible for constructing the proper runtime environment.