From e97b3f71b9198f27fac03f53eacc3e7c9d32b750 Mon Sep 17 00:00:00 2001 From: gumi Date: Mon, 20 Nov 2017 13:51:33 -0500 Subject: borrow evol's update script --- .gitignore | 4 + client/adler32.c | 79 +++++++++++++++++ client/adler32/.gitignore | 1 - client/adler32/Makefile | 16 ---- client/adler32/adler32.c | 68 -------------- client/make-music.sh | 51 +++++++++++ client/make-updates | 220 +++++++++++++--------------------------------- 7 files changed, 193 insertions(+), 246 deletions(-) create mode 100644 client/adler32.c delete mode 100644 client/adler32/.gitignore delete mode 100644 client/adler32/Makefile delete mode 100644 client/adler32/adler32.c create mode 100644 client/make-music.sh diff --git a/.gitignore b/.gitignore index f11fb40..4c5843f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,6 @@ /aligncsv *.pyc +/client/adler32 +/client/commit.txt +/client/musiccommit.txt +/client/files diff --git a/client/adler32.c b/client/adler32.c new file mode 100644 index 0000000..606c739 --- /dev/null +++ b/client/adler32.c @@ -0,0 +1,79 @@ +/* + * 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 +#include +#include + +/** + * 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/client/adler32/.gitignore b/client/adler32/.gitignore deleted file mode 100644 index cfcde45..0000000 --- a/client/adler32/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/adler32 diff --git a/client/adler32/Makefile b/client/adler32/Makefile deleted file mode 100644 index 42f101a..0000000 --- a/client/adler32/Makefile +++ /dev/null @@ -1,16 +0,0 @@ -prefix=/usr/local -bindir=${prefix}/bin - -LDLIBS=-lz - -all: adler32 - -adler32: adler32.c - -clean: - rm -f adler32 - -install: - install -D adler32 ${bindir}/ - -.PHONY: clean install diff --git a/client/adler32/adler32.c b/client/adler32/adler32.c deleted file mode 100644 index 5dd7e4c..0000000 --- a/client/adler32/adler32.c +++ /dev/null @@ -1,68 +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 -#include -#include - -/** - * 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 [file]...\n"); - exit(0); -} - -int main(int argc, char *argv[]) -{ - int i; /**< Loops through arguments. */ - - if (argc == 1) - { - print_usage(); - } - - for (i = 1; 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); - printf("%s %lx\n", argv[i], adler); - fclose(file); - } - - return 0; -} diff --git a/client/make-music.sh b/client/make-music.sh new file mode 100644 index 0000000..cdec1dc --- /dev/null +++ b/client/make-music.sh @@ -0,0 +1,51 @@ +#!/usr/bin/env bash + +# Copyright (C) 2011-2012 Evol Online +# Author: Andrei Karas (4144) + +dir=`pwd` +output=~/www/updates +cdata=../../client-data + +LDLIBS=-lz +prefix=/usr/local +CC=${CC:=gcc} + +echo "======= Legacy-music =======" + +echo ">> Building adler32..." +rm -f adler32 2>/dev/null || : +$CC -lz adler32.c -o adler32 + +echo ">> Creating directory tree..." +mkdir -pv files +mkdir -pv $output + +echo ">> Removing leftovers..." +rm -v files/Legacy-music.zip 2>/dev/null || : + +echo ">> Entering client-data..." +pushd $cdata +echo ">> Changing file dates..." +find -path ./sfx -prune -o -iregex ".+[.]\(ogg\)" -exec touch --date=2015-01-01 {} \; +echo ">> Compressing files..." +find -path ./sfx -prune -o -iregex ".+[.]\(ogg\)" -printf "%P\n" | zip -X -@ $dir/files/Legacy-music.zip +touch $dir/files/Legacy-music.zip +echo ">> Dumping git revision to file..." +git rev-parse HEAD >$dir/musiccommit.txt + +pushd $dir/files +echo ">> Calculating adler32 checksum..." +sum=`../adler32 1 Legacy-music.zip` + +echo ">> Generating xml file..." +echo " " >> xml_header.txt + +cp xml_header.txt resources.xml +cat xml_footer.txt >>resources.xml + +echo ">> Moving stuff around..." +cp Legacy-music.zip $output/ +cp resources.xml $output/ +popd +popd diff --git a/client/make-updates b/client/make-updates index 96925d8..1179a66 100755 --- a/client/make-updates +++ b/client/make-updates @@ -1,163 +1,61 @@ -#!/bin/bash -e -# This is a tool to automatically generate and ship client updates. -# It is entirely self-contained, storing its own state in the git repo. -# It is called by running 'make updates' in server-data. -# It also supports manually calls for maintenance work. -# TODO: make auto-mode work with music too. +#!/usr/bin/env bash -# local branch to keep update info on -# will be created on first run; updated thereafter -branch=update-zips -# must already exist -# must NOT be a relative path -output=~/www/updates - -function apply_function() -{ - $1 misc *.* COPYING rules/ - $1 graphics-images graphics/images/ graphics/guiicons/ - $1 graphics-items graphics/items/ - $1 graphics-minimaps graphics/minimaps/ - $1 graphics-particles graphics/particles/ - $1 graphics-skills graphics/skills/ - $1 graphics-sprites graphics/sprites/ - $1 graphics-tiles graphics/tiles/ - $1 items items/ - $1 maps maps/ - $1 monsters monsters/ - $1 npcs npcs/ - $1 quests quests/ - $1 sfx sfx/ - $1 tilesets tilesets/ -} - -function add_resource() -{ - pushd $output >/dev/null - adler32 $1 | tee -a resources2.txt | { - read name hash - chmod a+r $name - sed '/<\/updates>/i ' -i resources.xml - } - popd >/dev/null -} - -function add_music() -{ - pushd $output >/dev/null - adler32 $1 | { - read name hash - chmod a+r $name - sed '/<\/updates>/i ' -i resources.xml - } - popd >/dev/null -} - -function do_initial_zip() -{ - zip=$1-$this_update.zip; shift - git ls-files --with-tree=HEAD -- "$@" \ - | zip -q $output/$zip -@ - add_resource $zip -} -function do_initial_music() -{ - zip=music-$this_update.zip - ( cd music/ ; git ls-files --with-tree=HEAD ) \ - | sed 's:^:music/:' \ - | zip -q $output/$zip -@ - add_music $zip -} - -function git_diff_tree() -{ - git diff-tree -r --diff-filter=AM "$@" -} - -function do_delta_zip() -{ - zip=$1-$last_update..$this_update.zip; shift - if git_diff_tree --quiet $last_update $this_update -- "$@" - then - return - fi - git_diff_tree --name-only $last_update $this_update -- "$@" \ - | zip -q $output/$zip -@ - add_resource $zip -} -function do_delta_music() -{ - zip=music-$last_update..$this_update.zip - if (cd music; git_diff_tree --quiet $last_update $this_update ) - then - return - fi - (cd music; git_diff_tree --name-only $last_update $this_update ) \ - | sed 's:^:music/:' \ - | zip -q $output/$zip -@ - add_music $zip -} +# Copyright (C) 2011-2012 Evol Online +# Author: Andrei Karas (4144) -function do_initial_zips() -{ - apply_function do_initial_zip -} - -function do_delta_zips() -{ - apply_function do_delta_zip -} - -function main() -{ - if ! test -d $output - then - echo 'Fatal error: output directory does not exist' - echo "$output" - return 1 - fi - if ! test -f $output/resources.xml - then - ( - echo '' - echo '' - echo '' - ) > $output/resources.xml - fi - - this_update=$(git rev-parse --short HEAD) - if ! last_update=$(git rev-parse --short $branch 2>/dev/null) - then - echo 'Doing initial updates' - do_initial_zips - elif test "$this_update" = "$last_update" - then - echo 'No commits since last update generation ...' - else - echo 'Doing incremental updates' - do_delta_zips - fi - git branch -f $branch - - this_update=$(cd music; git rev-parse --short HEAD) - if ! last_update=$(cd music; git rev-parse --short $branch 2>/dev/null) - then - echo 'Doing initial music updates' - do_initial_music - elif test "$this_update" = "$last_update" - then - echo 'No commits since last music update generation ...' - else - echo 'Doing incremental music updates' - do_delta_music - fi - ( cd music; git branch -f $branch ) -} - -if test "$0" = "$BASH_SOURCE" -then - echo 'Generating updates automatically' - main -else - echo 'sourcing detected - you can do manual updates' -fi +dir=`pwd` +output=~/www/updates +cdata=../../client-data + +LDLIBS=-lz +prefix=/usr/local +CC=${CC:=gcc} + +echo "======= Legacy =======" + +echo ">> Building adler32..." +rm -f adler32 2>/dev/null || : +$CC -lz adler32.c -o adler32 + +echo ">> Creating directory tree..." +mkdir -pv files +mkdir -pv $output +mkdir -pv $cdata/music + +echo ">> Removing leftovers..." +rm -rv files/* 2>/dev/null || : +cp $output/news.txt files/ 2>/dev/null || : +cp $output/news.html files/ 2>/dev/null || : +rm -rv $output/* 2>/dev/null || : + +echo ">> Entering client-data..." +pushd $cdata +echo ">> Changing file dates..." +find -path ./music -prune -o -iregex ".+[.]\(xml\|png\|tmx\|ogg\|txt\|po\|tsx\)" -exec touch --date=2015-01-01 {} \; +echo ">> Compressing files..." +find -path ./music -prune -o -iregex ".+[.]\(xml\|png\|tmx\|ogg\|txt\|po\|tsx\)" -printf "%P\n" | zip -X -@ $dir/files/Legacy.zip +echo ">> Dumping git revision to file..." +git rev-parse HEAD >$dir/commit.txt + +pushd $dir/files +echo ">> Calculating adler32 checksum..." +sum=`../adler32 1 Legacy.zip` +echo "Legacy.zip ${sum}" >resources2.txt + +echo ">> Generating xml file..." +echo ' +' >xml_header.txt +echo '' >xml_footer.txt + +echo " " >> xml_header.txt +cp xml_header.txt resources.xml +cat xml_footer.txt >>resources.xml + +echo ">> Moving stuff around..." +cp -v Legacy.zip $output/ +cp -v resources2.txt $output/ +cp -v resources.xml $output/ +cp -v news.txt $output/ 2>/dev/null || : +cp -v news.html $output/ 2>/dev/null || : +popd +popd -- cgit v1.2.3-60-g2f50