1
+ # !/usr/bin/env pwsh
2
+ # Copyright 2022 Laurean Ray Bahala. All rights reserved. MIT license.
3
+ # TODO(everyone): Keep this script simple and easily auditable.
4
+
5
+ $ErrorActionPreference = ' Stop'
6
+
7
+ if ($v ) {
8
+ $Version = " v${v} "
9
+ }
10
+ if ($args.Length -eq 1 ) {
11
+ $Version = $args.Get (0 )
12
+ }
13
+
14
+ $ClibgenInstall = $env: CLIBGEN_INSTALL
15
+ $BinDir = if ($ClibgenInstall ) {
16
+ " $ClibgenInstall \bin"
17
+ } else {
18
+ " $Home \.clibgen\bin"
19
+ }
20
+
21
+ $ClibgenZip = " $BinDir \clibgen.zip"
22
+ $ClibgenExe = " $BinDir \clibgen.exe"
23
+ $Target = ' Windows-x86_64'
24
+
25
+ # GitHub requires TLS 1.2
26
+ [Net.ServicePointManager ]::SecurityProtocol = [Net.SecurityProtocolType ]::Tls12
27
+
28
+ $ClibgenUri = if (! $Version ) {
29
+ " https://github.com/laureanray/clibgen/releases/latest/download/clibgen_${Target} .zip"
30
+ } else {
31
+ " https://github.com/laureanray/clibgen/releases/download/${Version} /clibgen_${Target} .zip"
32
+ }
33
+
34
+ Write-Output $ClibgenUri
35
+
36
+ if (! (Test-Path $BinDir )) {
37
+ New-Item $BinDir - ItemType Directory | Out-Null
38
+ }
39
+
40
+ curl.exe - Lo $ClibgenZip $ClibgenUri
41
+
42
+ tar.exe xf $ClibgenZip - C $BinDir
43
+
44
+ Remove-Item $ClibgenZip
45
+
46
+ $User = [EnvironmentVariableTarget ]::User
47
+ $Path = [Environment ]::GetEnvironmentVariable(' Path' , $User )
48
+ if (! (" ;$Path ;" .ToLower() -like " *;$BinDir ;*" .ToLower())) {
49
+ [Environment ]::SetEnvironmentVariable(' Path' , " $Path ;$BinDir " , $User )
50
+ $Env: Path += " ;$BinDir "
51
+ }
52
+
53
+ Write-Output " Clibgen was installed successfully to $ClibgenExe "
54
+ Write-Output " Run 'clibgen --help' to get started"
0 commit comments