Files
runner-images/images/macos/provision/core/powershell.sh
Mikhail Timofeev cdd8150e00 [macOS] Allow using GitHub PAT to enlarge api requests limit (#4917)
* Use gh api pat

* Add gh token to 10.15

* Add github_api_pat for macos-12
2022-01-20 13:41:21 +03:00

38 lines
1.5 KiB
Bash

#!/bin/bash -e -o pipefail
source ~/utils/utils.sh
echo Installing PowerShell...
psRelease=$(curl -H "Authorization: token $API_PAT" -s "https://api.github.com/repos/PowerShell/PowerShell/releases/latest")
psDownloadUrl=$(echo $psRelease | jq -r '.assets[].browser_download_url | select(contains("osx-x64.pkg"))' | head -n 1)
download_with_retries $psDownloadUrl "/tmp" "powershell.pkg"
# Work around the issue on macOS Big Sur 11.5 or higher for possible error message ("can't be opened because Apple cannot check it for malicious software") when installing the package
if ! is_Catalina; then
sudo xattr -rd com.apple.quarantine /tmp/powershell.pkg
fi
sudo installer -pkg /tmp/powershell.pkg -target /
# Install PowerShell modules
psModules=$(get_toolset_value '.powershellModules[].name')
for module in ${psModules[@]}; do
echo "Installing $module module"
moduleVersions="$(get_toolset_value ".powershellModules[] | select(.name==\"$module\") | .versions[]?")"
if [[ -z "$moduleVersions" ]];then
pwsh -command "& {Install-Module $module -Force -Scope AllUsers}"
else
for version in ${moduleVersions[@]}; do
echo " - $version"
pwsh -command "& {Install-Module $module -RequiredVersion $version -Force -Scope AllUsers}"
done
fi
done
# A dummy call to initialize .IdentityService directory
pwsh -command "& {Import-Module Az}"
# powershell link was removed in powershell-6.0.0-beta9
sudo ln -s /usr/local/bin/pwsh /usr/local/bin/powershell
invoke_tests "Powershell"