Skip to content

Commit 878a900

Browse files
authored
[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
1 parent 3bf4e20 commit 878a900

File tree

5 files changed

+60
-24
lines changed

5 files changed

+60
-24
lines changed

src/powershell/devcontainer-feature.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"id": "powershell",
3-
"version": "1.4.0",
3+
"version": "1.5.0",
44
"name": "PowerShell",
55
"documentationURL": "https://github.com/devcontainers/features/tree/main/src/powershell",
66
"description": "Installs PowerShell along with needed dependencies. Useful for base Dockerfiles that often are missing required install dependencies like gpg.",
@@ -10,7 +10,9 @@
1010
"proposals": [
1111
"latest",
1212
"none",
13-
"7.1"
13+
"7.4",
14+
"7.3",
15+
"7.2"
1416
],
1517
"default": "latest",
1618
"description": "Select or enter a version of PowerShell."

src/powershell/install.sh

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ POWERSHELL_PROFILE_URL="${POWERSHELLPROFILEURL}"
1818

1919
MICROSOFT_GPG_KEYS_URI="https://packages.microsoft.com/keys/microsoft.asc"
2020
POWERSHELL_ARCHIVE_ARCHITECTURES="amd64"
21-
POWERSHELL_ARCHIVE_VERSION_CODENAMES="stretch buster bionic focal bullseye jammy"
21+
POWERSHELL_ARCHIVE_VERSION_CODENAMES="stretch buster bionic focal bullseye jammy bookworm noble"
2222
GPG_KEY_SERVERS="keyserver hkp://keyserver.ubuntu.com
2323
keyserver hkp://keyserver.ubuntu.com:80
2424
keyserver hkps://keys.openpgp.org
@@ -221,25 +221,32 @@ install_using_github() {
221221
echo "${powershell_archive_sha256} *${powershell_filename}" | sha256sum -c -
222222
fi
223223
tar xf "${powershell_filename}" -C "${powershell_target_path}"
224-
ln -s "${powershell_target_path}/pwsh" /usr/local/bin/pwsh
224+
chmod 755 "${powershell_target_path}/pwsh"
225+
ln -sf "${powershell_target_path}/pwsh" /usr/bin/pwsh
226+
add-shell "/usr/bin/pwsh"
227+
cd /tmp
225228
rm -rf /tmp/pwsh
226229
}
227230

228-
export DEBIAN_FRONTEND=noninteractive
229-
230-
# Source /etc/os-release to get OS info
231-
. /etc/os-release
232-
architecture="$(dpkg --print-architecture)"
231+
if ! type pwsh >/dev/null 2>&1; then
232+
export DEBIAN_FRONTEND=noninteractive
233+
234+
# Source /etc/os-release to get OS info
235+
. /etc/os-release
236+
architecture="$(dpkg --print-architecture)"
233237

234-
if [[ "${POWERSHELL_ARCHIVE_ARCHITECTURES}" = *"${architecture}"* ]] && [[ "${POWERSHELL_ARCHIVE_VERSION_CODENAMES}" = *"${VERSION_CODENAME}"* ]]; then
235-
install_using_apt || use_github="true"
238+
if [[ "${POWERSHELL_ARCHIVE_ARCHITECTURES}" = *"${architecture}"* ]] && [[ "${POWERSHELL_ARCHIVE_VERSION_CODENAMES}" = *"${VERSION_CODENAME}"* ]]; then
239+
install_using_apt || use_github="true"
240+
else
241+
use_github="true"
242+
fi
243+
244+
if [ "${use_github}" = "true" ]; then
245+
echo "Attempting install from GitHub release..."
246+
install_using_github
247+
fi
236248
else
237-
use_github="true"
238-
fi
239-
240-
if [ "${use_github}" = "true" ]; then
241-
echo "Attempting install from GitHub release..."
242-
install_using_github
249+
echo "PowerShell is already installed."
243250
fi
244251

245252
# If PowerShell modules are requested, loop through and install

test/powershell/install_powershell_fallback_test.sh

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ source dev-container-features-test-lib
88
# Extension-specific tests
99
check "az.resources" pwsh -Command "(Get-Module -ListAvailable -Name Az.Resources).Version.ToString()"
1010
check "az.storage" pwsh -Command "(Get-Module -ListAvailable -Name Az.Storage).Version.ToString()"
11-
check "profile" pwsh -Command "(Get-Variable $env:ProfileLoaded).Value"
11+
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 } }"
1212

1313
check "Powershell version as installed by feature" bash -c "pwsh --version"
1414

@@ -168,9 +168,11 @@ install_using_github() {
168168
echo "${powershell_archive_sha256} *${powershell_filename}" | sha256sum -c -
169169
fi
170170
sudo tar xf "${powershell_filename}" -C "${powershell_target_path}"
171-
sudo ln -s "${powershell_target_path}/pwsh" /usr/local/bin/pwsh
172-
sudo rm -rf /tmp/pwsh /usr/local/bin/pwsh
173-
171+
sudo chmod 755 "${powershell_target_path}/pwsh"
172+
sudo ln -sf "${powershell_target_path}/pwsh" /usr/bin/pwsh
173+
sudo add-shell "/usr/bin/pwsh"
174+
cd /tmp
175+
sudo rm -rf /tmp/pwsh
174176
}
175177

176178
echo -e "\nInstalling Powershell with find_prev_version_from_git_tags() fn 👈🏻"

test/powershell/scenarios.json

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"install_modules": {
3-
"image": "mcr.microsoft.com/devcontainers/base:jammy",
3+
"image": "mcr.microsoft.com/devcontainers/base:noble",
44
"features": {
55
"powershell": {
66
"modules": "az.resources, az.storage",
@@ -9,7 +9,7 @@
99
}
1010
},
1111
"install_powershell_fallback_test": {
12-
"image": "mcr.microsoft.com/devcontainers/base:jammy",
12+
"image": "mcr.microsoft.com/devcontainers/base:noble",
1313
"features": {
1414
"powershell": {
1515
"modules": "az.resources, az.storage",
@@ -18,11 +18,17 @@
1818
}
1919
},
2020
"install_modules_version": {
21-
"image": "mcr.microsoft.com/devcontainers/base:jammy",
21+
"image": "mcr.microsoft.com/devcontainers/base:noble",
2222
"features": {
2323
"powershell": {
2424
"modules": "az.resources==2.5.0, az.storage==4.3.0"
2525
}
2626
}
27+
},
28+
"validate_powershell_installation": {
29+
"image": "mcr.microsoft.com/devcontainers/base:noble",
30+
"features": {
31+
"powershell": {}
32+
}
2733
}
2834
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
# Import test library for `check` command
6+
source dev-container-features-test-lib
7+
8+
# Extension-specific tests
9+
check "pwsh file is symlink" bash -c "[ -L /usr/bin/pwsh ]"
10+
check "pwsh symlink is registered as shell" bash -c "[ $(grep -c '/usr/bin/pwsh' /etc/shells) -eq 1 ]"
11+
check "pwsh target is correct" bash -c "[ $(readlink /usr/bin/pwsh) = /opt/microsoft/powershell/7/pwsh ]"
12+
check "pwsh target is registered as shell" bash -c "[ $(grep -c '/opt/microsoft/powershell/7/pwsh' /etc/shells) -eq 1 ]"
13+
check "pwsh owner is root" bash -c "[ $(stat -c %U /opt/microsoft/powershell/7/pwsh) = root ]"
14+
check "pwsh group is root" bash -c "[ $(stat -c %G /opt/microsoft/powershell/7/pwsh) = root ]"
15+
check "pwsh file mode is -rwxr-xr-x" bash -c "[ $(stat -c '%A' /opt/microsoft/powershell/7/pwsh) = '-rwxr-xr-x' ]"
16+
check "pwsh is in PATH" bash -c "command -v pwsh"
17+
18+
# Report result
19+
reportResults

0 commit comments

Comments
 (0)