From 4dd8ef625df257dc5cbc8d80bdfd4a534810e304 Mon Sep 17 00:00:00 2001 From: DazedAnon Date: Sat, 7 Sep 2024 04:43:19 -0500 Subject: [PATCH] Add Patch.bat --- patch.bat | 105 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100644 patch.bat diff --git a/patch.bat b/patch.bat new file mode 100644 index 0000000..90ea09b --- /dev/null +++ b/patch.bat @@ -0,0 +1,105 @@ +@echo off +setlocal EnableExtensions EnableDelayedExpansion + +echo Checking for pwsh... +set _my_shell=pwsh + +REM Check if pwsh.exe exists +where /q !_my_shell! +if !errorlevel! neq 0 ( + echo pwsh not found. Falling back to powershell... + REM If pwsh is not found, set to powershell + set _my_shell=powershell + + REM Check if powershell.exe exists + echo Checking for powershell... + where /q !_my_shell! + if !errorlevel! neq 0 ( + echo.Error: Powershell not found! + pause + exit /B 1 + ) else ( + echo powershell found. + ) +) else ( + echo pwsh found. +) + +echo Using !_my_shell! for script execution. + +REM Check if patch-config.txt exists +if not exist patch-config.txt ( + echo "Config file (patch-config.txt) not found! Assuming no patching needed." + pause + exit /b +) + +REM Read configuration from file +for /f "tokens=1,2 delims==" %%a in (patch-config.txt) do ( + if "%%a"=="username" set "username=%%b" + if "%%a"=="repo" set "repo=%%b" + if "%%a"=="branch" set "branch=%%b" +) + +REM Get the latest hash +echo "Getting latest commit SHA hash" +!_my_shell! -Command "(Invoke-RestMethod -Uri 'https://gitgud.io/api/v4/projects/%username%%%2F%repo%/repository/branches/%branch%').commit.id" > latest_patch_sha.txt + +REM Read the latest SHA from the file +set /p latest_patch_sha= previous_patch_sha.txt +endlocal +pause +exit /b