Skip to content

Instantly share code, notes, and snippets.

@bitrot-alpha
Created August 1, 2022 02:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bitrot-alpha/d66fe614899398b70297ed8e1580e985 to your computer and use it in GitHub Desktop.
Save bitrot-alpha/d66fe614899398b70297ed8e1580e985 to your computer and use it in GitHub Desktop.
Bash script to download the latest Paper Minecraft server jar through their API
#!/usr/bin/bash
#Author: bitrot_alpha
#This script will download the latest Paper jars from PaperMC's API and copy them to the
# desired place(s)
#Programs required: curl, jq, wget, sha256sum
#cd wherever you want the script to run out of
cd ~/.ampdata/instances/
pwd
name=paper
version=1.19
api=https://api.papermc.io/v2
#location(s) of where you want the file copied to
#dirstmp=./minecraft_server/
dirstmp=$(ls | grep YC | grep -v YCP)
echo "Removing old Paper jars from current folder"
rm -Iv paper-*.jar
echo "Directories getting new Paper Jars: $dirstmp"
echo "Downloading new Paper jar"
#Get info about the latest build
latest_build="$(curl -sX GET "$api"/projects/"$name"/version_group/"$version"/builds -H 'accept: application/json' | jq '.builds [-1].build')"
revision="$(curl -sX GET "$api"/projects/"$name"/version_group/"$version"/builds -H 'accept: application/json' | jq -r '.builds [-1].version')"
filename="$(curl -sX GET "$api"/projects/"$name"/version_group/"$version"/builds -H 'accept: application/json' | jq -r '.builds [-1].downloads.application.name')"
checksum="$(curl -sX GET "$api"/projects/"$name"/version_group/"$version"/builds -H 'accept: application/json' | jq -r '.builds [-1].downloads.application.sha256')"
#cobble together the URL
download_url="$api"/projects/"$name"/versions/"$revision"/builds/"$latest_build"/downloads/"$filename"
#grab the jar
wget "$download_url"
#Verify jar checksum
echo "$checksum ./$filename" > check.tmp
sha256sum -cw check.tmp
filesum=$?
rm check.tmp
#Copy jar to destination folders
#for loop not necessary for one destination
if [[ $filesum -eq 0 ]]; then
echo "Copying $filename to $dirstmp folders"
for dirs in $dirstmp; do
cp -v ./$filename $dirs/Minecraft/
done
else
echo "Downloaded jar did not match checksum. Try again maybe."
fi
echo "Finished! :))"
@bitrot-alpha
Copy link
Author

This Reddit post was helpful in making this script: How to download the latest version of Paper using the v2 API

@silverace71
Copy link

would you mind if I use this in one of my scripts?

@bitrot-alpha
Copy link
Author

@silverace71 I know it's quite late, but sure, go ahead! If you already did, hope it was helpful.

@silverace71
Copy link

Done a while back, sorry. Had to fix some things tho but it seems to be broken again so im going to fix it again in like an hour from now lol

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment