-
-
Save avafloww/ec47f7bff4232d310c20 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 | |
## Get the right md5sum tool | |
if hash md5 2>/dev/null; then | |
MD5SUM="md5 -q" | |
else | |
MD5SUM="md5sum -b" | |
fi | |
## 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.jar" | |
BASEURL="http://www.spigotmc.org/spigot-updates" | |
## Spigot patch function | |
function patch_spigot () { | |
PATCHFILE=$1 | |
if [ -e $OUTPUT ]; then | |
echo -n "Output file exists. Removing... " | |
rm -f $OUTPUT | |
echo "Done!" | |
fi | |
echo "Patching Spigot with $PATCHFILE..." | |
echo | |
java -jar $PATCHER $SOURCE $PATCHFILE $OUTPUT | |
echo | |
echo "Patching complete!" | |
} | |
## Grab latest patch file from directory listing | |
echo -n "Locating latest Spigot patch... " | |
LASTPATCH=$(curl -L -s $BASEURL/ | egrep 'spigot-(.*)\.bps' | cut -d '>' -f 2 | cut -d '<' -f 1 | sort | tail -n 1) | |
ID=$(echo $LASTPATCH | sed 's,\.bps,,g') | |
URL="$BASEURL/$ID.bps" | |
## Fetch HTTP status code | |
STATUS=$(curl -L -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 "Fetching checksums... " | |
SUMS=$(curl -L -s $BASEURL/$ID.md5) | |
SUM_ORIG=$(echo "$SUMS" | grep -i original | awk '{print $2}') | |
SUM_PATCH=$(echo "$SUMS" | grep -i patch | awk '{print $2}') | |
SUM_FINAL=$(echo "$SUMS" | grep -i result | awk '{print $2}') | |
echo "Done!" | |
echo -n "Verifying source file... " | |
TEMPSUM_ORIG=$($MD5SUM $SOURCE | awk '{print $1}') | |
if [ $TEMPSUM_ORIG != $SUM_ORIG ]; then | |
echo "Failed: $TEMPSUM_ORIG" | |
echo "Please ensure that you've provided the correct source version of Spigot (#1649)." | |
exit 3 | |
else | |
echo "Success!" | |
fi | |
if [ -e $OUTPUT ]; then | |
echo -n "Output file exists. Checking if patch is necessary... " | |
TEMPSUM_FINAL=$($MD5SUM $OUTPUT | awk '{print $1}') | |
if [ $TEMPSUM_FINAL == $SUM_FINAL ]; then | |
echo "Patch not necessary!" | |
exit | |
else | |
echo "Checksum does not match desired value." | |
fi | |
fi | |
echo -n "Downloading patch file... " | |
curl -L -s -o ./$FILENAME $URL | |
echo "Done!" | |
echo -n "Verifying patch file... " | |
TEMPSUM_PATCH=$($MD5SUM $FILENAME | awk '{print $1}') | |
if [ $TEMPSUM_PATCH != $SUM_PATCH ]; then | |
echo "Failed: got $TEMPSUM_PATCH instead of $SUM_PATCH" | |
echo "Corrupt download? Try again later." | |
exit 4 | |
else | |
echo "Success!" | |
fi | |
patch_spigot $FILENAME | |
rm -f ./$FILENAME | |
echo -n "Verifying final jar... " | |
TEMPSUM_FINAL=$($MD5SUM $OUTPUT | awk '{print $1}') | |
if [ $TEMPSUM_FINAL != $SUM_FINAL ]; then | |
echo "Failed: $TEMPSUM_FINAL" | |
echo "Something is wrong with the patch or patcher. Are you up-to-date?" | |
exit 5 | |
else | |
echo "Success!" | |
fi | |
echo | |
echo "All done! Patched and updated file here: $OUTPUT" | |
exit | |
fi | |
echo "Received invalid response from server while trying to locate latest patch. Please try again later." | |
echo "Code: $STATUS" | |
exit 2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment