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:
|
volumes:
|
||||||
# For steamcmd files and resource files used by the scripts
|
# For steamcmd files and resource files used by the scripts
|
||||||
homedir_main:
|
homedir_main:
|
||||||
# For workshop.cfg, for now
|
# For Steam, for now
|
||||||
homedir_server:
|
homedir_server:
|
||||||
# Where the server files will be installed
|
# Where the server files will be installed
|
||||||
serverfiles:
|
serverfiles:
|
||||||
|
|
|
@ -4,6 +4,7 @@ source /files/dz-common
|
||||||
|
|
||||||
# Server container base directories
|
# Server container base directories
|
||||||
SERVER_PROFILE="/profiles"
|
SERVER_PROFILE="/profiles"
|
||||||
|
MPMISSIONS="${SERVER_FILES}/mpmissions"
|
||||||
|
|
||||||
mkdir -p ${SERVER_PROFILE}/battleye
|
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.
|
# 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"
|
parameters="-config=${SERVER_CFG_DST} -port=${port} -freezecheck -BEpath=${SERVER_PROFILE}/battleye -profiles=${SERVER_PROFILE} -nologs"
|
||||||
|
|
||||||
# Used to check if dayZ is installed
|
# Where mods are 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}"
|
|
||||||
WORKSHOP_DIR="/mods/${release_client_appid}"
|
WORKSHOP_DIR="/mods/${release_client_appid}"
|
||||||
mod_command_line=""
|
mod_command_line=""
|
||||||
|
|
||||||
|
@ -145,50 +142,54 @@ report() {
|
||||||
}
|
}
|
||||||
|
|
||||||
mergexml(){
|
mergexml(){
|
||||||
# Start with the upstream XML files from a pristine mpmissions directory
|
# First copy the pristine files from upstream
|
||||||
echo "Copying upstream XML files from mpmissions..."
|
echo "Copying pristine versions of cfgeconomycore.xml and cfgeventspawns.xml..."
|
||||||
for var in CFGEVENTSPAWNS CFGSPAWNABLETYPES EVENTS TYPES
|
find /mpmissions -name cfgeconomycore.xml -exec cp {} ${SERVER_FILES}{} \;
|
||||||
do
|
# find /mpmissions -name cfgeventspawns.xml -exec cp {} ${SERVER_FILES}{} \;
|
||||||
find /mpmissions -name "${var,,}.xml" -exec cp -vf {} ${SERVER_FILES}/{} \;
|
|
||||||
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)
|
for link in $(ls -tdr ${SERVER_PROFILE}/@* 2> /dev/null)
|
||||||
do
|
do
|
||||||
ID=$(readlink ${link} | awk -F/ '{print $NF}')
|
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
|
||||||
# Going to have to maintain a matrix of file names -> root node -> child node permutations
|
C=""
|
||||||
for i in "CFGEVENTSPAWNS:eventposdef:event" "CFGSPAWNABLETYPES:spawnabletypes:type" "EVENTS:events:event" "TYPES:types:type"
|
for i in "CFGSPAWNABLETYPES:spawnabletypes:type" "EVENTS:events:event" "TYPES:types:type"
|
||||||
do
|
do
|
||||||
var=$(echo ${i} | cut -d: -f1)
|
var=$(echo ${i} | cut -d: -f1)
|
||||||
CHECK=$(echo ${i} | cut -d: -f2)
|
CHECK=$(echo ${i} | cut -d: -f2)
|
||||||
CHILD=$(echo ${i} | cut -d: -f3)
|
CHILD=$(echo ${i} | cut -d: -f3)
|
||||||
if [ -f "${WORKSHOP_DIR}/${ID}/${var,,}.xml" ]
|
if [ -f "${WORKSHOP_DIR}/${ID}/${var,,}.xml" ]
|
||||||
then
|
then
|
||||||
echo "Merging ${WORKSHOP_DIR}/${ID}/${var,,}.xml..."
|
FOUND=1
|
||||||
cp ${WORKSHOP_DIR}/${ID}/${var,,}.xml /tmp/x
|
echo "Adding ${WORKSHOP_DIR}/${ID}/${var,,}.xml to cfgeconomycore..."
|
||||||
|
for dir in $(ls ${MPMISSIONS})
|
||||||
if ! grep -q '<'${CHECK}'>' /tmp/x
|
do
|
||||||
then
|
mkdir -pv ${MPMISSIONS}/${dir}/${ID}
|
||||||
echo " - has no root node <${CHECK}>. fixing..."
|
cp -v ${WORKSHOP_DIR}/${ID}/${var,,}.xml ${MPMISSIONS}/${dir}/${ID}/${var,,}.xml
|
||||||
xmlstarlet ed -s / -t elem -n "${CHECK}" -m /${CHILD} /${CHECK} /tmp/x > /tmp/y
|
done
|
||||||
mv /tmp/y /tmp/x
|
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
|
fi
|
||||||
|
done
|
||||||
if ! grep -q '<?xml' /tmp/x
|
if [[ ${C} != "" ]]
|
||||||
then
|
then
|
||||||
echo " - has no XML node, fixing..."
|
# Merge into every mpmissions file
|
||||||
xmlstarlet fo /tmp/x > /tmp/y
|
find ${MPMISSIONS} -name cfgeconomycore.xml -exec \
|
||||||
mv /tmp/y /tmp/x
|
xmlstarlet ed -L -s / -t elem -n ce \
|
||||||
fi
|
-a /ce -t attr -n folder -v "${ID}" \
|
||||||
|
${C} \
|
||||||
xmllint --noout /tmp/x || {
|
-m /ce /economycore {} \;
|
||||||
echo "The final file failed lint tests, aborting..."
|
fi
|
||||||
exit 1
|
# These still have to be merged into the upstream file
|
||||||
}
|
for i in "CFGEVENTSPAWNS:eventposdef:event"
|
||||||
|
do
|
||||||
# At this point it's normalized. Merge to the mpmissions file.
|
var=$(echo ${i} | cut -d: -f1)
|
||||||
echo " - merging to mpmissions..."
|
CHECK=$(echo ${i} | cut -d: -f2)
|
||||||
# xmlstarlet ed -s / -t elem -n "eventposdef" -m /event /eventposdef ${WORKSHOP_DIR}/${ID}/${var,,}.xml
|
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
|
fi
|
||||||
done
|
done
|
||||||
done
|
done
|
||||||
|
@ -201,7 +202,7 @@ start(){
|
||||||
report
|
report
|
||||||
' EXIT
|
' EXIT
|
||||||
get_mods
|
get_mods
|
||||||
mergexml
|
# mergexml
|
||||||
cd ${SERVER_FILES}
|
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
|
# 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.
|
# safely shut the container down without killing the server within.
|
||||||
|
@ -404,7 +405,7 @@ Working mod parameter: ${mod_command_line}"
|
||||||
}
|
}
|
||||||
|
|
||||||
backup(){
|
backup(){
|
||||||
cd "${SERVER_FILES}"/mpmissions
|
cd ${MPMISSIONS}
|
||||||
DATE=$(date +'%Y-%m-%d-%H-%M-%S')
|
DATE=$(date +'%Y-%m-%d-%H-%M-%S')
|
||||||
for i in $(ls)
|
for i in $(ls)
|
||||||
do
|
do
|
||||||
|
|
|
@ -32,7 +32,8 @@ RUN apt-get update && apt-get -y upgrade && apt-get -y install --no-install-reco
|
||||||
python3-pip \
|
python3-pip \
|
||||||
wget \
|
wget \
|
||||||
rename \
|
rename \
|
||||||
steamcmd
|
steamcmd \
|
||||||
|
xmlstarlet
|
||||||
|
|
||||||
RUN update-alternatives --install /usr/bin/python python /usr/bin/python3.9 1
|
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
|
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
|
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
|
s|status - Shows Steam login status, if base files are installed, installed mods
|
||||||
u|update - Update the server files
|
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}"
|
${default}"
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
@ -32,6 +33,7 @@ ${default}"
|
||||||
# "Manage" XML files.
|
# "Manage" XML files.
|
||||||
xml(){
|
xml(){
|
||||||
/files/mods/xml.sh ${1}
|
/files/mods/xml.sh ${1}
|
||||||
|
mergexml ${1}
|
||||||
}
|
}
|
||||||
|
|
||||||
# Copy mod keys
|
# Copy mod keys
|
||||||
|
@ -57,6 +59,41 @@ symlink(){
|
||||||
fi
|
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 a mod
|
||||||
add(){
|
add(){
|
||||||
if [ -d "${WORKSHOP_DIR}/${1}" ]
|
if [ -d "${WORKSHOP_DIR}/${1}" ]
|
||||||
|
@ -86,6 +123,7 @@ add(){
|
||||||
# Copy the key files
|
# Copy the key files
|
||||||
copy_keys 1 ${1}
|
copy_keys 1 ${1}
|
||||||
echo -e "Mod id ${1} - ${green}${MODNAME}${default} - added"
|
echo -e "Mod id ${1} - ${green}${MODNAME}${default} - added"
|
||||||
|
mergexml ${ID}
|
||||||
# checkTypesXML ${1} install
|
# checkTypesXML ${1} install
|
||||||
# checkInstall ${1} install
|
# checkInstall ${1} install
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue