Skip to content

Instantly share code, notes, and snippets.

@cheretbe
Last active December 27, 2017 11:00
Show Gist options
  • Save cheretbe/1965da139998cdc31e89759a9d33a0d4 to your computer and use it in GitHub Desktop.
Save cheretbe/1965da139998cdc31e89759a9d33a0d4 to your computer and use it in GitHub Desktop.
param(
[string]$scriptName,
[string]$gitBranch = "master",
[hashtable]$scriptParams = @{},
[switch]$localTest
)
$tmpDirName = Join-Path -Path ${Env:Temp} -ChildPath "vagrant-provision"
$tmpFileName = $tmpDirName + "\common.psm1"
if ($localTest.IsPresent) {
Write-Host "Local testing mode" -ForegroundColor Cyan
$commonModuleFilePath = Join-Path -Path ${Env:USERPROFILE} -ChildPath ("provision\common.psm1")
Write-Host ("Copying '{0}'" -f $commonModuleFilePath)
$commonModuleContent = Get-Content -Path $commonModuleFilePath
} else {
$downloadURL = ("https://raw.githubusercontent.com/cheretbe/vagrant-files/{0}/windows/provision/common.psm1" -f $gitBranch)
Write-Host ("Downloading {0}" -f $downloadURL)
$commonModuleContent = (New-Object System.Net.WebClient).DownloadString($downloadURL)
} #if
try {
New-Item -ItemType "Directory" -Path $tmpDirName -Force | Out-Null
$commonModuleContent | Out-File -FilePath $tmpFileName -Force
Write-Host ("Importing '{0}'" -f $tmpFileName)
Import-Module $tmpFileName
Set-VagrantProvisionLocalTestMode -testMode $localTest.IsPresent
Invoke-VagrantProvisionScript -scriptName $scriptName -gitBranch $gitBranch -scriptParams $scriptParams
} finally {
Remove-Item $tmpDirName -Recurse -Force
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment