Skip to content
This repository was archived by the owner on Nov 30, 2023. It is now read-only.

Commit c9d3b88

Browse files
joshspicerChuxel
andauthored
add version selection to powershell (#1080)
* add version selection to powershell * Apply suggestions from code review Co-authored-by: Chuck Lantz <[email protected]> * adjust regex Co-authored-by: Chuck Lantz <[email protected]>
1 parent 053beb1 commit c9d3b88

File tree

3 files changed

+25
-6
lines changed

3 files changed

+25
-6
lines changed

script-library/container-features/src/feature-scripts.env

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@ _VSC_INSTALL_GRADLE="gradle-debian.sh ${_BUILD_ARG_GRADLE_VERSION:-latest}"
1616
_VSC_INSTALL_MAVEN="maven-debian.sh ${_BUILD_ARG_MAVEN_VERSION:-latest}"
1717
_VSC_INSTALL_RUBY="ruby-debian.sh ${_BUILD_ARG_RUBY_VERSION:-latest}"
1818
_VSC_INSTALL_RUST=rust-debian.sh
19-
_VSC_INSTALL_POWERSHELL=powershell-debian.sh
19+
_VSC_INSTALL_POWERSHELL=powershell-debian.sh ${_BUILD_ARG_POWERSHELL_VERSION:-latest}
2020
_VSC_INSTALL_DESKTOP_LITE=desktop-lite-debian.sh

script-library/container-features/src/features.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -963,9 +963,9 @@
963963
"options": {
964964
"version": {
965965
"type": "string",
966-
"enum": ["latest"],
966+
"proposals": ["latest", "7.1"],
967967
"default": "latest",
968-
"description": "Currently unused."
968+
"description": "Select or enter a version of PowerShell."
969969
}
970970
},
971971
"init": true,

script-library/powershell-debian.sh

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
set -e
1313

14+
POWERSHELL_VERSION=${1:-"latest"}
1415
MICROSOFT_GPG_KEYS_URI="https://packages.microsoft.com/keys/microsoft.asc"
1516
POWERSHELL_ARCHIVE_ARCHITECTURES="amd64"
1617
POWERSHELL_ARCHIVE_VERSION_CODENAMES="stretch buster bionic focal"
@@ -98,12 +99,29 @@ install_using_apt() {
9899
get_common_setting MICROSOFT_GPG_KEYS_URI
99100
curl -sSL ${MICROSOFT_GPG_KEYS_URI} | gpg --dearmor > /usr/share/keyrings/microsoft-archive-keyring.gpg
100101
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/microsoft-archive-keyring.gpg] https://packages.microsoft.com/repos/microsoft-${ID}-${VERSION_CODENAME}-prod ${VERSION_CODENAME} main" > /etc/apt/sources.list.d/microsoft.list
102+
103+
# Update lists
101104
apt-get update -yq
102-
apt-get install -yq powershell || return 1
105+
106+
# Soft version matching for CLI
107+
if [ "${POWERSHELL_VERSION}" = "latest" ] || [ "${POWERSHELL_VERSION}" = "lts" ] || [ "${POWERSHELL_VERSION}" = "stable" ]; then
108+
# Empty, meaning grab whatever "latest" is in apt repo
109+
version_suffix=""
110+
else
111+
version_suffix="=$(apt-cache madison powershell | awk -F"|" '{print $2}' | sed -e 's/^[ \t]*//' | grep -E -m 1 "^(${POWERSHELL_VERSION})(\.|$|\+.*|-.*)")"
112+
113+
if [ -z ${version_suffix} ] || [ ${version_suffix} = "=" ]; then
114+
echo "Provided POWERSHELL_VERSION (${POWERSHELL_VERSION}) was not found in the apt-cache for this package+distribution combo";
115+
return 1
116+
fi
117+
echo "version_suffix ${version_suffix}"
118+
fi
119+
120+
apt-get install -yq powershell${version_suffix} || return 1
103121
}
104122

105123
install_using_github() {
106-
# Fall back on direct download if no apt package exists in microsoft pool
124+
# Fall back on direct download if no apt package exists in microsoft pool
107125
check_packages curl ca-certificates gnupg2 dirmngr libc6 libgcc1 libgssapi-krb5-2 liblttng-ust0 libstdc++6 libunwind8 libuuid1 zlib1g libicu[0-9][0-9]
108126
if ! type git > /dev/null 2>&1; then
109127
apt_get_update_if_needed
@@ -112,7 +130,6 @@ install_using_github() {
112130
if [ "${architecture}" = "amd64" ]; then
113131
architecture="x64"
114132
fi
115-
POWERSHELL_VERSION="latest"
116133
find_version_from_git_tags POWERSHELL_VERSION https://github.com/PowerShell/PowerShell
117134
powershell_filename="powershell-${POWERSHELL_VERSION}-linux-${architecture}.tar.gz"
118135
powershell_target_path="/opt/microsoft/powershell/$(echo ${POWERSHELL_VERSION} | grep -oE '[^\.]+' | head -n 1)"
@@ -138,13 +155,15 @@ export DEBIAN_FRONTEND=noninteractive
138155
# Source /etc/os-release to get OS info
139156
. /etc/os-release
140157
architecture="$(dpkg --print-architecture)"
158+
141159
if [[ "${POWERSHELL_ARCHIVE_ARCHITECTURES}" = *"${architecture}"* ]] && [[ "${POWERSHELL_ARCHIVE_VERSION_CODENAMES}" = *"${VERSION_CODENAME}"* ]]; then
142160
install_using_apt || use_github="true"
143161
else
144162
use_github="true"
145163
fi
146164

147165
if [ "${use_github}" = "true" ]; then
166+
echo "Attempting install from GitHub release..."
148167
install_using_github
149168
fi
150169

0 commit comments

Comments
 (0)