Last active
May 6, 2023 20:02
-
-
Save Vladkarok/56700917d1feb9518a253467679b7400 to your computer and use it in GitHub Desktop.
Powershell script that checks updates from https://github.com/tukui-org/ElvUI and if found some - replaces your directories
This file contains hidden or 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
# ------------------------------------------------------------------------------------------------- | |
# USAGE: | |
# open Powershell window in the directory where this script is located and paste the following string (without #) | |
# powershell -ExecutionPolicy RemoteSigned -File .\tukui-elvui-git-updater.ps1 | |
# | |
# REQUIREMENTS: | |
# - installed git and added into $PATH | |
# - cloned https://github.com/tukui-org/ElvUI repository to some directory, it is used as $SRC_DIR | |
# - change $SRC_DIR and $DST_DIR according to your setup | |
# ------------------------------------------------------------------------------------------------- | |
# Define the source and destination directories | |
$SRC_DIR = "C:\Path\To\Git\Repository" # example = "D:\Git\ElvUI" | |
$DST_DIR = "C:\Path\To\Destination\Folder" # example = "D:\Games\World of Warcraft\_classic_\Interface\AddOns" | |
# Define the folders to check and copy | |
$folders = @("ElvUI", "ElvUI_Libraries", "ElvUI_Options") | |
# Change to the source directory | |
Set-Location $SRC_DIR | |
# Update remote | |
git remote update | |
# Check the Git status | |
$status = git status 2>&1 | |
# If the status indicates that changes are available, prompt the user to pull the changes | |
if ($status -match "Your branch is behind") { | |
$pull = Read-Host "New changes are available. Do you want to pull them? (Y/N)" | |
if ($pull -eq "Y" -or $pull -eq "y") { | |
Write-Host "Pulling new changes from Git..." | |
git pull | |
# Delete the folders from the destination directory | |
foreach ($folder in $folders) { | |
$folder_path = Join-Path $DST_DIR $folder | |
if (Test-Path $folder_path) { | |
Write-Host "Deleting $folder_path..." | |
Remove-Item $folder_path -Recurse -Force | |
} | |
} | |
# Copy the folders from the source directory to the destination directory | |
foreach ($folder in $folders) { | |
$src_folder_path = Join-Path $SRC_DIR $folder | |
$dst_folder_path = Join-Path $DST_DIR $folder | |
Write-Host "Copying $src_folder_path to $dst_folder_path..." | |
Copy-Item $src_folder_path $dst_folder_path -Recurse | |
} | |
} | |
} elseif ($status -match "Your branch is up to date") { | |
# Check if the folders are present in the destination directory | |
$missing_folders = $folders | Where-Object { -not (Test-Path (Join-Path $DST_DIR $_)) } | |
if ($missing_folders.Count -gt 0) { | |
# Copy the missing folders from the source directory to the destination directory | |
foreach ($folder in $missing_folders) { | |
$src_folder_path = Join-Path $SRC_DIR $folder | |
$dst_folder_path = Join-Path $DST_DIR $folder | |
Write-Host "Copying $src_folder_path to $dst_folder_path..." | |
Copy-Item $src_folder_path $dst_folder_path -Recurse | |
} | |
} else { | |
Write-Host "There are no new changes. We are up to date!" | |
} | |
} else { | |
Write-Error $status | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment