Created
September 19, 2023 00:23
-
-
Save Hezkore/4c4d17cf5634dd15e14a3d740f880ebd to your computer and use it in GitHub Desktop.
Minecract PaperMC latest version download
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 | |
# ============================================================================== | |
# Downloads the latest PaperMC JAR file for the latest Minecraft version | |
# ============================================================================== | |
# This script requires the following packages to be installed: | |
# - curl | |
# - jq | |
# ============================================================================== | |
# Configuration ================================================================ | |
# Specify the output directory | |
DEST_DIR="./" | |
# Specify the name of the JAR file | |
JAR_FILE_NAME="papermc.jar" | |
# Code ======================================================================== | |
# Get the latest Minecraft version from the JSON | |
MINECRAFT_VERSION=$(curl -s "https://papermc.io/api/v2/projects/paper" | jq -r '.versions[-1]') | |
echo "Minecraft version: $MINECRAFT_VERSION" | |
# Get the latest PaperMC build version for the latest Minecraft version | |
BUILD_VERSION=$(curl -s "https://papermc.io/api/v2/projects/paper/versions/$MINECRAFT_VERSION" | jq -r '.builds[-1]') | |
echo "PaperMC build version: $BUILD_VERSION" | |
# Get the application name from the PaperMC build JSON | |
APPLICATION_NAME=$(curl -s "https://papermc.io/api/v2/projects/paper/versions/$MINECRAFT_VERSION/builds/$BUILD_VERSION" | jq -r '.downloads.application.name') | |
echo "Application name: $APPLICATION_NAME" | |
# Define the download URL for the PaperMC JAR file | |
JAR_URL="https://papermc.io/api/v2/projects/paper/versions/$MINECRAFT_VERSION/builds/$BUILD_VERSION/downloads/$APPLICATION_NAME" | |
echo "Download URL: $JAR_URL" | |
# Make sure the output directory exists | |
mkdir -p "$DEST_DIR" | |
# Remove any old JAR files | |
rm -f "$DEST_DIR/$APPLICATION_NAME" | |
# Download the PaperMC JAR file | |
curl -o "$DEST_DIR/$APPLICATION_NAME" "$JAR_URL" | |
# Make sure the download succeeded | |
if [ $? -ne 0 ]; then | |
echo "Failed to download $JAR_URL" | |
exit 1 | |
fi | |
# Sanity check if file size is less than 1 mb | |
if [ $(stat -c%s "$DEST_DIR/$APPLICATION_NAME") -lt 1000000 ]; then | |
echo "Downloaded file is too small, something went wrong" | |
exit 1 | |
fi | |
# Remove the previous version | |
rm -f "$DEST_DIR/$JAR_FILE_NAME" | |
# Rename the JAR file | |
mv "$DEST_DIR/$APPLICATION_NAME" "$DEST_DIR/$JAR_FILE_NAME" | |
# Print a message to confirm the download | |
echo "Downloaded PaperMC version $MINECRAFT_VERSION (build $BUILD_VERSION) to $DEST_DIR/$JAR_FILE_NAME" | |
# Exit with a success code | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment