WIP XML merging. Handle files without XML document node, as well as without their root node. This means we need a matrix of what file has what root node AND the names of the child nodes!

This commit is contained in:
Daniel Ceregatti 2023-05-19 23:41:34 -07:00
parent ebf961bb73
commit 92f9598910

View file

@ -147,38 +147,51 @@ report() {
mergexml(){
# Start with the upstream XML files from a pristine mpmissions directory
echo "Copying upstream XML files from mpmissions..."
pushd /mpmissions > /dev/null
for var in CFGEVENTSPAWNS CFGSPAWNABLETYPES EVENTS TYPES
ffff for var in CFGEVENTSPAWNS CFGSPAWNABLETYPES EVENTS TYPES
do
find -name "${var,,}.xml" -exec cp -vf {} ${SERVER_FILES}/mpmissions/{} \;
find /mpmissions -name "${var,,}.xml" -exec cp -vf {} ${SERVER_FILES}/{} \;
done
for link in $(ls -tdr ${SERVER_PROFILE}/@* 2> /dev/null)
do
ID=$(readlink ${link} | awk -F/ '{print $NF}')
MODNAME=$(get_mod_name ${ID})
# for var in CFGEVENTSPAWNS CFGSPAWNABLETYPES EVENTS TYPES
for var in EVENTS TYPES
# 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 "Merging ${WORKSHOP_DIR}/${ID}/${var,,}.xml..."
if ! grep -q '<?xml' ${WORKSHOP_DIR}/${ID}/${var,,}.xml
cp ${WORKSHOP_DIR}/${ID}/${var,,}.xml /tmp/x
if ! grep -q '<'${CHECK}'>' /tmp/x
then
# When we have no XML or root node
echo "The file has no root node"
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
}
# 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
fi
if ! grep -q '<?xml' ${WORKSHOP_DIR}/${ID}/${var,,}.xml
then
# When we have no XML node
else
# When it's normalized
xmlstarlet ed -s / -t elem -n "eventposdef" -m /event /eventposdef ${WORKSHOP_DIR}/${ID}/${var,,}.xml
fi
fi
done
done
popd > /dev/null
exit 0
}