mirror of
https://github.com/itzg/docker-minecraft-server.git
synced 2026-03-24 23:42:44 +00:00
Improved handling of MODS and PLUGINS lists (#2197)
This commit is contained in:
@@ -40,58 +40,41 @@ function handleMissingVersion() {
|
||||
if [[ $PAPER_CUSTOM_JAR ]]; then
|
||||
export SERVER="$PAPER_CUSTOM_JAR"
|
||||
elif [[ $PAPER_DOWNLOAD_URL ]]; then
|
||||
export SERVER=$(getFilenameFromUrl "${PAPER_DOWNLOAD_URL}")
|
||||
SERVER=$(getFilenameFromUrl "${PAPER_DOWNLOAD_URL}")
|
||||
export SERVER
|
||||
|
||||
if [ -f "$SERVER" ]; then
|
||||
zarg=(-z "$SERVER")
|
||||
log "Downloading custom ${PAPER_NAME} jar from $PAPER_DOWNLOAD_URL"
|
||||
if ! mc-image-helper mcopy \
|
||||
--scope=papermc \
|
||||
--to=/data \
|
||||
"${PAPER_DOWNLOAD_URL}"; then
|
||||
echo "ERROR: failed to download ${PAPER_NAME} from $PAPER_DOWNLOAD_URL"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Preparing custom ${PAPER_NAME} jar from $PAPER_DOWNLOAD_URL"
|
||||
|
||||
curl -fsSL -o "$SERVER" "${zarg[@]}" "${PAPER_DOWNLOAD_URL}"
|
||||
else
|
||||
# Paper API v2 docs : https://papermc.io/api/docs/swagger-ui/index.html?configUrl=/api/openapi/swagger-config
|
||||
|
||||
build=${PAPERBUILD:=$(curl -fsSL "https://papermc.io/api/v2/projects/${PAPER_PROJECT}/versions/${VANILLA_VERSION}" -H "accept: application/json" \
|
||||
| jq '.builds[-1]')}
|
||||
case $? in
|
||||
0)
|
||||
;;
|
||||
22)
|
||||
handleMissingVersion
|
||||
;;
|
||||
*)
|
||||
echo "ERROR: unknown error while looking up ${PAPER_NAME} version=${VANILLA_VERSION}"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
if ! build=${PAPERBUILD:=$(get --json-path=".builds[-1]" "https://papermc.io/api/v2/projects/${PAPER_PROJECT}/versions/${VANILLA_VERSION}")}; then
|
||||
log "ERROR: failed to lookup build number for ${PAPER_NAME} version=${VANILLA_VERSION}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ $build = null ]]; then
|
||||
handleMissingVersion
|
||||
fi
|
||||
|
||||
export SERVER=$(curl -fsSL "https://papermc.io/api/v2/projects/${PAPER_PROJECT}/versions/${VANILLA_VERSION}/builds/${build}" -H "accept: application/json" \
|
||||
| jq -r '.downloads.application.name')
|
||||
if [ $? != 0 ]; then
|
||||
if ! SERVER=$(get --json-path=.downloads.application.name "https://papermc.io/api/v2/projects/${PAPER_PROJECT}/versions/${VANILLA_VERSION}/builds/${build}"); then
|
||||
echo "ERROR: failed to lookup ${PAPER_NAME} download file from version=${VANILLA_VERSION} build=${build}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ -f "$SERVER" ]; then
|
||||
zarg=(-z "$SERVER")
|
||||
fi
|
||||
|
||||
log "Removing old ${PAPER_NAME} versions ..."
|
||||
shopt -s nullglob
|
||||
for f in paper-*.jar; do
|
||||
[[ $f != $SERVER ]] && rm $f
|
||||
done
|
||||
export SERVER
|
||||
|
||||
log "Downloading ${PAPER_NAME} $VANILLA_VERSION (build $build) ..."
|
||||
curl -fsSL -o "$SERVER" "${zarg[@]}" \
|
||||
"https://papermc.io/api/v2/projects/${PAPER_PROJECT}/versions/${VANILLA_VERSION}/builds/${build}/downloads/${SERVER}" \
|
||||
-H "accept: application/java-archive"
|
||||
if [ $? != 0 ]; then
|
||||
if ! mc-image-helper mcopy \
|
||||
--scope=papermc \
|
||||
--to=/data \
|
||||
"https://papermc.io/api/v2/projects/${PAPER_PROJECT}/versions/${VANILLA_VERSION}/builds/${build}/downloads/${SERVER}"; then
|
||||
echo "ERROR: failed to download ${PAPER_NAME} from version=${VANILLA_VERSION} build=${build} download=${SERVER}"
|
||||
exit 1
|
||||
fi
|
||||
@@ -100,4 +83,4 @@ fi
|
||||
# Normalize on Spigot for downstream operations
|
||||
export FAMILY=SPIGOT
|
||||
|
||||
exec ${SCRIPTS:-/}start-spiget "$@"
|
||||
exec "${SCRIPTS:-/}start-spiget" "$@"
|
||||
|
||||
@@ -3,7 +3,12 @@
|
||||
set -e -o pipefail
|
||||
|
||||
: "${REMOVE_OLD_MODS:=false}"
|
||||
: "${MODS:=}"
|
||||
: "${MODS_OUT_DIR:=/data/mods}"
|
||||
: "${MODS_FILE:=}"
|
||||
: "${PLUGINS:=}"
|
||||
: "${PLUGINS_OUT_DIR:=/data/plugins}"
|
||||
: "${PLUGINS_FILE:=}"
|
||||
: "${REMOVE_OLD_MODS_DEPTH:=1} "
|
||||
: "${REMOVE_OLD_MODS_INCLUDE:=*.jar,*-version.json}"
|
||||
sum_file=/data/.generic_pack.sum
|
||||
@@ -41,7 +46,7 @@ function handlePackwiz() {
|
||||
fi
|
||||
}
|
||||
|
||||
function handleModpackListOrFile() {
|
||||
function handleModpackZip() {
|
||||
# If supplied with a URL for a modpack (simple zip of jars), download it and unpack
|
||||
if [[ "$MODPACK" ]]; then
|
||||
if isURL "${MODPACK}"; then
|
||||
@@ -72,72 +77,65 @@ if [[ "$MODPACK" ]]; then
|
||||
fi
|
||||
fi
|
||||
rm -f /tmp/modpack.zip
|
||||
|
||||
elif [[ "$MODS" ]]; then
|
||||
if [ "$FAMILY" = "SPIGOT" ]; then
|
||||
out_dir=/data/plugins
|
||||
else
|
||||
out_dir=/data/mods
|
||||
fi
|
||||
mkdir -p "$out_dir"
|
||||
|
||||
for i in ${MODS//,/ }
|
||||
do
|
||||
if isURL "$i"; then
|
||||
log "Downloading mod/plugin $i ..."
|
||||
if ! get --skip-up-to-date -o "${out_dir}" "$i"; then
|
||||
log "ERROR: failed to download from $i into $out_dir"
|
||||
exit 2
|
||||
fi
|
||||
elif [[ -f "$i" && "$i" =~ .*\.jar ]]; then
|
||||
log "Copying plugin located at $i ..."
|
||||
out_file=$(basename "$i")
|
||||
if ! cp "$i" "${out_dir}/$out_file"; then
|
||||
log "ERROR: failed to copy from $i into $out_dir"
|
||||
exit 2
|
||||
fi
|
||||
elif [[ -d "$i" ]]; then
|
||||
log "Copying plugin jars from $i ..."
|
||||
cp "$i"/*.jar "${out_dir}"
|
||||
else
|
||||
log "ERROR Invalid URL or path given in MODS: $i"
|
||||
exit 2
|
||||
fi
|
||||
done
|
||||
|
||||
elif [[ "$MODS_FILE" ]]; then
|
||||
if [ ! -f "$MODS_FILE" ]; then
|
||||
log "ERROR: given MODS_FILE file does not exist"
|
||||
exit 2
|
||||
fi
|
||||
|
||||
if [ "$FAMILY" = "SPIGOT" ]; then
|
||||
out_dir=/data/plugins
|
||||
else
|
||||
out_dir=/data/mods
|
||||
fi
|
||||
mkdir -p "$out_dir"
|
||||
|
||||
args=(
|
||||
-o "${out_dir}"
|
||||
--log-progress-each
|
||||
--skip-up-to-date
|
||||
--uris-file "${MODS_FILE}"
|
||||
)
|
||||
if isTrue "${REMOVE_OLD_MODS}"; then
|
||||
args+=(
|
||||
--prune-others "${REMOVE_OLD_MODS_INCLUDE}"
|
||||
--prune-depth "${REMOVE_OLD_MODS_DEPTH}"
|
||||
)
|
||||
fi
|
||||
|
||||
if ! get "${args[@]}" ; then
|
||||
log "ERROR: failed to retrieve one or more mods"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
function handleListings() {
|
||||
if [[ "$MODS" ]]; then
|
||||
if usesMods; then
|
||||
mkdir -p "$MODS_OUT_DIR"
|
||||
mc-image-helper mcopy \
|
||||
--glob=*.jar \
|
||||
--scope=var-list \
|
||||
--to="$MODS_OUT_DIR" \
|
||||
"$MODS"
|
||||
else
|
||||
log "ERROR: TYPE=$TYPE does not support mods"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
if [[ "$PLUGINS" ]]; then
|
||||
if usesPlugins; then
|
||||
mkdir -p "$PLUGINS_OUT_DIR"
|
||||
mc-image-helper mcopy \
|
||||
--glob=*.jar \
|
||||
--scope=var-list \
|
||||
--to="$PLUGINS_OUT_DIR" \
|
||||
"$PLUGINS"
|
||||
else
|
||||
log "ERROR: TYPE=$TYPE does not support plugins"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ "$MODS_FILE" ]]; then
|
||||
if usesMods; then
|
||||
mkdir -p "$MODS_OUT_DIR"
|
||||
mc-image-helper mcopy \
|
||||
--file-is-listing \
|
||||
--scope=file-list \
|
||||
--to="$MODS_OUT_DIR" \
|
||||
"$MODS_FILE"
|
||||
else
|
||||
log "ERROR: TYPE=$TYPE does not support mods"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
if [[ "$PLUGINS_FILE" ]]; then
|
||||
if usesPlugins; then
|
||||
mkdir -p "$PLUGINS_OUT_DIR"
|
||||
mc-image-helper mcopy \
|
||||
--file-is-listing \
|
||||
--scope=file-list \
|
||||
--to="$PLUGINS_OUT_DIR" \
|
||||
"$PLUGINS_FILE"
|
||||
else
|
||||
log "ERROR: TYPE=$TYPE does not support plugins"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
function handleCurseForgeManifest() {
|
||||
if [[ "$MANIFEST" ]]; then
|
||||
if [[ -e "$MANIFEST" ]]; then
|
||||
@@ -293,7 +291,9 @@ function handleModrinthProjects() {
|
||||
|
||||
handlePackwiz
|
||||
|
||||
handleModpackListOrFile
|
||||
handleModpackZip
|
||||
|
||||
handleListings
|
||||
|
||||
handleCurseForgeManifest
|
||||
|
||||
|
||||
@@ -305,3 +305,19 @@ function checkSum() {
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
function usesMods() {
|
||||
case "$FAMILY" in
|
||||
FORGE|FABRIC|HYBRID|SPONGE)
|
||||
return 0
|
||||
esac
|
||||
return 1
|
||||
}
|
||||
|
||||
function usesPlugins() {
|
||||
case "$FAMILY" in
|
||||
SPIGOT|HYBRID)
|
||||
return 0
|
||||
esac
|
||||
return 1
|
||||
}
|
||||
Reference in New Issue
Block a user