-
-
Notifications
You must be signed in to change notification settings - Fork 731
/
install.ps1
213 lines (201 loc) · 6.9 KB
/
install.ps1
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
$ErrorActionPreference = 'Stop'
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
#region Variables
$spicetifyFolderPath = "$env:LOCALAPPDATA\spicetify"
$spicetifyOldFolderPath = "$HOME\spicetify-cli"
#endregion Variables
#region Functions
function Write-Success {
[CmdletBinding()]
param ()
process {
Write-Host -Object ' > OK' -ForegroundColor 'Green'
}
}
function Write-Unsuccess {
[CmdletBinding()]
param ()
process {
Write-Host -Object ' > ERROR' -ForegroundColor 'Red'
}
}
function Test-Admin {
[CmdletBinding()]
param ()
begin {
Write-Host -Object "Checking if the script is not being run as administrator..." -NoNewline
}
process {
$currentUser = New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent())
-not $currentUser.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
}
}
function Test-PowerShellVersion {
[CmdletBinding()]
param ()
begin {
$PSMinVersion = [version]'5.1'
}
process {
Write-Host -Object 'Checking if your PowerShell version is compatible...' -NoNewline
$PSVersionTable.PSVersion -ge $PSMinVersion
}
}
function Move-OldSpicetifyFolder {
[CmdletBinding()]
param ()
process {
if (Test-Path -Path $spicetifyOldFolderPath) {
Write-Host -Object 'Moving the old spicetify folder...' -NoNewline
Copy-Item -Path "$spicetifyOldFolderPath\*" -Destination $spicetifyFolderPath -Recurse -Force
Remove-Item -Path $spicetifyOldFolderPath -Recurse -Force
Write-Success
}
}
}
function Get-Spicetify {
[CmdletBinding()]
param ()
begin {
if ($env:PROCESSOR_ARCHITECTURE -eq 'AMD64') {
$architecture = 'x64'
}
elseif ($env:PROCESSOR_ARCHITECTURE -eq 'ARM64') {
$architecture = 'arm64'
}
else {
$architecture = 'x32'
}
if ($v) {
if ($v -match '^\d+\.\d+\.\d+$') {
$targetVersion = $v
}
else {
Write-Warning -Message "You have spicefied an invalid spicetify version: $v `nThe version must be in the following format: 1.2.3"
Pause
exit
}
}
else {
Write-Host -Object 'Fetching the latest spicetify version...' -NoNewline
$latestRelease = Invoke-RestMethod -Uri 'https://api.github.com/repos/spicetify/cli/releases/latest'
$targetVersion = $latestRelease.tag_name -replace 'v', ''
Write-Success
}
$archivePath = [System.IO.Path]::Combine([System.IO.Path]::GetTempPath(), "spicetify.zip")
}
process {
Write-Host -Object "Downloading spicetify v$targetVersion..." -NoNewline
$Parameters = @{
Uri = "https://github.com/spicetify/cli/releases/download/v$targetVersion/spicetify-$targetVersion-windows-$architecture.zip"
UseBasicParsin = $true
OutFile = $archivePath
}
Invoke-WebRequest @Parameters
Write-Success
}
end {
$archivePath
}
}
function Add-SpicetifyToPath {
[CmdletBinding()]
param ()
begin {
Write-Host -Object 'Making spicetify available in the PATH...' -NoNewline
$user = [EnvironmentVariableTarget]::User
$path = [Environment]::GetEnvironmentVariable('PATH', $user)
}
process {
$path = $path -replace "$([regex]::Escape($spicetifyOldFolderPath))\\*;*", ''
if ($path -notlike "*$spicetifyFolderPath*") {
$path = "$path;$spicetifyFolderPath"
}
}
end {
[Environment]::SetEnvironmentVariable('PATH', $path, $user)
$env:PATH = $path
Write-Success
}
}
function Install-Spicetify {
[CmdletBinding()]
param ()
begin {
Write-Host -Object 'Installing spicetify...'
}
process {
$archivePath = Get-Spicetify
Write-Host -Object 'Extracting spicetify...' -NoNewline
Expand-Archive -Path $archivePath -DestinationPath $spicetifyFolderPath -Force
Write-Success
Add-SpicetifyToPath
}
end {
Remove-Item -Path $archivePath -Force -ErrorAction 'SilentlyContinue'
Write-Host -Object 'spicetify was successfully installed!' -ForegroundColor 'Green'
}
}
#endregion Functions
#region Main
#region Checks
if (-not (Test-PowerShellVersion)) {
Write-Unsuccess
Write-Warning -Message 'PowerShell 5.1 or higher is required to run this script'
Write-Warning -Message "You are running PowerShell $($PSVersionTable.PSVersion)"
Write-Host -Object 'PowerShell 5.1 install guide:'
Write-Host -Object 'https://learn.microsoft.com/skypeforbusiness/set-up-your-computer-for-windows-powershell/download-and-install-windows-powershell-5-1'
Write-Host -Object 'PowerShell 7 install guide:'
Write-Host -Object 'https://learn.microsoft.com/powershell/scripting/install/installing-powershell-on-windows'
Pause
exit
}
else {
Write-Success
}
if (-not (Test-Admin)) {
Write-Unsuccess
Write-Warning -Message "The script was run as administrator. This can result in problems with the installation process or unexpected behavior. Do not continue if you do not know what you are doing."
$Host.UI.RawUI.Flushinputbuffer()
$choices = [System.Management.Automation.Host.ChoiceDescription[]] @(
(New-Object System.Management.Automation.Host.ChoiceDescription '&Yes', 'Abort installation.'),
(New-Object System.Management.Automation.Host.ChoiceDescription '&No', 'Resume installation.')
)
$choice = $Host.UI.PromptForChoice('', 'Do you want to abort the installation process?', $choices, 0)
if ($choice -eq 0) {
Write-Host -Object 'spicetify installation aborted' -ForegroundColor 'Yellow'
Pause
exit
}
}
else {
Write-Success
}
#endregion Checks
#region Spicetify
Move-OldSpicetifyFolder
Install-Spicetify
Write-Host -Object "`nRun" -NoNewline
Write-Host -Object ' spicetify -h ' -NoNewline -ForegroundColor 'Cyan'
Write-Host -Object 'to get started'
#endregion Spicetify
#region Marketplace
$Host.UI.RawUI.Flushinputbuffer()
$choices = [System.Management.Automation.Host.ChoiceDescription[]] @(
(New-Object System.Management.Automation.Host.ChoiceDescription "&Yes", "Install Spicetify Marketplace."),
(New-Object System.Management.Automation.Host.ChoiceDescription "&No", "Do not install Spicetify Marketplace.")
)
$choice = $Host.UI.PromptForChoice('', "`nDo you also want to install Spicetify Marketplace? It will become available within the Spotify client, where you can easily install themes and extensions.", $choices, 0)
if ($choice -eq 1) {
Write-Host -Object 'spicetify Marketplace installation aborted' -ForegroundColor 'Yellow'
}
else {
Write-Host -Object 'Starting the spicetify Marketplace installation script..'
$Parameters = @{
Uri = 'https://raw.githubusercontent.com/spicetify/spicetify-marketplace/main/resources/install.ps1'
UseBasicParsing = $true
}
Invoke-WebRequest @Parameters | Invoke-Expression
}
#endregion Marketplace
#endregion Main