This repository was archived by the owner on Apr 2, 2026. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathinstall.ps1
More file actions
139 lines (120 loc) · 4.88 KB
/
Copy pathinstall.ps1
File metadata and controls
139 lines (120 loc) · 4.88 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# CodeMapper Installation Script for Windows
# Usage: irm https://raw.githubusercontent.com/DennisDyallo/CodeMapper/main/install.ps1 | iex
# Or download and run: .\install.ps1
# Set $env:VERSION to install a specific version (default: latest)
# Set $env:INSTALL_DIR to install to a custom directory (default: $HOME\.local\bin)
$ErrorActionPreference = "Stop"
$Repo = "DennisDyallo/CodeMapper"
Write-Host "Installing CodeMapper..."
# Detect architecture
$Arch = if ([Environment]::Is64BitOperatingSystem) {
if ($env:PROCESSOR_ARCHITECTURE -eq "ARM64" -or $env:PROCESSOR_ARCHITEW6432 -eq "ARM64") {
"arm64"
} else {
"x64"
}
} else {
Write-Error "Error: 32-bit Windows is not supported."
exit 1
}
# Determine download URL based on VERSION
if ($env:VERSION) {
$Version = $env:VERSION
if (-not $Version.StartsWith("v")) {
$Version = "v$Version"
}
$DownloadUrl = "https://github.com/$Repo/releases/download/$Version/codemapper-win-$Arch.zip"
$ChecksumsUrl = "https://github.com/$Repo/releases/download/$Version/SHA256SUMS.txt"
} else {
$DownloadUrl = "https://github.com/$Repo/releases/latest/download/codemapper-win-$Arch.zip"
$ChecksumsUrl = "https://github.com/$Repo/releases/latest/download/SHA256SUMS.txt"
}
Write-Host "Platform: win-$Arch"
Write-Host "Downloading from: $DownloadUrl"
# Create temp directory
$TmpDir = Join-Path $env:TEMP "codemapper-install-$(Get-Random)"
New-Item -ItemType Directory -Path $TmpDir -Force | Out-Null
$TmpZip = Join-Path $TmpDir "codemapper-win-$Arch.zip"
try {
# Download the zip file
try {
Invoke-WebRequest -Uri $DownloadUrl -OutFile $TmpZip -UseBasicParsing
} catch {
Write-Error "Error: Failed to download CodeMapper. Check if the release exists."
exit 1
}
# Attempt to download checksums and validate
$TmpChecksums = Join-Path $TmpDir "SHA256SUMS.txt"
$ChecksumsAvailable = $false
try {
Invoke-WebRequest -Uri $ChecksumsUrl -OutFile $TmpChecksums -UseBasicParsing -ErrorAction SilentlyContinue
$ChecksumsAvailable = $true
} catch {
# Checksums not available, continue without validation
}
if ($ChecksumsAvailable) {
$ExpectedHash = (Get-Content $TmpChecksums | Where-Object { $_ -match "codemapper-win-$Arch\.zip" }) -replace '\s+.*$', ''
if ($ExpectedHash) {
$ActualHash = (Get-FileHash -Path $TmpZip -Algorithm SHA256).Hash.ToLower()
if ($ActualHash -eq $ExpectedHash.ToLower()) {
Write-Host "✓ Checksum validated"
} else {
Write-Error "Error: Checksum validation failed."
exit 1
}
}
}
# Determine install directory
if ($env:INSTALL_DIR) {
$InstallDir = $env:INSTALL_DIR
} else {
$InstallDir = Join-Path $HOME ".local\bin"
}
# Create install directory if it doesn't exist
if (-not (Test-Path $InstallDir)) {
try {
New-Item -ItemType Directory -Path $InstallDir -Force | Out-Null
} catch {
Write-Error "Error: Could not create directory $InstallDir. You may not have write permissions."
exit 1
}
}
# Check if binary already exists
$BinaryPath = Join-Path $InstallDir "codemapper.exe"
if (Test-Path $BinaryPath) {
Write-Host "Notice: Replacing codemapper.exe found at $BinaryPath."
}
# Extract zip
Expand-Archive -Path $TmpZip -DestinationPath $TmpDir -Force
# Move binary to install directory
$ExtractedBinary = Join-Path $TmpDir "codemapper.exe"
if (-not (Test-Path $ExtractedBinary)) {
Write-Error "Error: codemapper.exe not found in the downloaded archive."
exit 1
}
Move-Item -Path $ExtractedBinary -Destination $BinaryPath -Force
Write-Host "✓ CodeMapper installed to $BinaryPath"
# Check if install directory is in PATH
$UserPath = [Environment]::GetEnvironmentVariable("PATH", "User")
if ($UserPath -notlike "*$InstallDir*") {
Write-Host ""
Write-Host "Warning: $InstallDir is not in your PATH"
Write-Host "Add it to your PATH by running:"
Write-Host " `$env:PATH += `";$InstallDir`""
Write-Host ""
Write-Host "Or permanently add it with:"
Write-Host " [Environment]::SetEnvironmentVariable('PATH', `$env:PATH + ';$InstallDir', 'User')"
}
Write-Host ""
Write-Host "Installation complete! Run 'codemapper --help' to get started."
Write-Host ""
Write-Host "Usage examples:"
Write-Host " codemapper C:\path\to\repo # Scan repo, output text"
Write-Host " codemapper C:\path\to\repo --format json # Output as JSON"
Write-Host " codemapper C:\path\to\repo --output .\out # Custom output directory"
} finally {
# Cleanup temp directory
if (Test-Path $TmpDir) {
Remove-Item -Path $TmpDir -Recurse -Force -ErrorAction SilentlyContinue
}
}