-
Notifications
You must be signed in to change notification settings - Fork 3
/
install.ps1
93 lines (81 loc) · 2.58 KB
/
install.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
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
88
89
90
91
92
93
Set-StrictMode -version 2.0
$ErrorActionPreference = "Stop"
try {
$architecture = if ($env:PROCESSOR_ARCHITECTURE -eq "AMD64") { "x64" } else { "arm64" }
$packageName = "bcad-win-$architecture"
$archiveName = "$packageName.zip"
$downloadUrl = "https://pkgs.ixmilia.com/bcad/win/$archiveName"
$downloadPath = Join-Path $env:TEMP $archiveName
$programsDir = Join-Path $env:LOCALAPPDATA "Programs"
$installDir = Join-Path $programsDir $packageName
# wait for process to exit
$currentProcessId = "$env:BCAD_CURRENT_PROCESS_ID"
if ($currentProcessId -ne "") {
# wait for process to exit
Write-Host "Waiting for process $currentProcessId to exit..."
try {
$currentProcess = Get-Process -Id $currentProcessId
$waitTimeout = 10 * 1000 # 10s
$hasExited = $currentProcess.WaitForExit($waitTimeout)
if (-Not $hasExited) {
# process didn't exit on time, just quit
Write-Host "Process did not exit"
exit 1
}
}
catch {
# process not found, must have already exited
}
}
# remove existing installation
if (Test-Path $installDir) {
$doDeletion = $False
if ("$env:BCAD_INSTALL_QUIET" -ne "") {
$doDeletion = $True
}
else {
$deleteExistingP = Read-Host "Existing installation found, delete it? [Y/N]"
if ($deleteExistingP.ToUpper() -eq "Y") {
$doDeletion = $True
}
}
if (-Not $doDeletion) {
Write-Host "Exiting install"
exit 0
}
$retryCountMax = 5
For ($i = 0; $i -lt $retryCountMax; $i++) {
try {
Remove-Item $installDir -Recurse -Force
break
}
catch {
Start-Sleep -Seconds 2
}
}
if (Test-Path $installDir) {
Write-Host "Unable to remove existing installation"
exit 1
}
}
# download
if (Test-Path $downloadPath) {
Remove-Item $downloadPath -Force
}
Invoke-WebRequest $downloadUrl -OutFile $downloadPath
# extract
Expand-Archive -Path $downloadPath -DestinationPath $programsDir
# remove archive
Remove-Item $downloadPath -Force
# launch
if ("$env:BCAD_INSTALL_QUIET" -eq "") {
$exePath = Join-Path $installDir "bcad.exe"
Start-Process $exePath
}
}
catch {
Write-Host $_
Write-Host $_.Exception
Write-Host $_.ScriptStackTrace
exit 1
}