File: Download-mbedTLS.PS1

package info (click to toggle)
python-mbedtls 2.10.1-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 960 kB
  • sloc: python: 4,595; sh: 170; makefile: 18
file content (58 lines) | stat: -rw-r--r-- 1,216 bytes parent folder | download
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
<#
.SYNOPSIS
  Download mbedTLS

.PARAMETER Version
  The mbedTLS version to download

.PARAMETER DestinationPath
  Where the source code should be expanded.
#>

Param (
  [Parameter(Mandatory=$true)] $Version,
  [Parameter(Mandatory=$true)] $DestinationPath
)

$DebugPreference = "Continue"

$Name = "mbedtls"
$FileName = "$Name-$Version.zip"
$Uri = "https://github.com/ARMmbed/mbedtls/archive/$FileName"

if (Get-Command "New-TemporaryFile" -errorAction SilentlyContinue) {
  $TempFile = New-TemporaryFile
  if (-not(Test-Path $TempFile)) {
    throw "Could not create temporary file"
  } else {
    Write-Debug $TempFile
  }
} else {
  $TempFile = "download.tmp"
}

Write-Debug "Start download from $Uri"
try {
  Invoke-WebRequest -Uri $Uri -OutFile $TempFile
}
catch {
  Remove-Item $TempFile
}
Write-Debug "Done"

$TempZipFile = [io.path]::ChangeExtension($TempFile, "zip")
Move-Item $TempFile $TempZipFile

Write-Debug "Extract archive"
try {
  Expand-Archive -Path $TempZipFile -DestinationPath $DestinationPath
}
finally {
  Remove-Item $TempZipFile
}
Write-Debug "Done"

Move-Item $DestinationPath\$Name-$Name-$Version\* $DestinationPath
Remove-Item $DestinationPath\$Name-$Name-$Version

Write-Host "Done"