mirror of
https://github.com/itzg/docker-minecraft-server.git
synced 2026-04-01 11:22:47 +00:00
Verify content type when downloading SPIGET_RESOURCES entry (#1413)
For #1378
This commit is contained in:
@@ -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}} \
|
--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
|
--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}
|
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 \
|
RUN curl -fsSL ${MC_HELPER_BASE_URL}/mc-image-helper-${MC_HELPER_VERSION}.tgz \
|
||||||
| tar -C /usr/share -zxf - \
|
| tar -C /usr/share -zxf - \
|
||||||
|
|||||||
@@ -5,11 +5,11 @@ services:
|
|||||||
# Only using IMAGE variable to allow for local testing
|
# Only using IMAGE variable to allow for local testing
|
||||||
image: ${IMAGE:-itzg/minecraft-server}
|
image: ${IMAGE:-itzg/minecraft-server}
|
||||||
ports:
|
ports:
|
||||||
- 25565:25565
|
- "25565:25565"
|
||||||
environment:
|
environment:
|
||||||
EULA: "TRUE"
|
EULA: "TRUE"
|
||||||
TYPE: SPIGOT
|
TYPE: SPIGOT
|
||||||
SPIGET_RESOURCES: 9089,34315,3836
|
SPIGET_RESOURCES: 34315,3836
|
||||||
volumes:
|
volumes:
|
||||||
- data:/data
|
- data:/data
|
||||||
|
|
||||||
|
|||||||
@@ -2,11 +2,14 @@
|
|||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
IFS=$'\n\t'
|
IFS=$'\n\t'
|
||||||
|
|
||||||
. ${SCRIPTS:-/}start-utils
|
# shellcheck source=start-utils
|
||||||
|
. "${SCRIPTS:-/}start-utils"
|
||||||
handleDebugMode
|
handleDebugMode
|
||||||
|
|
||||||
: ${SPIGET_RESOURCES:=}
|
: "${SPIGET_RESOURCES:=}"
|
||||||
: ${SPIGET_DOWNLOAD_TOLERANCE:=5} # in minutes
|
: "${SPIGET_DOWNLOAD_TOLERANCE:=5}" # in minutes
|
||||||
|
|
||||||
|
acceptArgs=(--accept application/zip --accept application/java-archive)
|
||||||
|
|
||||||
containsJars() {
|
containsJars() {
|
||||||
file=${1?}
|
file=${1?}
|
||||||
@@ -17,7 +20,7 @@ containsJars() {
|
|||||||
if [[ $line =~ $pat ]]; then
|
if [[ $line =~ $pat ]]; then
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
done <<<$(unzip -l "$file")
|
done < <(unzip -l "$file")
|
||||||
|
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
@@ -31,7 +34,7 @@ containsPlugin() {
|
|||||||
if [[ $line =~ $pat ]]; then
|
if [[ $line =~ $pat ]]; then
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
done <<<$(unzip -l "$file")
|
done < <(unzip -l "$file")
|
||||||
|
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
@@ -49,7 +52,7 @@ getResourceFromSpiget() {
|
|||||||
if [ -f "$versionfile" ]; then
|
if [ -f "$versionfile" ]; then
|
||||||
if [[ -n $(find "$versionfile" -mmin +${SPIGET_DOWNLOAD_TOLERANCE}) ]]; then
|
if [[ -n $(find "$versionfile" -mmin +${SPIGET_DOWNLOAD_TOLERANCE}) ]]; then
|
||||||
urlVersion="https://api.spiget.org/v2/resources/${resource}/versions/latest"
|
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}"
|
log "ERROR failed to download resource version meta data '${resource}' from ${urlVersion}"
|
||||||
exit 2
|
exit 2
|
||||||
fi
|
fi
|
||||||
@@ -71,7 +74,7 @@ getResourceFromSpiget() {
|
|||||||
else
|
else
|
||||||
if downloadResourceFromSpiget "${resource}"; then
|
if downloadResourceFromSpiget "${resource}"; then
|
||||||
urlVersion="https://api.spiget.org/v2/resources/${resource}/versions/latest"
|
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}"
|
log "ERROR failed to download resource version meta data '${resource}' from ${urlVersion}"
|
||||||
exit 2
|
exit 2
|
||||||
fi
|
fi
|
||||||
@@ -84,29 +87,32 @@ getResourceFromSpiget() {
|
|||||||
downloadResourceFromSpiget() {
|
downloadResourceFromSpiget() {
|
||||||
resource=${1?}
|
resource=${1?}
|
||||||
|
|
||||||
tmpfile="/tmp/${resource}.zip"
|
resourceUrl="https://api.spiget.org/v2/resources/${resource}"
|
||||||
url="https://api.spiget.org/v2/resources/${resource}/download"
|
if ! outfile=$(get --output-filename -o /tmp "${acceptArgs[@]}" "${resourceUrl}/download"); then
|
||||||
if ! curl -o "${tmpfile}" -fsSL -H "User-Agent: itzg/minecraft-server" "${extraCurlArgs[@]}" "${url}"; then
|
log "ERROR: failed to download resource '${resource}' from ${resourceUrl}/download"
|
||||||
log "ERROR failed to download resource '${resource}' from ${url}"
|
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
|
exit 2
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if containsJars "${tmpfile}"; then
|
contentType=$(file -b --mime-type "$outfile")
|
||||||
|
if [[ $contentType == application/zip ]]; then
|
||||||
log "Extracting contents of resource ${resource} into plugins"
|
log "Extracting contents of resource ${resource} into plugins"
|
||||||
unzip -o -q -d /data/plugins "${tmpfile}"
|
extract "$outfile" /data/plugins
|
||||||
rm "${tmpfile}"
|
rm "$outfile"
|
||||||
elif containsPlugin "${tmpfile}"; then
|
elif [[ $contentType == application/java-archive ]]; then
|
||||||
log "Moving resource ${resource} into plugins"
|
log "Moving resource ${resource} into plugins"
|
||||||
mv "${tmpfile}" "/data/plugins/${resource}.jar"
|
mv "$outfile" /data/plugins
|
||||||
else
|
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
|
exit 2
|
||||||
fi
|
fi
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if [[ ${SPIGET_RESOURCES} ]]; then
|
if [[ ${SPIGET_RESOURCES} ]]; then
|
||||||
if isTrue ${REMOVE_OLD_MODS:-false}; then
|
if isTrue "${REMOVE_OLD_MODS:-false}"; then
|
||||||
removeOldMods /data/plugins
|
removeOldMods /data/plugins
|
||||||
REMOVE_OLD_MODS=false
|
REMOVE_OLD_MODS=false
|
||||||
fi
|
fi
|
||||||
@@ -118,4 +124,4 @@ if [[ ${SPIGET_RESOURCES} ]]; then
|
|||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
|
|
||||||
exec ${SCRIPTS:-/}start-setupWorld $@
|
exec "${SCRIPTS:-/}start-setupWorld" "$@"
|
||||||
|
|||||||
13
tests/setuponlytests/spiget/docker-compose.yml
Normal file
13
tests/setuponlytests/spiget/docker-compose.yml
Normal file
@@ -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
|
||||||
2
tests/setuponlytests/spiget/verify.sh
Normal file
2
tests/setuponlytests/spiget/verify.sh
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
mc-image-helper assert fileExists plugins/3836.jar
|
||||||
|
mc-image-helper assert fileExists plugins/34315.jar
|
||||||
Reference in New Issue
Block a user