Created
November 21, 2024 20:11
-
-
Save WizardlyBump17/0c65e9b34a8cfd01cc35c60ca9b78e67 to your computer and use it in GitHub Desktop.
a script to download software from Paper
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
| 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
love it