aboutsummaryrefslogtreecommitdiff
path: root/scripts/azure-pipelines/osx/Install-Prerequisites.ps1
blob: f2c0b3713953b779f823625a84c0400dfecf3227 (plain)
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!pwsh
#Requires -Version 6.0

<#
.SYNOPSIS
Installs the set of prerequisites for the macOS CI hosts.

.DESCRIPTION
Install-Prerequisites.ps1 installs all of the necessary prerequisites
to run the vcpkg macOS CI in a vagrant virtual machine,
skipping all prerequisites that are already installed.

.PARAMETER Force
Don't skip the prerequisites that are already installed.

.INPUTS
None

.OUTPUTS
None
#>
[CmdletBinding()]
Param(
    [Parameter()]
    [Switch]$Force
)

Set-StrictMode -Version 2

if (-not $IsMacOS) {
    Write-Error 'This script should only be run on a macOS host'
    throw
}

Import-Module "$PSScriptRoot/Utilities.psm1"

$Installables = Get-Content "$PSScriptRoot/configuration/installables.json" | ConvertFrom-Json

$Installables.Applications | ForEach-Object {
    if (-not (Get-CommandExists $_.TestCommand)) {
        Write-Host "$($_.Name) not installed; installing now"
    } elseif ($Force) {
        Write-Host "$($_.Name) found; attempting to upgrade or re-install"
    } else {
        Write-Host "$($_.Name) already installed"
        return
    }

    $pathToDmg = "~/Downloads/$($_.Name).dmg"
    Get-RemoteFile -OutFile $pathToDmg -Uri $_.DmgUrl -Sha256 $_.Sha256

    hdiutil attach $pathToDmg -mountpoint /Volumes/setup-installer
    sudo installer -pkg "/Volumes/setup-installer/$($_.InstallerPath)" -target /
    hdiutil detach /Volumes/setup-installer
}

# Install plugins
$installedExtensionPacks = Get-InstalledVirtualBoxExtensionPacks

$Installables.VBoxExtensions | ForEach-Object {
    $extension = $_
    $installedExts = $installedExtensionPacks | Where-Object { $_.Pack -eq $extension.FullName -and $_.Usable -eq 'true' }

    if ($null -eq $installedExts) {
        Write-Host "VBox extension: $($extension.Name) not installed; installing now"
    } elseif ($Force) {
        Write-Host "VBox extension: $($extension.Name) found; attempting to upgrade or re-install"
    } else {
        Write-Host "VBox extension: $($extension.Name) already installed"
        return
    }

    $pathToExt = "~/Downloads/$($extension.FullName -replace ' ','_').vbox-extpack"

    Get-RemoteFile -OutFile $pathToExt -Uri $extension.Url -Sha256 $extension.Sha256 | Out-Null

    Write-Host 'Attempting to install extension with sudo; you may need to enter your password'
    sudo VBoxManage extpack install --replace $pathToExt
    sudo VBoxManage extpack cleanup
}