New logger with color and specific types. Code cleanup (#3108)

This commit is contained in:
Tristan 2024-10-22 23:04:38 +02:00 committed by GitHub
parent a356c6810e
commit bef7b4719f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
38 changed files with 424 additions and 428 deletions

View file

@ -3,26 +3,22 @@
: "${CONSOLE_IN_NAMED_PIPE:=/tmp/minecraft-console-in}"
if isFalse "${CREATE_CONSOLE_IN_PIPE:-false}"; then
echo "ERROR: console pipe needs to be enabled by setting CREATE_CONSOLE_IN_PIPE to true"
error "Console pipe needs to be enabled by setting CREATE_CONSOLE_IN_PIPE to true"
fi
if [ $# = 0 ]; then
echo "ERROR: pass console commands as arguments"
error "Pass console commands as arguments"
exit 1
fi
if [ ! -p "${CONSOLE_IN_NAMED_PIPE}" ]; then
echo "ERROR: named pipe ${CONSOLE_IN_NAMED_PIPE} is missing"
error "Named pipe ${CONSOLE_IN_NAMED_PIPE} is missing"
exit 1
fi
if [ "$(id -u)" = 0 -a $UID != 0 ]; then
if [[ $(getDistro) == alpine ]]; then
exec su-exec minecraft bash -c "echo '$*' > '${CONSOLE_IN_NAMED_PIPE:-/tmp/minecraft-console-in}'"
else
exec gosu minecraft bash -c "echo '$*' > '${CONSOLE_IN_NAMED_PIPE:-/tmp/minecraft-console-in}'"
fi
exec $(getSudoFromDistro) minecraft bash -c "echo '$*' > '${CONSOLE_IN_NAMED_PIPE}'"
else
echo "$@" >"${CONSOLE_IN_NAMED_PIPE:-/tmp/minecraft-console-in}"
echo "$@" >"${CONSOLE_IN_NAMED_PIPE}"
fi

View file

@ -1,6 +1,6 @@
#!/bin/bash
echo "WARNING: mcstatus is deprecated; calling mc-monitor instead"
warning "mcstatus is deprecated; calling mc-monitor instead"
##### mcstatus shim for mc-monitor
# handles translating calls to
@ -11,8 +11,8 @@ addr="$1"
IFS=':'
read -a parts <<< "${addr}"
args=(--host ${parts[0]})
if [[ ${#parts[*]} -gt 1 ]]; then
exec mc-monitor status --host ${parts[0]} --port ${parts[1]}
else
exec mc-monitor status --host ${parts[0]}
args+=(--port ${parts[1]})
fi
exec mc-monitor ${args[@]}

View file

@ -48,12 +48,7 @@ if ! isTrue "${SKIP_SUDO:-false}" && [ "$(id -u)" = 0 ]; then
echo 'hosts: files dns' > /etc/nsswitch.conf
fi
distro=$(getDistro)
if [[ $distro == alpine ]]; then
exec su-exec ${runAsUser}:${runAsGroup} "${SCRIPTS:-/}start-configuration" "$@"
else
exec gosu ${runAsUser}:${runAsGroup} "${SCRIPTS:-/}start-configuration" "$@"
fi
exec $(getSudoFromDistro) ${runAsUser}:${runAsGroup} "${SCRIPTS:-/}start-configuration" "$@"
else
exec "${SCRIPTS:-/}start-configuration" "$@"
fi

View file

@ -26,60 +26,40 @@ isDebugging && set -x
cp /auto/knockd-config.cfg /tmp/knockd-config.cfg
# update server port to listen to
regseq="^\s*sequence\s*=\s*$SERVER_PORT\s*$"
linenum=$(grep -nm1 sequence /tmp/knockd-config.cfg | cut -d : -f 1 | tail -n1)
if ! [[ $(awk "NR==$linenum" /tmp/knockd-config.cfg) =~ $regseq ]]; then
sed -i "${linenum}s/sequence.*/sequence = $SERVER_PORT/" /tmp/knockd-config.cfg
log "Updated server port in knockd config"
fi
# update rcon port to listen to
regseq="^\s*sequence\s*=\s*$RCON_PORT\s*$"
linenum=$(grep -nm2 sequence /tmp/knockd-config.cfg | cut -d : -f 1 | tail -n1)
if ! [[ $(awk "NR==$linenum" /tmp/knockd-config.cfg) =~ $regseq ]]; then
sed -i "${linenum}s/sequence.*/sequence = $RCON_PORT/" /tmp/knockd-config.cfg
log "Updated rcon port in knockd config"
fi
function updatePort() {
regseq="^\s*sequence\s*=\s*$1\s*$"
linenum=$(grep -nm${2} sequence /tmp/knockd-config.cfg | cut -d : -f 1 | tail -n1)
if ! [[ $(awk "NR==$linenum" /tmp/knockd-config.cfg) =~ $regseq ]]; then
sed -i "${linenum}s/sequence.*/sequence = $1/" /tmp/knockd-config.cfg
log "Updated $3 port in knockd config"
fi
}
# update server port to listen to
updatePort $SERVER_PORT 1 "server"
# update rcon port to listen to
updatePort $RCON_PORT 2 "rcon"
isNumericElseSetToDefault "AUTOPAUSE_PERIOD" 10
checkIfNotZeroElseSetToDefault "AUTOPAUSE_PERIOD" 10
isNumericElseSetToDefault "AUTOPAUSE_TIMEOUT_KN" 120
isNumericElseSetToDefault "AUTOPAUSE_TIMEOUT_EST" 3600
isNumericElseSetToDefault "AUTOPAUSE_TIMEOUT_INIT" 600
if ! [[ $AUTOPAUSE_PERIOD =~ ^[0-9]+$ ]]; then
AUTOPAUSE_PERIOD=10
export AUTOPAUSE_PERIOD
log "Warning: AUTOPAUSE_PERIOD is not numeric, set to 10 (seconds)"
fi
if [ "$AUTOPAUSE_PERIOD" -eq "0" ] ; then
AUTOPAUSE_PERIOD=10
export AUTOPAUSE_PERIOD
log "Warning: AUTOPAUSE_PERIOD must not be 0, set to 10 (seconds)"
fi
if ! [[ $AUTOPAUSE_TIMEOUT_KN =~ ^[0-9]+$ ]] ; then
AUTOPAUSE_TIMEOUT_KN=120
export AUTOPAUSE_TIMEOUT_KN
log "Warning: AUTOPAUSE_TIMEOUT_KN is not numeric, set to 120 (seconds)"
fi
if ! [[ $AUTOPAUSE_TIMEOUT_EST =~ ^[0-9]+$ ]] ; then
AUTOPAUSE_TIMEOUT_EST=3600
export AUTOPAUSE_TIMEOUT_EST
log "Warning: AUTOPAUSE_TIMEOUT_EST is not numeric, set to 3600 (seconds)"
fi
if ! [[ $AUTOPAUSE_TIMEOUT_INIT =~ ^[0-9]+$ ]] ; then
AUTOPAUSE_TIMEOUT_INIT=600
export AUTOPAUSE_TIMEOUT_INIT
log "Warning: AUTOPAUSE_TIMEOUT_INIT is not numeric, set to 600 (seconds)"
fi
if [[ "$AUTOPAUSE_KNOCK_INTERFACE" == "lo" ]] ; then
log "Warning: AUTOPAUSE_KNOCK_INTERFACE is set to the local loopback interface."
log " This is not advisable, as incoming connections are likely not picked up there."
log " Continuing with this setting."
logWarning "AUTOPAUSE_KNOCK_INTERFACE is set to the local loopback interface."
logWarning " This is not advisable, as incoming connections are likely not picked up there."
logWarning " Continuing with this setting."
fi
if [[ -n "$MAX_TICK_TIME" && "$MAX_TICK_TIME" != "-1" ]] ; then
log "Warning: MAX_TICK_TIME is non-default, for autopause to work properly, this check should be disabled (-1 for versions >= 1.8.1)"
logWarning "MAX_TICK_TIME is non-default, for autopause to work properly, this check should be disabled (-1 for versions >= 1.8.1)"
elif [[ -z "$MAX_TICK_TIME" ]] ; then
MAX_TICK_TIME=-1
if versionLessThan 1.8.1; then
# 10 years
MAX_TICK_TIME=315360000000
else
MAX_TICK_TIME=-1
fi
export MAX_TICK_TIME
fi

View file

@ -20,25 +20,9 @@ log "Autostop functionality enabled"
isDebugging && set -x
if ! [[ $AUTOSTOP_PERIOD =~ ^[0-9]+$ ]]; then
AUTOSTOP_PERIOD=10
export AUTOSTOP_PERIOD
log "Warning: AUTOSTOP_PERIOD is not numeric, set to 10 (seconds)"
fi
if [ "$AUTOSTOP_PERIOD" -eq "0" ] ; then
AUTOSTOP_PERIOD=10
export AUTOSTOP_PERIOD
log "Warning: AUTOSTOP_PERIOD must not be 0, set to 10 (seconds)"
fi
if ! [[ $AUTOSTOP_TIMEOUT_EST =~ ^[0-9]+$ ]] ; then
AUTOSTOP_TIMEOUT_EST=3600
export AUTOSTOP_TIMEOUT_EST
log "Warning: AUTOSTOP_TIMEOUT_EST is not numeric, set to 3600 (seconds)"
fi
if ! [[ $AUTOSTOP_TIMEOUT_INIT =~ ^[0-9]+$ ]] ; then
AUTOSTOP_TIMEOUT_INIT=1800
export AUTOSTOP_TIMEOUT_INIT
log "Warning: AUTOSTOP_TIMEOUT_INIT is not numeric, set to 1800 (seconds)"
fi
isNumericElseSetToDefault "AUTOSTOP_PERIOD" 10
checkIfNotZeroElseSetToDefault "AUTOSTOP_PERIOD" 10
isNumericElseSetToDefault "AUTOSTOP_TIMEOUT_EST" 3600
isNumericElseSetToDefault "AUTOSTOP_TIMEOUT_INIT" 1800
/auto/autostop-daemon.sh &

View file

@ -36,10 +36,10 @@ log "Running as uid=$(id -u) gid=$(id -g) with /data as '$(ls -lnd /data)'"
if [ ! -e /data/eula.txt ]; then
if ! isTrue "$EULA"; then
log ""
log "Please accept the Minecraft EULA at"
log " https://account.mojang.com/documents/minecraft_eula"
log "by adding the following immediately after 'docker run':"
log " -e EULA=TRUE"
logError "Please accept the Minecraft EULA at"
logError " https://account.mojang.com/documents/minecraft_eula"
logError "by adding the following immediately after 'docker run':"
logError " -e EULA=TRUE"
log ""
exit 1
fi
@ -63,10 +63,10 @@ if isTrue "${ENABLE_RCON:-true}"; then
if [[ -v RCON_PASSWORD_FILE ]]; then
if [ ! -e "${RCON_PASSWORD_FILE}" ]; then
log ""
log "Initial RCON password file ${RCON_PASSWORD_FILE} does not seems to exist."
log "Please ensure your configuration."
log "If you are using Docker Secrets feature, please check this for further information: "
log " https://docs.docker.com/engine/swarm/secrets"
logError "Initial RCON password file ${RCON_PASSWORD_FILE} does not seems to exist."
logError "Please ensure your configuration."
logError "If you are using Docker Secrets feature, please check this for further information: "
logError " https://docs.docker.com/engine/swarm/secrets"
log ""
exit 1
else
@ -91,12 +91,12 @@ fi
# Auto-pause/stop
if isTrue "${ENABLE_AUTOPAUSE}" && isTrue "${EXEC_DIRECTLY:-false}"; then
log "EXEC_DIRECTLY=true is incompatible with ENABLE_AUTOPAUSE=true"
logError "EXEC_DIRECTLY=true is incompatible with ENABLE_AUTOPAUSE=true"
exit 1
fi
if isTrue "${ENABLE_AUTOPAUSE}" && isTrue "${ENABLE_AUTOSTOP}"; then
log "ENABLE_AUTOPAUSE=true is incompatible with ENABLE_AUTOSTOP=true"
logError "ENABLE_AUTOPAUSE=true is incompatible with ENABLE_AUTOSTOP=true"
exit 1
fi
@ -112,9 +112,9 @@ function fixJavaPath() {
# Some Docker management UIs grab all the image declared variables and present them for configuration.
# When upgrading images across Java versions, that creates a mismatch in PATH's expected by base image.
if ! which java > /dev/null; then
log "ERROR: your Docker provider has an annoying flaw where it"
log " tries to set PATH even though the container establishes"
log " a very specific value."
logError " Your Docker provider has an annoying flaw where it"
logError " tries to set PATH even though the container establishes"
logError " a very specific value."
sleep 2
# now find where java might be
for d in /opt/java/openjdk/bin /usr/bin; do
@ -129,7 +129,7 @@ function fixJavaPath() {
if ! fixJavaPath; then
log "ERROR: could not locate path that contains java"
logError "could not locate path that contains java"
exit 1
fi
@ -184,7 +184,7 @@ if [[ $MOD_PLATFORM ]]; then
;;
*)
log "ERROR; Invalid MOD_PLATFORM: '$MOD_PLATFORM'"
logError "Invalid MOD_PLATFORM: '$MOD_PLATFORM'"
exit 1
;;
esac
@ -219,7 +219,7 @@ case "${TYPE^^}" in
QUILT)
exec "${SCRIPTS:-/}start-deployQuilt" "$@"
;;
VANILLA)
exec "${SCRIPTS:-/}start-deployVanilla" "$@"
;;
@ -273,11 +273,11 @@ case "${TYPE^^}" in
;;
*)
log "ERROR: Invalid TYPE: '$TYPE'"
log "Must be: VANILLA, FORGE, BUKKIT, SPIGOT, PAPER, FOLIA, PURPUR, FABRIC, QUILT,"
log " SPONGEVANILLA, CUSTOM, MAGMA, MOHIST, CATSERVER, AIRPLANE, PUFFERFISH,"
log " CANYON, LIMBO, CRUCIBLE"
logError "Invalid TYPE: '$TYPE'"
logError "Must be: VANILLA, FORGE, BUKKIT, SPIGOT, PAPER, FOLIA, PURPUR, FABRIC, QUILT,"
logError " SPONGEVANILLA, CUSTOM, MAGMA, MOHIST, CATSERVER, AIRPLANE, PUFFERFISH,"
logError " CANYON, LIMBO, CRUCIBLE"
exit 1
;;
esac
esac

View file

@ -57,15 +57,11 @@ setArg --exclude-include-file CF_EXCLUDE_INCLUDE_FILE
setArg --downloads-repo CF_DOWNLOADS_REPO
if ! mc-image-helper install-curseforge "${args[@]}"; then
log "ERROR failed to auto-install CurseForge modpack"
logError "Failed to auto-install CurseForge modpack"
exit 1
fi
# grab SERVER, TYPE, VERSION and export it
set -a
# shellcheck disable=SC1090
source "${resultsFile}"
set +a
applyResultsFile ${resultsFile}
resolveFamily
exec "${SCRIPTS:-/}start-setupWorld" "$@"

View file

@ -6,47 +6,56 @@ isDebugging && set -x
set -eo pipefail
spigotBuildLog="/data/spigot_build.log"
function handleFailedSpigotBuild {
logError "Failed to build Spigot"
cat ${spigotBuildLog}
exit 1
}
function buildSpigotFromSource {
local tempDir="/data/temp"
if [[ ${TYPE^^} = *BUKKIT ]] && ! versionLessThan "1.14"; then
log "ERR craftbukkit build is only supported for versions less than 1.14"
logError "Craftbukkit build is only supported for versions less than 1.14"
exit 1
fi
log "Building Spigot $VANILLA_VERSION from source, might take a while, get some coffee"
rm -rf /data/temp
mkdir /data/temp
cd /data/temp
rm -rf ${tempDir}
mkdir ${tempDir}
cd ${tempDir}
jvmOpts="-Xms${INIT_MEMORY:-$MEMORY} -Xmx${MAX_MEMORY:-$MEMORY}"
logn ''
curl -sSL -o /data/temp/BuildTools.jar https://hub.spigotmc.org/jenkins/job/BuildTools/lastSuccessfulBuild/artifact/target/BuildTools.jar && \
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"
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"
case ${TYPE^^} in
SPIGOT)
if ! mv spigot-*.jar "/data/${SERVER}"; then
log "ERR failed to build Spigot"
cat /data/spigot_build.log
exit 1
handleFailedSpigotBuild
fi
;;
*BUKKIT)
if ! mv craftbukkit-*.jar "/data/${SERVER}"; then
log "ERR failed to build Spigot"
cat /data/spigot_build.log
exit 1
handleFailedSpigotBuild
fi
;;
esac
log "Cleaning up"
rm -rf /data/temp
rm -rf ${tempDir}
cd /data
}
function downloadSpigot {
local match
local getBukkitBaseUrl="https://getbukkit.org/download/"
local getBukkitSpigotUrl="${getBukkitBaseUrl}spigot"
case "$TYPE" in
*BUKKIT|*bukkit)
match="CraftBukkit"
@ -61,18 +70,21 @@ function downloadSpigot {
esac
if [[ ${VERSION^^} = LATEST ]]; then
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"
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"
exit 1
fi
fi
if [[ -z $downloadUrl ]]; then
downloadBaseUrl="https://"
downloadSuffixUrl=".getbukkit.org/${getbukkitFlavor}/${getbukkitFlavor}-${VERSION}.jar"
if versionLessThan 1.16.5 || { [[ ${getbukkitFlavor} = "craftbukkit" ]] && [[ ${VERSION} = "1.16.5" ]] ; }; then
downloadUrl="https://cdn.getbukkit.org/${getbukkitFlavor}/${getbukkitFlavor}-${VERSION}.jar"
downloadBaseUrl+="cdn"
else
downloadUrl="https://download.getbukkit.org/${getbukkitFlavor}/${getbukkitFlavor}-${VERSION}.jar"
downloadBaseUrl+="download"
fi
downloadUrl="${downloadBaseUrl}${downloadSuffixUrl}"
fi
setServerVar
@ -94,7 +106,7 @@ function downloadSpigot {
cat <<EOF
ERROR: failed to download from $downloadUrl
Visit https://getbukkit.org/download/${getbukkitFlavor} to lookup the
Visit ${getBukkitBaseUrl}${getbukkitFlavor} to lookup the
exact version or see if download site is unavailable.
Click into the version entry to find the **exact** version.

View file

@ -25,7 +25,7 @@ loadForgeVars() {
isDebugging && set -x
if [[ ${VERSION^^} == LATEST ]]; then
log "WARNING for the old TYPE=CURSEFORGE mechanism it is best to set VERSION to a specific value"
logWarning "For the old TYPE=CURSEFORGE mechanism it is best to set VERSION to a specific value"
fi
resolveVersion
@ -39,7 +39,7 @@ FTB_SERVER_MOD=${FTB_SERVER_MOD:-$CF_SERVER_MOD}
log "Looking for Feed-The-Beast / CurseForge server modpack."
if [[ ! $FTB_SERVER_MOD ]]; then
log "ERROR: CF_SERVER_MOD or FTB_SERVER_MOD is required to be set"
logError "CF_SERVER_MOD or FTB_SERVER_MOD is required to be set"
exit 1
fi
@ -48,7 +48,7 @@ downloadModpack() {
if isURL "${srv_modpack}"; then
log "Downloading modpack from ${srv_modpack}..."
if ! srv_modpack=$(get -o /data --output-filename --skip-existing "${srv_modpack}"); then
log "ERROR: failed to download modpack"
logError "Failed to download modpack"
exit 1
fi
fi
@ -61,12 +61,12 @@ downloadModpack() {
srv_modpack=/data/${srv_modpack}
fi
if [[ ! -f "${srv_modpack}" ]]; then
log "FTB server modpack ${srv_modpack} not found."
logError "FTB server modpack: ${srv_modpack} not found."
exit 2
fi
if [[ ! "${srv_modpack: -4}" == ".zip" ]]; then
log "FTB server modpack ${srv_modpack} is not a zip archive."
log "Please set FTB_SERVER_MOD to a file with a .zip extension."
logError "FTB server modpack: ${srv_modpack} is not a zip archive."
logError "Please set FTB_SERVER_MOD to a file with a .zip extension."
exit 2
fi
FTB_SERVER_MOD=${srv_modpack}
@ -104,7 +104,7 @@ if ! isTrue "${USE_MODPACK_START_SCRIPT:-true}"; then
if [[ $forgeInstallerUrl ]]; then
forgeInstallerJar="${FTB_BASE_DIR}/forge-installer.jar"
if ! curl -fsSL -o "$forgeInstallerJar" "$forgeInstallerUrl" ; then
log "ERROR failed to download Forge installer from $forgeInstallerUrl"
logError "Failed to download Forge installer from $forgeInstallerUrl"
exit 2
fi
fi
@ -113,9 +113,9 @@ if ! isTrue "${USE_MODPACK_START_SCRIPT:-true}"; then
fi
if [[ -z "${forgeInstallerJar}" ]]; then
log "ERROR Unable to find forge installer in modpack"
log " or download using modpack config."
log " Make sure you downloaded the server files."
logError "Unable to find forge installer in modpack"
logError " or download using modpack config."
logError " Make sure you downloaded the server files."
exit 2
fi
@ -129,7 +129,7 @@ if ! isTrue "${USE_MODPACK_START_SCRIPT:-true}"; then
SERVER=$(find "${FTB_BASE_DIR}" -maxdepth 2 -type f \( -path "/libraries/*" -o -path "/mods/*" \) -prune -o -name "forge*.jar" -not -name "forge*installer.jar" -print)
if [[ -z "${SERVER}" || ! -f "${SERVER}" ]]; then
log "ERROR unable to locate installed forge server jar"
logError "Unable to locate installed forge server jar"
isDebugging && find "${FTB_BASE_DIR}" -name "forge*.jar"
exit 2
fi
@ -213,7 +213,7 @@ EOF
startScript="${FTB_BASE_DIR}/ServerStart.sh"
chmod +x "$startScript"
else
log "ERROR: Modpack missing start script and unable to find Forge jar to generate one"
logError "Modpack missing start script and unable to find Forge jar to generate one"
exit 2
fi
fi
@ -244,7 +244,7 @@ legacyJavaFixerPath="${FTB_DIR}/mods/legacyjavafixer.jar"
if isTrue "${FTB_LEGACYJAVAFIXER}" && [ ! -e "${legacyJavaFixerPath}" ]; then
log "Installing legacy java fixer to ${legacyJavaFixerPath}"
if ! get -o "${legacyJavaFixerPath}" ${legacyJavaFixerUrl}; then
log "ERROR failed to download legacy java fixer from ${legacyJavaFixerUrl}"
logError "Failed to download legacy java fixer from ${legacyJavaFixerUrl}"
exit 1
fi
fi

View file

@ -9,20 +9,19 @@ isDebugging && set -x
: "${CANYON_BUILD:=lastSuccessfulBuild}"
if [ "${VERSION}" != "b1.7.3" ]; then
log "ERROR: Canyon server type only supports VERSION=b1.7.3"
logError "Canyon server type only supports VERSION=b1.7.3"
exit 1
fi
canyonJob="https://jenkins.glass-launcher.net/job/Canyon"
canyonJob="https://canyonmodded.p0rtal.gay/job/Canyonmodded"
githubUrl="https://github.com/KoboDev/SupplyAndDemand/releases/download"
canyonBuildJSON=$(curl -fsSL "${canyonJob}/${CANYON_BUILD}/api/json")
buildRelPath=$(
curl -fsSL "${canyonJob}/${CANYON_BUILD}/api/json" |
jq -r '.artifacts[0].relativePath'
)
jq '.artifacts[0].relativePath' <<< "$canyonBuildJSON"
)
buildNumber=$(
curl -fsSL "${canyonJob}/${CANYON_BUILD}/api/json" |
jq -r '.number'
jq '.number'<<< "$canyonBuildJSON"
)
baseName=$(basename "${buildRelPath}")
@ -51,7 +50,7 @@ if [ ! -f "$SERVER" ]; then
fi
curl -fsSL -o "$SERVER" "$downloadUrl"
if [ ! -f "$SERVER" ]; then
log "ERROR: failed to download from $downloadUrl (status=$?)"
logError "Failed to download from $downloadUrl (status=$?)"
exit 3
fi
fi

View file

@ -11,7 +11,7 @@ latestAsset=$(
)
if [[ -z "${latestAsset}" ]]; then
log "ERROR: latest release of Catserver is missing universal.jar asset"
logError "Latest release of Catserver is missing universal.jar asset"
exit 1
fi

View file

@ -18,18 +18,18 @@ fi
if ! downloadUrl=$(get --json-path "$.assets[?(@.name =~ /Crucible-${VERSION}-.*\.jar/)].browser_download_url" \
--accept "application/vnd.github.v3+json" "$crucibleReleaseUrl"); then
log "ERROR: failed to access ${CRUCIBLE_RELEASE} release of Crucible"
logError "Failed to access ${CRUCIBLE_RELEASE} release of Crucible"
exit 1
fi
if [[ $downloadUrl = null ]]; then
log "ERROR: failed to locate Crucible jar for $VERSION from ${CRUCIBLE_RELEASE}"
logError "Failed to locate Crucible jar for $VERSION from ${CRUCIBLE_RELEASE}"
exit 1
fi
log "Downloading Crucible from $downloadUrl"
if ! SERVER=$(get --skip-existing --output-filename -o /data "$downloadUrl"); then
log "ERROR: failed to download Crucible jar from $downloadUrl"
logError "Crucible jar from $downloadUrl"
exit 1
fi
@ -37,18 +37,18 @@ librariesDir=/data/libraries
if [ ! -d "$librariesDir" ]; then
if ! librariesUrl=$(get --json-path "$.assets[?(@.name == 'libraries.zip')].browser_download_url" \
--accept "application/vnd.github.v3+json" "$crucibleReleaseUrl"); then
log "ERROR: failed to access ${CRUCIBLE_RELEASE} release of Crucible for libraries"
logError "Failed to access ${CRUCIBLE_RELEASE} release of Crucible for libraries"
exit 1
fi
log "Downloading Crucible libraries"
if ! get -o /tmp/libraries.zip "$librariesUrl"; then
log "ERROR: failed to download Crucible libraries from $librariesUrl"
logError "Failed to download Crucible libraries from $librariesUrl"
exit 1
fi
if ! unzip /tmp/libraries.zip -d "$librariesDir"; then
log "ERROR: failed to unzip Crucible libraries"
logError "Failed to unzip Crucible libraries"
exit 1
fi
rm /tmp/libraries.zip

View file

@ -9,42 +9,47 @@ ftbInstallMarker=".ftb-installed"
isDebugging && set -x
set -e
function getVersion() {
jq -r --arg name "$1" '.targets|unique[] | select(.name == $name) | .version' version.json
}
if [[ $(getDistro) = alpine ]]; then
log "ERROR: the FTBA installer is not supported on Alpine. Use the java8-multiarch image tag instead."
logError "The FTBA installer is not supported on Alpine. Use the java8-multiarch image tag instead."
exit 1
fi
if ! [[ -v FTB_MODPACK_ID ]]; then
log "ERROR FTB_MODPACK_ID is required with TYPE=FTB"
logError "FTB_MODPACK_ID is required with TYPE=FTB"
exit 1
fi
if ! [[ ${FTB_MODPACK_ID} =~ [0-9]+ ]]; then
log "ERROR FTB_MODPACK_ID needs to be numeric"
logError "FTB_MODPACK_ID needs to be numeric"
exit 1
fi
if [[ ! $FTB_MODPACK_VERSION_ID ]]; then
if ! FTB_MODPACK_VERSION_ID=$(curl -fsSL https://api.modpacks.ch/public/modpack/${FTB_MODPACK_ID} | jq -r '.versions | sort_by(.updated)[-1].id'); then
log "ERROR unable to resolve latest modpack version ID for modpack ${FTB_MODPACK_ID}"
logError "Unable to resolve latest modpack version ID for modpack ${FTB_MODPACK_ID}"
exit 1
fi
elif ! [[ ${FTB_MODPACK_VERSION_ID} =~ [0-9]+ ]]; then
log "ERROR FTB_MODPACK_VERSION_ID needs to be numeric"
logError "FTB_MODPACK_VERSION_ID needs to be numeric"
exit 1
fi
if isTrue "$FTB_FORCE_REINSTALL" || ! [ -f "${ftbInstallMarker}" ] || [ "$(cat "${ftbInstallMarker}")" != "${FTB_MODPACK_ID}=${FTB_MODPACK_VERSION_ID}" ]; then
ftbInstaller=/data/ftb-installer
arm=
if ! [[ -f "${ftbInstaller}" ]]; then
log "Downloading FTB installer"
if [ "$(uname -m)" == "aarch64" ]; then
log "Downloading ARM installer"
curl -fsSL https://api.modpacks.ch/public/modpack/1/1/server/arm/linux -o "${ftbInstaller}"
$arm=/arm
else
log "Downloading x86 installer"
curl -fsSL https://api.modpacks.ch/public/modpack/1/1/server/linux -o "${ftbInstaller}"
fi
curl -fsSL https://api.modpacks.ch/public/modpack/1/1/server${arm}/linux -o "${ftbInstaller}"
chmod +x "${ftbInstaller}"
fi
@ -63,9 +68,9 @@ else
log "FTB modpack ID ${FTB_MODPACK_ID}, version ID ${FTB_MODPACK_VERSION_ID} is ready to go"
fi
forgeVersion=$(jq -r '.targets|unique[] | select(.name == "forge") | .version' version.json)
fabricVersion=$(jq -r '.targets|unique[] | select(.name == "fabric") | .version' version.json)
mcVersion=$(jq -r '.targets|unique[] | select(.name == "minecraft") | .version' version.json)
forgeVersion=$(getVersion "forge")
fabricVersion=$(getVersion "fabric")
mcVersion=$(getVersion "minecraft")
VERSION="$mcVersion"
export VERSION
@ -83,8 +88,8 @@ for f in "${variants[@]}"; do
fi
done
if ! [ -v SERVER ]; then
log "ERROR unable to locate the installed FTB server jar"
log " Tried looking for ${variants[*]}"
logError "Unable to locate the installed FTB server jar"
logError " Tried looking for ${variants[*]}"
exit 2
fi
@ -100,7 +105,7 @@ if [[ $SERVER = run.sh ]]; then
export FAMILY=FABRIC
export TYPE=FABRIC
else
log "ERROR: unrecognized loader type in $SERVER"
logError "Unrecognized loader type in $SERVER"
cat "$SERVER"
exit 1
fi
@ -112,7 +117,7 @@ elif [[ $SERVER = fabric* ]]; then
export FAMILY=FABRIC
export TYPE=FABRIC
else
log "ERROR: unrecognized loader type from $SERVER"
logError "Unrecognized loader type from $SERVER"
exit 1
fi

View file

@ -16,40 +16,35 @@ isDebugging && set -x
# Custom fabric jar
if [[ $FABRIC_LAUNCHER ]]; then
if ! mc-image-helper install-fabric-loader \
if ! mc-image-helper install-fabric-loader \
--results-file=${resultsFile} \
--from-local-file="$FABRIC_LAUNCHER"; then
log "ERROR failed to use provided Fabric launcher"
logError "Failed to use provided Fabric launcher"
exit 1
fi
# Custom fabric jar url
elif [[ $FABRIC_LAUNCHER_URL ]]; then
if ! mc-image-helper install-fabric-loader \
if ! mc-image-helper install-fabric-loader \
--results-file=${resultsFile} \
--from-url="$FABRIC_LAUNCHER_URL"; then
log "ERROR failed to install Fabric launcher from $FABRIC_LAUNCHER_URL"
logError "Failed to installFabric launcher from $FABRIC_LAUNCHER_URL"
exit 1
fi
# Official fabric launcher
else
if ! mc-image-helper install-fabric-loader \
if ! mc-image-helper install-fabric-loader \
--results-file=${resultsFile} \
--minecraft-version="${VERSION}" \
--installer-version="${FABRIC_LAUNCHER_VERSION}" \
--loader-version="${FABRIC_LOADER_VERSION}"; then
log "ERROR failed to install Fabric launcher given $VERSION, $FABRIC_LAUNCHER_VERSION, $FABRIC_LOADER_VERSION"
logError "Failed to installFabric launcher given $VERSION, $FABRIC_LAUNCHER_VERSION, $FABRIC_LOADER_VERSION"
exit 1
fi
fi
# grab SERVER, etc and export it
set -a
# shellcheck disable=SC1090
source "${resultsFile}"
set +a
applyResultsFile ${resultsFile}
export FAMILY=FABRIC
exec "${SCRIPTS:-/}start-setupWorld" "$@"

View file

@ -6,36 +6,29 @@
# shellcheck source=start-utils
. "${SCRIPTS:-$(dirname "$0")}/start-utils"
isDebugging && set -x
resultsFile=/data/.run-forge.env
function mc-image-helper-forge() {
mc-image-helper install-forge \
--output-directory=/data \
--results-file="${resultsFile}" \
--minecraft-version="${VERSION}" \
--force-reinstall="${FORGE_FORCE_REINSTALL}" "$@"
}
if [[ ${FORGE_INSTALLER} ]]; then
if ! mc-image-helper install-forge \
--output-directory=/data \
--results-file=/data/.run-forge.env \
--minecraft-version="${VERSION}" \
--forge-installer="${FORGE_INSTALLER}" \
--force-reinstall="${FORGE_FORCE_REINSTALL}"; then
log "ERROR failed to install Forge given installer ${FORGE_INSTALLER}"
if ! mc-image-helper-forge --forge-installer="${FORGE_INSTALLER}" ; then
logError "Failed to installForge given installer ${FORGE_INSTALLER}"
exit 1
fi
else
if ! mc-image-helper install-forge \
--output-directory=/data \
--results-file=/data/.run-forge.env \
--minecraft-version="${VERSION}" \
--forge-version="${FORGE_VERSION}" \
--force-reinstall="${FORGE_FORCE_REINSTALL}"; then
log "ERROR failed to install Forge"
if ! mc-image-helper-forge --forge-version="${FORGE_VERSION}"; then
logError "Failed to install Forge"
exit 1
fi
fi
# grab SERVER and export it
set -a
source /data/.run-forge.env
set +a
applyResultsFile ${resultsFile}
export FAMILY=FORGE

View file

@ -9,7 +9,7 @@ if ! SERVER=$(mc-image-helper github download-latest-asset \
--name-pattern="kettinglauncher-.+?(?<!-sources)\.jar" \
kettingpowered/kettinglauncher
); then
log "ERROR: failed to download Ketting launcher"
logError "Failed to download Ketting launcher"
exit 1
fi

View file

@ -22,7 +22,7 @@ baseUrl="https://ci.loohpjames.com/job/Limbo/${LIMBO_BUILD}"
buildInfoUrl="${baseUrl}/api/json"
buildJson=$(curl -fsSL "${buildInfoUrl}")
if [ $? != 0 ]; then
log "ERROR failed to get build info from ${buildInfoUrl} (status=$?)"
logError "Failed to get build info from ${buildInfoUrl} (status=$?)"
exit 1
fi
@ -30,8 +30,14 @@ if [[ ${LIMBO_BUILD} = lastStableBuild ]]; then
LIMBO_BUILD=$(jq -r '.number' <<<${buildJson})
log "Resolved latest Limbo build to ${LIMBO_BUILD}"
fi
artifactPath=$(jq -r '.artifacts[] | select(.fileName|test("^Limbo-")) | .relativePath' <<<${buildJson})
defaultSchemaPath=$(jq -r '.artifacts[] | select(.fileName|test(".*\\.schem")) | .relativePath' <<<${buildJson})
getRelativePath() {
local pattern=$1
jq -r --arg pattern "$pattern" '.artifacts[] | select(.fileName|test($pattern)) | .relativePath' <<<${buildJson}
}
artifactPath=$(getRelativePath "^Limbo-")
defaultSchemaPath=$(getRelativePath ".*\\.schem")
export SERVER="limbo-${LIMBO_BUILD}.jar"
@ -39,7 +45,7 @@ if [ ! -f "$SERVER" ] || isTrue "$FORCE_REDOWNLOAD"; then
downloadUrl="${baseUrl}/artifact/${artifactPath}"
log "Downloading Limbo from $downloadUrl ..."
if ! curl -fsSL -o "$SERVER" "$downloadUrl"; then
log "ERROR: failed to download from $downloadUrl (status=$?)"
logError "Failed to download from $downloadUrl (status=$?)"
exit 3
fi
@ -48,7 +54,7 @@ fi
if [ ! -f "${LIMBO_SCHEMA_FILENAME}" ]; then
log "Downloading default schem file"
if ! curl -o "${LIMBO_SCHEMA_FILENAME}" -fsSL "${baseUrl}/artifact/${defaultSchemaPath}"; then
log "ERROR: failed to download schema file $baseUrl (status=$?)"
logError "Failed to download schema file $baseUrl (status=$?)"
exit 3
fi
fi

View file

@ -9,17 +9,17 @@ isDebugging && set -x
resolveVersion
if ! downloadUrl=$(get --json-path '$.link' "https://api.magmafoundation.org/api/v2/${VERSION}/latest/${MAGMA_VERSION}"); then
log "ERROR failed to locate latest Magma download for ${VERSION}. Is that version supported?"
logError "Failed to locate latest Magma download for ${VERSION}. Is that version supported?"
exit 1
fi
if [[ $downloadUrl == null ]]; then
log "ERROR Magma does not seem to be available for $VERSION"
logError "Magma does not seem to be available for $VERSION"
exit 1
fi
if ! SERVER=$(get --output-filename --skip-up-to-date --output /data "$downloadUrl"); then
log "ERROR: failed to download Magma server jar from $downloadUrl"
logError "Failed to download Magma server jar from $downloadUrl"
exit 1
fi

View file

@ -10,7 +10,7 @@ isDebugging && set -x
resolveVersion
if [ -z $MAGMA_MAINTAINED_TAG ]; then
log "ERROR the variable MAGMA_MAINTAINED_TAG is not specified"
logError "The variable MAGMA_MAINTAINED_TAG is not specified"
exit 1
fi
@ -20,7 +20,7 @@ if [[ ${VERSION} = "1.12.2" ]]; then
fileName="Magma-${VERSION}-${MAGMA_MAINTAINED_TAG}-server.jar"
else
if [ -z $FORGE_VERSION ]; then
log "ERROR the variable FORGE_VERSION is not specified"
logError "The variable FORGE_VERSION is not specified"
exit 1
fi
fileName="magma-${VERSION}-${FORGE_VERSION}-${MAGMA_MAINTAINED_TAG}-server.jar"
@ -28,7 +28,7 @@ fi
downloadUrl="https://github.com/magmamaintained/Magma-${VERSION}/releases/download/${MAGMA_MAINTAINED_TAG}/${fileName}"
if ! SERVER=$(get --output-filename --skip-up-to-date --output /data "$downloadUrl"); then
log "ERROR: failed to download Magma Maintained server jar from $downloadUrl"
logError "Failed to download Magma Maintained server jar from $downloadUrl"
exit 1
fi

View file

@ -16,7 +16,7 @@ resultsFile=/data/.install-modrinth.env
: "${MODRINTH_DEFAULT_EXCLUDE_INCLUDES=/image/modrinth-exclude-include.json}"
if [[ ! $MODRINTH_MODPACK ]]; then
log "ERROR: MODRINTH_MODPACK must be set when using TYPE/MOD_PLATFORM of MODRINTH"
logError "MODRINTH_MODPACK must be set when using TYPE/MOD_PLATFORM of MODRINTH"
exit 1
fi
@ -64,15 +64,11 @@ setArg --overrides-exclusions MODRINTH_OVERRIDES_EXCLUSIONS
setArg --default-exclude-includes MODRINTH_DEFAULT_EXCLUDE_INCLUDES
if ! mc-image-helper install-modrinth-modpack "${args[@]}"; then
log "ERROR failed to install Modrinth modpack"
logError "Failed to installModrinth modpack"
exit 1
fi
# grab SERVER, TYPE, VERSION and export it
set -a
# shellcheck disable=SC1090
source "${resultsFile}"
set +a
applyResultsFile ${resultsFile}
resolveFamily
exec "${SCRIPTS:-/}start-setupWorld" "$@"

View file

@ -9,13 +9,18 @@ isDebugging && set -x
resolveVersion
: "${MOHIST_BUILD:=lastSuccessfulBuild}"
mohistJobs=https://ci.codemc.io/job/MohistMC/job/
mohistBaseUrl=https://ci.codemc.io/job/MohistMC/
mohistJobs=${mohistBaseUrl}job/
mohistJob=${mohistJobs}Mohist-${VERSION}/
function logMohistAvailableVerisons(){
logError " check ${mohistBaseUrl} for available versions"
logError " and set VERSION accordingly"
}
if ! get --exists "${mohistJob}"; then
log "ERROR: mohist builds do not exist for ${VERSION}"
log " check https://ci.codemc.io/job/MohistMC/ for available versions"
log " and set VERSION accordingly"
logError "Mohist builds do not exist for ${VERSION}"
logMohistAvailableVerisons
exit 1
fi
@ -25,9 +30,8 @@ buildRelPath=$(
baseName=$(basename "${buildRelPath}")
if [[ ${baseName} != *-server.jar* ]]; then
log "ERROR: mohist build for ${VERSION} is not a valid server jar, found ${baseName}"
log " check https://ci.codemc.io/job/MohistMC/ for available versions"
log " and set VERSION accordingly"
logError "Mohist build for ${VERSION} is not a valid server jar, found ${baseName}"
logMohistAvailableVerisons
exit 1
fi

View file

@ -15,15 +15,11 @@ if ! mc-image-helper install-neoforge \
--minecraft-version="${VERSION}" \
--neoforge-version="${NEOFORGE_VERSION}" \
--force-reinstall="${NEOFORGE_FORCE_REINSTALL}"; then
log "ERROR failed to install Forge"
logError "Failed to install NeoForge"
exit 1
fi
# grab SERVER and export it
set -a
# shellcheck disable=SC1090
source ${resultsFile}
set +a
applyResultsFile ${resultsFile}
export FAMILY=FORGE

View file

@ -20,15 +20,10 @@ elif [[ $PAPER_DOWNLOAD_URL ]]; then
--output-directory=/data \
--results-file="$resultsFile" \
--url="$PAPER_DOWNLOAD_URL"; then
log "ERROR: failed to download from custom PaperMC URL"
logError "Failed to download from custom PaperMC URL"
exit 1
fi
# grab SERVER and export it
set -a
# shellcheck disable=SC1090
source "${resultsFile}"
set +a
applyResultsFile ${resultsFile}
else
args=(
--output-directory=/data
@ -41,15 +36,10 @@ else
args+=(--build="$PAPER_BUILD")
fi
if ! mc-image-helper install-paper "${args[@]}"; then
log "ERROR: failed to download $PAPER_PROJECT"
logError "Failed to download $PAPER_PROJECT"
exit 1
fi
# grab SERVER and export it
set -a
# shellcheck disable=SC1090
source "${resultsFile}"
set +a
applyResultsFile ${resultsFile}
fi
# Download default configs to allow for consistent patching

View file

@ -9,7 +9,7 @@ isDebugging && set -x
IFS=$'\n\t'
if versionLessThan 1.17; then
log "ERROR: Pufferfish server type only supports versions 1.17, 1.18 or 1.19, use PUFFERFISH_BUILD to select the the correct build 47 => 1.18.1, 50 => 1.18.2 etc"
logError "Pufferfish server type only supports versions 1.17, 1.18 or 1.19, use PUFFERFISH_BUILD to select the the correct build 47 => 1.18.1, 50 => 1.18.2 etc"
exit 1
fi
@ -35,7 +35,7 @@ done
if [[ ! -f "$SERVER" ]] || isTrue "${FORCE_REDOWNLOAD:-false}"; then
log "Downloading Pufferfish from $PUFFERFISH_BUILD_DOWNLOAD_URL ..."
if ! get -o "$SERVER" "$PUFFERFISH_BUILD_DOWNLOAD_URL"; then
log "ERROR: failed to download from $PUFFERFISH_BUILD_DOWNLOAD_URL (status=$?)"
logError "Failed to download from $PUFFERFISH_BUILD_DOWNLOAD_URL (status=$?)"
exit 3
fi
fi

View file

@ -16,15 +16,9 @@ if [[ $PURPUR_DOWNLOAD_URL ]]; then
--output-directory=/data \
--results-file="$resultsFile" \
--url="$PURPUR_DOWNLOAD_URL}"; then
log "ERROR: failed to download from custom Purpur URL"
logError "Failed to download from custom Purpur URL"
exit 1
fi
# grab SERVER and export it
set -a
# shellcheck disable=SC1090
source "${resultsFile}"
set +a
else
args=(
--output-directory=/data
@ -35,16 +29,13 @@ else
args+=(--build="$PURPUR_BUILD")
fi
if ! mc-image-helper install-purpur "${args[@]}"; then
log "ERROR: failed to download Purpur"
logError "Failed to download Purpur"
exit 1
fi
# grab SERVER and export it
set -a
# shellcheck disable=SC1090
source "${resultsFile}"
set +a
fi
applyResultsFile ${resultsFile}
# Normalize on Spigot for later operations
export FAMILY=SPIGOT

View file

@ -12,10 +12,18 @@ set -eu
isDebugging && set -x
function mc-image-helper-quilt(){
mc-image-helper install-quilt \
--loader-version="$QUILT_LOADER_VERSION" \
--minecraft-version="$VERSION" \
--output-directory=/data \
--results-file="$resultsFile" "$@"
}
resultsFile=/data/.quilt.env
if [[ $QUILT_LAUNCHER ]]; then
log "WARNING: use of QUILT_LAUNCHER is a deprecated feature."
logWarning "Use of QUILT_LAUNCHER is a deprecated feature."
SERVER="$QUILT_LAUNCHER"
export SERVER
resolveVersion
@ -24,38 +32,24 @@ if [[ $QUILT_LAUNCHER ]]; then
exec "${SCRIPTS:-/}start-setupWorld" "$@"
elif [[ $QUILT_LAUNCHER_URL ]]; then
log "ERROR: QUILT_LAUNCHER_URL is not longer supported. Pre-download and use QUILT_LAUNCHER."
logError "QUILT_LAUNCHER_URL is not longer supported. Pre-download and use QUILT_LAUNCHER."
exit 2
elif [[ $QUILT_INSTALLER_URL ]]; then
if ! mc-image-helper install-quilt \
--loader-version="$QUILT_LOADER_VERSION" \
--minecraft-version="$VERSION" \
--output-directory=/data \
--results-file="$resultsFile" \
--installer-url="$QUILT_INSTALLER_URL"; then
log "ERROR: failed to install Quilt given custom installer URL $QUILT_INSTALLER_URL"
if ! mc-image-helper-quilt --installer-url="$QUILT_INSTALLER_URL"; then
logError "Failed to installQuilt given custom installer URL $QUILT_INSTALLER_URL"
exit 2
fi
else
if ! mc-image-helper install-quilt \
--loader-version="$QUILT_LOADER_VERSION" \
--minecraft-version="$VERSION" \
--output-directory=/data \
--results-file="$resultsFile" \
--installer-version="$QUILT_INSTALLER_VERSION"; then
log "ERROR: failed to install Quilt given installer version $QUILT_INSTALLER_VERSION"
if ! mc-image-helper-quilt --installer-version="$QUILT_INSTALLER_VERSION"; then
logError "Failed to installQuilt given installer version $QUILT_INSTALLER_VERSION"
exit 2
fi
fi
# grab SERVER, VERSION and export it
set -a
# shellcheck disable=SC1090
source "${resultsFile}"
set +a
applyResultsFile ${resultsFile}
export FAMILY=FABRIC
exec "${SCRIPTS:-/}start-setupWorld" "$@"

View file

@ -24,11 +24,7 @@ esac
# If not SPONGEVERSION selected, detect last version on selected branch
if [ -z $SPONGEVERSION ]; then
log "Choosing Version for Sponge"
if [ "$SPONGEBRANCH" == "stable" ]; then
SPONGEVERSION=$(curl -fsSL https://dl-api.spongepowered.org/v1/org.spongepowered/$TYPE | jq -r '.buildTypes.stable.latest.version')
else
SPONGEVERSION=$(curl -fsSL https://dl-api.spongepowered.org/v1/org.spongepowered/$TYPE | jq -r '.buildTypes.bleeding.latest.version')
fi
SPONGEVERSION=$(curl -fsSL https://dl-api.spongepowered.org/v1/org.spongepowered/$TYPE | jq -r --arg SPONGEBRANCH "$SPONGEBRANCH" '.buildTypes.$SPONGEBRANCH.latest.version')
fi
VERSION="$SPONGEVERSION"

View file

@ -13,20 +13,20 @@ if [ ! -e "$SERVER" ] || [ -n "$FORCE_REDOWNLOAD" ]; then
versionManifestUrl=$(get 'https://launchermeta.mojang.com/mc/game/version_manifest.json' | jq --arg VERSION "$VERSION" --raw-output '[.versions[]|select(.id == $VERSION)][0].url')
result=$?
if [ $result != 0 ]; then
log "ERROR: failed to obtain version manifest URL ($result)"
logError "Failed to obtain version manifest URL ($result)"
exit 1
fi
if [ "$versionManifestUrl" = "null" ]; then
log "ERROR: couldn't find a matching manifest entry for $VERSION"
logError "Couldn't find a matching manifest entry for $VERSION"
exit 1
fi
debug "Found version manifest at $versionManifestUrl"
if ! serverDownloadUrl=$(get --json-path '$.downloads.server.url' "${versionManifestUrl}"); then
log "ERROR: failed to obtain version manifest from $versionManifestUrl ($result)"
logError "Failed to obtain version manifest from $versionManifestUrl ($result)"
exit 1
elif [ "$serverDownloadUrl" = "null" ]; then
log "ERROR: there is not a server download for version $VERSION"
logError "There is not a server download for version $VERSION"
exit 1
fi
@ -35,19 +35,20 @@ if [ ! -e "$SERVER" ] || [ -n "$FORCE_REDOWNLOAD" ]; then
get -o "$SERVER" "$serverDownloadUrl"
result=$?
if [ $result != 0 ]; then
log "ERROR: failed to download server from $serverDownloadUrl ($result)"
logError "Failed to download server from $serverDownloadUrl ($result)"
exit 1
fi
fi
minecraftServerJarPath=/data/minecraft_server.jar
if versionLessThan 1.6; then
if ! [[ -L /data/minecraft_server.jar && /data/minecraft_server.jar -ef "/data/$SERVER" ]]; then
rm -f /data/minecraft_server.jar
ln -s "/data/$SERVER" /data/minecraft_server.jar
if ! [[ -L $minecraftServerJarPath && $minecraftServerJarPath -ef "/data/$SERVER" ]]; then
rm -f $minecraftServerJarPath
ln -s "/data/$SERVER" $minecraftServerJarPath
fi
SERVER=minecraft_server.jar
elif [[ -L /data/minecraft_server.jar ]]; then
rm -f /data/minecraft_server.jar
elif [[ -L $minecraftServerJarPath ]]; then
rm -f $minecraftServerJarPath
fi
isDebugging && ls -l

View file

@ -7,37 +7,42 @@
# shellcheck source=start-utils
. "${SCRIPTS:-/}start-utils"
isDebugging && set -x
baseDataDir=/data
tmpServerIconPath=/tmp/icon.img
serverIconPath=${baseDataDir}/server-icon.png
mcHealthEnvPath=${baseDataDir}/mc-health.env
bootstrapPath=${baseDataDir}/bootstrap.txt
if [ -n "$ICON" ]; then
if [ ! -e server-icon.png ] || isTrue "${OVERRIDE_ICON}"; then
log "Using server icon from $ICON..."
if isURL "$ICON"; then
# Not sure what it is yet...call it "img"
if ! get -o /tmp/icon.img "$ICON"; then
log "ERROR: failed to download icon from $ICON"
if ! get -o "$tmpServerIconPath" "$ICON"; then
logError "Failed to download icon from $ICON"
exit 1
fi
ICON=/tmp/icon.img
ICON="$tmpServerIconPath"
iconSrc="url"
elif [ -f "$ICON" ]; then
iconSrc="file"
else
log "ERROR: $ICON does not appear to be a URL or existing file"
logError "$ICON does not appear to be a URL or existing file"
exit 1
fi
read -r -a specs < <(identify "$ICON" | awk 'NR == 1 { print $2, $3 }')
if [ "${specs[0]} ${specs[1]}" = "PNG 64x64" ]; then
if [ $iconSrc = url ]; then
mv -f /tmp/icon.img /data/server-icon.png
mv -f "$tmpServerIconPath" "$serverIconPath"
else
cp -f "$ICON" /data/server-icon.png
cp -f "$ICON" "$serverIconPath"
fi
elif [ "${specs[0]}" = GIF ]; then
log "Converting GIF image to 64x64 PNG..."
convert "$ICON"[0] -resize 64x64! /data/server-icon.png
convert "$ICON"[0] -resize 64x64! "$serverIconPath"
else
log "Converting image to 64x64 PNG..."
convert "$ICON" -resize 64x64! /data/server-icon.png
convert "$ICON" -resize 64x64! "$serverIconPath"
fi
fi
fi
@ -45,10 +50,9 @@ fi
canUseRollingLogs=true
useFallbackJvmFlag=false
SERVER_DIR="$baseDataDir"
if [[ ${FTB_DIR:-} ]]; then
SERVER_DIR="$FTB_DIR"
else
SERVER_DIR=/data
fi
@ -56,7 +60,7 @@ patchLog4jConfig() {
file=${1?}
url=${2?}
if ! get -o "${SERVER_DIR}/${file}" "$url"; then
log "ERROR: failed to download corrected log4j config, fallback to JVM flag"
logError "Failed to download corrected log4j config, fallback to JVM flag"
useFallbackJvmFlag=true
return 1
fi
@ -101,7 +105,7 @@ fi
if isTrue "${ENABLE_ROLLING_LOGS:-false}"; then
if ! ${canUseRollingLogs}; then
log "ERROR: Using rolling logs is currently not possible in the selected version due to CVE-2021-44228"
logError "Using rolling logs is currently not possible in the selected version due to CVE-2021-44228"
exit 1
fi
# Set up log configuration
@ -214,31 +218,31 @@ if [[ ${INIT_MEMORY} || ${MAX_MEMORY} ]]; then
fi
function copyFilesForCurseForge() {
if [ ! -e "${FTB_DIR}/server-icon.png" ] && [ -e /data/server-icon.png ]; then
cp -f /data/server-icon.png "${FTB_DIR}/"
if [ ! -e "${FTB_DIR}/server-icon.png" ] && [ -e "$serverIconPath" ]; then
cp -f "$serverIconPath" "${FTB_DIR}/"
fi
cp -f /data/eula.txt "${FTB_DIR}/"
cp -f ${baseDataDir}/eula.txt "${FTB_DIR}/"
}
if versionLessThan 'b1.8'; then
echo "
DISABLE_HEALTHCHECK=true
" > /data/.mc-health.env
" > "$mcHealthEnvPath"
elif versionLessThan 1.7; then
echo "
MC_HEALTH_EXTRA_ARGS=(
--use-server-list-ping
)
" > /data/.mc-health.env
" > "$mcHealthEnvPath"
elif isTrue "$USES_PROXY_PROTOCOL"; then
echo "
MC_HEALTH_EXTRA_ARGS=(
--use-proxy
)
" > /data/.mc-health.env
" > "$mcHealthEnvPath"
else
rm -f /data/.mc-health.env
rm -f "$mcHealthEnvPath"
fi
mcServerRunnerArgs=(
@ -257,7 +261,7 @@ fi
if [[ ${TYPE} == "CURSEFORGE" && "${SERVER}" ]]; then
copyFilesForCurseForge
cd "${FTB_DIR}" || (log "ERROR: can't go into ${FTB_DIR}"; exit 1)
cd "${FTB_DIR}" || (logError "Can't go into ${FTB_DIR}"; exit 1)
log "Starting CurseForge server in ${FTB_DIR}..."
if isTrue "${DEBUG_EXEC}"; then
set -x
@ -279,7 +283,7 @@ EOF
sed -i "s/MAX_RAM=[^;]*/MAX_RAM=${MAX_MEMORY}/" "${FTB_DIR}/settings.cfg"
fi
cd "${FTB_DIR}" || (log "ERROR: can't go into ${FTB_DIR}"; exit 1)
cd "${FTB_DIR}" || (logError "Can't go into ${FTB_DIR}"; exit 1)
log "Running FTB ${FTB_SERVER_START} in ${FTB_DIR} ..."
finalArgs="${FTB_SERVER_START}"
@ -315,8 +319,8 @@ elif [[ $SERVER =~ run.sh ]]; then
exec mc-server-runner "${mcServerRunnerArgs[@]}" --shell bash "${SERVER}" $EXTRA_ARGS
else
# If we have a bootstrap.txt file... feed that in to the server stdin
if [ -f /data/bootstrap.txt ]; then
bootstrapArgs="--bootstrap /data/bootstrap.txt"
if [ -f $bootstrapPath ]; then
bootstrapArgs="--bootstrap $bootstrapPath"
fi
log "Starting the Minecraft server..."

View file

@ -22,15 +22,7 @@ log "Rcon cmds functionality enabled"
isDebugging && set -x
if ! [[ $RCON_CMDS_PERIOD =~ ^[0-9]+$ ]]; then
RCON_CMDS_PERIOD=10
export RCON_CMDS_PERIOD
log "Warning: RCON_CMDS_PERIOD is not numeric, set to 10 (seconds)"
fi
if [ "$RCON_CMDS_PERIOD" -eq "0" ] ; then
RCON_CMDS_PERIOD=10
export RCON_CMDS_PERIOD
log "Warning: RCON_CMDS_PERIOD must not be 0, set to 10 (seconds)"
fi
isNumericElseSetToDefault RCON_CMDS_PERIOD 10
checkIfNotZeroElseSetToDefault RCON_CMDS_PERIOD 10
/usr/local/bin/rcon-cmds-daemon.sh &

View file

@ -30,28 +30,28 @@ if [[ "$DATAPACKS" ]]; then
if isURL "$i"; then
log "Downloading datapack $i ..."
if ! get -o "${out_dir}" "$i"; then
log "ERROR: failed to download from $i into $out_dir"
logError "Failed to download from $i into $out_dir"
exit 2
fi
elif [[ -f "$i" && "$i" =~ .*\.zip ]]; then
log "Copying datapack 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"
logError "Failed to copy from $i into $out_dir"
exit 2
fi
elif [[ -d "$i" ]]; then
log "Copying datapacks from $i ..."
cp "$i"/*.zip "${out_dir}"
else
log "ERROR Invalid URL or path given in DATAPACKS: $i"
logError "Invalid URL or path given in DATAPACKS: $i"
exit 2
fi
done
elif [[ "$DATAPACKS_FILE" ]]; then
if [ ! -f "$DATAPACKS_FILE" ]; then
log "ERROR: given DATAPACKS_FILE file does not exist"
logError "Given DATAPACKS_FILE file does not exist"
exit 2
fi
@ -71,7 +71,7 @@ elif [[ "$DATAPACKS_FILE" ]]; then
fi
if ! get "${args[@]}" ; then
log "ERROR: failed to retrieve one or more datapacks"
logError "Failed to retrieve one or more datapacks"
exit 1
fi
fi

View file

@ -33,7 +33,7 @@ if [[ $DOWNLOAD_DEFAULT_CONFIGS ]]; then
--to /data/config \
--skip-existing --skip-up-to-date=false \
"$DOWNLOAD_DEFAULT_CONFIGS" 2> /dev/null; then
log "WARN: one or more default config files were not available from $DOWNLOAD_DEFAULT_CONFIGS"
logWarning "One or more default config files were not available from $DOWNLOAD_DEFAULT_CONFIGS"
fi
fi

View file

@ -34,13 +34,13 @@ function handlePackwiz() {
--maven-repo=https://maven.packwiz.infra.link/repository/release/ \
--group=link.infra.packwiz --artifact=packwiz-installer --classifier=dist \
--skip-existing); then
log "ERROR: failed to get packwiz installer"
logError "Failed to get packwiz installer"
exit 1
fi
log "Running packwiz installer against URL: ${PACKWIZ_URL}"
if ! java -cp "${packwizInstaller}" link.infra.packwiz.installer.Main -s server "${PACKWIZ_URL}"; then
log "ERROR failed to run packwiz installer"
logError "Failed to run packwiz installer"
exit 1
fi
fi
@ -52,28 +52,28 @@ if [[ "$MODPACK" ]]; then
if isURL "${MODPACK}"; then
log "Downloading mod/plugin pack"
if ! get -o /tmp/modpack.zip "${MODPACK}"; then
log "ERROR: failed to download from ${MODPACK}"
logError "Failed to download from ${MODPACK}"
exit 2
fi
elif [[ "$MODPACK" =~ .*\.zip ]]; then
if ! cp "$MODPACK" /tmp/modpack.zip; then
log "ERROR: failed to copy from $MODPACK"
logError "Failed to copy from $MODPACK"
exit 2
fi
else
log "ERROR Invalid URL or Path given for MODPACK: $MODPACK"
logError "Invalid URL or Path given for MODPACK: $MODPACK"
exit 1
fi
if [ "$FAMILY" = "SPIGOT" ]; then
mkdir -p "$PLUGINS_OUT_DIR"
if ! unzip -o -d "$PLUGINS_OUT_DIR" /tmp/modpack.zip; then
log "ERROR: failed to unzip the modpack from ${MODPACK}"
logError "Failed to unzip the modpack from ${MODPACK}"
fi
else
mkdir -p "$MODS_OUT_DIR"
if ! unzip -o -d "$MODS_OUT_DIR" /tmp/modpack.zip; then
log "ERROR: failed to unzip the modpack from ${MODPACK}"
logError "Failed to unzip the modpack from ${MODPACK}"
fi
fi
rm -f /tmp/modpack.zip
@ -166,7 +166,7 @@ function handleGenericPacks() {
mkdir -p /data/packs
log "Downloading generic pack from $pack"
if ! outfile=$(get -o /data/packs --output-filename --skip-up-to-date "$pack"); then
log "ERROR: failed to download $pack"
logError "Failed to download $pack"
exit 2
fi
packFiles+=("$outfile")
@ -200,7 +200,7 @@ function handleGenericPacks() {
--max-depth=3 --type=directory --name=mods,plugins,config \
--only-shallowest --fail-no-matches --format '%h' \
"$base_dir"); then
log "ERROR: Unable to find content base of generic packs ${GENERIC_PACKS}. Directories:"
logError "Unable to find content base of generic packs ${GENERIC_PACKS}. Directories:"
mc-image-helper find --name=* --max-depth=3 --type=directory --format '- %P' "$original_base_dir"
exit 1
fi
@ -240,8 +240,8 @@ function handleModrinthProjects() {
: "${MODRINTH_ALLOWED_VERSION_TYPE:=release}"
: "${MODRINTH_DOWNLOAD_DEPENDENCIES:=none}"
if [[ -v MODRINTH_DOWNLOAD_OPTIONAL_DEPENDENCIES ]]; then
log "WARNING The variable MODRINTH_DOWNLOAD_OPTIONAL_DEPENDENCIES is removed."
log " Use MODRINTH_DOWNLOAD_DEPENDENCIES=optional instead"
logWarning "The variable MODRINTH_DOWNLOAD_OPTIONAL_DEPENDENCIES is removed."
logWarning " Use MODRINTH_DOWNLOAD_DEPENDENCIES=optional instead"
fi
if [[ $MODRINTH_PROJECTS ]]; then
@ -298,14 +298,14 @@ handleModpackZip
handleListings
if [[ $MANIFEST ]]; then
log "ERROR: MANIFEST is no longer supported."
log " Use MOD_PLATFORM=AUTO_CURSEFORGE and CF_MODPACK_MANIFEST instead"
logError "MANIFEST is no longer supported."
logError " Use MOD_PLATFORM=AUTO_CURSEFORGE and CF_MODPACK_MANIFEST instead"
exit 1
fi
if [[ $MODS_FORGEAPI_KEY || $MODS_FORGEAPI_FILE || $MODS_FORGEAPI_PROJECTIDS ]]; then
log "ERROR the MODS_FORGEAPI_FILE / MODS_FORGEAPI_PROJECTIDS feature is no longer supported"
log " Use CURSEFORGE_FILES instead."
logError "The MODS_FORGEAPI_FILE / MODS_FORGEAPI_PROJECTIDS feature is no longer supported"
logError " Use CURSEFORGE_FILES instead."
exit 1
fi

View file

@ -26,19 +26,22 @@ else
subcommand=sync
fi
function mc-image-helper-mounts(){
mc-image-helper \
${subcommand} $updateArg \
--replace-env-file-suffixes="${REPLACE_ENV_SUFFIXES}" \
--replace-env-excludes="${REPLACE_ENV_VARIABLES_EXCLUDES}" \
--replace-env-exclude-paths="${REPLACE_ENV_VARIABLES_EXCLUDE_PATHS}" \
--replace-env-prefix="${REPLACE_ENV_VARIABLE_PREFIX}" "$@"
}
: "${COPY_PLUGINS_SRC:="/plugins"}"
: "${COPY_PLUGINS_DEST:=${PLUGINS_OUT_DIR}}"
if usesPlugins && [ -d "${COPY_PLUGINS_SRC}" ]; then
mkdir -p "${COPY_PLUGINS_DEST}"
log "Copying any plugins from ${COPY_PLUGINS_SRC} to ${COPY_PLUGINS_DEST}"
mc-image-helper \
${subcommand} $updateArg \
--replace-env-file-suffixes="${REPLACE_ENV_SUFFIXES}" \
--replace-env-excludes="${REPLACE_ENV_VARIABLES_EXCLUDES}" \
--replace-env-exclude-paths="${REPLACE_ENV_VARIABLES_EXCLUDE_PATHS}" \
--replace-env-prefix="${REPLACE_ENV_VARIABLE_PREFIX}" \
"${COPY_PLUGINS_SRC}" "${COPY_PLUGINS_DEST}"
mc-image-helper-mounts "${COPY_PLUGINS_SRC}" "${COPY_PLUGINS_DEST}"
fi
: "${COPY_MODS_SRC:="/mods"}"
@ -46,13 +49,7 @@ fi
if usesMods && [ -d "${COPY_MODS_SRC}" ]; then
log "Copying any mods from ${COPY_MODS_SRC} to ${COPY_MODS_DEST}"
mc-image-helper \
${subcommand} $updateArg \
--replace-env-file-suffixes="${REPLACE_ENV_SUFFIXES}" \
--replace-env-excludes="${REPLACE_ENV_VARIABLES_EXCLUDES}" \
--replace-env-exclude-paths="${REPLACE_ENV_VARIABLES_EXCLUDE_PATHS}" \
--replace-env-prefix="${REPLACE_ENV_VARIABLE_PREFIX}" \
"${COPY_MODS_SRC}" "${COPY_MODS_DEST}"
mc-image-helper-mounts "${COPY_MODS_SRC}" "${COPY_MODS_DEST}"
fi
: "${COPY_CONFIG_SRC:="/config"}"
@ -60,13 +57,7 @@ fi
if [ -d "${COPY_CONFIG_SRC}" ]; then
log "Copying any configs from ${COPY_CONFIG_SRC} to ${COPY_CONFIG_DEST}"
mc-image-helper \
${subcommand} $updateArg \
--replace-env-file-suffixes="${REPLACE_ENV_SUFFIXES}" \
--replace-env-excludes="${REPLACE_ENV_VARIABLES_EXCLUDES}" \
--replace-env-exclude-paths="${REPLACE_ENV_VARIABLES_EXCLUDE_PATHS}" \
--replace-env-prefix="${REPLACE_ENV_VARIABLE_PREFIX}" \
"${COPY_CONFIG_SRC}" "${COPY_CONFIG_DEST}"
mc-image-helper-mounts "${COPY_CONFIG_SRC}" "${COPY_CONFIG_DEST}"
fi
exec "${SCRIPTS:-/}start-setupServerProperties" "$@"

View file

@ -62,7 +62,7 @@ function customizeServerProps {
fi
;;
*)
log "ERROR: Invalid game mode: $MODE"
logError "Invalid game mode: $MODE"
exit 1
;;
esac
@ -99,7 +99,7 @@ function customizeServerProps {
fi
;;
*)
log "DIFFICULTY must be peaceful, easy, normal, or hard."
log "DIFFICULTY must be peaceful(0), easy(1), normal(2), or hard(3)."
exit 1
;;
esac
@ -121,7 +121,7 @@ function customizeServerProps {
handleDebugMode
if ! mc-image-helper set-properties "${setPropertiesArgs[@]}" "$SERVER_PROPERTIES"; then
log "ERROR: failed to update server.properties"
logError "Failed to update server.properties"
exit 1
fi
@ -167,9 +167,9 @@ if isTrue "${ENABLE_AUTOPAUSE}"; then
if [ -f "$SERVER_PROPERTIES" ]; then
current_max_tick=$( grep 'max-tick-time' "$SERVER_PROPERTIES" | sed -r 's/( )+//g' | awk -F= '{print $2}' )
if (( current_max_tick > 0 && current_max_tick < 86400000 )); then
log "Warning: The server.properties for the server doesn't have the Server Watchdog (effectively) disabled."
log " Autopause functionality resuming the process might trigger the Watchdog and restart the server completely."
log " Set the MAX_TICK_TIME env variable (or max-tick-time property) to a high value (or disable the Watchdog with value -1 for versions 1.8.1+)."
logWarning "The server.properties for the server doesn't have the Server Watchdog (effectively) disabled."
logWarning " Autopause functionality resuming the process might trigger the Watchdog and restart the server completely."
logWarning " Set the MAX_TICK_TIME env variable (or max-tick-time property) to a high value (or disable the Watchdog with value -1 for versions 1.8.1+)."
fi
fi
fi

View file

@ -27,7 +27,7 @@ if [[ "$WORLD" ]] && ( isTrue "${FORCE_WORLD_COPY}" || [ ! -d "$worldDest" ] );
if isURL "$WORLD"; then
log "Downloading world from $WORLD"
if ! get -o /tmp/world.bin "$WORLD"; then
log "ERROR: failed to download world from $WORLD"
logError "Failed to download world from $WORLD"
exit 1
fi
WORLD=/tmp/world.bin
@ -39,14 +39,14 @@ if [[ "$WORLD" ]] && ( isTrue "${FORCE_WORLD_COPY}" || [ ! -d "$worldDest" ] );
# Stage contents so that the correct subdirectory can be picked off
mkdir -p /tmp/world-data
if ! extract "$WORLD" /tmp/world-data; then
log "ERROR extracting world from $WORLD"
logError "Extracting world from $WORLD"
exit 1
fi
baseDirs=$(find /tmp/world-data -name "level.dat" -exec dirname "{}" \;)
if ! [[ $baseDirs ]]; then
log "ERROR world content is not valid since level.dat could not be found"
logError "World content is not valid since level.dat could not be found"
exit 2
fi
@ -60,24 +60,24 @@ if [[ "$WORLD" ]] && ( isTrue "${FORCE_WORLD_COPY}" || [ ! -d "$worldDest" ] );
else
baseDir="$(echo "$baseDirs" | sed -n ${WORLD_INDEX:-1}p)"
baseName=$(basename "$baseDir")
log "WARN multiple levels found, picking: $baseName"
logWarning "Multiple levels found, picking: $baseName"
fi
elif [[ $count -gt 0 ]]; then
baseDir="$baseDirs"
else
log "ERROR invalid world content"
logError "Invalid world content"
exit 1
fi
if [ -d "${baseDir}_nether/DIM-1" ]; then
if [ -d "$baseDir/DIM-1" ]; then
log "WARN found Nether dimension in both $baseDir and ${baseDir}_nether, picking ${baseDir}_nether"
logWarning "Found Nether dimension in both $baseDir and ${baseDir}_nether, picking ${baseDir}_nether"
rm -r "$baseDir/DIM-1"
fi
fi
if [ -d "${baseDir}_the_end/DIM1" ]; then
if [ -d "$baseDir/DIM1" ]; then
log "WARN found End dimension in both $baseDir and ${baseDir}_the_end, picking ${baseDir}_the_end"
logWarning "Found End dimension in both $baseDir and ${baseDir}_the_end, picking ${baseDir}_the_end"
rm -r "$baseDir/DIM1"
fi
fi
@ -116,7 +116,7 @@ if [[ "$WORLD" ]] && ( isTrue "${FORCE_WORLD_COPY}" || [ ! -d "$worldDest" ] );
log "Cloning world directory from $WORLD ..."
rsync --recursive --delete "${WORLD%/}"/ "$worldDest"
else
log "ERROR: world file/directory $WORLD is missing"
logError "World file/directory $WORLD is missing"
exit 1
fi

View file

@ -57,7 +57,7 @@ getResourceFromSpiget() {
if [[ -n $(find "$versionfile" -mmin +${SPIGET_DOWNLOAD_TOLERANCE}) ]]; then
urlVersion="https://api.spiget.org/v2/resources/${resource}/versions/latest"
if ! get -o "${versionfileNew}" "${urlVersion}"; then
log "ERROR failed to download resource version meta data '${resource}' from ${urlVersion}"
logError "Failed to download resource version meta data '${resource}' from ${urlVersion}"
exit 2
fi
@ -83,7 +83,7 @@ getResourceFromSpiget() {
if downloadResourceFromSpiget "${resource}"; then
urlVersion="https://api.spiget.org/v2/resources/${resource}/versions/latest"
if ! get -o "${versionfileNew}" "${urlVersion}"; then
log "ERROR failed to download resource version meta data '${resource}' from ${urlVersion}"
logError "Failed to download resource version meta data '${resource}' from ${urlVersion}"
exit 2
fi
mv "${versionfileNew}" "${versionfile}"
@ -99,16 +99,16 @@ downloadResourceFromSpiget() {
mkdir -p $tempDir
resourceUrl="https://api.spiget.org/v2/resources/${resource}"
if ! outfile=$(get_silent --output-filename -o $tempDir "${acceptArgs[@]}" "${resourceUrl}/download"); then
log "ERROR: failed to download resource '${resource}' from ${resourceUrl}/download"
logError "Failed to download resource '${resource}' from ${resourceUrl}/download"
if externalUrl=$(get --json-path '$.file.externalUrl' "${resourceUrl}"); then
log " Visit $externalUrl to pre-download the resource"
log " instead of using SPIGET_RESOURCES"
logError " Visit $externalUrl to pre-download the resource"
logError " instead of using SPIGET_RESOURCES"
fi
exit 1
fi
if ! fileType=$(get --json-path '.file.type' "${resourceUrl}"); then
log "ERROR: failed to retrieve file type of resource $resource"
logError "Failed to retrieve file type of resource $resource"
exit 1
fi
if [[ $fileType = .sk ]]; then
@ -122,7 +122,7 @@ downloadResourceFromSpiget() {
log "Extracting contents of resource ${resource} into plugins"
extract "$outfile" /data/plugins
else
log "ERROR: file for resource ${resource} has an unexpected file type: ${fileType}"
logError "File for resource ${resource} has an unexpected file type: ${fileType}"
exit 2
fi
fi

View file

@ -8,7 +8,7 @@ function get_from_gh() {
fi
if [[ ! "$oAuthScopes" =~ ^x-oauth-scopes:[[:space:]]*$ ]]; then
# Don't use what you don't have to...
log "ERROR: GH_TOKEN has permissions it doesn't need. Recreate or update this personal access token and disable ALL scopes."
logError "GH_TOKEN has permissions it doesn't need. Recreate or update this personal access token and disable ALL scopes."
exit 1
else
curl -fsSL -H "Authorization: token $GH_TOKEN" "${@:2}" "$1"
@ -18,6 +18,14 @@ function get_from_gh() {
fi
}
function applyResultsFile() {
# grab SERVER and export it
set -a
# shellcheck disable=SC1090
source "$1"
set +a
}
function join_by() {
local d=$1
shift
@ -47,7 +55,7 @@ function isValidFileURL() {
function resolveEffectiveUrl() {
url="${1:?Missing required url argument}"
if ! curl -Ls -o /dev/null -w "%{url_effective}" "$url"; then
log "ERROR failed to resolve effective URL from $url"
logError "Failed to resolve effective URL from $url"
exit 2
fi
}
@ -109,10 +117,107 @@ function log() {
if isDebugging || isTrue "${LOG_TIMESTAMP:-false}"; then
ts=" $(date --rfc-3339=seconds)"
fi
echo "[init]${ts} $*"
echo -e "[init]${ts} $*"
eval "$oldState"
}
function getSudoFromDistro(){
distro=$(getDistro)
command=
if [[ $distro == alpine ]]; then
command="su-exec"
else
command="gosu"
fi
echo $command
}
# Refer to https://unix.stackexchange.com/a/10065/102376
function isTerminal() {
if test -t 1; then
# see if it supports colors...
ncolors=$(tput colors)
test -n "$ncolors" && test "$ncolors" -ge 8
else
return 1
fi
}
errorLogTag="[ERROR]"
warningLogTag="[WARN]"
if isTerminal; then
normal="$(tput sgr0)"
red="$(tput setaf 1)"
yellow="$(tput setaf 3)"
function getErrorColoredLogString() {
echo "${red}$errorLogTag $* ${normal}"
}
function getWarningColoredLogString() {
echo "${yellow}$warningLogTag $* ${normal}"
}
else
function getErrorColoredLogString() {
echo "$errorLogTag $*"
}
function getWarningColoredLogString() {
echo "$warningLogTag $*"
}
fi
function error() {
echo -e "$(getErrorColoredLogString "$*")"
}
function logError() {
if isDebugging; then
set +x
fi
log "$(getErrorColoredLogString "$*")"
if isDebugging; then
set -x
fi
}
function warning() {
if isDebugging; then
set +x
fi
echo -e "$(getWarningColoredLogString "$*")"
if isDebugging; then
set -x
fi
}
function logWarning() {
log "$(getWarningColoredLogString "$*")"
}
function isNumeric() {
[[ $1 =~ ^[0-9]+$ ]]
}
function isNumericElseSetToDefault() {
local var_name="$1"
local default_value="$2"
if ! isNumeric ${!var_name} ; then
eval "$var_name=$default_value"
export "$var_name"
logWarning "$var_name is not numeric, set to $default_value (seconds)"
fi
}
function checkIfNotZeroElseSetToDefault() {
local var_name="$1"
local default_value="$2"
if [ "${!var_name}" -eq "0" ] ; then
eval "$var_name=$default_value"
export "$var_name"
logWarning "$var_name must not be 0, set to $default_value (seconds)"
fi
}
function logAutopause() {
echo "[Autopause loop] $*"
}
@ -255,37 +360,12 @@ function versionLessThan() {
compare_version "${VERSION}" "lt" "${1?}"
}
requireVar() {
if [ ! -v "$1" ]; then
log "ERROR: $1 is required to be set"
exit 1
fi
if [ -z "${!1}" ]; then
log "ERROR: $1 is required to be set"
exit 1
fi
}
requireEnum() {
var=${1?}
shift
for allowed in "$@"; do
if [[ ${!var} = "$allowed" ]]; then
return 0
fi
done
log "ERROR: $var must be set to one of $*"
# exit 1
}
function writeEula() {
if ! echo "# Generated via Docker
# $(date)
eula=${EULA,,}
" >/data/eula.txt; then
log "ERROR: unable to write eula to /data. Please make sure attached directory is writable by uid=${UID}"
logError "Unable to write eula to /data. Please make sure attached directory is writable by uid=${UID}"
exit 2
fi
}
@ -354,7 +434,7 @@ function extract() {
tar -C "${destDir}" --use-compress-program=unzstd -xf "${src}"
;;
*)
log "ERROR: unsupported archive type: $type"
logError "Unsupported archive type: $type"
return 1
;;
esac
@ -429,7 +509,7 @@ function ensureRemoveAllModsOff() {
reason=${1?}
if isTrue "${REMOVE_OLD_MODS:-false}"; then
log "WARNING using REMOVE_OLD_MODS interferes with $reason -- it is now disabled"
logWarning "Using REMOVE_OLD_MODS interferes with $reason -- it is now disabled"
REMOVE_OLD_MODS=false
fi
}