Skip to content

Instantly share code, notes, and snippets.

@FabulousCupcake
Created October 16, 2021 10:23
Show Gist options
  • Save FabulousCupcake/6b6285a50e4fd2e601e23da312e9f44d to your computer and use it in GitHub Desktop.
Save FabulousCupcake/6b6285a50e4fd2e601e23da312e9f44d to your computer and use it in GitHub Desktop.
Minecraft Mappings Fetcher Script
#!/usr/bin/env bash
VERSION_MANIFEST_FILE="/mnt/c/Users/fbcpck/AppData/Roaming/.minecraft/versions/version_manifest_v2.json"
# Prints usage help text
function usage {
echo "Usage: fetch-mapping.sh <version> [version-manifest-path]"
echo " <version>: Fetch server mappings of a specific version e.g. 21w41a"
echo " Use --latest-release to fetch latest release version"
echo " Use --latest-snapshot to fetch latest snapshot version"
echo
echo " [version-manifest-path]: Path to manifest version file. Defaults to the following value:"
echo " $VERSION_MANIFEST_FILE"
}
# Not enough args
if [[ "$1" == "" ]]; then
echo "fetch-mapping.sh – Script to fetch Minecraft mapping files"
echo
usage
exit
fi
# Too many args
if [[ "$3" != "" ]]; then
echo "Too many arguments!"
echo
usage
exit
fi
# Print version manifest location
if [[ "$2" != "" ]]; then
VERSION_MANIFEST_FILE="$2"
fi
echo "Version manifest location: $VERSION_MANIFEST_FILE"
# Resolve version
VERSION="$1"
if [[ "$1" == "--latest-release" ]]; then
VERSION="$(cat "$VERSION_MANIFEST_FILE" | jq -r ".latest.release")"
elif [[ "$1" == "--latest-snapshot" ]]; then
VERSION="$(cat "$VERSION_MANIFEST_FILE" | jq -r ".latest.snapshot")"
fi
echo "Version: $VERSION"
printf "$PRINTF_FORMAT" "ASSET_MANIFEST_URL... "
ASSET_MANIFEST_URL="$(cat "$VERSION_MANIFEST_FILE" | jq -r ".versions | map(select(.id==\"$VERSION\")) | .[0].url ")"
printf "$ASSET_MANIFEST_URL\n"
printf "$PRINTF_FORMAT" "SERVER_MAPPINGS_URL... "
ASSET_MANIFEST="$(curl -fsSL "$ASSET_MANIFEST_URL")"
SERVER_MAPPINGS_URL="$(echo $ASSET_MANIFEST | jq -r ".downloads.server_mappings.url")"
printf "$SERVER_MAPPINGS_URL\n"
printf "$PRINTF_FORMAT" "Saving to $VERSION.txt... "
curl -fsSL "$SERVER_MAPPINGS_URL" -o "$VERSION.txt"
echo "Done"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment