-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinstall.ps1
More file actions
114 lines (98 loc) · 4.29 KB
/
install.ps1
File metadata and controls
114 lines (98 loc) · 4.29 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
param(
[string]$InstallPath = "$env:LOCALAPPDATA\FaserF\SwitchCraft",
[switch]$Silent,
[switch]$Portable,
[string]$Version = "latest"
)
$ErrorActionPreference = 'Stop'
$Repo = "FaserF/SwitchCraft"
$ApiUrl = "https://api.github.com/repos/$Repo/releases/latest"
Write-Host "🧙♂️ SwitchCraft Installer" -ForegroundColor Cyan
try {
Write-Host "Fetching release info for: $Version..." -ForegroundColor Gray
if ($Version -eq "latest") {
$Release = Invoke-RestMethod -Uri $ApiUrl
} else {
$Release = Invoke-RestMethod -Uri "https://api.github.com/repos/$Repo/releases/tags/$Version"
}
$Tag = $Release.tag_name
Write-Host "Identified version: $Tag" -ForegroundColor Gray
# Detect OS
$IsWindows = $true
$IsLinux = $false
$IsMacOS = $false
if ($PSVersionTable.PSVersion.Major -ge 6) {
if ($IsWindows -and $env:OS -ne 'Windows_NT') { # PowerShell Core on non-Windows?
# Better detection
if ([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform([System.Runtime.InteropServices.OSPlatform]::Linux)) {
$IsWindows = $false; $IsLinux = $true
} elseif ([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform([System.Runtime.InteropServices.OSPlatform]::OSX)) {
$IsWindows = $false; $IsMacOS = $true
}
}
}
# Determine Asset
$Assets = $Release.assets
$TargetAsset = $null
$DownloadPath = ""
$IsInstaller = $false
if ($IsWindows) {
if ($Portable) {
$TargetAsset = $Assets | Where-Object { $_.name -like "*windows.exe" -and $_.name -notlike "*Setup.exe" } | Select-Object -First 1
$DownloadPath = "$env:USERPROFILE\Desktop\SwitchCraft-$Tag.exe"
$ModeName = "Portable Executable (Windows)"
} else {
# Try Installer First
$TargetAsset = $Assets | Where-Object { $_.name -like "*Setup.exe" } | Select-Object -First 1
if ($TargetAsset) {
$DownloadPath = "$env:TEMP\SwitchCraft-Setup.exe"
$ModeName = "Installer (Windows)"
$IsInstaller = $true
} else {
Write-Warning "Setup.exe not found in release. Falling back to Portable version."
$TargetAsset = $Assets | Where-Object { $_.name -like "*windows.exe" } | Select-Object -First 1
$DownloadPath = "$env:USERPROFILE\Desktop\SwitchCraft-$Tag.exe"
$ModeName = "Portable Executable (Fallback)"
}
}
} elseif ($IsLinux) {
$TargetAsset = $Assets | Where-Object { $_.name -like "*linux*" } | Select-Object -First 1
$DownloadPath = "./SwitchCraft-$Tag"
$ModeName = "Binary (Linux)"
} elseif ($IsMacOS) {
$TargetAsset = $Assets | Where-Object { $_.name -like "*macos*" } | Select-Object -First 1
$DownloadPath = "./SwitchCraft-$Tag"
$ModeName = "Binary (MacOS)"
} else {
throw "Unsupported Operating System."
}
if (-not $TargetAsset) {
throw "No suitable asset found for this platform in release $Tag."
}
$DownloadUrl = $TargetAsset.browser_download_url
Write-Host "Downloading $ModeName..." -ForegroundColor Yellow
Write-Host "URL: $DownloadUrl" -ForegroundColor Gray
Invoke-WebRequest -Uri $DownloadUrl -OutFile $DownloadPath
if ($IsWindows -and $IsInstaller) {
Write-Host "Installing..." -ForegroundColor Green
$ArgsList = "/VERYSILENT", "/SUPPRESSMSGBOXES", "/NORESTART"
if ($Silent) { $ArgsList += "/DEBUGMODE" } # Optional debug
Start-Process -FilePath $DownloadPath -ArgumentList $ArgsList -Wait
Write-Host "✅ Installation complete!" -ForegroundColor Green
Write-Host "Run 'switchcraft' to start." -ForegroundColor Cyan
} elseif ($IsWindows) {
Write-Host "✅ Downloaded to: $DownloadPath" -ForegroundColor Green
} else {
# Linux/Mac
try {
if ($IsLinux -or $IsMacOS) {
chmod +x $DownloadPath
}
} catch {}
Write-Host "✅ Downloaded to: $DownloadPath" -ForegroundColor Green
Write-Host "You may need to run: chmod +x $DownloadPath" -ForegroundColor Gray
}
} catch {
Write-Error "Installation failed: $_"
exit 1
}