Created
August 1, 2022 02:58
-
-
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
This file contains hidden or 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
#!/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! :))" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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