PowerShell-Snap icon indicating copy to clipboard operation
PowerShell-Snap copied to clipboard

Cannot set as login shell without manually adding to `/etc/shells`.

Open RokeJulianLockhart opened this issue 1 year ago • 3 comments

Prerequisites

  • [X] Write a descriptive title.
  • [X] Make sure you are able to repro it on the latest version
  • [X] Search the existing issues.

Steps to reproduce

As https://github.com/orgs/PowerShell/discussions/20962#discussioncomment-7937685 describes, the Snap package cannot be set as the login shell via chsh -s $Shell (where $Shell is the absolute path to the shell binary) without the user manually adding its path to /etc/shells. However, the native (.RPM) package automatically adds itself to that file as every other shell does. For instance, on my system, when the correct path for the snap package has been added, the content of /etc/shells is:

PS /home/RokeJulianLockhart> cat -vbET '/etc/shells'
     1  /bin/ash$
     2  /bin/bash$
     3  /bin/csh$
     4  /bin/dash$
     5  /bin/false$
     6  /bin/ksh$
     7  /bin/ksh93$
     8  /bin/mksh$
     9  /bin/pdksh$
    10  /bin/sh$
    11  /bin/tcsh$
    12  /bin/true$
    13  /bin/zsh$
    14  /usr/bin/csh$
    15  /usr/bin/dash$
    16  /usr/bin/ksh$
    17  /usr/bin/ksh93$
    18  /usr/bin/mksh$
    19  /usr/bin/passwd$
    20  /usr/bin/pdksh$
    21  /usr/bin/bash$
    22  /usr/bin/tcsh$
    23  /usr/bin/zsh$
    24  /usr/bin/fish$
    25  /usr/bin/scsh$
    26  /usr/bin/rash$
    27  /snap/powershell/current/opt/powershell/pwsh$
PS /home/RokeJulianLockhart> # This demonstrates correct manual addition of the path to the snap package rather than what the RPM package does.

Consequently, the installation process needs to add the path, and the uninstallation process remove it. The path should obviously be the vanity path as aforedepicted, not the mount-specific path, as https://github.com/PowerShell/PowerShell-Snap/issues/101#issuecomment-1892900143 explains.

Expected behaviour

The aforestated command should set it as the login shell.

Actual behaviour

It does not.

Error details

PS /home/RokeJulianLockhart> Get-Command pwsh                      

CommandType     Name                                               Version    Source
-----------     ----                                               -------    ------
Application     pwsh                                               0.0.0.0    /snap/powershell/261/opt/powershell/pwsh

PS /home/RokeJulianLockhart> chsh -s /snap/powershell/261/opt/powershell/pwsh
Password: 
chsh: /snap/powershell/261/opt/powershell/pwsh is an invalid shell
PS /home/RokeJulianLockhart> Get-Error       
PS /home/RokeJulianLockhart> chsh -s /snap/powershell/261/opt/powershell/pwsh
Password: 
chsh: /snap/powershell/261/opt/powershell/pwsh is an invalid shell
PS /home/RokeJulianLockhart> $?                   
False
PS /home/RokeJulianLockhart>

Environment data

PS /home/RokeJulianLockhart> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      7.4.0
PSEdition                      Core
GitCommitId                    7.4.0
OS                             openSUSE Tumbleweed
Platform                       Unix
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

PS /home/RokeJulianLockhart>

Version

{
	"version": "7.4.0",
	"channel": "latest/stable",
	"snap-id": "JSNnoJl3EqkMuWoy5Dgq8PMqZ0uNcpie"
}

Visuals

No response

RokeJulianLockhart avatar Jan 15 '24 22:01 RokeJulianLockhart

https://github.com/PowerShell/PowerShell/issues/20469#issuecomment-1892885515

Where does the 261 come from, is the path consistent across reboots? Are you supposed to use /snap/powershell/current/opt/powershell/pwsh ?

@rhubarb-geek-nz, I wondered that too, hence why I was hesitant to reboot. I don't know. However, https://snapcraft.io/docs/using-snapctl#heading--mount-control suggests that it could be either.

RokeJulianLockhart avatar Jan 16 '24 00:01 RokeJulianLockhart

The system /snap directory

This suggests you should use the current link so when PowerShell snap is updated you automatically get the new version.

rhubarb-geek-nz avatar Jan 16 '24 00:01 rhubarb-geek-nz

I have been having a look at snaps and now think the entry you need to add to /etc/shells should be /snap/bin/pwsh

That solves all the issues about versions and links.

rhubarb-geek-nz avatar Jan 18 '24 23:01 rhubarb-geek-nz