- `VirtualBox-Wrapper.ps1` now takes 'up' or 'down' as opposed to a machine name. This allows start/stop of a virtualmachine. - `VirtualBox-Wrapper.ps1` now relies on a gitignored `localenv.json` to work. - `VirtualBox-Wrapper.ps1` can also optionally monitor the log file generated from the serial adapter in VirtualBox. - `readme.md` updated to provide instructions on how to populate the `localenv.json` file. - `tasks.json` updated to have a "Clean" task to --remove-orphans, the Build task depends on this. - `tasks.json` updated to have a "Close VirtualBox" task, this runs the `virtualbox-wrapper.ps1` in 'down' mode. The Build task depends on this. - `launch.json` updated to run the `VirtualBox-Wrapper.ps1` with the "-Command up" argument, instead of machine name. - .gitignore updated to ignore any instances of `localenv.json`.
58 lines
1.3 KiB
PowerShell
58 lines
1.3 KiB
PowerShell
<#
|
|
You need a local git-ignored localenv.json file with the following content:
|
|
{
|
|
"virtualbox": {
|
|
"MachineName": "your-machine-name or guid"
|
|
}
|
|
}
|
|
#>
|
|
|
|
param (
|
|
[Parameter(Mandatory=$true)]
|
|
[ValidateSet('up', 'down')]
|
|
[String]$Command
|
|
)
|
|
|
|
$Config = Get-Content .\localenv.json | ConvertFrom-Json
|
|
$MachineName = $Config.virtualbox.MachineName
|
|
$LogLocation = $Config.virtualbox.LogLocation
|
|
$LogOutputEnabled = $LogLocation -ne $null
|
|
|
|
if ($Command -eq 'up') {
|
|
|
|
if($LogOutputEnabled) {
|
|
Clear-Content $LogLocation
|
|
}
|
|
|
|
$MonitorJob = Start-Job -ArgumentList $MachineName -ScriptBlock {
|
|
param($MachineName)
|
|
Write-Output "Starting $MachineName"
|
|
VBoxManage.exe startvm $MachineName
|
|
$running=$true
|
|
while($running) {
|
|
$status=(VBoxManage.exe list runningvms)
|
|
if($status) {
|
|
$running=$status.contains($MachineName)
|
|
} else {
|
|
$running=$false
|
|
}
|
|
}
|
|
}
|
|
|
|
if($LogOutputEnabled) {
|
|
$LogJob = Start-Job -ArgumentList $LogLocation -ScriptBlock {
|
|
param($LogLocation)
|
|
Get-Content -Path $LogLocation -Wait
|
|
}
|
|
}
|
|
|
|
while($MonitorJob.State -eq 'Running') {
|
|
if($LogOutputEnabled) {
|
|
Receive-Job $LogJob
|
|
}
|
|
Receive-Job $MonitorJob
|
|
}
|
|
} elseif ($Command -eq 'down') {
|
|
Write-Output "Stopping $MachineName"
|
|
VBoxManage.exe controlvm $MachineName poweroff
|
|
} |