Repository navigation
Expand file tree
/
Copy pathinstall.ps1
More file actions
51 lines (41 loc) · 2 KB
/
Copy pathinstall.ps1
File metadata and controls
51 lines (41 loc) · 2 KB
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
# ==========================================
# CONFIGURATION
# ==========================================
$repoUser = "modelica"
$repoName = "fmusim"
$appName = "fmusim" # The name of the folder where it will live
# The name of your zip file asset as it appears on GitHub:
$zipName = "fmusim-x86_64-windows.zip"
# ==========================================
# INSTALLATION LOGIC
# ==========================================
$ErrorActionPreference = "Stop"
# 1. Define paths (Installs to C:\Users\<User>\AppData\Local\<AppName>)
$installDir = Join-Path $env:LOCALAPPDATA $appName
$tempZip = Join-Path $env:TEMP "$zipName"
$downloadUrl = "https://github.com/$repoUser/$repoName/releases/latest/download/$zipName"
Write-Host "Installing $appName..." -ForegroundColor Cyan
# 2. Clean old installation if it exists
if (Test-Path $installDir) {
Write-Host "Removing older version..." -ForegroundColor Gray
Remove-Item -Recurse -Force $installDir
}
# 3. Download the zip artifact
Write-Host "Downloading latest release..." -ForegroundColor Gray
Invoke-WebRequest -Uri $downloadUrl -OutFile $tempZip -UseBasicParsing
# 4. Extract the ZIP file
Write-Host "Extracting files to $installDir..." -ForegroundColor Gray
Expand-Archive -Path $tempZip -DestinationPath $installDir -Force
# 5. Add to User PATH permanently (if not already there)
$userPath = [Environment]::GetEnvironmentVariable("Path", [EnvironmentVariableTarget]::User)
if ($userPath -notlike "*$installDir*") {
Write-Host "Adding $appName to User PATH..." -ForegroundColor Gray
$newPath = "$userPath;$installDir"
[Environment]::SetEnvironmentVariable("Path", $newPath, [EnvironmentVariableTarget]::User)
# Update current session PATH so they can use it immediately
$env:Path += ";$installDir"
}
# 6. Cleanup the downloaded zip
Remove-Item -Force $tempZip
Write-Host "`nSuccessfully installed $appName!" -ForegroundColor Green
Write-Host "You may need to restart your terminal/IDE for the PATH changes to take effect." -ForegroundColor Yellow