-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathinstall.ps1
More file actions
169 lines (144 loc) · 6.96 KB
/
Copy pathinstall.ps1
File metadata and controls
169 lines (144 loc) · 6.96 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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
# vibe auracle Windows Installer
# Usage: iex (irm https://raw.githubusercontent.com/nathfavour/vibeauracle/release/install.ps1)
$ErrorActionPreference = "Stop"
$Repo = "nathfavour/vibeauracle"
$GithubUrl = "https://github.com/$Repo"
# Detect Architecture
$Arch = "amd64"
if ($env:PROCESSOR_ARCHITECTURE -eq "ARM64") {
$Arch = "arm64"
}
$BinaryName = "vibeaura-windows-$Arch.exe"
Write-Host "Detected Platform: Windows/$Arch" -ForegroundColor Cyan
# --- Source & Config Detection ---
$BuildFromSource = $false
$SourceMode = "none"
$ConfigFile = Join-Path $HOME ".vibeauracle\config.yaml"
if (Test-Path $ConfigFile) {
$Content = Get-Content $ConfigFile -Raw
if ($Content -match "build_from_source:\s*true" -or $Content -match "beta:\s*true") {
$BuildFromSource = $true
}
}
# Detect if we are inside the source tree
if ((Test-Path "go.work") -and (Test-Path "cmd\vibeaura")) {
$BuildFromSource = $true
$SourceMode = "local"
}
# Detect if existing installation is a source build
$ExistingVibe = $null
if (Get-Command vibeaura -ErrorAction SilentlyContinue) {
$ExistingVibe = (Get-Command vibeaura).Source
$VersionOut = (& $ExistingVibe version)
if ($VersionOut -match "Version\s*:\s*(master|main|release|dev)") {
$BuildFromSource = $true
}
} elseif (Test-Path "$HOME\.vibeaura\bin\vibeaura.exe") {
$ExistingVibe = "$HOME\.vibeaura\bin\vibeaura.exe"
}
if ($BuildFromSource) {
Write-Host "Existing configuration or environment suggests building from source." -ForegroundColor Cyan
if (Get-Command go -ErrorAction SilentlyContinue) {
if ($SourceMode -eq "local") {
Write-Host "Building from current directory..." -ForegroundColor Cyan
$Commit = (git rev-parse HEAD 2>$null)
if (-not $Commit) { $Commit = "unknown" }
$Date = (Get-Date -UFormat "%Y-%m-%dT%H:%M:%SZ")
$Branch = (git rev-parse --abbrev-ref HEAD 2>$null)
if (-not $Branch) { $Branch = "master" }
go build -ldflags "-s -w -X main.Version=$Branch -X main.Commit=$Commit -X main.BuildDate=$Date" -o vibeaura.exe ./cmd/vibeaura
# We continue with the rest of the script to install the binary we just built
} else {
if ($ExistingVibe) {
Write-Host "Handing over to 'vibeaura update' for source-based update..." -ForegroundColor Cyan
& $ExistingVibe update
return
} else {
Write-Host "Building from remote source..." -ForegroundColor Cyan
$TmpSrc = Join-Path $env:TEMP "vibeaura-src-$([Guid]::NewGuid().ToString().Substring(0,8))"
git clone --depth 1 "https://github.com/$Repo.git" $TmpSrc
$OldDir = Get-Location
Set-Location $TmpSrc
try {
$Commit = (git rev-parse HEAD 2>$null)
if (-not $Commit) { $Commit = "unknown" }
$Date = (Get-Date -UFormat "%Y-%m-%dT%H:%M:%SZ")
$Branch = "master"
$env:GOTOOLCHAIN = "local"
go build -ldflags "-s -w -X main.Version=$Branch -X main.Commit=$Commit -X main.BuildDate=$Date" -o "$OldDir\vibeaura.exe" ./cmd/vibeaura
} finally {
Set-Location $OldDir
Remove-Item -Recurse -Force $TmpSrc
}
# We continue with the rest of the script to install the binary we just built
}
}
} else {
Write-Host "Warning: Source build preferred but 'go' not found. Falling back to binary release." -ForegroundColor Yellow
}
}
if (-not (Test-Path "vibeaura.exe")) {
# Get latest release tag
$ReleaseInfo = Invoke-RestMethod -Uri "https://api.github.com/repos/$Repo/releases/latest"
$LatestTag = $ReleaseInfo.tag_name
if (-not $LatestTag) {
Write-Error "Could not find latest release. Please check $GithubUrl/releases"
}
# Check if vibeaura is already installed and up-to-date
if ($ExistingVibe) {
$VersionOutput = (& $ExistingVibe version)
$VersionLine = ($VersionOutput | Select-String "Version")
$CommitLine = ($VersionOutput | Select-String "Commit")
if ($VersionLine -and $CommitLine) {
$LocalVersion = $VersionLine.ToString().Split(":")[1].Trim()
$LocalCommit = $CommitLine.ToString().Split(":")[1].Trim()
# Resolve the SHA of the latest tag to be sure
$LatestSHA = $null
if (Get-Command git -ErrorAction SilentlyContinue) {
$Match = (git ls-remote --tags "$GithubUrl.git" | Select-String "refs/tags/$LatestTag$")
if ($Match) {
$LatestSHA = $Match.ToString().Split("`t")[0].Trim()
}
}
# If the local version matches the latest tag, OR the local commit matches the latest SHA, we can skip
if (($LocalVersion -eq $LatestTag) -or ($null -ne $LatestSHA -and $LocalCommit -eq $LatestSHA)) {
Write-Host "Vibe Auracle is already up to date ($LatestTag / $($LocalCommit.Substring(0,7)))." -ForegroundColor Green
return
}
}
}
$DownloadUrl = "$GithubUrl/releases/download/$LatestTag/$BinaryName"
$ChecksumUrl = "$GithubUrl/releases/download/$LatestTag/checksums.txt"
Write-Host "Downloading $BinaryName ($LatestTag)..." -ForegroundColor Cyan
Invoke-WebRequest -Uri $DownloadUrl -OutFile "vibeaura.exe"
Invoke-WebRequest -Uri $ChecksumUrl -OutFile "checksums.txt"
# --- Verify Integrity ---
Write-Host "Verifying integrity..." -ForegroundColor Cyan
$ExpectedSha = (Select-String -Path "checksums.txt" -Pattern $BinaryName).ToString().Split(" ")[0].Trim()
$ActualSha = (Get-FileHash -Path "vibeaura.exe" -Algorithm SHA256).Hash.ToLower()
if ($ExpectedSha -ne $ActualSha) {
Write-Error "Checksum mismatch! The downloaded binary may be corrupted or tampered with."
Remove-Item -Force "vibeaura.exe", "checksums.txt"
return
}
Remove-Item -Force "checksums.txt"
}
$InstallDir = Join-Path $HOME ".vibeaura\bin"
if (-not (Test-Path $InstallDir)) {
New-Item -Path $InstallDir -ItemType Directory | Out-Null
}
$ExePath = Join-Path $InstallDir "vibeaura.exe"
# Move the binary to the install directory
Move-Item -Path "vibeaura.exe" -Destination $ExePath -Force
# Add to Path for current session
if ($env:Path -notlike "*$InstallDir*") {
Write-Host "Adding $InstallDir to User Path..." -ForegroundColor Yellow
$UserPath = [Environment]::GetEnvironmentVariable("Path", "User")
if ($UserPath -notlike "*$InstallDir*") {
[Environment]::SetEnvironmentVariable("Path", "$UserPath;$InstallDir", "User")
}
$env:Path += ";$InstallDir"
}
Write-Host "Successfully installed vibe auracle to $ExePath" -ForegroundColor Green
Write-Host "You may need to restart your terminal for changes to take effect." -ForegroundColor Yellow
& "$ExePath" --help