mirror of
https://ceregatti.org/git/daniel/dayzdockerserver.git
synced 2025-05-06 22:31:18 +00:00
Make types.sh be able to handle any XML file with types.xml data.
This commit is contained in:
parent
412b4e692c
commit
6c68dd292f
1 changed files with 58 additions and 23 deletions
|
@ -1,33 +1,68 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
# A generic script to merge a mod's types.xml into all installed missions
|
||||
# A generic script to manage a mod's types.xml against all installed missions
|
||||
|
||||
set -eE
|
||||
|
||||
cd "$(dirname ${0})"
|
||||
|
||||
ID=${1}
|
||||
MODE=${2}
|
||||
TYPES_FILE="${workshopfolder}/${ID}/extras/types.xml"
|
||||
|
||||
echo
|
||||
if [[ ${MODE} = "uninstall" ]]
|
||||
if [[ ${3} != "" ]]
|
||||
then
|
||||
echo "Restoring original types.xml files in missions:"
|
||||
echo
|
||||
for file in $(ls *.orig)
|
||||
do
|
||||
cp -v $(file} ${HOME}/serverfiles/mpmissions/${file/.orig/}/db/types.xml
|
||||
done
|
||||
else
|
||||
echo "Merging extras/types.xml to server missions directory:"
|
||||
echo
|
||||
cp -v ${HOME}/serverfiles/steamapps/workshop/content/221100/${ID}/extras/types.xml .
|
||||
for dir in $(ls ${HOME}/serverfiles/mpmissions)
|
||||
do
|
||||
cp -v ${dir}/db/types.xml ${dir}.orig
|
||||
head -n-1 ${dir}.orig > /tmp/types.xml
|
||||
tail -n+2 types.xml >> /tmp/types.xml
|
||||
xmllint --noout /tmp/types.xml && cp -v /tmp/types.xml ${C}/db/types.xml
|
||||
done
|
||||
TYPES_FILE="${3}"
|
||||
fi
|
||||
echo
|
||||
|
||||
for file in $(find ${SERVER_FILES}/mpmissions -name types.xml -print -prune)
|
||||
do
|
||||
if [[ ${MODE} = "uninstall" ]]
|
||||
then
|
||||
# Remove the lines that were added by the mod's extras/types.xml from
|
||||
# every db/types.xml in all mission directories
|
||||
|
||||
# Chop the top tag from the source file
|
||||
tail -n+2 ${TYPES_FILE} > /tmp/types-tmp.xml
|
||||
|
||||
# Chop the bottom tag from the source file
|
||||
head -n-1 /tmp/types-tmp.xml > /tmp/types-src.xml
|
||||
|
||||
# Remove that content from the original file
|
||||
grep -qvxFf /tmp/types-src.xml ${file}
|
||||
else
|
||||
# Add the contents of extras/types.xml to every db/types.xml in all
|
||||
# mission directories
|
||||
xmllint --noout ${TYPES_FILE} && {
|
||||
echo -e "${green}${TYPES_FILE} passes XML lint test!"
|
||||
echo -e "Merging to $file...${default}"
|
||||
# Chop the bottom tag from the destination file
|
||||
head -n-1 ${file} > /tmp/types-dst.xml
|
||||
|
||||
# Chop the top 2 tags, xml and types, from the source file
|
||||
tail -n+2 ${TYPES_FILE} > /tmp/types-src.xml
|
||||
|
||||
# Concatenate the two files back into the source file
|
||||
cat /tmp/types-dst.xml /tmp/types-src.xml > /tmp/types.xml
|
||||
|
||||
xmllint --noout /tmp/types.xml && {
|
||||
cp -v /tmp/types.xml ${file}
|
||||
} || {
|
||||
# Try again, but chop the top 3 tags, hopefully xml and types, from the source file...
|
||||
echo "First merge attempt failed, trying again..."
|
||||
tail -n+3 ${TYPES_FILE} > /tmp/types-src.xml
|
||||
|
||||
# Concatenate the two files back into the source file
|
||||
cat /tmp/types-dst.xml /tmp/types-src.xml > /tmp/types.xml
|
||||
|
||||
# And lint again. This should probably be a recursive function...
|
||||
xmllint --noout /tmp/types.xml && {
|
||||
cp -v /tmp/types.xml ${file}
|
||||
} || {
|
||||
echo "XML lint check after merge failed! No files changed!"
|
||||
}
|
||||
}
|
||||
} || {
|
||||
echo -e "${red}${TYPES_FILE} fails XML lint test!"
|
||||
echo -e "This will have to be merged by hand!${default}"
|
||||
}
|
||||
fi
|
||||
done
|
||||
|
|
Loading…
Add table
Reference in a new issue