. ./exiter.ps1

try {
  $BOSH_INSTALL_TARGET = Resolve-Path $env:BOSH_INSTALL_TARGET
  $COMPILE_ENV = Join-Path -Path "${BOSH_INSTALL_TARGET}" -ChildPath "bosh"
} catch {
  Write-Host "$_.Exception.Message"
  Exit 1
}

$path=(Get-ChildItem "go1.12*.windows-amd64.zip").FullName

Add-Type -AssemblyName System.IO.Compression.FileSystem
function Unzip
{
  param([string]$zipfile, [string]$outpath)
  [System.IO.Compression.ZipFile]::ExtractToDirectory($zipfile, $outpath)
}

try {
  Write-Host "unzipping $path $BOSH_INSTALL_TARGET"
  Unzip "$path" "${BOSH_INSTALL_TARGET}"
} catch {
  Write-Host "$_.Exception.Message"
  Exit 1
}

try {
  Write-Host "Copying item compile.env.windows ${COMPILE_ENV}"
  New-Item "${COMPILE_ENV}" -type directory
  Copy-Item (Get-ChildItem -Path "1.12\compile.env.windows").FullName -Destination "${COMPILE_ENV}\compile.ps1"
  Copy-Item (Get-ChildItem -Path "1.12\runtime.env.windows").FullName -Destination "${COMPILE_ENV}\runtime.ps1"
} catch {
  Write-Host "$_.Exception.Message"
  Exit 1
}

Exit 0
