-
Notifications
You must be signed in to change notification settings - Fork 0
/
Installer.ps1
177 lines (157 loc) · 7.14 KB
/
Installer.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
# This script is available at https://github.com/yodaluca23/SpotX-Spicetify-Universal-Installer
# To run on MacOS Install PowerShell 7 with "brew install PowerShell". To run on Win install PowerShell 7 with "winget install --id Microsoft.Powershell --source winget".
# To run Open PowerShell 7 and run "iex "& { $(iwr -useb 'https://raw.githubusercontent.com/yodaluca23/SpotX-Spicetify-Universal-Installer/main/Installer.ps1') }""
# Parameters include "-clean" which will perform a clean install of Spotify, first uninstalling and then running the main patching scripts.
# Parameter example "iex "& { $(iwr -useb 'https://raw.githubusercontent.com/yodaluca23/SpotX-Spicetify-Universal-Installer/main/Installer.ps1') } -clean""
# Ealier revisions of this script are available here: https://github.com/yodaluca23/Random-Crap/blob/main/Spotify.ps1
param (
[Parameter()]
[switch]$clean
)
# Function to run Windows scripts
function Run-WindowsScripts {
Write-Output "Running on Windows"
if ($clean) {
Write-Output "Uninstalling Spotify..."
$uninstallScriptUrl = "https://raw.githubusercontent.com/amd64fox/Uninstall-Spotify/main/Uninstall-Spotify.bat"
$uninstallScriptPath = "$env:TEMP\Uninstall-Spotify.bat"
Invoke-WebRequest -Uri $uninstallScriptUrl -OutFile $uninstallScriptPath
Start-Process -FilePath "cmd.exe" -ArgumentList "/c $uninstallScriptPath" -Wait
}
# Download and run the SpotX-Win batch script
$batchScriptUrl = "https://raw.githubusercontent.com/SpotX-Official/SpotX/main/Install_New_theme.bat"
$batchScriptPath = "$env:TEMP\Install_New_theme.bat"
Invoke-WebRequest -Uri $batchScriptUrl -OutFile $batchScriptPath
Start-Process -FilePath "cmd.exe" -ArgumentList "/c $batchScriptPath" -Wait
# Open Spotify, thank you to SpotX Installation script for following code to locate executable.
$spotifyDirectory = Join-Path $env:APPDATA 'Spotify'
$spotifyDirectory2 = Join-Path $env:LOCALAPPDATA 'Spotify'
$spotifyExecutable = Join-Path $spotifyDirectory 'Spotify.exe'
Start-Process -FilePath $spotifyExecutable
Write-Output "Openning the Spotify Application for 30 seconds to avoid conflicts with the Spicetify installation. If it does not open automatically please open it manually."
Start-Sleep -Seconds 30
Stop-Process -Name "Spotify" -Force -ErrorAction SilentlyContinue
# Run the spicetify update command and capture the output
$spicetifyUpdate = & spicetify update 2>&1
if ($clean) {
$psScriptUrl = "https://raw.githubusercontent.com/spicetify/cli/main/install.ps1"
Invoke-Expression (Invoke-WebRequest -Uri $psScriptUrl -UseBasicParsing).Content
} else {
# Check if need to install
if ($spicetifyUpdate -match "success") {
Write-Output "Spicetify already installed, reapplying."
$spicetifyBackUp = & spicetify backup apply 2>&1
if ($spicetifyBackUp -match "spicetify restore backup"){
Write-Output "Restoring Backup"
spicetify restore backup
spicetify backup apply
}
} else {
Write-Output "Spicetify not installed, or install is broken, installing."
# Run the Spicetify-Win installation script
$psScriptUrl = "https://raw.githubusercontent.com/spicetify/cli/main/install.ps1"
Invoke-Expression (Invoke-WebRequest -Uri $psScriptUrl -UseBasicParsing).Content
}
}
}
# Function to run macOS/Linux scripts
function Run-UnixScripts {
if ($IsMacOS) {
Write-Output "Running on MacOS"
}
if ($IsLinux) {
Write-Output "Running on Linux"
}
if ($clean) {
Write-Output "Uninstalling Spotify..."
$uninstallScript = "bash <(curl -sSL https://gist.github.com/jetfir3/f620e44fc246c1bed45ed040bbfa2d68/raw/uninstallify.sh)"
bash -c "$uninstallScript"
}
# Run the SpotX-Bash installation script
if ($IsMacOS) {
$spotxScript = "bash <(curl -sSL https://spotx-official.github.io/run.sh) --installmac -i"
} ElseIf ($IsLinux) {
$spotxScript = "bash <(curl -sSL https://spotx-official.github.io/run.sh) --installdeb -i"
}
bash -c "$spotxScript"
# Open Spotify
Start-Process -FilePath "open" -ArgumentList "spotify://open"
Write-Output "Openning the Spotify Application for 30 seconds to avoid conflicts with the Spicetify installation. If it does not open automatically please open it manually."
Start-Sleep -Seconds 30
pkill -f "Spotify"
# Run the spicetify update command and capture the output
$spicetifyUpdate = & spicetify update 2>&1
# Check if need to install
if ($clean) {
$spicetifyScript = "curl -fsSL https://raw.githubusercontent.com/spicetify/cli/main/install.sh | sh"
bash -c "$spicetifyScript"
} else {
if ($spicetifyUpdate -match "success") {
Write-Output "Spicetify already installed, reapplying."
$spicetifyBackUp = & spicetify backup apply 2>&1
if ($spicetifyBackUp -match "spicetify restore backup"){
Write-Output "Restoring Backup"
spicetify restore backup
spicetify backup apply
}
} else {
Write-Output "Spicetify not installed, or install is broken, installing."
$spicetifyScript = "curl -fsSL https://raw.githubusercontent.com/spicetify/cli/main/install.sh | sh"
bash -c "$spicetifyScript"
}
}
}
# Function to clean up temporary files
function Cleanup {
# Delete Install_New_theme.bat
$batchScriptPath = "$env:TEMP\Install_New_theme.bat"
if (Test-Path $batchScriptPath) {
Remove-Item $batchScriptPath -Force
}
# Delete spicetify.zip
$spicetifyZipPath = "$env:TEMP\spicetify.zip"
if (Test-Path $spicetifyZipPath) {
Remove-Item $spicetifyZipPath -Force
}
# Delete Uninstall-Spotify.bat if it was downloaded
$uninstallScriptPath = "$env:TEMP\Uninstall-Spotify.bat"
if (Test-Path $uninstallScriptPath) {
Remove-Item $uninstallScriptPath -Force
}
}
function UnsupportedOS {
Write-Output "Your running an Unsupported OS. The currently supported Operating systems for this script include Windows, MacOS, and Linux."
Exit 1
}
# Set OS variables if on unsupported version
if ($PSVersionTable.PSVersion.Major -lt 7) {
[bool] $IsMacOS = $IsLinux = $IsWindows = $false
}
# Ask user for OS if cannot detect
if ($IsMacOS -eq $false -and $IsLinux -eq $false -and $IsWindows -eq $false) {
$os = Read-Host 'What operating system is this? Windows (w), MacOS (m), Linux (l), or Other (o)?'
if ($os -eq 'w' -or $os -eq 'W') {
[bool] $IsWindows = $true
}
if ($os -eq 'm' -or $os -eq 'M') {
[bool] $IsMacOS = $true
}
if ($os -eq 'l' -or $os -eq 'L') {
[bool] $IsLinux = $true
}
if ($os -eq 'o' -or $os -eq 'O') {
UnsupportedOS
}
Write-Output "Tip: Install PowerShell 7 or newer to skip this prompt next time."
}
# Main script execution
if ($IsWindows) {
Run-WindowsScripts
} elseif ($IsMacOS -or $IsLinux) {
Run-UnixScripts
} else {
UnsupportedOS
}
# Clean up temporary files
Cleanup
Return