mirror of
https://github.com/itzg/docker-minecraft-server.git
synced 2024-06-07 19:40:43 +00:00
104 lines
3.2 KiB
Bash
Executable File
104 lines
3.2 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# shellcheck source=start-utils
|
|
. "${SCRIPTS:-/}start-utils"
|
|
set -o pipefail
|
|
handleDebugMode
|
|
|
|
: "${PAPER_CUSTOM_JAR:=}"
|
|
|
|
ourScript="$0"
|
|
ourArgs=("$@")
|
|
|
|
# Check if we're running Folia.
|
|
if [[ -z $PAPER_PROJECT ]]; then
|
|
PAPER_PROJECT="paper"
|
|
PAPER_NAME="PaperMC"
|
|
fi
|
|
|
|
function handleMissingVersion() {
|
|
expectedVersion=${VANILLA_VERSION}
|
|
versions=$(curl -fsSL "https://papermc.io/api/v2/projects/${PAPER_PROJECT}" -H "accept: application/json")
|
|
if [[ $VERSION = LATEST ]]; then
|
|
tries=0
|
|
while ((tries++ < 5)); do
|
|
VANILLA_VERSION=$(echo "$versions" | jq -r ".versions[$((- tries))]")
|
|
if [[ $(curl -fsSL "https://papermc.io/api/v2/projects/${PAPER_PROJECT}/versions/${VANILLA_VERSION}" -H "accept: application/json" \
|
|
| jq '.builds[-1]') != null ]]; then
|
|
log "WARN: using ${VANILLA_VERSION} since that's the latest provided by ${PAPER_NAME}"
|
|
# re-execute the current script with the newly computed version
|
|
exec "$ourScript" "${ourArgs[@]}"
|
|
fi
|
|
done
|
|
fi
|
|
log "ERROR: ${expectedVersion} is not published by ${PAPER_NAME}"
|
|
log " Set VERSION to one of the following: "
|
|
log " $(echo "$versions" | jq -r '.versions | join(", ")')"
|
|
exit 1
|
|
}
|
|
|
|
if [[ $PAPER_CUSTOM_JAR ]]; then
|
|
export SERVER="$PAPER_CUSTOM_JAR"
|
|
elif [[ $PAPER_DOWNLOAD_URL ]]; then
|
|
export SERVER=$(getFilenameFromUrl "${PAPER_DOWNLOAD_URL}")
|
|
|
|
if [ -f "$SERVER" ]; then
|
|
zarg=(-z "$SERVER")
|
|
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 = 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
|
|
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
|
|
|
|
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
|
|
echo "ERROR: failed to download ${PAPER_NAME} from version=${VANILLA_VERSION} build=${build} download=${SERVER}"
|
|
exit 1
|
|
fi
|
|
fi
|
|
|
|
# Normalize on Spigot for downstream operations
|
|
export FAMILY=SPIGOT
|
|
|
|
exec ${SCRIPTS:-/}start-spiget "$@"
|