From 57d9da96a143a5cba17e9bbe928257f8f81034ab Mon Sep 17 00:00:00 2001 From: Geoff Bourne Date: Sun, 10 Oct 2021 12:05:37 -0500 Subject: [PATCH 1/2] Converted vanilla downloads to image helper `get` #1031 --- Dockerfile | 2 +- start-configuration | 15 +++++++++------ start-deployVanilla | 18 ++++++++---------- start-utils | 2 +- 4 files changed, 19 insertions(+), 18 deletions(-) diff --git a/Dockerfile b/Dockerfile index f513ee51..00cc0aea 100644 --- a/Dockerfile +++ b/Dockerfile @@ -60,7 +60,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.5.2 +ARG MC_HELPER_VERSION=1.5.3 RUN curl -fsSL https://github.com/itzg/mc-image-helper/releases/download/v${MC_HELPER_VERSION}/mc-image-helper-${MC_HELPER_VERSION}.tgz \ | tar -C /usr/share -zxf - \ && ln -s /usr/share/mc-image-helper-${MC_HELPER_VERSION}/bin/mc-image-helper /usr/bin diff --git a/start-configuration b/start-configuration index 0d5cb5de..5d425a15 100755 --- a/start-configuration +++ b/start-configuration @@ -2,14 +2,17 @@ set -euo pipefail IFS=$'\n\t' +# shellcheck source=start-utils . ${SCRIPTS:-/}start-utils -: ${EULA:=} -: ${PROXY:=} -: ${RCON_PASSWORD_FILE:=} +: "${EULA:=}" +: "${PROXY:=}" +: "${RCON_PASSWORD_FILE:=}" shopt -s nullglob +isDebugging && set -x + #umask 002 export HOME=/data @@ -63,10 +66,10 @@ export VERSIONS_JSON=https://launchermeta.mojang.com/mc/game/version_manifest.js case "X$VERSION" in X|XLATEST|Xlatest) - VANILLA_VERSION=$(curl -fsSL $VERSIONS_JSON | jq -r '.latest.release') + VANILLA_VERSION=$(get "$VERSIONS_JSON" | jq -r '.latest.release') ;; XSNAPSHOT|Xsnapshot) - VANILLA_VERSION=$(curl -fsSL $VERSIONS_JSON | jq -r '.latest.snapshot') + VANILLA_VERSION=$(get "$VERSIONS_JSON" | jq -r '.latest.snapshot') ;; *) VANILLA_VERSION=$VERSION @@ -124,7 +127,7 @@ case "${TYPE^^}" in ;; VANILLA) - exec ${SCRIPTS:-/}start-deployVanilla "$@" + exec "${SCRIPTS:-/}start-deployVanilla" "$@" ;; SPONGEVANILLA) diff --git a/start-deployVanilla b/start-deployVanilla index 93582889..c1daed64 100755 --- a/start-deployVanilla +++ b/start-deployVanilla @@ -1,41 +1,39 @@ #!/bin/bash +# shellcheck source=start-utils . ${SCRIPTS:-/}start-utils isDebugging && set -x set -o pipefail export SERVER="minecraft_server.${VANILLA_VERSION// /_}.jar" -if [ ! -e $SERVER ] || [ -n "$FORCE_REDOWNLOAD" ]; then +if [ ! -e "$SERVER" ] || [ -n "$FORCE_REDOWNLOAD" ]; then log "Downloading $SERVER ..." debug "Finding version manifest for $VANILLA_VERSION" - versionManifestUrl=$(curl -fsSL 'https://launchermeta.mojang.com/mc/game/version_manifest.json' | jq --arg VANILLA_VERSION "$VANILLA_VERSION" --raw-output '[.versions[]|select(.id == $VANILLA_VERSION)][0].url') + versionManifestUrl=$(get 'https://launchermeta.mojang.com/mc/game/version_manifest.json' | jq --arg VANILLA_VERSION "$VANILLA_VERSION" --raw-output '[.versions[]|select(.id == $VANILLA_VERSION)][0].url') result=$? if [ $result != 0 ]; then log "ERROR failed to obtain version manifest URL ($result)" exit 1 fi - if [ $versionManifestUrl = "null" ]; then + if [ "$versionManifestUrl" = "null" ]; then log "ERROR couldn't find a matching manifest entry for $VANILLA_VERSION" exit 1 fi debug "Found version manifest at $versionManifestUrl" - serverDownloadUrl=$(curl -fsSL ${versionManifestUrl} | jq --raw-output '.downloads.server.url') + serverDownloadUrl=$(get "${versionManifestUrl}" | jq --raw-output '.downloads.server.url') result=$? if [ $result != 0 ]; then log "ERROR failed to obtain version manifest from $versionManifestUrl ($result)" exit 1 - elif [ $serverDownloadUrl = null ]; then + elif [ "$serverDownloadUrl" = "null" ]; then log "ERROR version $VANILLA_VERSION does not provide a server download" exit 1 fi debug "Downloading server from $serverDownloadUrl" - if isDebugging; then - verbose=-v - fi - curl $verbose -fsSL -o $SERVER $serverDownloadUrl + get -o "$SERVER" "$serverDownloadUrl" result=$? if [ $result != 0 ]; then log "ERROR failed to download server from $serverDownloadUrl ($result)" @@ -45,4 +43,4 @@ fi isDebugging && ls -l -exec ${SCRIPTS:-/}start-setupWorld $@ +exec "${SCRIPTS:-/}start-setupWorld" "$@" diff --git a/start-utils b/start-utils index 9e1cdd6c..497a4257 100755 --- a/start-utils +++ b/start-utils @@ -183,7 +183,7 @@ function removeOldMods { function get() { local flags=() - if isDebugging; then + if isTrue "${DEBUG_GET:-false}"; then flags+=("--debug") fi mc-image-helper "${flags[@]}" get "$@" From 63b919f1a953cb87bee7c75f65f5e4eb38a708af Mon Sep 17 00:00:00 2001 From: Geoff Bourne Date: Mon, 11 Oct 2021 15:53:09 -0500 Subject: [PATCH 2/2] Used json-path of image helper `get` for vanilla lookup --- Dockerfile | 2 +- start-configuration | 10 ++++++++-- start-deployVanilla | 4 ++-- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/Dockerfile b/Dockerfile index 00cc0aea..e1fee7b6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -60,7 +60,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.5.3 +ARG MC_HELPER_VERSION=1.6.1 RUN curl -fsSL https://github.com/itzg/mc-image-helper/releases/download/v${MC_HELPER_VERSION}/mc-image-helper-${MC_HELPER_VERSION}.tgz \ | tar -C /usr/share -zxf - \ && ln -s /usr/share/mc-image-helper-${MC_HELPER_VERSION}/bin/mc-image-helper /usr/bin diff --git a/start-configuration b/start-configuration index 5d425a15..5f3fa21a 100755 --- a/start-configuration +++ b/start-configuration @@ -66,10 +66,16 @@ export VERSIONS_JSON=https://launchermeta.mojang.com/mc/game/version_manifest.js case "X$VERSION" in X|XLATEST|Xlatest) - VANILLA_VERSION=$(get "$VERSIONS_JSON" | jq -r '.latest.release') + if ! VANILLA_VERSION=$(get --json-path '$.latest.release' "$VERSIONS_JSON"); then + log "ERROR: version lookup failed: $VANILLA_VERSION" + exit 1 + fi ;; XSNAPSHOT|Xsnapshot) - VANILLA_VERSION=$(get "$VERSIONS_JSON" | jq -r '.latest.snapshot') + if ! VANILLA_VERSION=$(get --json-path '$.latest.snapshot' "$VERSIONS_JSON"); then + log "ERROR: version lookup failed: $VANILLA_VERSION" + exit 1 + fi ;; *) VANILLA_VERSION=$VERSION diff --git a/start-deployVanilla b/start-deployVanilla index c1daed64..0b618800 100755 --- a/start-deployVanilla +++ b/start-deployVanilla @@ -1,7 +1,7 @@ #!/bin/bash # shellcheck source=start-utils -. ${SCRIPTS:-/}start-utils +. "${SCRIPTS:-/}start-utils" isDebugging && set -x set -o pipefail @@ -22,7 +22,7 @@ if [ ! -e "$SERVER" ] || [ -n "$FORCE_REDOWNLOAD" ]; then fi debug "Found version manifest at $versionManifestUrl" - serverDownloadUrl=$(get "${versionManifestUrl}" | jq --raw-output '.downloads.server.url') + serverDownloadUrl=$(get --json-path '$.downloads.server.url' "${versionManifestUrl}") result=$? if [ $result != 0 ]; then log "ERROR failed to obtain version manifest from $versionManifestUrl ($result)"