fix: verify that the downloaded resource is a valid plugin (#1210)

This commit is contained in:
Daniel Hoffend 2021-12-20 02:24:02 +01:00 committed by GitHub
parent 9dee47cb6d
commit cc885276f5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -22,6 +22,20 @@ containsJars() {
return 1 return 1
} }
containsPlugin() {
file=${1?}
pat='plugin.yml$'
while read -r line; do
if [[ $line =~ $pat ]]; then
return 0
fi
done <<<$(unzip -l "$file")
return 1
}
getResourceFromSpiget() { getResourceFromSpiget() {
resource=${1?} resource=${1?}
@ -81,9 +95,12 @@ downloadResourceFromSpiget() {
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}"
rm "${tmpfile}" rm "${tmpfile}"
else elif containsPlugin "${tmpfile}"; then
log "Moving resource ${resource} into plugins" log "Moving resource ${resource} into plugins"
mv "${tmpfile}" "/data/plugins/${resource}.jar" mv "${tmpfile}" "/data/plugins/${resource}.jar"
else
log "ERROR downloaded resource '${resource}' seems to be not a valid plugin"
exit 2
fi fi
} }