Repository navigation
Expand file tree
/
Copy pathget.ps1
More file actions
152 lines (120 loc) · 6.11 KB
/
Copy pathget.ps1
File metadata and controls
152 lines (120 loc) · 6.11 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
# MediaTab one-command installer for Windows.
#
# Paste this into Command Prompt or PowerShell:
#
# powershell -c "irm https://raw.githubusercontent.com/destination/mediatab/main/get.ps1 | iex"
#
# It installs anything missing (Git, Node.js), downloads MediaTab, builds it
# against the latest Vencord, and hooks it up. Run it again any time to update.
#
# Nothing here needs administrator rights, and Discord's own files are never
# modified. Read the script first if you like - that's the point of it being
# short.
$ErrorActionPreference = "Stop"
function Say($msg) { Write-Host " $msg" }
function Step($msg) { Write-Host "`n==> $msg" -ForegroundColor Cyan }
function Fail($msg) { Write-Host "`n!! $msg" -ForegroundColor Red; exit 1 }
Write-Host @"
MediaTab - a media browser for Discord
https://github.com/destination/mediatab
"@ -ForegroundColor Magenta
$InstallDir = if ($env:MEDIATAB_DIR) { $env:MEDIATAB_DIR } else { Join-Path $HOME "mediatab" }
# ── refresh PATH so tools installed a moment ago are visible ────────────────
function Update-Path {
$env:Path = [Environment]::GetEnvironmentVariable("Path", "Machine") + ";" +
[Environment]::GetEnvironmentVariable("Path", "User")
}
function Have($name) { $null -ne (Get-Command $name -ErrorAction SilentlyContinue) }
# ── prerequisites ──────────────────────────────────────────────────────────
Step "Checking what's already installed"
$needs = @()
if (-not (Have git)) { $needs += "Git.Git" }
if (-not (Have node)) { $needs += "OpenJS.NodeJS.LTS" }
if ($needs.Count -gt 0) {
if (-not (Have winget)) {
Fail @"
Missing: $($needs -join ', ')
This installer uses winget to fetch them, but winget isn't available on this PC.
Install these two by hand, then run this command again:
Git https://git-scm.com/download/win
Node.js https://nodejs.org/ (choose the LTS version)
"@
}
foreach ($pkg in $needs) {
Step "Installing $pkg (this can take a couple of minutes)"
winget install --id $pkg --exact --source winget `
--accept-package-agreements --accept-source-agreements `
--silent --disable-interactivity | Out-Null
}
Update-Path
} else {
Say "Git and Node.js are already here"
}
if (-not (Have git)) { Fail "Git still isn't on PATH. Close this window, open a new one, and run the command again." }
if (-not (Have node)) { Fail "Node.js still isn't on PATH. Close this window, open a new one, and run the command again." }
$nodeMajor = [int]((node -p "process.versions.node.split('.')[0]"))
if ($nodeMajor -lt 22) {
Fail "Node.js 22 or newer is required, but this PC has $(node -v). Update it at https://nodejs.org/"
}
Say "Node $(node -v), $(git --version)"
# the build scripts are bash; Git for Windows ships one
$bash = @(
"$env:ProgramFiles\Git\bin\bash.exe",
"${env:ProgramFiles(x86)}\Git\bin\bash.exe",
"$env:LOCALAPPDATA\Programs\Git\bin\bash.exe"
) | Where-Object { Test-Path $_ } | Select-Object -First 1
if (-not $bash) {
$gitCmd = (Get-Command git).Source
$candidate = Join-Path (Split-Path (Split-Path $gitCmd)) "bin\bash.exe"
if (Test-Path $candidate) { $bash = $candidate }
}
if (-not $bash) { Fail "Couldn't find Git Bash, which the build needs. Reinstall Git from https://git-scm.com/download/win" }
# ── Vencord must already be installed ──────────────────────────────────────
$vencordDir = if ($env:VENCORD_DIR) { $env:VENCORD_DIR } else { Join-Path $env:APPDATA "Vencord" }
if (-not (Test-Path (Join-Path $vencordDir "dist"))) {
Fail @"
Vencord doesn't look installed yet.
MediaTab is a Vencord plugin, so Vencord has to be there first:
1. Download it from https://vencord.dev/download/
2. Run the installer, click Install
3. Start Discord and check Settings has a Vencord section
4. Run this command again
"@
}
Say "Found Vencord at $vencordDir"
# ── get the code ───────────────────────────────────────────────────────────
if (Test-Path (Join-Path $InstallDir ".git")) {
Step "Updating MediaTab"
git -C $InstallDir pull --ff-only | Out-Null
} else {
Step "Downloading MediaTab to $InstallDir"
git clone --quiet https://github.com/destination/mediatab.git $InstallDir
}
# ── close Discord ──────────────────────────────────────────────────────────
$discord = Get-Process -Name Discord, DiscordCanary, DiscordPTB, Vesktop -ErrorAction SilentlyContinue
if ($discord) {
Step "Closing Discord"
Say "It has to be shut for the last step. It'll be fine to reopen straight after."
$discord | ForEach-Object { $_.CloseMainWindow() | Out-Null }
Start-Sleep -Seconds 3
Get-Process -Name Discord, DiscordCanary, DiscordPTB, Vesktop -ErrorAction SilentlyContinue |
Stop-Process -Force -ErrorAction SilentlyContinue
Start-Sleep -Seconds 2
}
# ── build and hook up ──────────────────────────────────────────────────────
$env:MEDIATAB_BOOTSTRAP = "1"
Step "Building against the latest Vencord (a couple of minutes the first time)"
& $bash -lc "cd '$($InstallDir -replace '\\','/')' && ./scripts/setup.sh"
if ($LASTEXITCODE -ne 0) { Fail "The build failed. The output above should say why." }
Step "Hooking it into Discord"
& $bash -lc "cd '$($InstallDir -replace '\\','/')' && ./scripts/install.sh"
if ($LASTEXITCODE -ne 0) { Fail "Couldn't hook it in. The output above should say why." }
Write-Host @"
Done.
1. Open Discord
2. Settings -> Vencord -> Plugins
3. Search "MediaTab" and switch it on
4. Press Ctrl+R to reload
A picture icon appears at the top right of any chat, next to the pin.
To update later, run this same command again.
"@ -ForegroundColor Green