2022-12-29 12:56:54 -05:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
set -euo pipefail
|
|
|
|
|
|
|
|
# Reference: https://docs.microsoft.com/en-us/powershell/scripting/install/installing-powershell-core-on-linux?view=powershell-7
|
|
|
|
# Slightly modified to always retrieve latest stable Powershell version
|
|
|
|
# If changing PWSH_VERSION='latest' to a specific version, use format PWSH_VERSION='tags/v7.0.2'
|
|
|
|
|
2023-04-21 23:57:35 -04:00
|
|
|
case $TARGETARCH in
|
|
|
|
amd64)
|
|
|
|
target=x64
|
|
|
|
;;
|
|
|
|
# arm64)
|
|
|
|
# only on ubuntu
|
|
|
|
*)
|
|
|
|
echo "$TARGETARCH is not supported"
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2022-12-29 12:56:54 -05:00
|
|
|
mkdir -p "${PWSH_DIRECTORY}"
|
|
|
|
url=$(curl -s \
|
|
|
|
-H "Accept: application/vnd.github+json" \
|
2023-01-04 00:41:31 -05:00
|
|
|
-H "Authorization: Bearer $(cat /run/secrets/GITHUB_TOKEN)" \
|
2022-12-29 12:56:54 -05:00
|
|
|
"https://api.github.com/repos/powershell/powershell/releases/${PWSH_VERSION}" |
|
2023-04-21 23:57:35 -04:00
|
|
|
jq --arg target "${target}" -r '.assets | .[] | select(.name | contains("linux-alpine-" + $target)) | .url')
|
2022-12-29 12:56:54 -05:00
|
|
|
curl --retry 5 --retry-delay 5 -sL \
|
|
|
|
-H "Accept: application/octet-stream" \
|
2023-01-04 00:41:31 -05:00
|
|
|
-H "Authorization: Bearer $(cat /run/secrets/GITHUB_TOKEN)" \
|
2022-12-29 12:56:54 -05:00
|
|
|
"${url}" | tar -xz -C "${PWSH_DIRECTORY}"
|
|
|
|
chmod +x "${PWSH_DIRECTORY}/pwsh"
|
|
|
|
ln -sf "${PWSH_DIRECTORY}/pwsh" /usr/bin/pwsh
|
|
|
|
pwsh -c "Install-Module -Name PSScriptAnalyzer -RequiredVersion ${PSSA_VERSION} -Scope AllUsers -Force"
|