2021-03-21 16:43:21 +00:00
|
|
|
#!/bin/bash
|
|
|
|
set -euo pipefail
|
|
|
|
IFS=$'\n\t'
|
|
|
|
|
|
|
|
. ${SCRIPTS:-/}start-utils
|
|
|
|
handleDebugMode
|
|
|
|
|
|
|
|
: ${SPIGET_RESOURCES:=}
|
|
|
|
|
|
|
|
containsJars() {
|
|
|
|
file=${1?}
|
|
|
|
|
|
|
|
pat='\.jar$'
|
|
|
|
|
|
|
|
while read -r line; do
|
|
|
|
if [[ $line =~ $pat ]]; then
|
|
|
|
return 0
|
|
|
|
fi
|
2021-04-24 19:06:31 +00:00
|
|
|
done <<<$(unzip -l "$file")
|
2021-03-21 16:43:21 +00:00
|
|
|
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
getResourceFromSpiget() {
|
|
|
|
resource=${1?}
|
|
|
|
|
|
|
|
log "Downloading resource ${resource} ..."
|
|
|
|
|
|
|
|
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}"
|
|
|
|
exit 2
|
|
|
|
fi
|
|
|
|
|
|
|
|
mkdir -p /data/plugins
|
|
|
|
if containsJars "${tmpfile}"; then
|
|
|
|
log "Extracting contents of resource ${resource} into plugins"
|
|
|
|
unzip -o -q -d /data/plugins "${tmpfile}"
|
|
|
|
rm "${tmpfile}"
|
|
|
|
else
|
|
|
|
log "Moving resource ${resource} into plugins"
|
|
|
|
mv "${tmpfile}" "/data/plugins/${resource}.jar"
|
|
|
|
fi
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if [[ ${SPIGET_RESOURCES} ]]; then
|
2021-04-24 19:06:31 +00:00
|
|
|
if isTrue ${REMOVE_OLD_MODS:-false}; then
|
2021-04-28 21:29:47 +00:00
|
|
|
removeOldMods /data/plugins
|
2021-04-24 19:06:31 +00:00
|
|
|
REMOVE_OLD_MODS=false
|
|
|
|
fi
|
|
|
|
|
2021-03-21 16:43:21 +00:00
|
|
|
log "Getting plugins via Spiget"
|
2021-04-24 19:06:31 +00:00
|
|
|
IFS=',' read -r -a resources <<<"${SPIGET_RESOURCES}"
|
|
|
|
for resource in "${resources[@]}"; do
|
2021-03-21 16:43:21 +00:00
|
|
|
getResourceFromSpiget "${resource}"
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Continue to Final Setup
|
|
|
|
exec ${SCRIPTS:-/}start-finalSetupWorld $@
|