-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathinstall.ps1
More file actions
115 lines (95 loc) · 5.69 KB
/
Copy pathinstall.ps1
File metadata and controls
115 lines (95 loc) · 5.69 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
# Git Switch installer for Windows.
#
# Usage:
# irm https://raw.githubusercontent.com/Avijit07x/git-switch/main/install.ps1 | iex
#
# Re-running this script installs the newest published release, so it
# works as both an installer and an updater.
$ErrorActionPreference = "Stop"
# ───────────────────────────────────────────────────────────────────────
# Configuration
# ───────────────────────────────────────────────────────────────────────
$Repo = "Avijit07x/git-switch"
$AppName = "Git Switch"
# ───────────────────────────────────────────────────────────────────────
# Output helpers
# ───────────────────────────────────────────────────────────────────────
function Write-Step($msg) { Write-Host " > $msg" -ForegroundColor Cyan }
function Write-Ok($msg) { Write-Host " + $msg" -ForegroundColor Green }
function Write-Warn($msg) { Write-Host " ! $msg" -ForegroundColor Yellow }
function Stop-WithErr($msg) {
Write-Host " x $msg" -ForegroundColor Red
exit 1
}
function Show-Banner {
Write-Host ""
Write-Host " $AppName" -ForegroundColor Blue -NoNewline
Write-Host " Windows installer" -ForegroundColor DarkGray
Write-Host " a native Git client that runs your dev servers" -ForegroundColor DarkGray
Write-Host ""
}
# ───────────────────────────────────────────────────────────────────────
# Pre-flight
# ───────────────────────────────────────────────────────────────────────
function Test-Windows {
if (-not $IsWindows -and $PSVersionTable.Platform -ne $null -and $PSVersionTable.Platform -ne "Win32NT") {
Stop-WithErr "$AppName Windows installer only runs on Windows."
}
}
# ───────────────────────────────────────────────────────────────────────
# Resolve latest release
# ───────────────────────────────────────────────────────────────────────
function Resolve-Release {
Write-Step "Resolving latest release"
try {
$script:Release = Invoke-RestMethod "https://api.github.com/repos/$Repo/releases/latest" -UseBasicParsing
} catch {
Stop-WithErr "Couldn't reach GitHub. Check your network."
}
$script:Asset = $script:Release.assets | Where-Object { $_.name -like "*.msi" } | Select-Object -First 1
if (-not $script:Asset) {
Stop-WithErr "Release $($script:Release.tag_name) has no Windows .msi attached."
}
Write-Ok "Found $($script:Release.tag_name)"
}
# ───────────────────────────────────────────────────────────────────────
# Download + install
# ───────────────────────────────────────────────────────────────────────
function Install-Msi {
$tempDir = Join-Path $env:TEMP "git-switch-install"
if (Test-Path $tempDir) { Remove-Item $tempDir -Recurse -Force -ErrorAction SilentlyContinue }
New-Item -ItemType Directory -Path $tempDir | Out-Null
$msiPath = Join-Path $tempDir $script:Asset.name
Write-Step "Downloading $($script:Asset.name)"
try {
$ProgressPreference = "SilentlyContinue"
Invoke-WebRequest -Uri $script:Asset.browser_download_url -OutFile $msiPath -UseBasicParsing
} catch {
Stop-WithErr "Download failed."
} finally {
$ProgressPreference = "Continue"
}
Write-Step "Running installer (may prompt for admin)"
$proc = Start-Process msiexec.exe `
-ArgumentList "/i", "`"$msiPath`"", "/qb", "/norestart" `
-Wait `
-PassThru
if ($proc.ExitCode -ne 0) {
Stop-WithErr "msiexec exited with code $($proc.ExitCode)."
}
Remove-Item $tempDir -Recurse -Force -ErrorAction SilentlyContinue
Write-Host ""
Write-Ok "Installed $AppName $($script:Release.tag_name)"
Write-Host ""
Write-Host " Launch: Start menu > $AppName" -ForegroundColor DarkGray
Write-Host " Update: re-run this same command" -ForegroundColor DarkGray
Write-Host " Issues: https://github.com/$Repo/issues" -ForegroundColor DarkGray
Write-Host ""
}
# ───────────────────────────────────────────────────────────────────────
# Run
# ───────────────────────────────────────────────────────────────────────
Show-Banner
Test-Windows
Resolve-Release
Install-Msi