Determine SPIGET file type from API (#1427)

This commit is contained in:
Geoff Bourne 2022-03-14 21:07:06 -05:00 committed by GitHub
parent 2042450f9b
commit 5ae5733741
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 13 additions and 9 deletions

View file

@ -89,24 +89,27 @@ downloadResourceFromSpiget() {
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"
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
exit 1
fi
contentType=$(file -b --mime-type "$outfile")
if [[ $contentType == application/zip ]]; then
if ! fileType=$(get --json-path '.file.type' "${resourceUrl}"); then
log "ERROR: failed to retrieve file type of resource $resource"
exit 1
fi
if [[ $fileType == .zip ]]; then
log "Extracting contents of resource ${resource} into plugins"
extract "$outfile" /data/plugins
rm "$outfile"
elif [[ $contentType == application/java-archive ]]; then
elif [[ $fileType == .jar ]]; then
log "Moving resource ${resource} into plugins"
mv "$outfile" /data/plugins
else
log "ERROR: file for resource ${resource} is not a valid content type: ${contentType}"
log "ERROR: file for resource ${resource} has an unexpected file type: ${fileType}"
exit 2
fi
}

View file

@ -234,7 +234,7 @@ function extract() {
type=$(file -b --mime-type "${src}")
case "${type}" in
application/zip)
unzip -q -d "${destDir}" "${src}"
unzip -o -q -d "${destDir}" "${src}"
;;
application/x-tar|application/gzip|application/x-gzip|application/x-bzip2|application/zstd|application/x-zstd)
tar -C "${destDir}" -xf "${src}"

View file

@ -8,6 +8,6 @@ services:
EULA: "TRUE"
SETUP_ONLY: "TRUE"
TYPE: PAPER
SPIGET_RESOURCES: "34315,3836"
SPIGET_RESOURCES: "34315,3836,6245"
volumes:
- ./data:/data

View file

@ -1,2 +1,3 @@
mc-image-helper assert fileExists plugins/3836.jar
mc-image-helper assert fileExists plugins/34315.jar
mc-image-helper assert fileExists plugins/34315.jar
mc-image-helper assert fileExists plugins/6245.jar