Repository navigation
Expand file tree
/
Copy pathinstall.ps1
More file actions
85 lines (72 loc) · 3.03 KB
/
Copy pathinstall.ps1
File metadata and controls
85 lines (72 loc) · 3.03 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
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
$ErrorActionPreference = 'Stop'
# 1. Check for Admin Privileges
$isAdmin = ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
if (-not $isAdmin) {
Write-Error "Error: This installer must be run with Administrator privileges."
Exit 1
}
function Get-DiskTrackerArchiveSuffix {
try {
if ([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture -eq [System.Runtime.InteropServices.Architecture]::Arm64) {
return 'windows-arm64'
}
} catch {
# Fall through to environment-variable detection.
}
if (($env:PROCESSOR_ARCHITECTURE -eq 'ARM64') -or ($env:PROCESSOR_ARCHITEW6432 -eq 'ARM64')) {
return 'windows-arm64'
}
return 'windows-x64'
}
Write-Output "Checking for the latest DiskTracker version from GitHub..."
$repoUrl = "https://api.github.com/repos/pratham15541/disktracker/releases/latest"
try {
# Resolve the latest release info
$release = Invoke-RestMethod -Uri $repoUrl -Headers @{ "User-Agent" = "DiskTracker-Installer" } -ErrorAction Stop
$tag = $release.tag_name
} catch {
Write-Error "Failed to fetch release info from GitHub. Please check your network connection."
Exit 1
}
$archiveSuffix = Get-DiskTrackerArchiveSuffix
Write-Output "Latest version found: $tag ($archiveSuffix)"
$zipUrl = "https://github.com/pratham15541/disktracker/releases/download/$tag/disktracker-$tag-$archiveSuffix.zip"
$tempZip = Join-Path $env:TEMP "disktracker-$tag.zip"
Write-Output "Downloading from $zipUrl..."
try {
Invoke-WebRequest -Uri $zipUrl -OutFile $tempZip -UseBasicParsing -ErrorAction Stop
} catch {
Write-Error "Failed to download DiskTracker ZIP file from GitHub."
Exit 1
}
$installDir = "C:\Program Files\DiskTracker"
if (-not (Test-Path $installDir)) {
New-Item -ItemType Directory -Path $installDir | Out-Null
}
Write-Output "Extracting DiskTracker to $installDir..."
try {
# Extract ZIP
Expand-Archive -Path $tempZip -DestinationPath $installDir -Force
} catch {
Write-Error "Failed to extract DiskTracker ZIP."
Remove-Item -Path $tempZip -ErrorAction SilentlyContinue
Exit 1
}
# Clean up ZIP
Remove-Item -Path $tempZip -ErrorAction SilentlyContinue
# Update Path System Environment Variable
Write-Output "Updating system PATH..."
$pathEnv = [Environment]::GetEnvironmentVariable("Path", [EnvironmentVariableTarget]::Machine)
$paths = $pathEnv -split ';'
if ($paths -notcontains $installDir) {
[Environment]::SetEnvironmentVariable("Path", $pathEnv + ";$installDir", [EnvironmentVariableTarget]::Machine)
Write-Output "Added $installDir to System PATH."
} else {
Write-Output "$installDir is already in System PATH."
}
# Inform about session reload
Write-Output ""
Write-Output "=================================================="
Write-Output "DiskTracker $tag installed successfully!"
Write-Output "Please restart your terminal to use the 'disktracker' command."
Write-Output "=================================================="