Merge branch 'main' of ssh.gitgud.io:dazed-translations/holy-knight-cecilia

This commit is contained in:
DazedAnon 2024-07-07 08:43:23 -05:00
commit b9041e06fb
2 changed files with 90 additions and 27 deletions

View file

@ -7,40 +7,69 @@ function check_dependency() {
fi
}
# --- Dependency Checks ---
check_dependency git
check_dependency awk
# Check for jq and unzip
check_dependency jq
check_dependency unzip
# --- Configuration ---
CONFIG_FILE="patch-config.txt"
# Check if CONFIG_FILE exists
if [ ! -f "$CONFIG_FILE" ]; then
echo "Config file ('$CONFIG_FILE') not found! Assuming no patching needed."
exit 0
echo "Config file '$CONFIG_FILE' not found! Assuming no patching needed."
exit 0
fi
# Convert line endings to Unix format using sed (didn't want to add another dependency in dos2unix)
# Convert line endings to Unix format
sed -i 's/\r$//' "$CONFIG_FILE"
# Read configuration from file
source "$CONFIG_FILE"
# --- Input Validation ---
if [[ -z "$username" || -z "$repo" || -z "$branch" ]]; then
echo "Error: Missing username, repo, or branch in config file ('$CONFIG_FILE')."
exit 1
# Get the latest hash
echo "Getting latest commit SHA hash"
latest_patch_sha=$(curl -s "https://gitgud.io/api/v4/projects/$username%2F$repo/repository/branches/$branch" | jq -r '.commit.id')
function download_extract() {
# Download zip file
echo "Downloading latest patch..."
curl -sL "https://gitgud.io/$username/$repo/-/archive/$branch/$repo-$branch.zip" -o repo.zip
# Extract contents, overwriting conflicts
echo "Extracting..."
unzip -qo repo.zip
echo "Applying patch..."
if [ -d "$repo-$branch/"www ]; then
cp -r "$repo-$branch/"* .
jq --arg repo "$repo" 'if (.name | test("^[[:space:]]*$")) then .name = $repo else . end' package.json > package.json
else
cp -r "$repo-$branch/"* ./www
fi
echo "Cleaning up..."
rm repo.zip
rm -rf "$repo-$branch"
rm latest_patch_sha.txt
# Store latest SHA for next check
echo "$latest_patch_sha" > previous_patch_sha.txt
}
# Check if previous_patch_sha.txt exists
if [ ! -f previous_patch_sha.txt ]; then
echo "Previous SHA hash not found!"
echo "Assuming first time patching..."
download_extract
else
# Read the stored SHA from previous check
previous_patch_sha=$(<previous_patch_sha.txt)
# Compare trimmed SHAs
if [ "$latest_patch_sha" != "$previous_patch_sha" ]; then
echo "Update found! Patching..."
download_extract
else
echo "Patch is up to date."
fi
fi
# --- Download and Apply Patch ---
echo "Update found! Patching..."
echo "Cloning the latest patch..."
git clone -b "$branch" "https://gitgud.io/$username/$repo.git" "patch-$repo"
echo "Applying patch..."
rm "patch-$repo/GameUpdate_linux.sh" # rm the script from the patch folder, so it doesn't override the running script.
cp -rf "patch-$repo/"* .
# --- Cleanup ---
echo "Cleaning up..."
rm -rf "patch-$repo"
echo "Patching complete!"
exit 0

View file

@ -40,7 +40,39 @@ for /f "tokens=1,2 delims==" %%a in (patch-config.txt) do (
if "%%a"=="repo" set "repo=%%b"
if "%%a"=="branch" set "branch=%%b"
)
goto download_extract
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=<latest_patch_sha.txt
REM Check if previous_patch_sha.txt exists
if not exist previous_patch_sha.txt (
echo "Previous SHA hash not found!"
echo "Assuming first time patching..."
goto download_extract
)
REM Read the stored SHA from previous check
set /p previous_patch_sha=<previous_patch_sha.txt
REM Trim whitespace from SHA strings
set "previous_patch_sha=%previous_patch_sha: =%"
set "latest_patch_sha=%latest_patch_sha: =%"
REM Compare trimmed SHAs
if "%latest_patch_sha%" neq "%previous_patch_sha%" (
echo "Update found! Patching..."
goto download_extract
) else (
echo "Patch is up to date."
)
REM Delete latest_patch_sha.txt
del latest_patch_sha.txt
endlocal
pause
exit /b
@ -64,8 +96,10 @@ REM Clean up
echo "Cleaning up..."
del repo.zip
rmdir /s /q "%repo%-%branch%"
del latest_patch_sha.txt
REM Store latest SHA for next check
echo %latest_patch_sha% > previous_patch_sha.txt
endlocal
pause
exit /b
exit /b