2017-11-01 05:42:44 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
2023-06-17 18:00:22 +00:00
|
|
|
# shellcheck source=start-utils
|
|
|
|
. "${SCRIPTS:-/}start-utils"
|
2020-10-30 22:03:13 +00:00
|
|
|
isDebugging && set -x
|
2020-03-06 15:52:17 +00:00
|
|
|
|
2024-02-19 16:57:00 +00:00
|
|
|
set -eo pipefail
|
2019-02-27 04:19:43 +00:00
|
|
|
|
2017-11-01 05:42:44 +00:00
|
|
|
function buildSpigotFromSource {
|
2020-05-12 01:14:01 +00:00
|
|
|
if [[ ${TYPE^^} = *BUKKIT ]] && ! versionLessThan "1.14"; then
|
|
|
|
log "ERR craftbukkit build is only supported for versions less than 1.14"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2020-03-06 15:52:17 +00:00
|
|
|
log "Building Spigot $VANILLA_VERSION from source, might take a while, get some coffee"
|
2019-07-23 02:33:54 +00:00
|
|
|
rm -rf /data/temp
|
2017-11-01 05:42:44 +00:00
|
|
|
mkdir /data/temp
|
|
|
|
cd /data/temp
|
2019-02-27 04:19:43 +00:00
|
|
|
|
|
|
|
jvmOpts="-Xms${INIT_MEMORY:-$MEMORY} -Xmx${MAX_MEMORY:-$MEMORY}"
|
|
|
|
|
2020-03-06 15:52:17 +00:00
|
|
|
logn ''
|
2018-06-26 00:13:47 +00:00
|
|
|
curl -sSL -o /data/temp/BuildTools.jar https://hub.spigotmc.org/jenkins/job/BuildTools/lastSuccessfulBuild/artifact/target/BuildTools.jar && \
|
2023-08-20 18:00:06 +00:00
|
|
|
java $jvmOpts -jar /data/temp/BuildTools.jar --rev "$VERSION" 2>&1 |tee /data/spigot_build.log| while read l; do echo -n .; done; log "done"
|
2020-05-12 01:14:01 +00:00
|
|
|
|
|
|
|
case ${TYPE^^} in
|
|
|
|
SPIGOT)
|
2024-02-19 16:57:00 +00:00
|
|
|
if ! mv spigot-*.jar "/data/${SERVER}"; then
|
2020-05-12 01:14:01 +00:00
|
|
|
log "ERR failed to build Spigot"
|
|
|
|
cat /data/spigot_build.log
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
*BUKKIT)
|
2024-02-19 16:57:00 +00:00
|
|
|
if ! mv craftbukkit-*.jar "/data/${SERVER}"; then
|
2020-05-12 01:14:01 +00:00
|
|
|
log "ERR failed to build Spigot"
|
|
|
|
cat /data/spigot_build.log
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2020-03-06 15:52:17 +00:00
|
|
|
log "Cleaning up"
|
2017-11-01 05:42:44 +00:00
|
|
|
rm -rf /data/temp
|
|
|
|
cd /data
|
|
|
|
}
|
|
|
|
|
|
|
|
function downloadSpigot {
|
|
|
|
local match
|
|
|
|
case "$TYPE" in
|
|
|
|
*BUKKIT|*bukkit)
|
2018-08-18 23:51:45 +00:00
|
|
|
match="CraftBukkit"
|
2017-11-01 05:42:44 +00:00
|
|
|
downloadUrl=${BUKKIT_DOWNLOAD_URL}
|
2018-03-16 22:03:21 +00:00
|
|
|
getbukkitFlavor=craftbukkit
|
2017-11-01 05:42:44 +00:00
|
|
|
;;
|
|
|
|
*)
|
|
|
|
match="Spigot"
|
|
|
|
downloadUrl=${SPIGOT_DOWNLOAD_URL}
|
2018-03-16 22:03:21 +00:00
|
|
|
getbukkitFlavor=spigot
|
2017-11-01 05:42:44 +00:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2020-09-27 15:21:33 +00:00
|
|
|
if [[ ${VERSION^^} = LATEST ]]; then
|
2024-02-19 16:57:00 +00:00
|
|
|
if ! VERSION=$(restify https://getbukkit.org/download/spigot --attribute='property=og:title' | jq -r '.[0] | .attributes | select(.property == "og:title") | .content | split(" ") | .[-1]'); then
|
|
|
|
log "ERROR: failed to retrieve latest version from https://getbukkit.org/download/spigot -- site might be down"
|
|
|
|
exit 1
|
|
|
|
fi
|
2020-09-27 15:21:33 +00:00
|
|
|
fi
|
|
|
|
|
2017-11-01 05:42:44 +00:00
|
|
|
if [[ -z $downloadUrl ]]; then
|
2024-02-19 16:57:00 +00:00
|
|
|
if versionLessThan 1.16.5 || { [[ ${getbukkitFlavor} = "craftbukkit" ]] && [[ ${VERSION} = "1.16.5" ]] ; }; then
|
2023-06-17 18:00:22 +00:00
|
|
|
downloadUrl="https://cdn.getbukkit.org/${getbukkitFlavor}/${getbukkitFlavor}-${VERSION}.jar"
|
2021-07-10 00:55:46 +00:00
|
|
|
else
|
2023-06-17 18:00:22 +00:00
|
|
|
downloadUrl="https://download.getbukkit.org/${getbukkitFlavor}/${getbukkitFlavor}-${VERSION}.jar"
|
2021-07-10 00:55:46 +00:00
|
|
|
fi
|
2017-11-01 05:42:44 +00:00
|
|
|
fi
|
|
|
|
|
2020-11-03 22:49:38 +00:00
|
|
|
setServerVar
|
2024-03-16 19:01:21 +00:00
|
|
|
curlArgs=()
|
2022-12-28 20:05:31 +00:00
|
|
|
if [ -f "$SERVER" ] && ! isTrue "$FORCE_REDOWNLOAD"; then
|
2020-07-11 18:17:28 +00:00
|
|
|
# tell curl to only download when newer
|
2024-03-16 19:01:21 +00:00
|
|
|
curlArgs+=(-z "$SERVER")
|
2020-11-03 22:49:38 +00:00
|
|
|
fi
|
|
|
|
if isDebugging; then
|
2024-03-16 19:01:21 +00:00
|
|
|
curlArgs+=(-v)
|
2020-07-11 18:17:28 +00:00
|
|
|
fi
|
2020-03-06 15:52:17 +00:00
|
|
|
log "Downloading $match from $downloadUrl ..."
|
2024-03-16 19:01:21 +00:00
|
|
|
|
|
|
|
tempFile="$SERVER.$$"
|
|
|
|
|
|
|
|
# HTTP error or download site responded with an HTML error page
|
2024-03-18 03:07:34 +00:00
|
|
|
if ! curl -fsSL -o "$tempFile" "${curlArgs[@]}" "$downloadUrl" || ( [ -f "$tempFile" ] && grep -iq "doctype html" "$tempFile" ); then
|
2024-03-16 19:01:21 +00:00
|
|
|
|
2018-03-16 22:03:21 +00:00
|
|
|
cat <<EOF
|
|
|
|
|
|
|
|
ERROR: failed to download from $downloadUrl
|
|
|
|
Visit https://getbukkit.org/download/${getbukkitFlavor} to lookup the
|
2024-03-16 19:01:21 +00:00
|
|
|
exact version or see if download site is unavailable.
|
|
|
|
Click into the version entry to find the **exact** version.
|
2018-03-16 22:03:21 +00:00
|
|
|
|
|
|
|
EOF
|
2020-11-04 23:04:57 +00:00
|
|
|
|
2024-03-16 19:01:21 +00:00
|
|
|
if isDebugging && grep -iq "doctype html" "$tempFile"; then
|
|
|
|
cat "$tempFile"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -f "$SERVER" ]; then
|
|
|
|
log "Continuing with existing $SERVER file"
|
|
|
|
else
|
|
|
|
# remove invalid download
|
|
|
|
rm "$tempFile"
|
|
|
|
exit 3
|
2020-11-04 23:04:57 +00:00
|
|
|
fi
|
|
|
|
|
2024-03-16 19:01:21 +00:00
|
|
|
else
|
2024-03-18 03:07:34 +00:00
|
|
|
if [ -f "$tempFile" ]; then
|
|
|
|
mv "$tempFile" "$SERVER"
|
|
|
|
fi
|
2024-03-16 19:01:21 +00:00
|
|
|
|
2017-11-01 05:42:44 +00:00
|
|
|
fi
|
2020-04-18 23:42:55 +00:00
|
|
|
|
2024-03-16 19:01:21 +00:00
|
|
|
|
2020-04-18 23:42:55 +00:00
|
|
|
JVM_OPTS="${JVM_OPTS} -DIReallyKnowWhatIAmDoingISwear"
|
|
|
|
export JVM_OPTS
|
2017-11-01 05:42:44 +00:00
|
|
|
}
|
|
|
|
|
2020-11-03 22:49:38 +00:00
|
|
|
function setServerVar {
|
|
|
|
case "$TYPE" in
|
|
|
|
*BUKKIT|*bukkit)
|
2023-06-17 18:00:22 +00:00
|
|
|
export SERVER=craftbukkit_server-${VERSION}.jar
|
2020-11-03 22:49:38 +00:00
|
|
|
;;
|
|
|
|
*)
|
2023-06-17 18:00:22 +00:00
|
|
|
export SERVER=spigot_server-${VERSION}.jar
|
2020-11-03 22:49:38 +00:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
}
|
2017-11-01 05:42:44 +00:00
|
|
|
|
2020-07-11 18:17:28 +00:00
|
|
|
if isTrue "$BUILD_SPIGOT_FROM_SOURCE" || isTrue "$BUILD_FROM_SOURCE"; then
|
2023-06-17 18:00:22 +00:00
|
|
|
resolveVersion
|
2020-11-03 22:49:38 +00:00
|
|
|
setServerVar
|
2022-12-28 20:05:31 +00:00
|
|
|
if [ ! -f "$SERVER" ] || isTrue "$FORCE_REDOWNLOAD"; then
|
2020-07-11 18:17:28 +00:00
|
|
|
buildSpigotFromSource
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
downloadSpigot
|
2017-11-01 05:42:44 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Normalize on Spigot for operations below
|
2021-12-11 02:50:40 +00:00
|
|
|
export FAMILY=SPIGOT
|
2017-11-01 05:42:44 +00:00
|
|
|
|
2024-02-19 16:57:00 +00:00
|
|
|
exec "${SCRIPTS:-/}start-spiget" "$@"
|