summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjak1 <jak1@themanaworld.org>2022-06-18 21:37:28 +0200
committerjak1 <jak1@themanaworld.org>2022-06-18 21:37:28 +0200
commitb3cd9a5dd68c8a973795931149a254563bda2865 (patch)
tree2110f496a061997fbf120f6ac7e82ff28f7b556e
parent6c2ad98dfd4a2d6e39423c5b4f1e7828fd79566a (diff)
downloadmessworld-tools-b3cd9a5dd68c8a973795931149a254563bda2865.tar.gz
messworld-tools-b3cd9a5dd68c8a973795931149a254563bda2865.tar.bz2
messworld-tools-b3cd9a5dd68c8a973795931149a254563bda2865.tar.xz
messworld-tools-b3cd9a5dd68c8a973795931149a254563bda2865.zip
ported adler32 to py3, updated bash update scripts
-rwxr-xr-xupdate/addmods.sh18
-rwxr-xr-xupdate/adler3249
-rw-r--r--update/adler32.c79
-rwxr-xr-xupdate/createnew.sh24
-rwxr-xr-xupdate/musicnew.sh23
-rwxr-xr-xupdate/pseudo_update.sh2
-rwxr-xr-xupdate/update.sh23
-rwxr-xr-xupdate/update_music.sh18
8 files changed, 123 insertions, 113 deletions
diff --git a/update/addmods.sh b/update/addmods.sh
index a45f9ed..5255021 100755
--- a/update/addmods.sh
+++ b/update/addmods.sh
@@ -4,13 +4,17 @@
# Author: Andrei Karas (4144)
dir=`pwd`
-CC=${CC:=gcc}
+tmp_path=$PATH
-rm adler32
-$CC -lz adler32.c -o adler32
+export PATH="$dir:$PATH"
-mkdir files
-mkdir upload
+if [[ ! -d "files" ]]; then
+ mkdir -p files
+fi
+
+if [[ ! -d "upload" ]]; then
+ mkdir -p upload
+fi
previous=`cat commit.txt`
@@ -22,7 +26,7 @@ for file in $FILES; do
cd $file
find . -type f | xargs zip -9 -r ../../../../evol-tools/update/files/mod-$file.zip
cd $dir/files
- sum=`../adler32 1 mod-$file.zip`
+ sum=`adler32 1 mod-$file.zip`
echo " <update type=\"data\" group=\"$file\" file=\"mod-$file.zip\" hash=\"${sum}\" />" >> xml_header.txt
cp xml_header.txt resources.xml
cat xml_footer.txt >>resources.xml
@@ -30,3 +34,5 @@ for file in $FILES; do
cp resources2.txt ../upload/
cp resources.xml ../upload/
done
+
+export PATH="$tmp_path" \ No newline at end of file
diff --git a/update/adler32 b/update/adler32
new file mode 100755
index 0000000..187e34d
--- /dev/null
+++ b/update/adler32
@@ -0,0 +1,49 @@
+#!/usr/bin/env python3
+
+"""
+ Project: TheManaWorld
+ Author: Bjorn Lindeijer, jak1
+ License: GPLv3
+ Description: Calculates adler32 checksums for all files passed as argument.
+ Credits: adler32.c 2006 Bjorn Lindeijer
+"""
+
+from zlib import adler32
+import sys
+import os
+
+def adler32sum(filepath):
+ BLOCKSIZE = 256*1024*1024
+ asum = 1
+ with open(filepath, 'rb') as f:
+ while (data := f.read(BLOCKSIZE)):
+ asum = adler32(data, asum)
+ return hex(asum)
+
+def cmd_help():
+ print(f"Usage: adler32.py <mode> <file>")
+ print(f" mode: 0 prints file & checksum")
+ print(f" mode: 1 prints only checksum")
+
+if __name__ == "__main__":
+ if len(sys.argv) >= 3:
+ try:
+ mode = int(sys.argv[1])
+ zfiles = sys.argv[2:]
+ for zfile in zfiles:
+ file_exists = os.path.exists(zfile)
+ if file_exists:
+ if mode == 0:
+ print(zfile + " " + adler32sum(zfile)[2:])
+ elif mode == 1:
+ print(adler32sum(zfile)[2:])
+ else:
+ cmd_help()
+ else:
+ print("file not found!")
+ exit(-1)
+ except ValueError:
+ print("mode needs to be an integer value!")
+ exit(-1)
+ else:
+ cmd_help()
diff --git a/update/adler32.c b/update/adler32.c
deleted file mode 100644
index 606c739..0000000
--- a/update/adler32.c
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- * adler32.c (c) 2006 Bjorn Lindeijer
- * License: GPL, v2 or later
- *
- * Calculates Adler-32 checksums for all files passed as argument.
- *
- * Usage: adler32 [file]...
- */
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <zlib.h>
-
-/**
- * Calculates the Adler-32 checksum for the given file.
- */
-unsigned long fadler32(FILE *file)
-{
- // Obtain file size
- fseek(file, 0, SEEK_END);
- long fileSize = ftell(file);
- rewind(file);
-
- // Calculate Adler-32 checksum
- char *buffer = (char*) malloc(fileSize);
- fread(buffer, 1, fileSize, file);
- unsigned long adler = adler32(0L, Z_NULL, 0);
- adler = adler32(adler, (Bytef*) buffer, fileSize);
- free(buffer);
-
- return adler;
-}
-
-/**
- * Prints out usage and exists.
- */
-void print_usage()
-{
- printf("Usage: adler32 mode [file]...\n");
- exit(0);
-}
-
-int main(int argc, char *argv[])
-{
- int i; /**< Loops through arguments. */
-
- if (argc < 2)
- {
- print_usage();
- }
-
- int mode = atoi(argv[1]);
-
- for (i = 2; i < argc; ++i)
- {
- FILE *file = fopen(argv[i], "r");
-
- if (!file)
- {
- printf("Error while opening '%s' for reading!\n", argv[i]);
- exit(1);
- }
-
- unsigned long adler = fadler32(file);
- switch (mode)
- {
- case 0:
- default:
- printf("%s %lx\n", argv[i], adler);
- break;
- case 1:
- printf("%lx", adler);
- break;
- }
- fclose(file);
- }
-
- return 0;
-}
diff --git a/update/createnew.sh b/update/createnew.sh
index c0bb6fd..c29844f 100755
--- a/update/createnew.sh
+++ b/update/createnew.sh
@@ -4,22 +4,30 @@
# Author: Andrei Karas (4144)
dir=`pwd`
-#CC=${CC:=gcc}
+tmp_path=$PATH
-#rm adler32
-#$CC -lz adler32.c -o adler32
+export PATH="$dir:$PATH"
-mkdir -p files
-mkdir -p upload
+if [[ ! -d "files" ]]; then
+ mkdir -p files
+fi
+
+if [[ ! -d "upload" ]]; then
+ mkdir -p upload
+fi
+
+if [[ -f files/themanaworld.zip ]]; then
+ rm files/themanaworld.zip
+fi
-rm files/themanaworld.zip
cd ../../client-data
find -iregex ".+[.]\(xml\|png\|tmx\|ogg\|txt\|po\|tsx\)" -exec touch --date=2015-01-01 {} \;
find -iregex ".+[.]\(xml\|png\|tmx\|ogg\|txt\|po\|tsx\)" -printf "%P\n" | zip -X -@ ../tools/update/files/themanaworld.zip
git log --pretty=oneline -n 1 | awk '{print $1}' >../tools/update/commit.txt
cd $dir/files
-sum=`adler32 themanaworld.zip | awk '{print $2}'`
+sum=`adler32 1 themanaworld.zip`
+
echo "themanaworld.zip ${sum}" >resources2.txt
echo '<?xml version="1.0"?>
@@ -34,3 +42,5 @@ cp themanaworld.zip ../upload/
cp resources2.txt ../upload/
cp resources.xml ../upload/
cp ../news.txt ../upload/
+
+export PATH="$tmp_path" \ No newline at end of file
diff --git a/update/musicnew.sh b/update/musicnew.sh
index 91a9f5e..a9a6dd5 100755
--- a/update/musicnew.sh
+++ b/update/musicnew.sh
@@ -4,22 +4,29 @@
# Author: Andrei Karas (4144)
dir=`pwd`
-CC=${CC:=gcc}
+tmp_path=$PATH
-rm adler32
-$CC -lz adler32.c -o adler32
+export PATH="$dir:$PATH"
-mkdir files
-mkdir upload
+if [[ ! -d "files" ]]; then
+ mkdir -p files
+fi
+
+if [[ ! -d "upload" ]]; then
+ mkdir -p upload
+fi
+
+if [[ ! -f "files/music.zip" ]]; then
+ rm files/music.zip
+fi
-rm files/music.zip
cd ../../music
find -iregex ".+[.]\(ogg\)" -exec touch --date=2015-01-01 {} \;
find -iregex ".+[.]\(ogg\)" -printf "%P\n" | zip -X -@ ../tools/update/files/music.zip
git log --pretty=oneline -n 1 | awk '{print $1}' >../tools/update/musiccommit.txt
cd $dir/files
-sum=`../adler32 1 music.zip`
+sum=`adler32 1 music.zip`
echo " <update type=\"music\" required=\"no\" file=\"music.zip\" hash=\"${sum}\" description=\"TMW music\" />" >> xml_header.txt
@@ -29,3 +36,5 @@ cat xml_footer.txt >>resources.xml
cp music.zip ../upload/
cp resources.xml ../upload/
cp ../news.txt ../upload/
+
+export PATH="$tmp_path" \ No newline at end of file
diff --git a/update/pseudo_update.sh b/update/pseudo_update.sh
index 9893b88..13c7820 100755
--- a/update/pseudo_update.sh
+++ b/update/pseudo_update.sh
@@ -18,7 +18,7 @@ xargs zip -X -9 -r ../tools/update/upload/Extra.zip
cd $dir/upload
-sum=`adler32 Extra.zip | awk '{print $2}'`
+sum=`adler32 1 Extra.zip`
echo "Update ID: ${u1}..${u2}"
echo "Checksum: ${sum}"
diff --git a/update/update.sh b/update/update.sh
index c0bb6fd..aab3415 100755
--- a/update/update.sh
+++ b/update/update.sh
@@ -4,22 +4,29 @@
# Author: Andrei Karas (4144)
dir=`pwd`
-#CC=${CC:=gcc}
+tmp_path=$PATH
-#rm adler32
-#$CC -lz adler32.c -o adler32
+export PATH="$dir:$PATH"
-mkdir -p files
-mkdir -p upload
+if [[ ! -d "files" ]]; then
+ mkdir -p files
+fi
+
+if [[ ! -d "upload" ]]; then
+ mkdir -p upload
+fi
+
+if [[ -f files/themanaworld.zip ]]; then
+ rm files/themanaworld.zip
+fi
-rm files/themanaworld.zip
cd ../../client-data
find -iregex ".+[.]\(xml\|png\|tmx\|ogg\|txt\|po\|tsx\)" -exec touch --date=2015-01-01 {} \;
find -iregex ".+[.]\(xml\|png\|tmx\|ogg\|txt\|po\|tsx\)" -printf "%P\n" | zip -X -@ ../tools/update/files/themanaworld.zip
git log --pretty=oneline -n 1 | awk '{print $1}' >../tools/update/commit.txt
cd $dir/files
-sum=`adler32 themanaworld.zip | awk '{print $2}'`
+sum=`adler32 1 themanaworld.zip`
echo "themanaworld.zip ${sum}" >resources2.txt
echo '<?xml version="1.0"?>
@@ -34,3 +41,5 @@ cp themanaworld.zip ../upload/
cp resources2.txt ../upload/
cp resources.xml ../upload/
cp ../news.txt ../upload/
+
+export PATH="$tmp_path" \ No newline at end of file
diff --git a/update/update_music.sh b/update/update_music.sh
index 7954b45..57e688e 100755
--- a/update/update_music.sh
+++ b/update/update_music.sh
@@ -4,13 +4,17 @@
# Author: Andrei Karas (4144)
dir=`pwd`
-CC=${CC:=gcc}
+tmp_path=$PATH
-rm adler32
-$CC -lz adler32.c -o adler32
+export PATH="$dir:$PATH"
-mkdir files
-mkdir upload
+if [[ ! -d "files" ]]; then
+ mkdir -p files
+fi
+
+if [[ ! -d "upload" ]]; then
+ mkdir -p upload
+fi
previous=`cat musiccommit.txt`
@@ -28,7 +32,7 @@ cd $dir/files
if [ -f evol-${u1}..${u2}.zip ]; then
mv ../muciscommit.txt ../muciscommit_old.txt
echo ${head} >../muciscommit.txt
- sum=`../adler32 1 music-${u1}..${u2}.zip`
+ sum=`adler32 1 music-${u1}..${u2}.zip`
echo " <update type=\"music\" required=\"no\" file=\"music-${u1}..${u2}.zip\" hash=\"${sum}\" description=\"TMW music\" />" >> xml_header.txt
cp xml_header.txt resources.xml
cat xml_footer.txt >>resources.xml
@@ -38,3 +42,5 @@ if [ -f evol-${u1}..${u2}.zip ]; then
cp resources.xml ../upload/
cp ../news.txt ../upload
fi
+
+export PATH="$tmp_path" \ No newline at end of file