Fix lack of root node in XML when normalizing.

Refine output to only show relevant info when starting the server.
Filter mod integration by current map, even if other mpmissions directories should exist.
Remove previous cfgeconomy directories when starting, to prevent previous files from possibly existing.
Orchestrate the retrieval and normalization of XML files as 'dz x ID' now does both.
This commit is contained in:
Daniel Ceregatti 2023-09-08 12:13:29 -07:00
parent 974550da94
commit e6a381315f
2 changed files with 58 additions and 34 deletions

View file

@ -128,10 +128,13 @@ mergexml(){
# First copy the pristine files from upstream # First copy the pristine files from upstream
for i in cfgeconomycore.xml #cfgeventspawns.xml for i in cfgeconomycore.xml #cfgeventspawns.xml
do do
echo "Copying pristine version of ${i} into local mpmission(s)..." echo "Copying pristine version of ${i} into local mpmission ${MAP}..."
for dir in $(ls -d ${MPMISSIONS}/*) for dir in $(ls -d ${MPMISSIONS}/*)
do do
#echo "dir: ${dir}, basename: $(basename ${dir})" if [[ ${dir} != ${MAP} ]]
then
continue
fi
find /mpmissions/$(basename ${dir}) -name ${i} -exec cp -v {} ${SERVER_FILES}{} \; find /mpmissions/$(basename ${dir}) -name ${i} -exec cp -v {} ${SERVER_FILES}{} \;
done done
done done
@ -143,6 +146,7 @@ mergexml(){
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 # Going to have to maintain a matrix of file names -> root node -> child node permutations
C="" C=""
FOUND=0
for i in "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)
@ -150,11 +154,22 @@ mergexml(){
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
if [[ ${FOUND} = 0 ]]
then
MODNAME=$(get_mod_name ${ID})
echo " Adding mod ${MODNAME}"
FOUND=1 FOUND=1
echo "Adding ${WORKSHOP_DIR}/${ID}/${var,,}.xml to cfgeconomycore..." fi
echo -n " "
for dir in $(ls ${MPMISSIONS}) for dir in $(ls ${MPMISSIONS})
do do
mkdir -pv ${MPMISSIONS}/${dir}/${ID} # Only copy for the current map
if [[ ${dir} != ${MAP} ]]
then
continue
fi
rm -rf ${MPMISSIONS}/${dir}/${ID}
mkdir -p ${MPMISSIONS}/${dir}/${ID}
cp -v ${WORKSHOP_DIR}/${ID}/${var,,}.xml ${MPMISSIONS}/${dir}/${ID}/${var,,}.xml cp -v ${WORKSHOP_DIR}/${ID}/${var,,}.xml ${MPMISSIONS}/${dir}/${ID}/${var,,}.xml
done 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 " 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 "
@ -170,17 +185,17 @@ mergexml(){
-m /ce /economycore {} \; -m /ce /economycore {} \;
fi fi
# These still have to be merged into the upstream file # These still have to be merged into the upstream file
for i in "CFGEVENTSPAWNS:eventposdef:event" # for i in "CFGEVENTSPAWNS:eventposdef:event"
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 ${var,,}.xml..." # echo "Merging ${var,,}.xml (Not really...WIP)"
# xmlstarlet ed -L -s / -t name event # xmlstarlet ed -L -s / -t name event
fi # fi
done # done
done done
} }
@ -329,6 +344,16 @@ activelist(){
fi fi
} }
get_map_name(){
MAP="none"
# Map name
if [[ -f ${SERVER_CFG_DST} ]]
then
MAP=$(grep -E "template=" ${SERVER_CFG_DST} | grep -vE "^//" | cut -d= -f2 | cut -d\; -f1 | tr -d '"')
fi
echo ${MAP}
}
# Display the status of everything # Display the status of everything
status(){ status(){
loadconfig loadconfig
@ -354,13 +379,7 @@ status(){
# Current parameters # Current parameters
RUNNING="${RUNNING}\nRunning Parameters: $(cat /tmp/parameters)\nRunning mod parameter: $(cat /tmp/mod_command_line)" RUNNING="${RUNNING}\nRunning Parameters: $(cat /tmp/parameters)\nRunning mod parameter: $(cat /tmp/mod_command_line)"
fi fi
MAP=$(get_map_name)
MAP="none"
# Map name
if [[ -f ${SERVER_CFG_DST} ]]
then
MAP=$(grep -E "template=" ${SERVER_CFG_DST} | grep -vE "^//")
fi
# Number of mods plus the list denoting on or off # Number of mods plus the list denoting on or off
echo -ne " echo -ne "
Server files installed: ${INSTALLED}" Server files installed: ${INSTALLED}"
@ -393,11 +412,13 @@ backup(){
do do
B="${BACKUP_DIR}/${DATE}/" B="${BACKUP_DIR}/${DATE}/"
echo "Backing up ${i} to ${B}..." echo "Backing up ${i} to ${B}..."
mkdir -p ${B} mkdir -p ${B} 1> /dev/null
cp -a "${i}" "${B}" cp -a "${i}" "${B}"
done done
} }
MAP=$(get_map_name)
# Capture the first argument and shift it off so we can pass $@ to every function # Capture the first argument and shift it off so we can pass $@ to every function
C=${1} C=${1}
shift || { shift || {

View file

@ -64,8 +64,10 @@ installxml(){
if ! grep -q '<'${CHECK}'>' /tmp/x if ! grep -q '<'${CHECK}'>' /tmp/x
then then
echo " - has no root node <${CHECK}>. fixing..." echo " - has no root node <${CHECK}>. fixing..."
xmlstarlet ed -s / -t elem -n "${CHECK}" -m /${CHILD} /${CHECK} /tmp/x > /tmp/y echo '<'${CHECK}'>' > /tmp/y
mv /tmp/y /tmp/x cat /tmp/x >> /tmp/y
echo '</'${CHECK}'>' >> /tmp/y
xmlstarlet fo /tmp/y > /tmp/x
fi fi
if ! grep -q '<?xml' /tmp/x if ! grep -q '<?xml' /tmp/x
then then
@ -73,12 +75,13 @@ installxml(){
xmlstarlet fo /tmp/x > /tmp/y xmlstarlet fo /tmp/x > /tmp/y
mv /tmp/y /tmp/x mv /tmp/y /tmp/x
fi fi
xmllint --noout /tmp/x || { xmllint --noout /tmp/x && (
echo "The final file failed lint tests, aborting..." # Keep the normalized version in the /mods directory
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 cp /tmp/x ${WORKSHOP_DIR}/${ID}/${var,,}.xml
echo -e "${green}${WORKSHOP_DIR}/${ID}/${var,,}.xml passes XML lint test!${default}"
) || (
echo -e "${yellow}The final ${WORKSHOP_DIR}/${ID}/${var,,}.xml does not pass XML lint test! IT WAS NOT COPIED!${default}"
)
fi fi
done done
exit 0 exit 0
@ -301,7 +304,7 @@ mod_install(){
# "Manage" XML files. # "Manage" XML files.
xml(){ xml(){
/files/bin/xml.sh ${1} /files/bin/xml.sh ${1}
#installxml ${1} installxml ${1}
} }
# Capture the first argument and shift it off so we can pass $@ to every function # Capture the first argument and shift it off so we can pass $@ to every function