-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathinstall-hpegl-provider-windows.ps1
executable file
·53 lines (39 loc) · 1.45 KB
/
install-hpegl-provider-windows.ps1
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
param ($VERSION)
$os="windows"
$arch="amd64"
$repo="HPE/terraform-provider-hpegl"
$windows_hpegl_dir="$env:appdata\terraform.d\plugins\registry.terraform.io\hpe\hpegl"
$users_pwd = Get-Location
function get_latest_release {
Write-Host Getting latest release
$release_url="https://api.github.com/repos/${repo}/releases/latest"
$tag = (Invoke-WebRequest $release_url | ConvertFrom-Json)[0].tag_name
$VERSION=${tag}
$VERSION
}
if (!$VERSION) {
$VERSION=get_latest_release
}
$version_number=$VERSION -replace 'v'
$dest_dir="${windows_hpegl_dir}\${version_number}\${os}_${arch}\"
$hpegl_zip="terraform-provider-hpegl_${version_number}_${os}_${arch}.zip"
$hpegl=$hpegl_zip -replace '.zip'
$hpegl_dl_url="https://github.com/${repo}/releases/download/${VERSION}/${hpegl_zip}"
mkdir "$dest_dir"
Set-Location "$dest_dir"
try {
Invoke-WebRequest $hpegl_dl_url -Out $hpegl_zip
}
catch {
Write-Host "Error: The version that was specified does not exist."
Set-Location "${users_pwd}"
Remove-Item -Path "${windows_hpegl_dir}\${version_number}" -Recurse -Force -ErrorAction SilentlyContinue
Write-Host "Exiting..."
Return
}
Write-Host Extracting release files
Expand-Archive $hpegl_zip -Force
Get-ChildItem -Path $hpegl -Recurse -File | Move-Item -Destination $dest_dir
Remove-Item $hpegl_zip -Recurse -Force -ErrorAction SilentlyContinue
Remove-Item $hpegl -Recurse -Force -ErrorAction SilentlyContinue
Write-Host Complete