11
11
12
12
set -e
13
13
14
+ POWERSHELL_VERSION=${1:- " latest" }
14
15
MICROSOFT_GPG_KEYS_URI=" https://packages.microsoft.com/keys/microsoft.asc"
15
16
POWERSHELL_ARCHIVE_ARCHITECTURES=" amd64"
16
17
POWERSHELL_ARCHIVE_VERSION_CODENAMES=" stretch buster bionic focal"
@@ -98,12 +99,29 @@ install_using_apt() {
98
99
get_common_setting MICROSOFT_GPG_KEYS_URI
99
100
curl -sSL ${MICROSOFT_GPG_KEYS_URI} | gpg --dearmor > /usr/share/keyrings/microsoft-archive-keyring.gpg
100
101
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
101
104
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
103
121
}
104
122
105
123
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
107
125
check_packages curl ca-certificates gnupg2 dirmngr libc6 libgcc1 libgssapi-krb5-2 liblttng-ust0 libstdc++6 libunwind8 libuuid1 zlib1g libicu[0-9][0-9]
108
126
if ! type git > /dev/null 2>&1 ; then
109
127
apt_get_update_if_needed
@@ -112,7 +130,6 @@ install_using_github() {
112
130
if [ " ${architecture} " = " amd64" ]; then
113
131
architecture=" x64"
114
132
fi
115
- POWERSHELL_VERSION=" latest"
116
133
find_version_from_git_tags POWERSHELL_VERSION https://github.com/PowerShell/PowerShell
117
134
powershell_filename=" powershell-${POWERSHELL_VERSION} -linux-${architecture} .tar.gz"
118
135
powershell_target_path=" /opt/microsoft/powershell/$( echo ${POWERSHELL_VERSION} | grep -oE ' [^\.]+' | head -n 1) "
@@ -138,13 +155,15 @@ export DEBIAN_FRONTEND=noninteractive
138
155
# Source /etc/os-release to get OS info
139
156
. /etc/os-release
140
157
architecture=" $( dpkg --print-architecture) "
158
+
141
159
if [[ " ${POWERSHELL_ARCHIVE_ARCHITECTURES} " = * " ${architecture} " * ]] && [[ " ${POWERSHELL_ARCHIVE_VERSION_CODENAMES} " = * " ${VERSION_CODENAME} " * ]]; then
142
160
install_using_apt || use_github=" true"
143
161
else
144
162
use_github=" true"
145
163
fi
146
164
147
165
if [ " ${use_github} " = " true" ]; then
166
+ echo " Attempting install from GitHub release..."
148
167
install_using_github
149
168
fi
150
169
0 commit comments