diff --git a/Dockerfile b/Dockerfile index 1d7e7916..a7c8cb99 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.16.9 +ARG MC_HELPER_VERSION=1.16.11 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/examples/docker-compose-spiget.yml b/examples/docker-compose-spiget.yml index 0806dbf1..a98c1834 100644 --- a/examples/docker-compose-spiget.yml +++ b/examples/docker-compose-spiget.yml @@ -5,11 +5,11 @@ services: # Only using IMAGE variable to allow for local testing image: ${IMAGE:-itzg/minecraft-server} ports: - - 25565:25565 + - "25565:25565" environment: EULA: "TRUE" TYPE: SPIGOT - SPIGET_RESOURCES: 9089,34315,3836 + SPIGET_RESOURCES: 34315,3836 volumes: - data:/data diff --git a/scripts/start-spiget b/scripts/start-spiget index 4dfa7575..186074f6 100755 --- a/scripts/start-spiget +++ b/scripts/start-spiget @@ -2,11 +2,14 @@ set -euo pipefail IFS=$'\n\t' -. ${SCRIPTS:-/}start-utils +# shellcheck source=start-utils +. "${SCRIPTS:-/}start-utils" handleDebugMode -: ${SPIGET_RESOURCES:=} -: ${SPIGET_DOWNLOAD_TOLERANCE:=5} # in minutes +: "${SPIGET_RESOURCES:=}" +: "${SPIGET_DOWNLOAD_TOLERANCE:=5}" # in minutes + +acceptArgs=(--accept application/zip --accept application/java-archive) containsJars() { file=${1?} @@ -17,7 +20,7 @@ containsJars() { if [[ $line =~ $pat ]]; then return 0 fi - done <<<$(unzip -l "$file") + done < <(unzip -l "$file") return 1 } @@ -31,7 +34,7 @@ containsPlugin() { if [[ $line =~ $pat ]]; then return 0 fi - done <<<$(unzip -l "$file") + done < <(unzip -l "$file") return 1 } @@ -49,7 +52,7 @@ getResourceFromSpiget() { if [ -f "$versionfile" ]; then if [[ -n $(find "$versionfile" -mmin +${SPIGET_DOWNLOAD_TOLERANCE}) ]]; then urlVersion="https://api.spiget.org/v2/resources/${resource}/versions/latest" - if ! curl -o "${versionfileNew}" -fsSL -H "User-Agent: itzg/minecraft-server" "${extraCurlArgs[@]}" "${urlVersion}"; then + if ! get -o "${versionfileNew}" "${urlVersion}"; then log "ERROR failed to download resource version meta data '${resource}' from ${urlVersion}" exit 2 fi @@ -71,7 +74,7 @@ getResourceFromSpiget() { else if downloadResourceFromSpiget "${resource}"; then urlVersion="https://api.spiget.org/v2/resources/${resource}/versions/latest" - if ! curl -o "${versionfileNew}" -fsSL -H "User-Agent: itzg/minecraft-server" "${extraCurlArgs[@]}" "${urlVersion}"; then + if ! get -o "${versionfileNew}" "${urlVersion}"; then log "ERROR failed to download resource version meta data '${resource}' from ${urlVersion}" exit 2 fi @@ -84,29 +87,32 @@ getResourceFromSpiget() { downloadResourceFromSpiget() { resource=${1?} - tmpfile="/tmp/${resource}.zip" - url="https://api.spiget.org/v2/resources/${resource}/download" - if ! curl -o "${tmpfile}" -fsSL -H "User-Agent: itzg/minecraft-server" "${extraCurlArgs[@]}" "${url}"; then - log "ERROR failed to download resource '${resource}' from ${url}" + resourceUrl="https://api.spiget.org/v2/resources/${resource}" + if ! outfile=$(get --output-filename -o /tmp "${acceptArgs[@]}" "${resourceUrl}/download"); then + log "ERROR: failed to download resource '${resource}' from ${resourceUrl}/download" + if externalUrl=$(get --json-path '$.file.externalUrl' "${resourceUrl}"); then + log " Visit $externalUrl to pre-download the resource" + log " instead of using SPIGET_RESOURCES" + fi exit 2 fi - if containsJars "${tmpfile}"; then + contentType=$(file -b --mime-type "$outfile") + if [[ $contentType == application/zip ]]; then log "Extracting contents of resource ${resource} into plugins" - unzip -o -q -d /data/plugins "${tmpfile}" - rm "${tmpfile}" - elif containsPlugin "${tmpfile}"; then + extract "$outfile" /data/plugins + rm "$outfile" + elif [[ $contentType == application/java-archive ]]; then log "Moving resource ${resource} into plugins" - mv "${tmpfile}" "/data/plugins/${resource}.jar" + mv "$outfile" /data/plugins else - log "ERROR downloaded resource '${resource}' seems to be not a valid plugin" + log "ERROR: file for resource ${resource} is not a valid content type: ${contentType}" exit 2 fi - } if [[ ${SPIGET_RESOURCES} ]]; then - if isTrue ${REMOVE_OLD_MODS:-false}; then + if isTrue "${REMOVE_OLD_MODS:-false}"; then removeOldMods /data/plugins REMOVE_OLD_MODS=false fi @@ -118,4 +124,4 @@ if [[ ${SPIGET_RESOURCES} ]]; then done fi -exec ${SCRIPTS:-/}start-setupWorld $@ +exec "${SCRIPTS:-/}start-setupWorld" "$@" diff --git a/tests/setuponlytests/spiget/docker-compose.yml b/tests/setuponlytests/spiget/docker-compose.yml new file mode 100644 index 00000000..fd58b737 --- /dev/null +++ b/tests/setuponlytests/spiget/docker-compose.yml @@ -0,0 +1,13 @@ +version: "3" + +services: + mc: + restart: "no" + image: ${IMAGE_TO_TEST:-itzg/minecraft-server} + environment: + EULA: "TRUE" + SETUP_ONLY: "TRUE" + TYPE: PAPER + SPIGET_RESOURCES: "34315,3836" + volumes: + - ./data:/data diff --git a/tests/setuponlytests/spiget/verify.sh b/tests/setuponlytests/spiget/verify.sh new file mode 100644 index 00000000..86e3011f --- /dev/null +++ b/tests/setuponlytests/spiget/verify.sh @@ -0,0 +1,2 @@ +mc-image-helper assert fileExists plugins/3836.jar +mc-image-helper assert fileExists plugins/34315.jar \ No newline at end of file