From 705af6001647089727fd64691ff782600d5fd0f9 Mon Sep 17 00:00:00 2001 From: Adam Dodman Date: Tue, 30 Apr 2024 22:12:42 +0100 Subject: [PATCH 1/2] Initial pass of reworked entrypoint --- entrypoint | 74 ++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 49 insertions(+), 25 deletions(-) diff --git a/entrypoint b/entrypoint index b0ea741b..44e8f661 100644 --- a/entrypoint +++ b/entrypoint @@ -4,42 +4,66 @@ if [ -n "$DEBUG" ]; then set -x fi -if ! find . -mindepth 1 | read -r; then - >&2 echo "Creating default configs..." - cp -r /opt/cfx-server-data/* /config - RCON_PASS="${RCON_PASSWORD-$(tr -dc 'a-zA-Z0-9' < /dev/urandom | head -c 16)}" - sed -i "s/{RCON_PASS}/${RCON_PASS}/g" /config/server.cfg; - >&2 echo "----------------------------------------------" - >&2 echo "RCON password is set to: ${RCON_PASS}" - >&2 echo "----------------------------------------------" -fi +# Empty config args defaults to loading txAdmin +CONFIG_ARGS= -if [ -z "$NO_ONESYNC" ]; then - ONESYNC_ARGS="+set onesync on +set onesync_population true" -fi +# Temporary during the transition - this way old configs still trigger the old (no txadmin by default) behaviour. +NO_TXADMIN = "DONTANSWERTHEPHONETOLESTERCREST" -CONFIG_ARGS= -if [ -z "${NO_DEFAULT_CONFIG}" ]; then - CONFIG_ARGS="$CONFIG_ARGS $ONESYNC_ARGS +exec /config/server.cfg" +# Warn if NO_TXADMIN is the default. +if [ "${NO_TXADMIN}" = "DONTANSWERTHEPHONETOLESTERCREST" ]; then + >&2 echo "------------------------------------------------------" + >&2 echo "WARNING - Default options will soon change to enabling" + >&2 echo "txAdmin by default. Set \$NO_TXADMIN to disable this." + >&2 echo "------------------------------------------------------" fi -# English is hard -if [ -z "${NO_LICENSE_KEY}${NO_LICENCE_KEY}" ]; then - if [ -z "${LICENSE_KEY}" ] && [ -n "${LICENCE_KEY}" ]; then - LICENSE_KEY="${LICENCE_KEY}" +# If NO_TXADMIN is defined, configure the server as standalone. +if [ -n "${NO_TXADMIN}" ]; then + if ! find . -mindepth 1 | read -r; then + >&2 echo "Creating default configs..." + cp -r /opt/cfx-server-data/* /config + RCON_PASS="${RCON_PASSWORD-$(tr -dc 'a-zA-Z0-9' < /dev/urandom | head -c 16)}" + sed -i "s/{RCON_PASS}/${RCON_PASS}/g" /config/server.cfg; + >&2 echo "----------------------------------------------" + >&2 echo "RCON password is set to: ${RCON_PASS}" + >&2 echo "----------------------------------------------" fi - if [ -z "${NO_DEFAULT_CONFIG}"] && [ -z "${LICENSE_KEY}" ]; then - >&2 printf "License key not found in environment, please create one at https://keymaster.fivem.net!\n" + # If all these are true (& NO_TXADMIN above), CONFIG_ARGS will be empty, and txAdmin would start. + if [ -n "${NO_DEFAULT_CONFIG}" ] && [ -z "${$*}"]; then + >&2 printf "NO_TXADMIN specified, but no config args given. Server would load txAdmin anyway." exit 1 fi - if [ -z "${CONFIG_ARGS}" ] && [ -n "${LICENSE_KEY}" ] && [ -n "${NO_DEFAULT_CONFIG}" ]; then - >&2 printf "txadmin does not use the \$LICENSE_KEY environment variable.\nPlease remove it and set it through the txadmin web UI\n\n" - exit 1 + # Set some default options. + if [ -z "${NO_DEFAULT_CONFIG}" ]; then + CONFIG_ARGS="$CONFIG_ARGS $ONESYNC_ARGS +exec /config/server.cfg" fi - CONFIG_ARGS="$CONFIG_ARGS +set sv_licenseKey ${LICENSE_KEY}" + # I pronounce everything below this point.. Deprecated! + if [ -z "$NO_ONESYNC" ]; then + ONESYNC_ARGS="+set onesync on +set onesync_population true" + fi + + # English is hard + if [ -z "${NO_LICENSE_KEY}${NO_LICENCE_KEY}" ]; then + if [ -z "${LICENSE_KEY}" ] && [ -n "${LICENCE_KEY}" ]; then + LICENSE_KEY="${LICENCE_KEY}" + fi + + if [ -z "${NO_DEFAULT_CONFIG}"] && [ -z "${LICENSE_KEY}" ]; then + >&2 printf "License key not found in environment, please create one at https://keymaster.fivem.net!\n" + exit 1 + fi + + if [ -z "${CONFIG_ARGS}" ] && [ -n "${LICENSE_KEY}" ] && [ -n "${NO_DEFAULT_CONFIG}" ]; then + >&2 printf "txAdmin does not use the \$LICENSE_KEY environment variable.\nPlease remove it and set it through the txadmin web UI\n\n" + exit 1 + fi + + CONFIG_ARGS="$CONFIG_ARGS +set sv_licenseKey ${LICENSE_KEY}" + fi fi exec /opt/cfx-server/ld-musl-x86_64.so.1 \ From 64053cfff9974346aae0d498d730fa13c61e6d16 Mon Sep 17 00:00:00 2001 From: Adam Dodman Date: Tue, 30 Apr 2024 22:56:54 +0100 Subject: [PATCH 2/2] Rework the deprecated logic --- Dockerfile | 3 +++ entrypoint | 62 +++++++++++++++++++++++++++++------------------------- 2 files changed, 36 insertions(+), 29 deletions(-) diff --git a/Dockerfile b/Dockerfile index 931d1e70..81540f8d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -43,6 +43,9 @@ LABEL maintainer="Spritsail " \ COPY --from=builder /output/ / +# Temporary to allow soft deprecation. +ENV NO_TXADMIN="DONTANSWERTHEPHONETOLESTERCREST" + WORKDIR /config EXPOSE 30120 diff --git a/entrypoint b/entrypoint index 44e8f661..84f5c9dd 100644 --- a/entrypoint +++ b/entrypoint @@ -7,16 +7,9 @@ fi # Empty config args defaults to loading txAdmin CONFIG_ARGS= -# Temporary during the transition - this way old configs still trigger the old (no txadmin by default) behaviour. -NO_TXADMIN = "DONTANSWERTHEPHONETOLESTERCREST" - -# Warn if NO_TXADMIN is the default. -if [ "${NO_TXADMIN}" = "DONTANSWERTHEPHONETOLESTERCREST" ]; then - >&2 echo "------------------------------------------------------" - >&2 echo "WARNING - Default options will soon change to enabling" - >&2 echo "txAdmin by default. Set \$NO_TXADMIN to disable this." - >&2 echo "------------------------------------------------------" -fi +# Temporary magic string during the transition - this way old configs still trigger the old (no txadmin by default) behaviour. +# This is set in the Docker file so it can be overridden - here for reference. +# NO_TXADMIN = "DONTANSWERTHEPHONETOLESTERCREST" # If NO_TXADMIN is defined, configure the server as standalone. if [ -n "${NO_TXADMIN}" ]; then @@ -32,8 +25,10 @@ if [ -n "${NO_TXADMIN}" ]; then # If all these are true (& NO_TXADMIN above), CONFIG_ARGS will be empty, and txAdmin would start. if [ -n "${NO_DEFAULT_CONFIG}" ] && [ -z "${$*}"]; then - >&2 printf "NO_TXADMIN specified, but no config args given. Server would load txAdmin anyway." - exit 1 + if [ "${NO_TXADMIN}" != "DONTANSWERTHEPHONETOLESTERCREST" ]; then # Remove this if block when we remove the magic string - silly edge case! + >&2 printf "NO_DEFAULT_CONFIG specified, but no config args given. Server would load txAdmin anyway." + exit 1 + fi fi # Set some default options. @@ -41,28 +36,37 @@ if [ -n "${NO_TXADMIN}" ]; then CONFIG_ARGS="$CONFIG_ARGS $ONESYNC_ARGS +exec /config/server.cfg" fi - # I pronounce everything below this point.. Deprecated! - if [ -z "$NO_ONESYNC" ]; then - ONESYNC_ARGS="+set onesync on +set onesync_population true" - fi + # If it's set to the magic value, we can assume it's the deprecated logic. Do all the old things! + if [ "${NO_TXADMIN}" = "DONTANSWERTHEPHONETOLESTERCREST" ]; then + >&2 echo "------------------------------------------------------" + >&2 echo "WARNING - Default options will soon change to enabling" + >&2 echo "txAdmin by default. Set \$NO_TXADMIN to disable this." + >&2 echo "------------------------------------------------------" - # English is hard - if [ -z "${NO_LICENSE_KEY}${NO_LICENCE_KEY}" ]; then - if [ -z "${LICENSE_KEY}" ] && [ -n "${LICENCE_KEY}" ]; then - LICENSE_KEY="${LICENCE_KEY}" + # I pronounce everything below this point.. Deprecated! + if [ -z "$NO_ONESYNC" ]; then + ONESYNC_ARGS="+set onesync on +set onesync_population true" + >2& "Automaticly defined Onesync is deprecated. Please ensure 'onesync on' is set in your server.cfg" fi - if [ -z "${NO_DEFAULT_CONFIG}"] && [ -z "${LICENSE_KEY}" ]; then - >&2 printf "License key not found in environment, please create one at https://keymaster.fivem.net!\n" - exit 1 - fi + # English is hard + if [ -z "${NO_LICENSE_KEY}${NO_LICENCE_KEY}" ]; then + if [ -z "${LICENSE_KEY}" ] && [ -n "${LICENCE_KEY}" ]; then + LICENSE_KEY="${LICENCE_KEY}" + fi - if [ -z "${CONFIG_ARGS}" ] && [ -n "${LICENSE_KEY}" ] && [ -n "${NO_DEFAULT_CONFIG}" ]; then - >&2 printf "txAdmin does not use the \$LICENSE_KEY environment variable.\nPlease remove it and set it through the txadmin web UI\n\n" - exit 1 - fi + if [ -z "${NO_DEFAULT_CONFIG}"] && [ -z "${LICENSE_KEY}" ]; then + >&2 printf "License key not found in environment, please create one at https://keymaster.fivem.net!\n" + exit 1 + fi - CONFIG_ARGS="$CONFIG_ARGS +set sv_licenseKey ${LICENSE_KEY}" + if [ -z "${CONFIG_ARGS}" ] && [ -n "${LICENSE_KEY}" ] && [ -n "${NO_DEFAULT_CONFIG}" ]; then + >&2 printf "txAdmin does not use the \$LICENSE_KEY environment variable.\nPlease remove it and set it through the txadmin web UI\n\n" + exit 1 + fi + + CONFIG_ARGS="$CONFIG_ARGS +set sv_licenseKey ${LICENSE_KEY}" + fi fi fi