From 887374587df8efeddb6dc840f7058b9c40014363 Mon Sep 17 00:00:00 2001 From: Daniel Ceregatti Date: Thu, 7 Sep 2023 12:08:12 -0700 Subject: [PATCH] There are no mpmissions in the server container when it starts for the first time. Ensure Chernarus is copied over as a default when this is detected, as the server is expected to start successfully. Presumes a default config where the map hasn't been changed. Make development work by setting an environment variable. Set the web container to restart instead of not, should the express server crash. Copy XML files that are merged when the server starts only when the mpmissions directory exists. Refactor XML functions for better naming. Handle display of lists when no mods are installed. Add support for adding mpmissions for Deer Isle and mpmissions in general via mod integrations. Add support for Red Falcon Watercraft XML files. WIP. Add a deer isle DayZ bicycle spawn file. --- docker-compose.yml | 18 +++++++----- files/bin/dz-common | 67 ++++++++++++++++++++++++-------------------- files/bin/install.sh | 20 ++++++------- files/bin/xml.sh | 5 ++++ server/bin/dz | 28 ++++++++++++------ server/start.sh | 9 ++---- web/bin/dz | 30 ++++++++++++-------- 7 files changed, 102 insertions(+), 75 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 9446357..a985ba8 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -32,7 +32,7 @@ services: ports: - "8001:8001/tcp" - "8000:8000/tcp" - restart: no + restart: always environment: # The use of the Steam API in the (very incomplete) web app requires a key. Get yours here: https://steamcommunity.com/dev/apikey - STEAMAPIKEY=YOUR_STEAM_API_KEY_HERE @@ -63,11 +63,15 @@ services: # - 27016:27016/udp # Always restart, unless stopped restart: unless-stopped + environment: + # To prevent the server from starting to allow for development, set this to 1 + - DEVELOPMENT=0 # Allows attaching a debugger from the host - cap_add: - - SYS_PTRACE +# cap_add: +# - SYS_PTRACE # Allows core files to be created within the container. These are VERY LARGE! Enable only for debugging! - ulimits: - core: - soft: -1 - hard: -1 + # One must also set the sysctl kernel.core_pattern parameter ON THE HOST to a path that is writable within the container. YMMV +# ulimits: +# core: +# soft: -1 +# hard: -1 diff --git a/files/bin/dz-common b/files/bin/dz-common index 868148c..dbd24a0 100755 --- a/files/bin/dz-common +++ b/files/bin/dz-common @@ -67,15 +67,20 @@ prompt_yn(){ # List mods list(){ X=1 - C="${green}" + C="${green}" spaces=" " - echo - echo -e " ID Name URL Size" - echo "------------------------------------------------------------------------------------------------------------------------" - for link in $(ls -d ${SERVER_FILES}/@* | sort) - do + FIRST=1 + for link in $(ls -d ${SERVER_FILES}/@* 2> /dev/null | sort) + do + if [[ ${FIRST} = 1 ]] + then + echo + echo -e " ID Name URL Size" + echo "------------------------------------------------------------------------------------------------------------------------" + FIRST=0 + fi ID=$(readlink ${link} | awk -F/ '{print $NF}') - MODNAME=$(get_mod_name ${ID}) + MODNAME=$(get_mod_name ${ID}) SIZE=$(du -sh "${WORKSHOP_DIR}/${ID}" | awk '{print $1}') printf "${C}%.3d %s %.30s %s https://steamcommunity.com/sharedfiles/filedetails/?id=%s %s${default}\n" ${X} ${ID} "${MODNAME}" "${spaces:${#MODNAME}+1}" ${ID} ${SIZE} X=$((X+1)) @@ -102,19 +107,19 @@ get_mod_id(){ echo -n ${1} return fi - # If we have a second argument, we want to iterate over active server mods - DIR=${SERVER_FILES} - ARG="-d" - if [[ ${2} = "0" ]] - then - ARG="-tdr" - DIR=${SERVER_PROFILE} - fi -# echo "DIR: ${DIR}, ARG: ${ARG}" >&2 + # If we have a second argument, we want to iterate over active server mods + DIR=${SERVER_FILES} + ARG="-d" + if [[ ${2} = "0" ]] + then + ARG="-tdr" + DIR=${SERVER_PROFILE} + fi +# echo "DIR: ${DIR}, ARG: ${ARG}" >&2 X=1 # Loop over mods - for link in $(ls ${ARG} ${DIR}/@* 2> /dev/null) - do + for link in $(ls ${ARG} ${DIR}/@* 2> /dev/null) + do ID=$(readlink ${link} | awk -F/ '{print $NF}') if [[ ${X} = ${1} ]] then @@ -127,27 +132,27 @@ get_mod_id(){ get_mods(){ workshoplist="" - for link in $(ls -d ${SERVER_FILES}/@* 2> /dev/null | sort) - do + for link in $(ls -d ${SERVER_FILES}/@* 2> /dev/null | sort) + do ID=$(readlink ${link} | awk -F/ '{print $NF}') MODNAME=$(get_mod_name ${ID}) workshoplist+=" +workshop_download_item "${release_client_appid}" "${ID} - done - get_mod_command_line + done + get_mod_command_line } get_mod_command_line(){ - mod_command_line="" - for link in $(ls -tdr ${SERVER_PROFILE}/@* 2> /dev/null) - do + mod_command_line="" + for link in $(ls -tdr ${SERVER_PROFILE}/@* 2> /dev/null) + do ID=$(readlink ${link} | awk -F/ '{print $NF}') MODNAME=$(get_mod_name ${ID}) - mod_command_line+="@${MODNAME};" - done - if [[ ${mod_command_line} != "" ]] - then - mod_command_line='-mod='${mod_command_line::-1} - fi + mod_command_line+="@${MODNAME};" + done + if [[ ${mod_command_line} != "" ]] + then + mod_command_line='-mod='${mod_command_line::-1} + fi } # Copy mod keys diff --git a/files/bin/install.sh b/files/bin/install.sh index 3ce30b1..719d434 100755 --- a/files/bin/install.sh +++ b/files/bin/install.sh @@ -2,27 +2,27 @@ set -eE -source /files/mods/${1}/install.env +if [ -f /files/mods/${1}/install.env ] +then + source /files/mods/${1}/install.env +else + echo "install.env not found for mod id ${1}..." + exit 1 +fi -echo if [[ ${2} = "uninstall" ]] then echo "Backing up, as uninstalling will remove the ${MAP} mpmissions directory" - dayzserver backup - echo "Uninstalling mpmissions..." - echo + dz backup rm -rf ${SERVER_FILES}/mpmissions/${MPDIR} elif [[ ${2} = "update" ]] then - echo "Updating mpmissions directory..." - echo cd /tmp git clone ${REPO} 2> /dev/null 1> /dev/null cp -a ${DIR}/${MPDIR} ${SERVER_FILES}/mpmissions rm -rf ${DIR} -else - echo "Installing mpmissions files..." - echo +elif [[ ${2} = "install" ]] +then cd /tmp git clone ${REPO} 2> /dev/null 1> /dev/null cp -a ${DIR}/${MPDIR} ${SERVER_FILES}/mpmissions diff --git a/files/bin/xml.sh b/files/bin/xml.sh index c28193b..6f9e9bb 100755 --- a/files/bin/xml.sh +++ b/files/bin/xml.sh @@ -7,6 +7,11 @@ set -eE ID=${1} +if ! [ -f ${FILES}/mods/${ID}/xml.env ] +then + exit 0 +fi + source ${FILES}/mods/${ID}/xml.env # Iterate over the file names we can handle diff --git a/server/bin/dz b/server/bin/dz index af302ae..093d775 100755 --- a/server/bin/dz +++ b/server/bin/dz @@ -126,15 +126,21 @@ report() { mergexml(){ # First copy the pristine files from upstream - echo "Copying pristine versions of cfgeconomycore.xml and cfgeventspawns.xml..." - find /mpmissions -name cfgeconomycore.xml -exec cp -v {} ${SERVER_FILES}{} \; -# find /mpmissions -name cfgeventspawns.xml -exec cp {} ${SERVER_FILES}{} \; + for i in cfgeconomycore.xml #cfgeventspawns.xml + do + echo "Copying pristine version of ${i} into local mpmission(s)..." + for dir in $(ls -d ${MPMISSIONS}/*) + do + #echo "dir: ${dir}, basename: $(basename ${dir})" + find /mpmissions/$(basename ${dir}) -name ${i} -exec cp -v {} ${SERVER_FILES}{} \; + done + done # Follow https://community.bistudio.com/wiki/DayZ:Central_Economy_mission_files_modding and make a single XML # file for the ones that can go into it. for link in $(ls -tdr ${SERVER_PROFILE}/@* 2> /dev/null) do - ID=$(readlink ${link} | awk -F/ '{print $NF}') + ID=$(readlink ${link} | awk -F/ '{print $NF}') # Going to have to maintain a matrix of file names -> root node -> child node permutations C="" for i in "CFGSPAWNABLETYPES:spawnabletypes:type" "EVENTS:events:event" "TYPES:types:type" @@ -180,13 +186,20 @@ mergexml(){ # Start the server in the foreground start(){ - # Ensure mpmissions has at least one map. If not, block the server from starting + # Ensure mpmissions has at least one map. If not, copy it from the local read-only volume that stores pristine mpmissons directories if [ ! -d "${MPMISSIONS}/dayzOffline.chernarusplus" ] then echo echo "Performing one-time copy of Chernarus mpmissions..." echo - cp -a /mpmission/dayzOffline.chernarusplus ${MPMISSIONS} + cp -av /mpmissions/dayzOffline.chernarusplus ${MPMISSIONS} + fi + # If we're developing, just block the container + if [[ ${DEVELOPMENT} = "1" ]] + then + echo "DEVELOPMENT mode, blocking..." + tail -f /dev/null + exit 0 fi # Do the report on exit. Set here so that it only happens once we're starting the server, and not for other actions. trap ' @@ -422,9 +435,6 @@ case "${C}" in n|rcon) rcon "${@}" ;; - r|remove) - remove "${@}" - ;; r|restart) restart "${@}" ;; diff --git a/server/start.sh b/server/start.sh index 899f5eb..d8749c0 100755 --- a/server/start.sh +++ b/server/start.sh @@ -1,14 +1,11 @@ #!/usr/bin/env bash -# Set PS1 so we know we're in the container +# Set PS1 so we know we're in the container, should we exec into it. cat > .bashrc <