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
|
|
|
|
2024-10-22 21:04:38 +00:00
|
|
|
spigotBuildLog="/data/spigot_build.log"
|
|
|
|
|
|
|
|
function handleFailedSpigotBuild {
|
|
|
|
logError "Failed to build Spigot"
|
|
|
|
cat ${spigotBuildLog}
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-11-01 05:42:44 +00:00
|
|
|
function buildSpigotFromSource {
|
2024-10-22 21:04:38 +00:00
|
|
|
local tempDir="/data/temp"
|
|
|
|
|
2020-05-12 01:14:01 +00:00
|
|
|
if [[ ${TYPE^^} = *BUKKIT ]] && ! versionLessThan "1.14"; then
|
2024-10-22 21:04:38 +00:00
|
|
|
logError "Craftbukkit build is only supported for versions less than 1.14"
|
2020-05-12 01:14:01 +00:00
|
|
|
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"
|
2024-10-22 21:04:38 +00:00
|
|
|
rm -rf ${tempDir}
|
|
|
|
mkdir ${tempDir}
|
|
|
|
cd ${tempDir}
|
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 ''
|
2024-10-22 21:04:38 +00:00
|
|
|
curl -sSL -o ${tempDir}/BuildTools.jar https://hub.spigotmc.org/jenkins/job/BuildTools/lastSuccessfulBuild/artifact/target/BuildTools.jar && \
|
|
|
|
java $jvmOpts -jar ${tempDir}/BuildTools.jar --rev "$VERSION" 2>&1 |tee ${spigotBuildLog}| 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
|
2024-10-22 21:04:38 +00:00
|
|
|
handleFailedSpigotBuild
|
2020-05-12 01:14:01 +00:00
|
|
|
fi
|
|
|
|
;;
|
|
|
|
*BUKKIT)
|
2024-02-19 16:57:00 +00:00
|
|
|
if ! mv craftbukkit-*.jar "/data/${SERVER}"; then
|
2024-10-22 21:04:38 +00:00
|
|
|
handleFailedSpigotBuild
|
2020-05-12 01:14:01 +00:00
|
|
|
fi
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2020-03-06 15:52:17 +00:00
|
|
|
log "Cleaning up"
|
2024-10-22 21:04:38 +00:00
|
|
|
rm -rf ${tempDir}
|
2017-11-01 05:42:44 +00:00
|
|
|
cd /data
|
|
|
|
}
|
|
|
|
|
|
|
|
function downloadSpigot {
|
|
|
|
local match
|
2024-10-22 21:04:38 +00:00
|
|
|
local getBukkitBaseUrl="https://getbukkit.org/download/"
|
|
|
|
local getBukkitSpigotUrl="${getBukkitBaseUrl}spigot"
|
2017-11-01 05:42:44 +00:00
|
|
|
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-10-22 21:04:38 +00:00
|
|
|
if ! VERSION=$(restify ${getBukkitSpigotUrl} --attribute='property=og:title' | jq -r '.[0] | .attributes | select(.property == "og:title") | .content | split(" ") | .[-1]'); then
|
|
|
|
logError "Failed to retrieve latest version from ${getBukkitSpigotUrl} -- site might be down"
|
2024-02-19 16:57:00 +00:00
|
|
|
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-10-22 21:04:38 +00:00
|
|
|
downloadBaseUrl="https://"
|
|
|
|
downloadSuffixUrl=".getbukkit.org/${getbukkitFlavor}/${getbukkitFlavor}-${VERSION}.jar"
|
2024-02-19 16:57:00 +00:00
|
|
|
if versionLessThan 1.16.5 || { [[ ${getbukkitFlavor} = "craftbukkit" ]] && [[ ${VERSION} = "1.16.5" ]] ; }; then
|
2024-10-22 21:04:38 +00:00
|
|
|
downloadBaseUrl+="cdn"
|
2021-07-10 00:55:46 +00:00
|
|
|
else
|
2024-10-22 21:04:38 +00:00
|
|
|
downloadBaseUrl+="download"
|
2021-07-10 00:55:46 +00:00
|
|
|
fi
|
2024-10-22 21:04:38 +00:00
|
|
|
downloadUrl="${downloadBaseUrl}${downloadSuffixUrl}"
|
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
|
2024-10-22 21:04:38 +00:00
|
|
|
Visit ${getBukkitBaseUrl}${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" "$@"
|