-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinstall.ps1
More file actions
71 lines (57 loc) · 2.26 KB
/
install.ps1
File metadata and controls
71 lines (57 loc) · 2.26 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
# xtop installer for Windows
# Installs xtop by building from source (requires Rust/Cargo)
$ErrorActionPreference = "Stop"
$AppName = "xtop"
$RepoUrl = "https://github.com/xscriptor/xtop.git" # Replace with actual repo URL
$InstallDir = "$env:USERPROFILE\.cargo\bin" # Standard Cargo bin location
Write-Host "Installing $AppName..." -ForegroundColor Green
# Check for Cargo
if (-not (Get-Command "cargo" -ErrorAction SilentlyContinue)) {
Write-Host "Error: Cargo (Rust) is not installed." -ForegroundColor Red
Write-Host "Please install Rust first from https://rustup.rs/"
exit 1
}
# Create temp directory
$TempDir = Join-Path $env:TEMP "xtop_install"
if (Test-Path $TempDir) { Remove-Item -Recurse -Force $TempDir }
New-Item -ItemType Directory -Force -Path $TempDir | Out-Null
Write-Host "Working in $TempDir"
# Clone or Copy Source
if (Test-Path "Cargo.toml") {
Write-Host "Detected local source, building from current directory..." -ForegroundColor Cyan
Copy-Item -Recurse . "$TempDir\$AppName"
} elseif (Get-Command "git" -ErrorAction SilentlyContinue) {
Write-Host "Cloning repository..." -ForegroundColor Cyan
git clone --depth 1 "$RepoUrl" "$TempDir\$AppName"
if ($LASTEXITCODE -ne 0) {
Write-Host "Failed to clone repository." -ForegroundColor Red
exit 1
}
} else {
Write-Host "Error: git is not installed and no local source found." -ForegroundColor Red
exit 1
}
Set-Location "$TempDir\$AppName"
Write-Host "Building $AppName..." -ForegroundColor Cyan
cargo build --release
if ($LASTEXITCODE -ne 0) {
Write-Host "Build failed." -ForegroundColor Red
exit 1
}
# Ensure Install Dir exists (it should if cargo is installed)
if (-not (Test-Path $InstallDir)) {
New-Item -ItemType Directory -Force -Path $InstallDir | Out-Null
}
$BinaryPath = "target\release\$AppName.exe"
if (Test-Path $BinaryPath) {
Write-Host "Installing binary to $InstallDir..." -ForegroundColor Cyan
Copy-Item -Force $BinaryPath "$InstallDir\$AppName.exe"
Write-Host "$AppName installed successfully!" -ForegroundColor Green
Write-Host "Run it with: $AppName"
} else {
Write-Host "Error: Compiled binary not found." -ForegroundColor Red
exit 1
}
# Cleanup
Set-Location $env:USERPROFILE
Remove-Item -Recurse -Force $TempDir