Unverified Commit 878a900d authored by Julian Pawlowski's avatar Julian Pawlowski Committed by GitHub

`[powershell]`: Fix manual PowerShell installation binary execution permissions (#1050)

* Align manual pwsh install with DEB package

- ensure execution permissions for pwsh
- correct path from /usr/local/bin/pwsh to /usr/bin/pwsh
- register as shell in /etc/shells

* Update versions

* Update repositories

* Check for existing pwsh installation

This will avoid build failures when multiple features depend on this PowerShell package

* test: Fix PS profile test

* Test: Fix install_using_github

* Test: Fix getcwd warning

* fix: Move out of directory before deleting it

* test: Add validate_powershell_installation

* test: Change Ubuntu test base image to upcoming new LTS version
parent 3bf4e20e
{ {
"id": "powershell", "id": "powershell",
"version": "1.4.0", "version": "1.5.0",
"name": "PowerShell", "name": "PowerShell",
"documentationURL": "https://github.com/devcontainers/features/tree/main/src/powershell", "documentationURL": "https://github.com/devcontainers/features/tree/main/src/powershell",
"description": "Installs PowerShell along with needed dependencies. Useful for base Dockerfiles that often are missing required install dependencies like gpg.", "description": "Installs PowerShell along with needed dependencies. Useful for base Dockerfiles that often are missing required install dependencies like gpg.",
...@@ -10,7 +10,9 @@ ...@@ -10,7 +10,9 @@
"proposals": [ "proposals": [
"latest", "latest",
"none", "none",
"7.1" "7.4",
"7.3",
"7.2"
], ],
"default": "latest", "default": "latest",
"description": "Select or enter a version of PowerShell." "description": "Select or enter a version of PowerShell."
......
...@@ -18,7 +18,7 @@ POWERSHELL_PROFILE_URL="${POWERSHELLPROFILEURL}" ...@@ -18,7 +18,7 @@ POWERSHELL_PROFILE_URL="${POWERSHELLPROFILEURL}"
MICROSOFT_GPG_KEYS_URI="https://packages.microsoft.com/keys/microsoft.asc" MICROSOFT_GPG_KEYS_URI="https://packages.microsoft.com/keys/microsoft.asc"
POWERSHELL_ARCHIVE_ARCHITECTURES="amd64" POWERSHELL_ARCHIVE_ARCHITECTURES="amd64"
POWERSHELL_ARCHIVE_VERSION_CODENAMES="stretch buster bionic focal bullseye jammy" POWERSHELL_ARCHIVE_VERSION_CODENAMES="stretch buster bionic focal bullseye jammy bookworm noble"
GPG_KEY_SERVERS="keyserver hkp://keyserver.ubuntu.com GPG_KEY_SERVERS="keyserver hkp://keyserver.ubuntu.com
keyserver hkp://keyserver.ubuntu.com:80 keyserver hkp://keyserver.ubuntu.com:80
keyserver hkps://keys.openpgp.org keyserver hkps://keys.openpgp.org
...@@ -221,25 +221,32 @@ install_using_github() { ...@@ -221,25 +221,32 @@ install_using_github() {
echo "${powershell_archive_sha256} *${powershell_filename}" | sha256sum -c - echo "${powershell_archive_sha256} *${powershell_filename}" | sha256sum -c -
fi fi
tar xf "${powershell_filename}" -C "${powershell_target_path}" tar xf "${powershell_filename}" -C "${powershell_target_path}"
ln -s "${powershell_target_path}/pwsh" /usr/local/bin/pwsh chmod 755 "${powershell_target_path}/pwsh"
ln -sf "${powershell_target_path}/pwsh" /usr/bin/pwsh
add-shell "/usr/bin/pwsh"
cd /tmp
rm -rf /tmp/pwsh rm -rf /tmp/pwsh
} }
export DEBIAN_FRONTEND=noninteractive if ! type pwsh >/dev/null 2>&1; then
export DEBIAN_FRONTEND=noninteractive
# Source /etc/os-release to get OS info
. /etc/os-release # Source /etc/os-release to get OS info
architecture="$(dpkg --print-architecture)" . /etc/os-release
architecture="$(dpkg --print-architecture)"
if [[ "${POWERSHELL_ARCHIVE_ARCHITECTURES}" = *"${architecture}"* ]] && [[ "${POWERSHELL_ARCHIVE_VERSION_CODENAMES}" = *"${VERSION_CODENAME}"* ]]; then if [[ "${POWERSHELL_ARCHIVE_ARCHITECTURES}" = *"${architecture}"* ]] && [[ "${POWERSHELL_ARCHIVE_VERSION_CODENAMES}" = *"${VERSION_CODENAME}"* ]]; then
install_using_apt || use_github="true" install_using_apt || use_github="true"
else
use_github="true"
fi
if [ "${use_github}" = "true" ]; then
echo "Attempting install from GitHub release..."
install_using_github
fi
else else
use_github="true" echo "PowerShell is already installed."
fi
if [ "${use_github}" = "true" ]; then
echo "Attempting install from GitHub release..."
install_using_github
fi fi
# If PowerShell modules are requested, loop through and install # If PowerShell modules are requested, loop through and install
......
...@@ -8,7 +8,7 @@ source dev-container-features-test-lib ...@@ -8,7 +8,7 @@ source dev-container-features-test-lib
# Extension-specific tests # Extension-specific tests
check "az.resources" pwsh -Command "(Get-Module -ListAvailable -Name Az.Resources).Version.ToString()" check "az.resources" pwsh -Command "(Get-Module -ListAvailable -Name Az.Resources).Version.ToString()"
check "az.storage" pwsh -Command "(Get-Module -ListAvailable -Name Az.Storage).Version.ToString()" check "az.storage" pwsh -Command "(Get-Module -ListAvailable -Name Az.Storage).Version.ToString()"
check "profile" pwsh -Command "(Get-Variable $env:ProfileLoaded).Value" check "profile" pwsh -Command "if (\$null -eq \$env:ProfileLoaded) { echo 'Not set!'; exit 1 } else { if ( [bool]\$env:ProfileLoaded ) { echo 'Profile loaded.'; exit 0 } else { echo 'False value!'; exit 1 } }"
check "Powershell version as installed by feature" bash -c "pwsh --version" check "Powershell version as installed by feature" bash -c "pwsh --version"
...@@ -168,9 +168,11 @@ install_using_github() { ...@@ -168,9 +168,11 @@ install_using_github() {
echo "${powershell_archive_sha256} *${powershell_filename}" | sha256sum -c - echo "${powershell_archive_sha256} *${powershell_filename}" | sha256sum -c -
fi fi
sudo tar xf "${powershell_filename}" -C "${powershell_target_path}" sudo tar xf "${powershell_filename}" -C "${powershell_target_path}"
sudo ln -s "${powershell_target_path}/pwsh" /usr/local/bin/pwsh sudo chmod 755 "${powershell_target_path}/pwsh"
sudo rm -rf /tmp/pwsh /usr/local/bin/pwsh sudo ln -sf "${powershell_target_path}/pwsh" /usr/bin/pwsh
sudo add-shell "/usr/bin/pwsh"
cd /tmp
sudo rm -rf /tmp/pwsh
} }
echo -e "\nInstalling Powershell with find_prev_version_from_git_tags() fn 👈🏻" echo -e "\nInstalling Powershell with find_prev_version_from_git_tags() fn 👈🏻"
......
{ {
"install_modules": { "install_modules": {
"image": "mcr.microsoft.com/devcontainers/base:jammy", "image": "mcr.microsoft.com/devcontainers/base:noble",
"features": { "features": {
"powershell": { "powershell": {
"modules": "az.resources, az.storage", "modules": "az.resources, az.storage",
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
} }
}, },
"install_powershell_fallback_test": { "install_powershell_fallback_test": {
"image": "mcr.microsoft.com/devcontainers/base:jammy", "image": "mcr.microsoft.com/devcontainers/base:noble",
"features": { "features": {
"powershell": { "powershell": {
"modules": "az.resources, az.storage", "modules": "az.resources, az.storage",
...@@ -18,11 +18,17 @@ ...@@ -18,11 +18,17 @@
} }
}, },
"install_modules_version": { "install_modules_version": {
"image": "mcr.microsoft.com/devcontainers/base:jammy", "image": "mcr.microsoft.com/devcontainers/base:noble",
"features": { "features": {
"powershell": { "powershell": {
"modules": "az.resources==2.5.0, az.storage==4.3.0" "modules": "az.resources==2.5.0, az.storage==4.3.0"
} }
} }
},
"validate_powershell_installation": {
"image": "mcr.microsoft.com/devcontainers/base:noble",
"features": {
"powershell": {}
}
} }
} }
#!/bin/bash
set -e
# Import test library for `check` command
source dev-container-features-test-lib
# Extension-specific tests
check "pwsh file is symlink" bash -c "[ -L /usr/bin/pwsh ]"
check "pwsh symlink is registered as shell" bash -c "[ $(grep -c '/usr/bin/pwsh' /etc/shells) -eq 1 ]"
check "pwsh target is correct" bash -c "[ $(readlink /usr/bin/pwsh) = /opt/microsoft/powershell/7/pwsh ]"
check "pwsh target is registered as shell" bash -c "[ $(grep -c '/opt/microsoft/powershell/7/pwsh' /etc/shells) -eq 1 ]"
check "pwsh owner is root" bash -c "[ $(stat -c %U /opt/microsoft/powershell/7/pwsh) = root ]"
check "pwsh group is root" bash -c "[ $(stat -c %G /opt/microsoft/powershell/7/pwsh) = root ]"
check "pwsh file mode is -rwxr-xr-x" bash -c "[ $(stat -c '%A' /opt/microsoft/powershell/7/pwsh) = '-rwxr-xr-x' ]"
check "pwsh is in PATH" bash -c "command -v pwsh"
# Report result
reportResults
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment