summaryrefslogtreecommitdiff
path: root/tmwdelta.sh
diff options
context:
space:
mode:
Diffstat (limited to 'tmwdelta.sh')
-rwxr-xr-xtmwdelta.sh119
1 files changed, 119 insertions, 0 deletions
diff --git a/tmwdelta.sh b/tmwdelta.sh
new file mode 100755
index 0000000..d003ed2
--- /dev/null
+++ b/tmwdelta.sh
@@ -0,0 +1,119 @@
+#!/bin/bash
+
+# Original data info
+repofile="https://github.com/themanaworld/tmwa-client-data/archive/master.zip"
+# repofile First directory name
+repofirstdir="tmwa-client-data-master"
+
+# Modified data info
+patchrepoaddr="liviorecchia.gitlab.io"
+patchreponame="testworld"
+# That's the directory with content modified from original zip NOT the modified repo
+patchdir="_patch"
+
+# Working file names
+repotemp="original.zip"
+
+update(){
+ echo "Downloading original files"
+ rm $repotemp
+ wget $repofile -O $repotemp
+}
+
+restore(){
+ echo "Uncompressing original data"
+ rm $repofirstdir -Rf
+ unzip $repotemp
+ rm ../_uncompressed -Rf
+}
+
+patch(){
+ # compile adler32 utility
+ gcc -Wall adler32.c -o adler32
+
+ mkdir _uncompressed
+ # copy TMW files and then those in patching directory
+ cp $repofirstdir/* _uncompressed/ -urf --preserve=all
+ echo "Patching original data"
+ cp $patchdir/* _uncompressed/ -rf
+ #--preserve=all
+ # remove all _includes.xml files from patching directory!
+
+ echo "Packing files for updates"
+ mkdir $patchreponame
+ cd _uncompressed # change to uncompressed patched files directory
+ # Zip compress any subdirectory (-r), show the remaining data to be compressed (-db), maxing out compression -0, and following file system updates (-FS)
+ zip ../$patchreponame/graphics -r -0 -FS graphics
+ zip ../$patchreponame/items -r -0 -FS items
+ zip ../$patchreponame/maps -r -0 -FS maps
+ zip ../$patchreponame/monsters -r -0 -FS monsters
+ zip ../$patchreponame/music -r -0 -FS music
+ zip ../$patchreponame/npcs -r -0 -FS npcs
+ zip ../$patchreponame/quests -r -0 -FS quests
+ zip ../$patchreponame/rules -r -0 -FS rules
+ zip ../$patchreponame/sfx -r -0 -FS sfx
+ zip ../$patchreponame/tilesets -r -0 -FS tilesets
+ zip ../$patchreponame/rootdir -r -0 -FS *.*
+ cd ..
+
+ echo "Computing resources' adler32 checksums"
+ cd $patchreponame # entering repo directory
+ #jacksum -a adler32 -x *.zip > .za32 # writing a temp file with checksums
+ ../adler32 0 *.zip > .za32
+
+ echo "Creating resource.xml"
+ declare -a array
+ readarray -t array < .za32
+ echo '<?xml version="1.0"?>' > resources.xml # overwrite resource file
+ echo '<updates>' >> resources.xml
+ for element in "${array[@]}" # scan temp file lines for data
+ do
+ IFS=$(echo -e ' \t ') read -r -a array2 <<< "${element}" # split by tabs
+ echo "<update type='data' file='${array2[0]}' hash='${array2[1]}'/>" >> resources.xml
+ done
+ echo '</updates>' >> resources.xml
+ rm .za32 # remove temp file
+ #echo "Deleting uncompressed directory"
+ #rm ../_uncompressed -Rf
+ echo "Local sync"
+ rm $HOME/.local/share/mana/updates/$patchrepoaddr/$patchreponame/*.zip -Rf
+ mkdir $HOME/.local/share/mana/updates/$patchrepoaddr/
+ mkdir $HOME/.local/share/mana/updates/$patchrepoaddr/$patchreponame/
+ cp *.zip $HOME/.local/share/mana/updates/$patchrepoaddr/$patchreponame/
+ cp resources.xml $HOME/.local/share/mana/updates/$patchrepoaddr/$patchreponame/resources.xml
+}
+
+push(){
+ echo "Git pushing"
+ cd $patchreponame
+ git add .
+ git commit -m "Test of resource packing"
+ git push -u origin master
+ cd ..
+}
+
+if [ "$1" == "repatch" ]
+then
+ restore
+ patch
+fi
+
+if [ "$1" == "patch" ]
+then
+ patch
+fi
+
+if [ "$1" == "update" ]
+then
+ update
+fi
+
+if [ "$1" == "restore" ]
+then
+ restore
+fi
+
+if [ "$1" == "push" ]
+then
+ push
+fi