Created
July 7, 2022 17:19
-
-
Save thakyZ/24551e95bb78bfecc766c9b9af21e1e7 to your computer and use it in GitHub Desktop.
Update PowerCord Plugins via a PowerShell 7 script file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
param() | |
$PrevWD = "${PWD}"; | |
Set-Location "${PSScriptRoot}\src\Powercord\plugins"; | |
$Git = (Get-Command -Name "git") | |
if ($null -eq $Git) { | |
Write-Error -Message "[ERR] Git not found on path. Exiting..." | |
Set-Location "${PrevWD}"; | |
Exit 1 | |
} | |
Get-ChildItem -Path "${PWD}" -Depth 0 -Directory | ForEach-Object { | |
$FullName = $_.FullName; | |
$BaseName = $_.BaseName; | |
if ($null -eq (Get-ChildItem -Path "${FullName}\.git" -ErrorAction SilentlyContinue)) { | |
Write-Warning -Message "[WRN] Plugin `"${BaseName}`" is not a git repository."; | |
return; | |
} | |
Set-Location -Path ${FullName}; | |
$CurrentBranch = (& "${Git}" "rev-parse" "--abbrev-ref" "HEAD"); | |
$GitOutput = (& "${Git}" "remote" "-v"); | |
if (($GitOutput -match "upstream") -and ($GitOutput -match "upstream").ToLower().Split('\n')[0].ToString().Contains("upstream")) { | |
$GitOutput = (& "${Git}" "fetch" "upstream"); | |
if ($GitOutput) { | |
$GitOutput = (& "${Git}" "pull" "upstream" "${CurrentBranch}"); | |
if ($GitOutput -contains "Already up to date.") { | |
Write-Host -Object "Plugin `"${BaseName}`" is already up to date."; | |
} | |
elseif ($GitOutput -like "Merge made by the '*' strategy.") { | |
Write-Host -Objecy "Plugin `"${BaseName}`" automatically merged." | |
} | |
elseif ($GitOutput.Split("\n")[$GitOutput.Split("\n").length - 1].ToString().Contains("Automatic merge failed")) { | |
Write-Warning -Message "[WRN] Failed to automatically merge plugin `"${BaseName}`" you must do this yourself." | |
Write-Host -Object $GitOutput; | |
} | |
else { | |
Write-Host -Object "[INF] Undescript output in plugin `"${BaseName}`". `nPlease patch accordingly...`n${GitOutput}" | |
} | |
} | |
else { | |
$GitOutput = (& "${Git}" "pull" "origin" "${CurrentBranch}"); | |
if ($GitOutput -contains "Already up to date.") { | |
Write-Host -Object "Plugin `"${BaseName}`" is already up to date."; | |
} | |
elseif ($GitOutput -like "Merge made by the '*' strategy.") { | |
Write-Host -Objecy "Plugin `"${BaseName}`" automatically merged."; | |
} | |
elseif ($GitOutput.Split("\n")[$GitOutput.Split("\n").length - 1].ToString().Contains("Automatic merge failed")) { | |
Write-Warning -Message "[WRN] Failed to automatically merge plugin `"${BaseName}`" you must do this yourself."; | |
Write-Host -Object $GitOutput; | |
} | |
else { | |
Write-Host -Object "[INF] Undescript output in plugin `"${BaseName}`". `nPlease patch accordingly...`n${GitOutput}"; | |
} | |
} | |
} | |
elseif (($GitOutput -match "remote") -and ($GitOutput -match "remote").ToLower().Split('\n')[0].ToString().Contains("remote")) { | |
$GitOutput = (& "${Git}" "fetch" "remote") | |
if ($GitOutput) { | |
$GitOutput = (& "${Git}" "pull" "remote" "${CurrentBranch}"); | |
if ($GitOutput -contains "Already up to date.") { | |
Write-Host -Object "Plugin `"${BaseName}`" is already up to date."; | |
} | |
elseif ($GitOutput -like "Merge made by the '*' strategy.") { | |
Write-Host -Objecy "Plugin `"${BaseName}`" automatically merged."; | |
} | |
elseif ($GitOutput.Split("\n")[$GitOutput.Split("\n").length - 1].ToString().Contains("Automatic merge failed")) { | |
Write-Warning -Message "[WRN] Failed to automatically merge plugin `"${BaseName}`" you must do this yourself."; | |
Write-Host -Object $GitOutput; | |
} | |
else { | |
Write-Host -Object "[INF] Undescript output in plugin `"${BaseName}`". `nPlease patch accordingly...`n${GitOutput}" | |
} | |
} | |
else { | |
$GitOutput = (& "${Git}" "pull" "origin" "${CurrentBranch}"); | |
if ($GitOutput -contains "Already up to date.") { | |
Write-Host -Object "Plugin `"${BaseName}`" is already up to date."; | |
} | |
elseif ($GitOutput -like "Merge made by the '*' strategy.") { | |
Write-Host -Objecy "Plugin `"${BaseName}`" automatically merged."; | |
} | |
elseif ($GitOutput.Split("\n")[$GitOutput.Split("\n").length - 1].ToString().Contains("Automatic merge failed")) { | |
Write-Warning -Message "[WRN] Failed to automatically merge plugin `"${BaseName}`" you must do this yourself."; | |
Write-Host -Object $GitOutput; | |
} | |
else { | |
Write-Host -Object "[INF] Undescript output in plugin `"${BaseName}`". `nPlease patch accordingly...`n${GitOutput}"; | |
} | |
} | |
} | |
else { | |
$GitOutput = (& "${Git}" "pull" "origin" "${CurrentBranch}") | |
if ($GitOutput -contains "Already up to date.") { | |
Write-Host -Object "Plugin `"${BaseName}`" is already up to date."; | |
} | |
elseif ($GitOutput -like "Merge made by the '*' strategy.") { | |
Write-Host -Objecy "Plugin `"${BaseName}`" automatically merged."; | |
} | |
elseif ($GitOutput.Split("\n")[$GitOutput.Split("\n").length - 1].ToString().Contains("Automatic merge failed")) { | |
Write-Warning -Message "[WRN] Failed to automatically merge plugin `"${BaseName}`" you must do this yourself."; | |
Write-Host -Object $GitOutput; | |
} | |
else { | |
Write-Host -Object "[INF] Undescript output in plugin `"${BaseName}`". `nPlease patch accordingly...`n${GitOutput}"; | |
} | |
} | |
} | |
Set-Location -Path "${PrevWD}"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment