mirror of
https://github.com/itzg/docker-minecraft-server
synced 2024-12-16 23:23:06 +00:00
Auto-merging via docker-versions-create
This commit is contained in:
commit
349f27f345
1 changed files with 53 additions and 17 deletions
46
start-spiget
46
start-spiget
|
@ -6,6 +6,7 @@ IFS=$'\n\t'
|
||||||
handleDebugMode
|
handleDebugMode
|
||||||
|
|
||||||
: ${SPIGET_RESOURCES:=}
|
: ${SPIGET_RESOURCES:=}
|
||||||
|
: ${SPIGET_DOWNLOAD_TOLERANCE:=5} # in minutes
|
||||||
|
|
||||||
containsJars() {
|
containsJars() {
|
||||||
file=${1?}
|
file=${1?}
|
||||||
|
@ -28,9 +29,47 @@ getResourceFromSpiget() {
|
||||||
|
|
||||||
mkdir -p /data/plugins
|
mkdir -p /data/plugins
|
||||||
|
|
||||||
if [ -f /data/plugins/.${resource} ]; then
|
versionfile="/data/plugins/.${resource}-version.json"
|
||||||
log "Resource '${resource}' already downloaded"
|
versionfileNew="/tmp/.${resource}-version.json"
|
||||||
|
|
||||||
|
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
|
||||||
|
log "ERROR failed to download resource version meta data '${resource}' from ${urlVersion}"
|
||||||
|
exit 2
|
||||||
|
fi
|
||||||
|
|
||||||
|
installedVersion=$(jq '.name' $versionfile)
|
||||||
|
newVersion=$(jq '.name' $versionfileNew)
|
||||||
|
|
||||||
|
if [ "$installedVersion" = "$newVersion" ]; then
|
||||||
|
log "resource '${resource}' not downloaded because installed version '${installedVersion}' already up to date ('${newVersion}')"
|
||||||
|
mv "${versionfileNew}" "${versionfile}"
|
||||||
else
|
else
|
||||||
|
if downloadResourceFromSpiget "${resource}"; then
|
||||||
|
mv "${versionfileNew}" "${versionfile}"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
log "resource '${resource}' not checked because version meta file newer than '${SPIGET_DOWNLOAD_TOLERANCE}' minutes"
|
||||||
|
fi
|
||||||
|
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
|
||||||
|
log "ERROR failed to download resource version meta data '${resource}' from ${urlVersion}"
|
||||||
|
exit 2
|
||||||
|
fi
|
||||||
|
mv "${versionfileNew}" "${versionfile}"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
downloadResourceFromSpiget() {
|
||||||
|
resource=${1?}
|
||||||
|
|
||||||
tmpfile="/tmp/${resource}.zip"
|
tmpfile="/tmp/${resource}.zip"
|
||||||
url="https://api.spiget.org/v2/resources/${resource}/download"
|
url="https://api.spiget.org/v2/resources/${resource}/download"
|
||||||
if ! curl -o "${tmpfile}" -fsSL -H "User-Agent: itzg/minecraft-server" "${extraCurlArgs[@]}" "${url}"; then
|
if ! curl -o "${tmpfile}" -fsSL -H "User-Agent: itzg/minecraft-server" "${extraCurlArgs[@]}" "${url}"; then
|
||||||
|
@ -41,13 +80,10 @@ getResourceFromSpiget() {
|
||||||
if containsJars "${tmpfile}"; then
|
if containsJars "${tmpfile}"; then
|
||||||
log "Extracting contents of resource ${resource} into plugins"
|
log "Extracting contents of resource ${resource} into plugins"
|
||||||
unzip -o -q -d /data/plugins "${tmpfile}"
|
unzip -o -q -d /data/plugins "${tmpfile}"
|
||||||
touch "/data/plugins/.${resource}"
|
|
||||||
rm "${tmpfile}"
|
rm "${tmpfile}"
|
||||||
else
|
else
|
||||||
log "Moving resource ${resource} into plugins"
|
log "Moving resource ${resource} into plugins"
|
||||||
mv "${tmpfile}" "/data/plugins/${resource}.jar"
|
mv "${tmpfile}" "/data/plugins/${resource}.jar"
|
||||||
touch "/data/plugins/.${resource}"
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue