Add function that handles custom installations of mod files, e.g. MMGMightysMilitaryGear, which ships separate types files that must all be used for the mod to work.

This commit is contained in:
Daniel Ceregatti 2025-07-28 16:32:44 -06:00
parent 0f2ecce170
commit 625dce94ec
3 changed files with 55 additions and 45 deletions

View file

@ -114,6 +114,20 @@ get_mod_name(){
echo -n ${NAME} echo -n ${NAME}
} }
# Lint XML files
lint(){
FILE=${1}
ID=${2}
var=${3}
xmllint --noout ${FILE} && (
# Keep the normalized version in the /mods directory
echo -e "${green}The ${var,,} file passes XML lint test! Copying to install location ${WORKSHOP_DIR}/${ID}/${var,,}.xml${default}"
cp -v ${FILE} ${WORKSHOP_DIR}/${ID}/${var,,}.xml
) || (
echo -e "${yellow}The ${var,,} file does not pass XML lint test! IT WAS NOT COPIED!${default}"
)
}
get_mod_id(){ get_mod_id(){
# If we were passed a valid mod id, just return it # If we were passed a valid mod id, just return it
if [ -d "${WORKSHOP_DIR}/${1}" ] if [ -d "${WORKSHOP_DIR}/${1}" ]

View file

@ -1,3 +1,5 @@
# Merge all the XML files into a single types.xml file in the run time mods directory: # Merge all the XML files into a single types.xml file in the run time mods directory:
source /files/bin/dz-common
cd /mods/221100/2663169692/files/types cd /mods/221100/2663169692/files/types
xmlmerge -o /mods/221100/2663169692/types.xml *.xml xmlmerge -o /tmp/x *.xml
lint /tmp/x 2663169692 TYPES

View file

@ -6,7 +6,7 @@ source dz-common
WORKSHOP_DIR="/mods/${release_client_appid}" WORKSHOP_DIR="/mods/${release_client_appid}"
if [ ! -d ${WORKSHOP_DIR} ] if [ ! -d ${WORKSHOP_DIR} ]
then then
mkdir -p ${WORKSHOP_DIR} mkdir -p ${WORKSHOP_DIR}
fi fi
workshoplist="" workshoplist=""
@ -15,7 +15,7 @@ workshoplist=""
# Usage # Usage
usage(){ usage(){
echo -e " echo -e "
${red}Bad option or arguments! ${yellow}${*}${default} ${red}Bad option or arguments! ${yellow}${*}${default}
Usage: ${green}$(basename $0)${yellow} option [ arg1 [ arg2 ] ] Usage: ${green}$(basename $0)${yellow} option [ arg1 [ arg2 ] ]
@ -50,19 +50,19 @@ symlink(){
} }
installxml(){ installxml(){
ID=${1} ID=${1}
# 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
for i in "CFGEVENTGROUPS:eventgroupdef:group" "CFGEVENTSPAWNS:eventposdef:event" "CFGSPAWNABLETYPES:spawnabletypes:type" "EVENTS:events:event" "TYPES:types:type" for i in "CFGEVENTGROUPS:eventgroupdef:group" "CFGEVENTSPAWNS:eventposdef:event" "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)
if [ -f "${WORKSHOP_DIR}/${ID}/${var,,}.xml" ] if [ -f "${WORKSHOP_DIR}/${ID}/${var,,}.xml" ]
then then
echo "Normalizing ${WORKSHOP_DIR}/${ID}/${var,,}.xml..." echo "Normalizing ${WORKSHOP_DIR}/${ID}/${var,,}.xml..."
cp ${WORKSHOP_DIR}/${ID}/${var,,}.xml /tmp/x cp ${WORKSHOP_DIR}/${ID}/${var,,}.xml /tmp/x
# Quirks # Quirks
# Some cfgeventspanws.xml files have <events> instead of <eventposdef>. Let's just try to fix that first. # Some cfgeventspanws.xml files have <events> instead of <eventposdef>. Let's just try to fix that first.
if [[ ${var} = "CFGEVENTSPAWNS" ]] if [[ ${var} = "CFGEVENTSPAWNS" ]]
then then
if grep -q '<events>' /tmp/x if grep -q '<events>' /tmp/x
then then
@ -70,30 +70,23 @@ installxml(){
xmlstarlet ed -L -r "events" -v "eventposdef" /tmp/x xmlstarlet ed -L -r "events" -v "eventposdef" /tmp/x
fi fi
fi fi
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..."
echo '<'${CHECK}'>' > /tmp/y echo '<'${CHECK}'>' > /tmp/y
cat /tmp/x >> /tmp/y cat /tmp/x >> /tmp/y
echo '</'${CHECK}'>' >> /tmp/y echo '</'${CHECK}'>' >> /tmp/y
xmlstarlet fo /tmp/y > /tmp/x xmlstarlet fo /tmp/y > /tmp/x
fi fi
if ! grep -q '<?xml' /tmp/x if ! grep -q '<?xml' /tmp/x
then then
echo " - has no XML node, fixing..." echo " - has no XML node, fixing..."
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 && ( lint /tmp/x ${ID} ${var}
# Keep the normalized version in the /mods directory fi
cp /tmp/x ${WORKSHOP_DIR}/${ID}/${var,,}.xml done
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
done
exit 0
} }
# Add a mod # Add a mod
@ -122,8 +115,8 @@ add(){
symlink 1 ${1} "${MODNAME}" symlink 1 ${1} "${MODNAME}"
echo -e "Mod id ${1} - ${green}${MODNAME}${default} - added" echo -e "Mod id ${1} - ${green}${MODNAME}${default} - added"
xml ${ID} xml ${ID}
map ${ID}
installMod ${ID} installMod ${ID}
map ${ID}
} }
# Remove a mod # Remove a mod
@ -149,11 +142,12 @@ remove(){
# Handle custom scripts after installing a mod # Handle custom scripts after installing a mod
installMod(){ installMod(){
FILE="${WORKSHOP_DIR}/${1:?}/install.sh" FILE="${FILES}/mods/${1}/install.sh"
if [ -f "${FILE}" ] if [ -f "${FILE}" ]
then then
MODNAME=$(get_mod_name ${1}) MODNAME=$(get_mod_name ${1})
echo "Running custom install script ${FILE} for mod id ${1}" echo
echo "Running custom install script for ${MODNAME}"
${FILE} ${FILE}
fi fi
} }
@ -360,8 +354,8 @@ 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