-
-
Save DeprecatedNether/2b490b6d94f5fb73374b to your computer and use it in GitHub Desktop.
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
#!/bin/bash | |
## Validate arguments | |
if [ "$#" -ne 2 ]; then | |
echo "Fetches latest Spigot patch and applies it." | |
echo | |
echo "Usage: <spigot-1649-jar-path> <output-file>" | |
exit 1 | |
fi | |
## Vars | |
SOURCE=$1 | |
OUTPUT=$2 | |
PATCHER="./SpigotPatcher-1.0.jar" | |
BASEURL="http://www.spigotmc.org/spigot-updates" | |
TIME=$(TZ="Australia/Sydney" date +%s) | |
DAYS=30 # How far back to look | |
END_TIME=$((TIME - (60 * 60 * 24 * DAYS))) | |
## Spigot patch function | |
function patch_spigot () { | |
PATCHFILE=$1 | |
echo "Patching Spigot with $PATCHFILE..." | |
echo | |
java -jar $PATCHER $SOURCE $PATCHFILE $OUTPUT | |
echo | |
echo "Patching complete!" | |
} | |
## Iterate through possible filenames | |
echo -n "Locating latest Spigot patch... " | |
while [ $TIME -gt $END_TIME ]; do | |
DATE=$(TZ="Australia/Sydney" date -d @$TIME -I | sed 's,-,,g') | |
for i in {z..a}; do | |
ID="spigot-$DATE$i" | |
URL="$BASEURL/$ID.bps" | |
## Fetch HTTP status code | |
STATUS=$(curl -s -I $URL | grep HTTP | cut -d ' ' -f 2) | |
## Check if file exists via HTTP 200 | |
if [ $STATUS -eq 200 ]; then | |
echo "Found: $ID" | |
TIMESTAMP=$(date +%s) | |
FILENAME="$ID-$TIMESTAMP.bps" | |
echo -n "Downloading patch file... " | |
curl -s -o ./$FILENAME $URL | |
echo "Done!" | |
patch_spigot $FILENAME | |
rm -f ./$FILENAME | |
echo "All done! Patched and updated file here: $OUTPUT" | |
exit | |
fi | |
done | |
TIME=$((TIME-86400)) | |
done | |
echo "Failed to locate patch. That's probably not a good sign." | |
exit 2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment