-
Notifications
You must be signed in to change notification settings - Fork 3.3k
/
Copy pathazpowershell.sh
34 lines (30 loc) · 1.39 KB
/
azpowershell.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/bin/bash -e
################################################################################
## File: azpowershell.sh
## Desc: Installed Azure PowerShell
################################################################################
# List of versions
toolset="$INSTALLER_SCRIPT_FOLDER/toolset.json"
versions=$(jq -r '.azureModules[] | select(.name | contains("az")) | .versions[]' $toolset)
# Try to install and update PowerShellGet before the actual installation
pwsh -Command "Install-Module -Name PowerShellGet -Force"
pwsh -Command "Update-Module -Name PowerShellGet -Force"
# Install Azure CLI (instructions taken from https://docs.microsoft.com/en-us/cli/azure/install-azure-cli)
for version in ${versions[@]}; do
pwsh -Command "Save-Module -Name Az -LiteralPath /usr/share/az_$version -RequiredVersion $version -Force -Verbose"
done
# Run tests to determine that the software installed as expected
echo "Testing to make sure that script performed as expected, and basic scenarios work"
for version in ${versions[@]}; do
modulePath="/usr/share/az_$version"
pwsh -Command "
\$env:PSModulePath = '${modulePath}:' + \$env:PSModulePath;
if ( -not (Get-Module -ListAvailable -Name Az.Accounts)) {
Write-Host 'Az Module was not installed'
exit 1
}"
if [ $? -ne 0 ]; then
echo "Az version $version is not installed"
exit 1
fi
done