Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -334,3 +334,4 @@ __pycache__/
archives
.DS_Store
prefab/
*.swp
63 changes: 63 additions & 0 deletions scripts/azure-pipelines/osx/Install-Prerequisites.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#!pwsh
#Requires -Version 6.0
Comment thread
strega-nil marked this conversation as resolved.

<##>
[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
Comment thread
strega-nil marked this conversation as resolved.
}

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 = VBoxManage list extpacks | ConvertFrom-VirtualBoxExtensionPacks

$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
}
69 changes: 69 additions & 0 deletions scripts/azure-pipelines/osx/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# `vcpkg-eg-mac` VMs

## Table of Contents

- [`vcpkg-eg-mac` VMs](#vcpkg-eg-mac-vms)
- [Table of Contents](#table-of-contents)
- [Basic Usage](#basic-usage)
- [Setting up a new macOS machine](#setting-up-a-new-macos-machine)

## Basic Usage

The simplest usage, and one which should be used for when spinning up
new VMs, and when restarting old ones, is a simple:

```
$ cd ~/vagrant/vcpkg-eg-mac
$ vagrant up
```

Any modifications to the machines should be made in `configuration/VagrantFile`
and `Setup-VagrantMachines.ps1`, and make sure to push any changes!

## Setting up a new macOS machine

Before anything else, one must download `brew` and `powershell`.

```sh
$ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
$ brew cask install powershell
```

Then, we need to download the `vcpkg` repository:

```sh
$ git clone https://github.com/microsoft/vcpkg
```

And now all we need to do is set it up! Replace `XX` with the number of
the virtual machine. Generally, that should be the same as the number
for the physical machine; i.e., vcpkgmm-04 will have vcpkg-eg-mac-04.

```sh
$ cd vcpkg/scripts/azure-pipelines/osx
$ ./Install-Prerequisites.ps1 -Force
# NOTE: you may get an error about CoreCLR; see the following paragraph if you do
$ ./Setup-VagrantMachines.ps1 XX \
-Pat '<get this from azure>' \
-ArchivesUsername '<get this from the archives share>' \
-ArchivesAccessKey '<get this from the archives share>' \
-ArchivesUri '<something>.file.core.windows.net' \
-ArchivesShare 'archives'
$ cd ~/vagrant/vcpkg-eg-mac
$ vagrant up
```

If you see the following error:

```
Failed to initialize CoreCLR, HRESULT: 0x8007001F
```

You have to reboot the machine; run

```sh
$ sudo shutdown -r now
```

and wait for the machine to start back up. Then, start again from
`Install-Prerequisites.ps1`.
71 changes: 71 additions & 0 deletions scripts/azure-pipelines/osx/Setup-VagrantMachines.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#!pwsh
#Requires -Version 6.0

<##>
[CmdletBinding(PositionalBinding=$False)]
Param(
[Parameter(Mandatory=$True)]
[String]$Pat,

[Parameter(Mandatory=$True)]
[String]$ArchivesUsername,

[Parameter(Mandatory=$True)]
[String]$ArchivesAccessKey,

[Parameter(Mandatory=$True)]
[String]$ArchivesUri,

[Parameter(Mandatory=$True)]
[String]$ArchivesShare,
Comment thread
strega-nil marked this conversation as resolved.

[Parameter()]
[String]$BaseName = 'vcpkg-eg-mac',
Comment thread
strega-nil marked this conversation as resolved.

[Parameter()]
[Switch]$Force,

[Parameter()]
[Int]$DiskSize = 425,

[Parameter(Mandatory=$True, ValueFromRemainingArguments)]
[String[]]$MachineIdentifiers
)

Set-StrictMode -Version 2

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

if (Test-Path '~/vagrant') {
if ($Force) {
Write-Host 'Deleting existing directories'
Remove-Item -Recurse -Force -Path '~/vagrant' | Out-Null
} else {
throw '~/vagrant already exists; try re-running with -Force'
}
}

Write-Host 'Creating new directories'
New-Item -ItemType 'Directory' -Path '~/vagrant' | Out-Null
New-Item -ItemType 'Directory' -Path '~/vagrant/vcpkg-eg-mac' | Out-Null

Copy-Item `
-Path "$PSScriptRoot/configuration/VagrantFile" `
-Destination '~/vagrant/vcpkg-eg-mac/VagrantFile'

$configuration = @{
pat = $Pat;
base_name = $BaseName;
machine_identifiers = $MachineIdentifiers;
disk_size = $DiskSize;
archives = @{
username = $ArchivesUsername;
access_key = $ArchivesAccessKey;
url = $ArchivesUri;
share = $ArchivesShare;
};
}
ConvertTo-Json -InputObject $configuration -Depth 5 `
| Set-Content -Path '~/vagrant/vcpkg-eg-mac/vagrant-configuration.json'
108 changes: 108 additions & 0 deletions scripts/azure-pipelines/osx/Utilities.psm1
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
#Requires -Version 6.0
Set-StrictMode -Version 2

<#
.SYNOPSIS
Returns whether the specified command exists in the current environment.

.DESCRIPTION
Get-CommandExists takes a string as a parameter,
and returns whether it exists in the current environment;
either a function, alias, or an executable in the path.
It's somewhat equivalent to `which`.

.PARAMETER Name
Specifies the name of the command which may or may not exist.

.INPUTS
System.String
The name of the command.

.OUTPUTS
System.Boolean
Whether the command exists.
#>
function Get-CommandExists
{
[CmdletBinding()]
[OutputType([Boolean])]
Param(
[Parameter(ValueFromPipeline)]
[String]$Name
)

$null -ne (Get-Command -Name $Command -ErrorAction SilentlyContinue)
}

<##>
function Get-RemoteFile
Comment thread
BillyONeal marked this conversation as resolved.
{
[CmdletBinding(PositionalBinding=$False)]
[OutputType([System.IO.FileInfo])]
Param(
[Parameter(Mandatory=$True)]
[String]$OutFile,
[Parameter(Mandatory=$True)]
[String]$Uri,
[Parameter(Mandatory=$True)]
[String]$Sha256
)

Invoke-WebRequest -OutFile $OutFile -Uri $Uri
$actualHash = Get-FileHash -Algorithm SHA256 -Path $OutFile

if ($actualHash.Hash -ne $Sha256) {
throw @"
Invalid hash for file $OutFile;
expected: $Hash
found: $($actualHash.Hash)
Please make sure that the hash in the powershell file is correct.
"@
}

Get-Item $OutFile
}

<##>
function ConvertFrom-VirtualBoxExtensionPacks
{
[CmdletBinding()]
[OutputType([PSCustomObject])]
Param(
[Parameter(ValueFromPipeline)]
[String]$Line
)

Begin {
$currentObject = $null
$currentKey = ""
$currentString = ""
}

Process {
if ($Line[0] -eq ' ') {
$currentString += "`n$($Line.Trim())"
} else {
if ($null -ne $currentObject) {
$currentObject.$currentKey = $currentString
}
$currentKey, $currentString = $Line -Split ':'
$currentString = $currentString.Trim()

if ($currentKey.StartsWith('Pack no')) {
$currentKey = 'Pack'
if ($null -ne $currentObject) {
$PSCmdlet.WriteObject([PSCustomObject]$currentObject)
}
$currentObject = @{}
}
}
}

End {
if ($null -ne $currentObject) {
$currentObject.$currentKey = $currentString
$PSCmdlet.WriteObject([PSCustomObject]$currentObject)
}
}
}
Loading