From 93ee8f63f05b3d903f90276b9a3313b4584afc2a Mon Sep 17 00:00:00 2001 From: Geoff Bourne Date: Wed, 29 Jun 2022 22:05:22 -0500 Subject: [PATCH] VanillaTweaks uses mc-image-helper and auto-cleans old files --- DEVELOPMENT.md | 4 +- Dockerfile | 2 +- README.md | 30 ++--- scripts/start-setupVanillaTweaks | 119 +----------------- ...ompose.yml.disabled => docker-compose.yml} | 35 +++--- .../vanillatweaks_file/fake.jar | 0 .../vanillatweaks_file/verify.sh | 4 +- .../docker-compose.yml | 4 +- .../vanillatweaks_sharecode/fake.jar | 0 .../vanillatweaks_sharecode/verify.sh | 4 +- 10 files changed, 48 insertions(+), 154 deletions(-) rename tests/setuponlytests/vanillatweaks_file/{docker-compose.yml.disabled => docker-compose.yml} (85%) create mode 100644 tests/setuponlytests/vanillatweaks_file/fake.jar create mode 100644 tests/setuponlytests/vanillatweaks_sharecode/fake.jar diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md index c34f9324973..230f6970407 100644 --- a/DEVELOPMENT.md +++ b/DEVELOPMENT.md @@ -78,7 +78,7 @@ In the cloned copy of [`mc-image-helper`](https://github.com/itzg/mc-image-helpe Assuming [http-server](https://www.npmjs.com/package/http-server) is installed globally, start a static web server using: ```shell -http-server ./build/distributions -p 0 +http-server ./build/distributions -p 8080 ``` Note the port that was selected by http-server and pass the build arguments, such as: @@ -88,7 +88,7 @@ Note the port that was selected by http-server and pass the build arguments, suc --build-arg MC_HELPER_BASE_URL=http://host.docker.internal:8080 ``` -Now the image can be built like normal and it will install mc-image-helper from the locally built copy. +Now the image can be built like normal, and it will install mc-image-helper from the locally built copy. ## Generating release notes diff --git a/Dockerfile b/Dockerfile index 4c3d6b0aff0..b90495c6bcf 100644 --- a/Dockerfile +++ b/Dockerfile @@ -46,7 +46,7 @@ RUN easy-add --var os=${TARGETOS} --var arch=${TARGETARCH}${TARGETVARIANT} \ --var version=0.1.1 --var app=maven-metadata-release --file {{.app}} \ --from https://github.com/itzg/{{.app}}/releases/download/{{.version}}/{{.app}}_{{.version}}_{{.os}}_{{.arch}}.tar.gz -ARG MC_HELPER_VERSION=1.18.3 +ARG MC_HELPER_VERSION=1.19.0 ARG MC_HELPER_BASE_URL=https://github.com/itzg/mc-image-helper/releases/download/v${MC_HELPER_VERSION} RUN curl -fsSL ${MC_HELPER_BASE_URL}/mc-image-helper-${MC_HELPER_VERSION}.tgz \ | tar -C /usr/share -zxf - \ diff --git a/README.md b/README.md index 32a5f677494..634ae045837 100644 --- a/README.md +++ b/README.md @@ -876,28 +876,30 @@ Datapacks will be placed in `/data/$LEVEL/datapacks` ### VanillaTweaks -VanillaTweaks datapacks can be installed with a share code from the website UI **OR** a json file to specify packs to download and install. +[VanillaTweaks](https://vanillatweaks.net/) datapacks, crafting tweaks, and resource packs can be installed with a share code from the website **OR** a json file to specify packs to download and install. Datapacks and crafting tweaks will be installed into the current world directory specified by `$LEVEL`. As new versions of the packs are retrieved the previous versions will automatically be cleaned up. -Datapacks will be placed in `/data/$LEVEL/datapacks` -Resourcepacks will be placed in `/data/resourcepacks` +The share code is the part following the hash sign, as shown here: + +``` +https://vanillatweaks.net/share/#MGr52E + ------ + | + +- share code MGr52E +``` Accepted Parameters: -- `VANILLATWEAKS_FILE` -- `VANILLATWEAKS_SHARECODE` -- `REMOVE_OLD_VANILLATWEAKS` -- `REMOVE_OLD_VANILLATWEAKS_DEPTH` -- `REMOVE_OLD_VANILLATWEAKS_INCLUDE` -- `REMOVE_OLD_VANILLATWEAKS_EXCLUDE` +- `VANILLATWEAKS_FILE`: comma separated list of JSON VanillaTweak pack files accessible within the container +- `VANILLATWEAKS_SHARECODE`: comma separated list of share codes -Example of expected Vanillatweaks sharecode: +Example of expected VanillaTweaks share codes: **Note**: ResourcePacks, DataPacks, and CraftingTweaks all have separate sharecodes ```yaml VANILLATWEAKS_SHARECODE: MGr52E,tF1zL2,LnEDwT ``` -Example of expected Vanillatweaks file format: +Example of expected VanillaTweaks files: ```yaml VANILLATWEAKS_FILE: /config/vt-datapacks.json,/config/vt-craftingtweaks.json,/config/vt-resourcepacks.json @@ -925,8 +927,7 @@ Resourcepacks Json: "version": "1.18", "packs": { "aesthetic": ["CherryPicking", "BlackNetherBricks", "AlternateBlockDestruction"] - }, - "result": "ok" + } } ``` @@ -941,8 +942,7 @@ CraftingTweaks Json: "double slabs", "back to blocks" ] - }, - "result": "ok" + } } ``` diff --git a/scripts/start-setupVanillaTweaks b/scripts/start-setupVanillaTweaks index 2e78d619113..28b59856385 100644 --- a/scripts/start-setupVanillaTweaks +++ b/scripts/start-setupVanillaTweaks @@ -2,125 +2,18 @@ set -e -o pipefail -: "${REMOVE_OLD_VANILLATWEAKS:=false}" : "${VANILLATWEAKS_FILE:=}" : "${VANILLATWEAKS_SHARECODE:=}" -: "${REMOVE_OLD_VANILLATWEAKS_DEPTH:=1} " -: "${REMOVE_OLD_VANILLATWEAKS_INCLUDE:=*.zip}" # shellcheck source=start-utils . "${SCRIPTS:-/}start-utils" -isDebugging && set -x -VT_VERSION="" -DATAPACKS_DIR="/data/${LEVEL:-world}/datapacks" -RESOURCEPACKS_DIR="/data/resourcepacks" - -# Remove old VANILLATWEAKS -if isTrue "${REMOVE_OLD_VANILLATWEAKS}"; then - # NOTE: datapacks include crafting tweaks. - if [ -d "$DATAPACKS_DIR" ]; then - find "$DATAPACKS_DIR" -mindepth 1 -maxdepth ${REMOVE_OLD_VANILLATWEAKS_DEPTH:-16} -wholename "${REMOVE_OLD_VANILLATWEAKS_INCLUDE:-*}" -not -wholename "${REMOVE_OLD_VANILLATWEAKS_EXCLUDE:-}" -delete - fi - if [ -d "$RESOURCEPACKS_DIR" ]; then - find "$RESOURCEPACKS_DIR" -mindepth 1 -maxdepth ${REMOVE_OLD_VANILLATWEAKS_DEPTH:-16} -wholename "${REMOVE_OLD_VANILLATWEAKS_INCLUDE:-*}" -not -wholename "${REMOVE_OLD_VANILLATWEAKS_EXCLUDE:-}" -delete - fi -fi - -# Gets the download url and downloads the actual files. -getUrlAndDownload(){ - VT_FILE=$1 - URL_SUFFIX=$2 - OUTPUT_FILE=$3 - PACKS=$(jq -jc '.packs // empty' $VT_FILE) - if [ ! "$PACKS" ]; then - log "ERROR: unable to retrieve ${URL_SUFFIX} from ${VT_FILE}" - exit 2 - fi - - ZIPDATA_URL="https://vanillatweaks.net/assets/server/zip${URL_SUFFIX}.php" - DOWNLOAD_URL=$(curl -X POST -F "packs=${PACKS}" -F "version=${VT_VERSION}" $ZIPDATA_URL | jq -r '.link // empty') - if [ ! "$DOWNLOAD_URL" ]; then - log "ERROR: unable to retrieve ${URL_SUFFIX} packs from vanillatweaks.net!" - exit 2 - fi - - if ! get -o $OUTPUT_FILE "https://vanillatweaks.net${DOWNLOAD_URL}"; then - log "ERROR: failed to download ${URL_SUFFIX} from ${DOWNLOAD_URL}" - exit 2 - fi -} - -# Datapacks Handler -downloadDatapacks(){ - VT_FILE=$1 - URL_SUFFIX="datapacks" - OUTPUT_FILE="/tmp/vanillatweaks.zip" - getUrlAndDownload $VT_FILE $URL_SUFFIX $OUTPUT_FILE - mkdir -p "$DATAPACKS_DIR" - if ! unzip -o -d "$DATAPACKS_DIR" $OUTPUT_FILE; then - log "ERROR: failed to unzip the datapacks ${DATAPACKS} from ${OUTPUT_FILE}" - fi - rm -f $OUTPUT_FILE -} - -# Crafting Tweaks Handler -downloadCraftingtweaks(){ - VT_FILE=$1 - mkdir -p "$DATAPACKS_DIR" - getUrlAndDownload $VT_FILE "craftingtweaks" "${DATAPACKS_DIR}/craftingtweaks.zip" -} - -# Resourcepacks Handler -downloadResourcepacks(){ - VT_FILE=$1 - mkdir -p "$RESOURCEPACKS_DIR" - getUrlAndDownload $VT_FILE "resourcepacks" "${RESOURCEPACKS_DIR}/resourcepacks.zip" -} - -# Example: VANILLATWEAKS_SHARECODE=MGr52E -# Code generated from the UI website, typically a alphanumeric 6 digit code. -if [[ "$VANILLATWEAKS_SHARECODE" ]]; then - VANILLATWEAKS_FILE=() - for SHARECODE in ${VANILLATWEAKS_SHARECODE//,/ }; do - TMP_FILE="/tmp/${SHARECODE}.json" - SHARECODE_LOOKUP_URL="https://vanillatweaks.net/assets/server/sharecode.php?code=${SHARECODE}" - if ! get -o "$TMP_FILE" "$SHARECODE_LOOKUP_URL"; then - log "ERROR: Unable to use ${SHARECODE} share code provided to retrieve vanillatweaks file" - exit 2 - fi - VANILLATWEAKS_FILE+="${TMP_FILE}," - done -fi - -# Use vanillatweaks file to specify VT and datapacks and crafting tweaks -if [[ "$VANILLATWEAKS_FILE" ]]; then - for VT_FILE in ${VANILLATWEAKS_FILE//,/ }; do - if [ ! -f "$VT_FILE" ]; then - log "ERROR: given VANILLATWEAKS_FILE file does not exist" - exit 2 - fi - - VT_VERSION=$(jq -jc '.version // empty' $VT_FILE) - if [ ! "$VT_VERSION" ]; then - log "ERROR: unable to retrieve version from $VT_FILE" - exit 2 - fi - - TYPE=$(jq -jc '.type // empty' $VT_FILE) - if [[ "$TYPE" = "datapacks" ]]; then - downloadDatapacks $VT_FILE - elif [[ "$TYPE" = "craftingtweaks" ]]; then - downloadCraftingtweaks $VT_FILE - elif [[ "$TYPE" = "resourcepacks" ]]; then - downloadResourcepacks $VT_FILE - fi - - # cleans up temp vanilla tweaks file download to get stored packs - if [[ "$VANILLATWEAKS_SHARECODE" ]]; then - rm -f $VT_FILE - fi - done +if [[ ${VANILLATWEAKS_FILE} || ${VANILLATWEAKS_SHARECODE} ]]; then + mc-image-helper vanillatweaks \ + --output-directory="/data" \ + --world-subdir="${LEVEL:-world}" \ + --share-codes="$VANILLATWEAKS_SHARECODE" \ + --pack-files="$VANILLATWEAKS_FILE" fi exec "${SCRIPTS:-/}start-setupDatapack" "$@" diff --git a/tests/setuponlytests/vanillatweaks_file/docker-compose.yml.disabled b/tests/setuponlytests/vanillatweaks_file/docker-compose.yml similarity index 85% rename from tests/setuponlytests/vanillatweaks_file/docker-compose.yml.disabled rename to tests/setuponlytests/vanillatweaks_file/docker-compose.yml index 494fb6f10e2..a2d31f01f94 100644 --- a/tests/setuponlytests/vanillatweaks_file/docker-compose.yml.disabled +++ b/tests/setuponlytests/vanillatweaks_file/docker-compose.yml @@ -1,17 +1,18 @@ -version: "3" - -services: - mc: - restart: "no" - image: ${IMAGE_TO_TEST:-itzg/minecraft-server} - environment: - EULA: "TRUE" - SETUP_ONLY: "TRUE" - VERSION: ${MINECRAFT_VERSION:-LATEST} - VANILLATWEAKS_FILE: /config/vt-datapacks.json,/config/vt-craftingtweaks.json,/config/vt-resourcepacks.json - REMOVE_OLD_VANILLATWEAKS: "FALSE" - volumes: - - ./data:/data - - ./vt-datapacks.json:/config/vt-datapacks.json:ro - - ./vt-craftingtweaks.json:/config/vt-craftingtweaks.json:ro - - ./vt-resourcepacks.json:/config/vt-resourcepacks.json:ro +version: "3" + +services: + mc: + restart: "no" + image: ${IMAGE_TO_TEST:-itzg/minecraft-server} + environment: + EULA: "TRUE" + SETUP_ONLY: "TRUE" + CUSTOM_SERVER: /servers/fake.jar + VANILLATWEAKS_FILE: /config/vt-datapacks.json,/config/vt-craftingtweaks.json,/config/vt-resourcepacks.json + REMOVE_OLD_VANILLATWEAKS: "FALSE" + volumes: + - ./data:/data + - ./vt-datapacks.json:/config/vt-datapacks.json:ro + - ./vt-craftingtweaks.json:/config/vt-craftingtweaks.json:ro + - ./vt-resourcepacks.json:/config/vt-resourcepacks.json:ro + - ./fake.jar:/servers/fake.jar diff --git a/tests/setuponlytests/vanillatweaks_file/fake.jar b/tests/setuponlytests/vanillatweaks_file/fake.jar new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/setuponlytests/vanillatweaks_file/verify.sh b/tests/setuponlytests/vanillatweaks_file/verify.sh index be7c0136e27..1fba268367a 100644 --- a/tests/setuponlytests/vanillatweaks_file/verify.sh +++ b/tests/setuponlytests/vanillatweaks_file/verify.sh @@ -1,4 +1,4 @@ mc-image-helper assert fileExists "/data/world/datapacks/afk*" mc-image-helper assert fileExists "/data/world/datapacks/graves*" -mc-image-helper assert fileExists "/data/world/datapacks/craftingtweaks*" -mc-image-helper assert fileExists "/data/resourcepacks/resourcepacks*" +mc-image-helper assert fileExists "/data/world/datapacks/VanillaTweaks_*" +mc-image-helper assert fileExists "/data/resourcepacks/VanillaTweaks_*" diff --git a/tests/setuponlytests/vanillatweaks_sharecode/docker-compose.yml b/tests/setuponlytests/vanillatweaks_sharecode/docker-compose.yml index 4e9b27ca276..35c8bd34a5f 100644 --- a/tests/setuponlytests/vanillatweaks_sharecode/docker-compose.yml +++ b/tests/setuponlytests/vanillatweaks_sharecode/docker-compose.yml @@ -7,8 +7,8 @@ services: environment: EULA: "TRUE" SETUP_ONLY: "TRUE" - VERSION: ${MINECRAFT_VERSION:-LATEST} + CUSTOM_SERVER: /servers/fake.jar VANILLATWEAKS_SHARECODE: MGr52E,tF1zL2,LnEDwT - REMOVE_OLD_VANILLATWEAKS: "FALSE" volumes: - ./data:/data + - ./fake.jar:/servers/fake.jar diff --git a/tests/setuponlytests/vanillatweaks_sharecode/fake.jar b/tests/setuponlytests/vanillatweaks_sharecode/fake.jar new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/setuponlytests/vanillatweaks_sharecode/verify.sh b/tests/setuponlytests/vanillatweaks_sharecode/verify.sh index be7c0136e27..0e6f54dc296 100644 --- a/tests/setuponlytests/vanillatweaks_sharecode/verify.sh +++ b/tests/setuponlytests/vanillatweaks_sharecode/verify.sh @@ -1,4 +1,4 @@ mc-image-helper assert fileExists "/data/world/datapacks/afk*" mc-image-helper assert fileExists "/data/world/datapacks/graves*" -mc-image-helper assert fileExists "/data/world/datapacks/craftingtweaks*" -mc-image-helper assert fileExists "/data/resourcepacks/resourcepacks*" +mc-image-helper assert fileExists "/data/world/datapacks/VanillaTweaks_488158f.zip" +mc-image-helper assert fileExists "/data/resourcepacks/VanillaTweaks_d1d810f.zip"