Last active
February 12, 2024 21:48
-
-
Save ferdinandkeller/9813c301f8710778510b9fe0a59b785e to your computer and use it in GitHub Desktop.
Bash script to automatically and smartly update PaperMC whenever a new version is available. You need to install `jq` and `wget`.
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 | |
# set a target minecraft major version | |
target_mc_version=1.19 | |
# retrieve the latest minecraft minor version | |
latest_mc_version=$(curl "https://api.papermc.io/v2/projects/paper" | jq -r '[.versions[] | select(. | test("^'$target_mc_version'"))] | last') | |
# retrieve the matching latest paper version | |
latest_paper_version=$(curl "https://api.papermc.io/v2/projects/paper/versions/${latest_mc_version}" | jq -r '[.builds[]] | last') | |
# check if the .mc_version file exists | |
if [ -a .mc_version ]; then | |
# if the file exists, find the currently installed version of paper | |
current_paper_version=$(cat .mc_version) | |
# if the currently installed version matches the version, no need to update | |
if [ "$current_paper_version" == "$latest_paper_version" ]; then | |
# inform the user that we are not updating the jar | |
echo "paper is already up-to-date" | |
# return without error | |
exit 0 | |
fi | |
fi | |
# delete the existing har | |
rm -rf paper.jar | |
# download the new jar | |
wget "https://api.papermc.io/v2/projects/paper/versions/${latest_mc_version}/builds/${latest_paper_version}/downloads/paper-${latest_mc_version}-${latest_paper_version}.jar" | |
# move the jar | |
mv "paper-${latest_mc_version}-${latest_paper_version}.jar" paper.jar | |
# update the .mc_version | |
echo $latest_paper_version > .mc_version | |
# inform the user that we updated the jar | |
echo "downloaded the new paper version" | |
# return without error | |
exit 0 |
You are right about the recursive part, but I think if you don’t use -f it will ask you to remove it and you might get errors, which makes the auto-update aspect kind of pointless. I used -rf out of reflex to be absolutely sure it cleans it well, the je is public anyway, it’s not like it’s valuable.
By the way how did you end up on that script ? It’s kind of lost on the web 😅.
Haha I literally just Google'd paper update bash
and found this!
Ah I suppose force is fine, it typically won't ask if it should be removed or not either way, unless it's had the write permissions removed (which I assume would usually be explicitly/intentionally done).
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Why
rm -rf
? Isn't that unnecessarily dangerous? Just userm
without flags, you're removing one jar.