Skip to content

Instantly share code, notes, and snippets.

@WizardlyBump17
Created November 21, 2024 20:11
Show Gist options
  • Select an option

  • Save WizardlyBump17/0c65e9b34a8cfd01cc35c60ca9b78e67 to your computer and use it in GitHub Desktop.

Select an option

Save WizardlyBump17/0c65e9b34a8cfd01cc35c60ca9b78e67 to your computer and use it in GitHub Desktop.
a script to download software from Paper
help() {
echo "Usage: ./$0 [project] [version] [output]"
exit 0
}
check_command() {
if ! [ -x "$(command -v $1)" ]; then
echo "The $1 command is not available. Install the package related to it and run this script again."
exit 1
fi
}
if [ "$1" == "--help" ]; then
help
fi
check_command jq
check_command curl
PROJECT="${1:-paper}"
VERSION="${2:-$(curl -s https://api.papermc.io/v2/projects/$PROJECT | jq -r '.versions[-1]')}"
OUT_JAR_NAME="${3:-server.jar}"
BASE_URL="https://api.papermc.io/v2/projects/$PROJECT/versions/$VERSION"
LATEST_BUILD=$(curl -s $BASE_URL/builds | jq -r '.builds[-1].build')
if [ "$LATEST_BUILD" == "null" ]; then
echo "Error. Check if you specified a valid project and version. You tried to download the project $PROJECT $VERSION."
exit 1
fi
JAR_NAME="$PROJECT-$VERSION-$LATEST_BUILD.jar"
DOWNLOAD_URL="$BASE_URL/builds/$LATEST_BUILD/downloads/$JAR_NAME"
echo "Downloading $PROJECT $VERSION build $LATEST_BUILD. Output file name: $JAR_NAME."
curl $DOWNLOAD_URL -o $OUT_JAR_NAME
@M0rais
Copy link

M0rais commented Nov 21, 2024

love it

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