-
Notifications
You must be signed in to change notification settings - Fork 88
Expand file tree
/
Copy pathinstall.ps1
More file actions
146 lines (117 loc) · 4.31 KB
/
install.ps1
File metadata and controls
146 lines (117 loc) · 4.31 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
#Requires -Version 5.1
<#
.SYNOPSIS
Install skillshare on Windows
.DESCRIPTION
Downloads and installs the latest skillshare release from GitHub
.EXAMPLE
irm https://raw.githubusercontent.com/runkids/skillshare/main/install.ps1 | iex
#>
$ErrorActionPreference = "Stop"
# PowerShell 5.1 defaults to TLS 1.0/1.1; GitHub requires TLS 1.2+
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$Repo = "runkids/skillshare"
$BinaryName = "skillshare"
function Write-Info { param($Message) Write-Host $Message -ForegroundColor Green }
function Write-Warn { param($Message) Write-Host $Message -ForegroundColor Yellow }
function Write-Err { param($Message) Write-Host $Message -ForegroundColor Red; exit 1 }
# Detect architecture
function Get-Arch {
$arch = $env:PROCESSOR_ARCHITECTURE
switch ($arch) {
"AMD64" { return "amd64" }
"ARM64" { return "arm64" }
default { Write-Err "Unsupported architecture: $arch" }
}
}
# Get latest version using redirect (avoids API rate limit)
function Get-LatestVersion {
try {
# Use redirect to get latest version (no API rate limit)
$response = Invoke-WebRequest -Uri "https://github.com/$Repo/releases/latest" `
-MaximumRedirection 0 -UseBasicParsing -ErrorAction SilentlyContinue
} catch {
# PowerShell 5.1 throws on 3xx redirects; extract from the exception
$response = $_.Exception.Response
}
$location = ""
if ($response -and $response.Headers -and $response.Headers["Location"]) {
$location = $response.Headers["Location"]
}
if ($location -match "/tag/([^/\s]+)") {
return $Matches[1]
}
# Fallback to API if redirect fails
try {
$release = Invoke-RestMethod -Uri "https://api.github.com/repos/$Repo/releases/latest"
return $release.tag_name
} catch {
Write-Err "Failed to get latest version. Please check your internet connection."
}
}
# Get install directory
function Get-InstallDir {
$dir = "$env:LOCALAPPDATA\Programs\skillshare"
if (-not (Test-Path $dir)) {
New-Item -ItemType Directory -Path $dir -Force | Out-Null
}
return $dir
}
# Add to PATH if not already present
function Add-ToPath {
param($Dir)
$currentPath = [Environment]::GetEnvironmentVariable("Path", "User")
if ($currentPath -notlike "*$Dir*") {
Write-Info "Adding $Dir to PATH..."
[Environment]::SetEnvironmentVariable("Path", "$currentPath;$Dir", "User")
$env:Path = "$env:Path;$Dir"
return $true
}
return $false
}
function Install-Skillshare {
Write-Info "Installing skillshare..."
Write-Host ""
$arch = Get-Arch
$version = Get-LatestVersion
$versionNum = $version.TrimStart("v")
$installDir = Get-InstallDir
$url = "https://github.com/$Repo/releases/download/$version/${BinaryName}_${versionNum}_windows_${arch}.zip"
Write-Info "Downloading skillshare $version for windows/$arch..."
# Create temp directory
$tempDir = Join-Path $env:TEMP "skillshare-install-$(Get-Random)"
New-Item -ItemType Directory -Path $tempDir -Force | Out-Null
try {
$zipPath = Join-Path $tempDir "skillshare.zip"
# Download
Invoke-WebRequest -Uri $url -OutFile $zipPath -UseBasicParsing
# Extract
Expand-Archive -Path $zipPath -DestinationPath $tempDir -Force
# Find and move binary
$exePath = Join-Path $tempDir "$BinaryName.exe"
if (-not (Test-Path $exePath)) {
Write-Err "Binary not found in archive"
}
$destPath = Join-Path $installDir "$BinaryName.exe"
Move-Item -Path $exePath -Destination $destPath -Force
# Add to PATH
$pathAdded = Add-ToPath -Dir $installDir
Write-Host ""
Write-Info "Successfully installed skillshare to $destPath"
Write-Host ""
# Show version
& $destPath version
Write-Host ""
if ($pathAdded) {
Write-Warn "PATH updated. Restart your terminal for changes to take effect."
Write-Host ""
}
Write-Info "Get started:"
Write-Info " skillshare init"
Write-Info " skillshare --help"
} finally {
# Cleanup
Remove-Item -Path $tempDir -Recurse -Force -ErrorAction SilentlyContinue
}
}
Install-Skillshare