mirror of
https://ceregatti.org/git/daniel/dayzdockerserver.git
synced 2025-05-06 14:21:18 +00:00
First version where XML merging is working using the cfgeconomy method!
Split up the XML wrangling between the two containers. This means the web one needs xmlstarlet.
This commit is contained in:
parent
3a41001b9f
commit
f755b6fe6d
4 changed files with 84 additions and 44 deletions
|
@ -3,7 +3,7 @@ version: "3.3"
|
|||
volumes:
|
||||
# For steamcmd files and resource files used by the scripts
|
||||
homedir_main:
|
||||
# For workshop.cfg, for now
|
||||
# For Steam, for now
|
||||
homedir_server:
|
||||
# Where the server files will be installed
|
||||
serverfiles:
|
||||
|
|
|
@ -4,6 +4,7 @@ source /files/dz-common
|
|||
|
||||
# Server container base directories
|
||||
SERVER_PROFILE="/profiles"
|
||||
MPMISSIONS="${SERVER_FILES}/mpmissions"
|
||||
|
||||
mkdir -p ${SERVER_PROFILE}/battleye
|
||||
|
||||
|
@ -15,11 +16,7 @@ SERVER_CFG_SRC="${FILES}/${SERVER_CFG_FILE}"
|
|||
# Command line parameters except mod, as that is handled separately.
|
||||
parameters="-config=${SERVER_CFG_DST} -port=${port} -freezecheck -BEpath=${SERVER_PROFILE}/battleye -profiles=${SERVER_PROFILE} -nologs"
|
||||
|
||||
# Used to check if dayZ is installed
|
||||
SERVER_INSTALL_FILE="${SERVER_FILES}/DayZServer"
|
||||
|
||||
# An array to store Workshop items. Each element contains the mod's ID, name, and state (active or not).
|
||||
#WORKSHOP_DIR="${SERVER_FILES}/steamapps/workshop/content/${release_client_appid}"
|
||||
# Where mods are installed.
|
||||
WORKSHOP_DIR="/mods/${release_client_appid}"
|
||||
mod_command_line=""
|
||||
|
||||
|
@ -145,50 +142,54 @@ report() {
|
|||
}
|
||||
|
||||
mergexml(){
|
||||
# Start with the upstream XML files from a pristine mpmissions directory
|
||||
echo "Copying upstream XML files from mpmissions..."
|
||||
for var in CFGEVENTSPAWNS CFGSPAWNABLETYPES EVENTS TYPES
|
||||
do
|
||||
find /mpmissions -name "${var,,}.xml" -exec cp -vf {} ${SERVER_FILES}/{} \;
|
||||
done
|
||||
# First copy the pristine files from upstream
|
||||
echo "Copying pristine versions of cfgeconomycore.xml and cfgeventspawns.xml..."
|
||||
find /mpmissions -name cfgeconomycore.xml -exec cp {} ${SERVER_FILES}{} \;
|
||||
# find /mpmissions -name cfgeventspawns.xml -exec cp {} ${SERVER_FILES}{} \;
|
||||
|
||||
# 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}')
|
||||
MODNAME=$(get_mod_name ${ID})
|
||||
# Going to have to maintain a matrix of file names -> root node -> child node permutations
|
||||
for i in "CFGEVENTSPAWNS:eventposdef:event" "CFGSPAWNABLETYPES:spawnabletypes:type" "EVENTS:events:event" "TYPES:types:type"
|
||||
C=""
|
||||
for i in "CFGSPAWNABLETYPES:spawnabletypes:type" "EVENTS:events:event" "TYPES:types:type"
|
||||
do
|
||||
var=$(echo ${i} | cut -d: -f1)
|
||||
CHECK=$(echo ${i} | cut -d: -f2)
|
||||
CHILD=$(echo ${i} | cut -d: -f3)
|
||||
if [ -f "${WORKSHOP_DIR}/${ID}/${var,,}.xml" ]
|
||||
then
|
||||
echo "Merging ${WORKSHOP_DIR}/${ID}/${var,,}.xml..."
|
||||
cp ${WORKSHOP_DIR}/${ID}/${var,,}.xml /tmp/x
|
||||
|
||||
if ! grep -q '<'${CHECK}'>' /tmp/x
|
||||
then
|
||||
echo " - has no root node <${CHECK}>. fixing..."
|
||||
xmlstarlet ed -s / -t elem -n "${CHECK}" -m /${CHILD} /${CHECK} /tmp/x > /tmp/y
|
||||
mv /tmp/y /tmp/x
|
||||
FOUND=1
|
||||
echo "Adding ${WORKSHOP_DIR}/${ID}/${var,,}.xml to cfgeconomycore..."
|
||||
for dir in $(ls ${MPMISSIONS})
|
||||
do
|
||||
mkdir -pv ${MPMISSIONS}/${dir}/${ID}
|
||||
cp -v ${WORKSHOP_DIR}/${ID}/${var,,}.xml ${MPMISSIONS}/${dir}/${ID}/${var,,}.xml
|
||||
done
|
||||
C+="-s / -t elem -n file -a /file -t attr -n name -v ${var,,}.xml -a /file -t attr -n type -v ${CHECK} -m /file /ce "
|
||||
fi
|
||||
|
||||
if ! grep -q '<?xml' /tmp/x
|
||||
done
|
||||
if [[ ${C} != "" ]]
|
||||
then
|
||||
echo " - has no XML node, fixing..."
|
||||
xmlstarlet fo /tmp/x > /tmp/y
|
||||
mv /tmp/y /tmp/x
|
||||
# Merge into every mpmissions file
|
||||
find ${MPMISSIONS} -name cfgeconomycore.xml -exec \
|
||||
xmlstarlet ed -L -s / -t elem -n ce \
|
||||
-a /ce -t attr -n folder -v "${ID}" \
|
||||
${C} \
|
||||
-m /ce /economycore {} \;
|
||||
fi
|
||||
|
||||
xmllint --noout /tmp/x || {
|
||||
echo "The final file failed lint tests, aborting..."
|
||||
exit 1
|
||||
}
|
||||
|
||||
# At this point it's normalized. Merge to the mpmissions file.
|
||||
echo " - merging to mpmissions..."
|
||||
# xmlstarlet ed -s / -t elem -n "eventposdef" -m /event /eventposdef ${WORKSHOP_DIR}/${ID}/${var,,}.xml
|
||||
|
||||
# These still have to be merged into the upstream file
|
||||
for i in "CFGEVENTSPAWNS:eventposdef:event"
|
||||
do
|
||||
var=$(echo ${i} | cut -d: -f1)
|
||||
CHECK=$(echo ${i} | cut -d: -f2)
|
||||
CHILD=$(echo ${i} | cut -d: -f3)
|
||||
if [ -f "${WORKSHOP_DIR}/${ID}/${var,,}.xml" ]
|
||||
then
|
||||
echo "Merging ${var,,}.xml..."
|
||||
# xmlstarlet ed -L -s / -t name event
|
||||
fi
|
||||
done
|
||||
done
|
||||
|
@ -201,7 +202,7 @@ start(){
|
|||
report
|
||||
' EXIT
|
||||
get_mods
|
||||
mergexml
|
||||
# mergexml
|
||||
cd ${SERVER_FILES}
|
||||
# Run the server. Allow docker to restart the container if the script exits with a code other than 0. This is so we can
|
||||
# safely shut the container down without killing the server within.
|
||||
|
@ -404,7 +405,7 @@ Working mod parameter: ${mod_command_line}"
|
|||
}
|
||||
|
||||
backup(){
|
||||
cd "${SERVER_FILES}"/mpmissions
|
||||
cd ${MPMISSIONS}
|
||||
DATE=$(date +'%Y-%m-%d-%H-%M-%S')
|
||||
for i in $(ls)
|
||||
do
|
||||
|
|
|
@ -32,7 +32,8 @@ RUN apt-get update && apt-get -y upgrade && apt-get -y install --no-install-reco
|
|||
python3-pip \
|
||||
wget \
|
||||
rename \
|
||||
steamcmd
|
||||
steamcmd \
|
||||
xmlstarlet
|
||||
|
||||
RUN update-alternatives --install /usr/bin/python python /usr/bin/python3.9 1
|
||||
RUN update-alternatives --install /usr/bin/pip pip /usr/bin/pip3 1
|
||||
|
|
38
web/bin/dz
38
web/bin/dz
|
@ -25,6 +25,7 @@ Options and arguments:
|
|||
r|remove id - Remove all files and directories of a Workshop item by id
|
||||
s|status - Shows Steam login status, if base files are installed, installed mods
|
||||
u|update - Update the server files
|
||||
x|xml id - Get and normalize XML files from a mod's template by id (Presumes template exists)
|
||||
${default}"
|
||||
exit 1
|
||||
}
|
||||
|
@ -32,6 +33,7 @@ ${default}"
|
|||
# "Manage" XML files.
|
||||
xml(){
|
||||
/files/mods/xml.sh ${1}
|
||||
mergexml ${1}
|
||||
}
|
||||
|
||||
# Copy mod keys
|
||||
|
@ -57,6 +59,41 @@ symlink(){
|
|||
fi
|
||||
}
|
||||
|
||||
mergexml(){
|
||||
ID=${1}
|
||||
# Going to have to maintain a matrix of file names -> root node -> child node permutations
|
||||
for i in "CFGEVENTSPAWNS:eventposdef:event" "CFGSPAWNABLETYPES:spawnabletypes:type" "EVENTS:events:event" "TYPES:types:type"
|
||||
do
|
||||
var=$(echo ${i} | cut -d: -f1)
|
||||
CHECK=$(echo ${i} | cut -d: -f2)
|
||||
CHILD=$(echo ${i} | cut -d: -f3)
|
||||
if [ -f "${WORKSHOP_DIR}/${ID}/${var,,}.xml" ]
|
||||
then
|
||||
echo "Normalizing ${WORKSHOP_DIR}/${ID}/${var,,}.xml..."
|
||||
cp ${WORKSHOP_DIR}/${ID}/${var,,}.xml /tmp/x
|
||||
if ! grep -q '<'${CHECK}'>' /tmp/x
|
||||
then
|
||||
echo " - has no root node <${CHECK}>. fixing..."
|
||||
xmlstarlet ed -s / -t elem -n "${CHECK}" -m /${CHILD} /${CHECK} /tmp/x > /tmp/y
|
||||
mv /tmp/y /tmp/x
|
||||
fi
|
||||
if ! grep -q '<?xml' /tmp/x
|
||||
then
|
||||
echo " - has no XML node, fixing..."
|
||||
xmlstarlet fo /tmp/x > /tmp/y
|
||||
mv /tmp/y /tmp/x
|
||||
fi
|
||||
xmllint --noout /tmp/x || {
|
||||
echo "The final file failed lint tests, aborting..."
|
||||
exit 1
|
||||
}
|
||||
# Keep the normalized version in the /mods directory, where they should have been from the start
|
||||
cp /tmp/x ${WORKSHOP_DIR}/${ID}/${var,,}.xml
|
||||
fi
|
||||
done
|
||||
exit 0
|
||||
}
|
||||
|
||||
# Add a mod
|
||||
add(){
|
||||
if [ -d "${WORKSHOP_DIR}/${1}" ]
|
||||
|
@ -86,6 +123,7 @@ add(){
|
|||
# Copy the key files
|
||||
copy_keys 1 ${1}
|
||||
echo -e "Mod id ${1} - ${green}${MODNAME}${default} - added"
|
||||
mergexml ${ID}
|
||||
# checkTypesXML ${1} install
|
||||
# checkInstall ${1} install
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue