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
38 changed files with 424 additions and 428 deletions

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..."