Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

download.ps1 2.0 KB

You have to be logged in to leave a comment. Sign In
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
  1. $runtimeUrl = $args[0]
  2. $overrideUrl = $args[1]
  3. $current = [string] (Get-Location -PSProvider FileSystem)
  4. $client = New-Object System.Net.WebClient
  5. function downloadWithRetry {
  6. param([string]$url, [string]$dest, [int]$retry)
  7. Write-Host
  8. Write-Host "Attempt: $retry"
  9. Write-Host
  10. trap {
  11. Write-Host $_.Exception.ToString()
  12. if ($retry -lt 5) {
  13. $retry=$retry+1
  14. Write-Host
  15. Write-Host "Waiting 5 seconds and retrying"
  16. Write-Host
  17. Start-Sleep -s 5
  18. downloadWithRetry $url $dest $retry $client
  19. }
  20. else {
  21. Write-Host "Download failed"
  22. throw "Max number of retries downloading [5] exceeded"
  23. }
  24. }
  25. $client.downloadfile($url, $dest)
  26. }
  27. function download($url, $dest) {
  28. Write-Host "Downloading $url"
  29. downloadWithRetry $url $dest 1
  30. }
  31. function copyOnVerify($file, $output) {
  32. Write-Host "Verifying $file"
  33. $verify = Get-AuthenticodeSignature $file
  34. Out-Host -InputObject $verify
  35. if ($verify.Status -ne "Valid") {
  36. throw "Invalid signature for runtime package $file"
  37. }
  38. else {
  39. mv $file $output
  40. }
  41. }
  42. if ($overrideUrl) {
  43. Write-Host "Using override url: $overrideUrl"
  44. $url = $overrideUrl
  45. }
  46. else {
  47. $url = $runtimeUrl
  48. }
  49. foreach($singleUrl in $url -split ";")
  50. {
  51. $suffix = Get-Random
  52. $downloaddir = $current + "\sandbox" + $suffix
  53. mkdir $downloaddir
  54. $dest = $downloaddir + "\sandbox.exe"
  55. download $singleUrl $dest
  56. $final = $downloaddir + "\runtime.exe"
  57. copyOnVerify $dest $final
  58. if (Test-Path -LiteralPath $final)
  59. {
  60. cd $downloaddir
  61. if ($host.Version.Major -eq 3)
  62. {
  63. .\runtime.exe -y | Out-Null
  64. .\setup.cmd
  65. }
  66. else
  67. {
  68. Start-Process -FilePath $final -ArgumentList -y -Wait
  69. $cmd = $downloaddir + "\setup.cmd"
  70. Start-Process -FilePath $cmd -Wait
  71. }
  72. }
  73. else
  74. {
  75. throw "Unable to verify package"
  76. }
  77. cd $current
  78. if (Test-Path -LiteralPath $downloaddir)
  79. {
  80. Remove-Item -LiteralPath $downloaddir -Force -Recurse
  81. }
  82. }
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...