holy-knight-cecilia/GameUpdate_linux.sh
2024-07-01 19:21:50 -05:00

46 lines
1.2 KiB
Bash

#!/bin/bash
function check_dependency() {
if ! command -v "$1" &> /dev/null; then
echo "Error: '$1' is not installed. Please install it."
exit 1
fi
}
# --- Dependency Checks ---
check_dependency git
check_dependency awk
# --- Configuration ---
CONFIG_FILE="patch-config.txt"
if [ ! -f "$CONFIG_FILE" ]; then
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)
sed -i 's/\r$//' "$CONFIG_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
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!"