devcontainers / features

A collection of Dev Container Features managed by Dev Container spec maintainers. See https://github.com/devcontainers/feature-starter to publish your own
https://containers.dev/features
MIT License
869 stars 346 forks source link

Powershell feature fails to install version 7.4.3 OR 7.4.4 properly for linux arm64 #1041

Closed DonPwrShellHunt closed 1 week ago

DonPwrShellHunt commented 1 month ago

PowerShell feature install of 7.4.3 for linux arm64 Issue

Issue with install.sh

If an install using GitHub is attempted, install.sh logic for devcontainers/features/src/powershell does not explicitly set pwsh as executable. Successful installation currently depends on the permissions in the tar file.

Symptoms of Failure

If I pinned the version to 7.4.2, the powershell feature would function correctly. Looking at the permissions inside the tar file showed the execute bit was set on pwsh.

tar -tvf /Users/donhunt/local/powershell-7.4.2-linux-arm64.tar.gz pwsh
-rwxr-xr-x  0 cloudtest cloudtest 72544 Apr  9 18:48 pwsh

Using an explicit version of 7.4.3, latest or not specifying a version, pwsh could not be run because permissions were not set to execute. The install did not return an error code. It just did not function at runtime.

tar -tvf /Users/donhunt/local/powershell-7.4.3-linux-arm64.tar.gz pwsh
-rw-rw-r--  0 root   root    72544 Jun 18 10:15 pwsh

NOTE: The instructions from the powershell team to install powershell into linux using the binaries does include setting pwsh as an executable. In my case I am running MacOS on a MacBook Pro with an M1 processor. Docker Desktop is installed using a linux arm64 virtual machine. When installing devcontainer features, such as powershell, install scripts are running as root in a linux arm64 environment.

In the case of installing from github, powershell-7.4.3-linux-arm64.tar.gz is extracted into /opt/microsoft/powershell/7 but the pwsh executable does not have proper permissions to run.

Fix install.sh

Add chmod after the extract to make pwsh executable.


223 tar xf "${powershell_filename}" -C "${powershell_target_path}"
224 chmod 755 "${powershell_target_path}/pwsh"      
225 ln -s "${powershell_target_path}/pwsh" /usr/local/bin/pwsh

Fixed as the vscode user with the commands

cd /opt/microsoft/powershell/7
sudo chmod 755 pwsh

Log snippets showing before and after fix

vscode ➜ /opt/microsoft/powershell/7 $ ls -l pwsh
-rw-rw-r-- 1 root root  72544 Jun 18 14:15 pwsh
...
vscode ➜ /opt/microsoft/powershell/7 $ ls -l $(which zsh)
-rwxr-xr-x 1 root root 898808 Feb 12  2022 /usr/bin/zsh
vscode ➜ /opt/microsoft/powershell/7 $ ls -l $(which bash)
-rwxr-xr-x 1 root root 1399416 Mar 14 11:31 /usr/bin/bash

vscode ➜ /opt/microsoft/powershell/7 $ sudo chmod 755 pwsh
vscode ➜ /opt/microsoft/powershell/7 $ ls -l pwsh         
-rwxr-xr-x 1 root root 72544 Jun 18 14:15 pwsh

vscode ➜ /opt/microsoft/powershell/7 $ ./pwsh
PowerShell 7.4.3
PS /opt/microsoft/powershell/7> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      7.4.3
PSEdition                      Core
GitCommitId                    7.4.3
OS                             Ubuntu 22.04.4 LTS
Platform                       Unix
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

PS /opt/microsoft/powershell/7>
DonPwrShellHunt commented 1 month ago

Similar problem with newly released powershell-7.4.4-linux-arm64

Execute bit is not set for pwsh in the archive.

tar -tvf /Users/donhunt/local/powershell-7.4.4-linux-arm64.tar.gz pwsh
-rw-rw-r--  0 root   root    72544 Jul 17 15:22 pwsh
samruddhikhandale commented 1 month ago

Thanks @DonPwrShellHunt for reporting the issue and thank you @jpawlowski for opening a quick fix PR 🙌

jpawlowski commented 2 weeks ago

@DonPwrShellHunt Apologies for the delay. To be honest, I've been busy with my own powershell-extended feature 🙃

@samruddhikhandale, could you please check again if my adjustments in #1050 are sufficient to be merged into the main repository?