From e47df6fdfe1cee5eaa3583b6959161b24c4b6bcc Mon Sep 17 00:00:00 2001 From: Vincent Petithory Date: Sun, 20 Jan 2013 23:22:56 +0100 Subject: Add Client updates tools to generate zip updates. --- tools/client-updates/src/adler32.c | 68 ++++++++++++++++++++++ tools/client-updates/src/client-updates-gen | 68 ++++++++++++++++++++++ tools/client-updates/src/client-updates-inspect | 20 +++++++ tools/client-updates/src/client-updates-news | 14 +++++ tools/client-updates/src/client-updates-push | 8 +++ .../client-updates/src/client-updates.conf.example | 15 +++++ tools/client-updates/src/makefile | 9 +++ 7 files changed, 202 insertions(+) create mode 100644 tools/client-updates/src/adler32.c create mode 100755 tools/client-updates/src/client-updates-gen create mode 100755 tools/client-updates/src/client-updates-inspect create mode 100755 tools/client-updates/src/client-updates-news create mode 100755 tools/client-updates/src/client-updates-push create mode 100644 tools/client-updates/src/client-updates.conf.example create mode 100644 tools/client-updates/src/makefile (limited to 'tools/client-updates/src') diff --git a/tools/client-updates/src/adler32.c b/tools/client-updates/src/adler32.c new file mode 100644 index 00000000..5dd7e4c1 --- /dev/null +++ b/tools/client-updates/src/adler32.c @@ -0,0 +1,68 @@ +/* + * 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/tools/client-updates/src/client-updates-gen b/tools/client-updates/src/client-updates-gen new file mode 100755 index 00000000..76c0ed34 --- /dev/null +++ b/tools/client-updates/src/client-updates-gen @@ -0,0 +1,68 @@ +#!/bin/sh + +# config +SRC=$(dirname $(readlink -f "$0")) + +. ${SRC}/client-updates.conf + +# Check we are on the $CLIENT_DATA_BRANCH branch +git --git-dir "${CLIENT_DATA_DIR}/.git" branch | grep -q "^* $CLIENT_DATA_BRANCH" || { echo "The client-data repository is not on $CLIENT_DATA_BRANCH branch. Exiting"; exit 2; } + +# Unless specified on 1st argument, we'll use the latest revision that was +# included in updates, as starting revision. +# If this is the initial generation, this argument is mandatory. +if [ $# -gt 0 ]; then + OLD_CLIENT_DATA_HEAD="$1" +else + # Get the last commit sha where we generated an update + # This assumes the generated zip names follow the pattern: update-SHA1..SHA2.zip + OLD_CLIENT_DATA_HEAD=$(tail -n 1 ${UPDATES_DIR}/release/resources2.txt | cut -d . -f 3) +fi + +# Unless specified on 2nd argument, we'll use the HEAD as final revision. +if [ $# -gt 1 ]; then + NEW_CLIENT_DATA_HEAD="$2" +else + # get the commit SHA from the client data repo + NEW_CLIENT_DATA_HEAD=$(git --git-dir "${CLIENT_DATA_DIR}/.git" rev-parse HEAD | cut -c 1-7) +fi + +if [ "$OLD_CLIENT_DATA_HEAD" = "$NEW_CLIENT_DATA_HEAD" ]; then + echo "Everything is up-to-date." + exit 0 +fi + +update_basename="update-${OLD_CLIENT_DATA_HEAD}..${NEW_CLIENT_DATA_HEAD}" + +# generate a diff of files to package +cd ${CLIENT_DATA_DIR} +git --git-dir "${CLIENT_DATA_DIR}/.git" log --name-status ${OLD_CLIENT_DATA_HEAD}..${NEW_CLIENT_DATA_HEAD} | awk '/^(A|M)\t/ {print $2}' | sort | uniq | xargs zip -9 -r "${UPDATES_DIR}/${update_basename}.zip" > /dev/null +cd - > /dev/null + +if [ ! -f "${UPDATES_DIR}/${update_basename}.zip" ];then + echo "Error while generating ${update_basename}.zip. Exiting." > /dev/stderr + exit 1 +fi + +# package update +cd "${UPDATES_DIR}" +mkdir -p "release" +${SRC}/adler32 "${update_basename}.zip" >> "release/resources2.txt" +hash=$(tail -n 1 "release/resources2.txt" | awk '{ print $2; }') +# populate resources.xml as well +xmlentry="" + +sed -i '$d' 'release/resources.xml' +echo " $xmlentry" >> 'release/resources.xml' +echo '' >> 'release/resources.xml' + +echo "Adding ${update_basename}.zip:" +# Display the contents of the update +unzip -l ${update_basename}.zip +mv "${update_basename}.zip" "release/" +# Copy resources +git add 'release' +git commit -m "Updating resources to ${NEW_CLIENT_DATA_HEAD}" > /dev/null +cd - > /dev/null + +exit 0 diff --git a/tools/client-updates/src/client-updates-inspect b/tools/client-updates/src/client-updates-inspect new file mode 100755 index 00000000..03ae2d65 --- /dev/null +++ b/tools/client-updates/src/client-updates-inspect @@ -0,0 +1,20 @@ +#!/bin/sh + +#config +SRC=$(dirname $(readlink -f "$0")) + +. ${SRC}/client-updates.conf + +DIRECTORY="${UPDATES_DIR}/release" +listing=$(mktemp) +IFS=' +' +for f in $(tac $DIRECTORY/resources2.txt); do + file=$(awk '{ print $1; }' <<< $f) + unzip -l "$DIRECTORY/$file" >> $listing +done + +if [ -f "$listing" ]; then + less "$listing" +fi +rm -f "$listing" diff --git a/tools/client-updates/src/client-updates-news b/tools/client-updates/src/client-updates-news new file mode 100755 index 00000000..bc78e4ef --- /dev/null +++ b/tools/client-updates/src/client-updates-news @@ -0,0 +1,14 @@ +#!/bin/sh + +# config +SRC=$(dirname $(readlink -f "$0")) + +. ${SRC}/client-updates.conf + +# Edit news.txt +nano "${UPDATES_DIR}"/release/news.txt + +# Commit if changed +cd "${UPDATES_DIR}" +git status | grep -q 'news.txt' && { git add release/news.txt; git commit -m 'Updating news.txt' > /dev/null; } +cd - > /dev/null diff --git a/tools/client-updates/src/client-updates-push b/tools/client-updates/src/client-updates-push new file mode 100755 index 00000000..edeae490 --- /dev/null +++ b/tools/client-updates/src/client-updates-push @@ -0,0 +1,8 @@ +#!/bin/sh + +# config +SRC=$(dirname $(readlink -f "$0")) + +. ${SRC}/client-updates.conf + +rsync -av --delete "$UPDATES_DIR/release/" "$UPDATES_PUBLISH_DIR" diff --git a/tools/client-updates/src/client-updates.conf.example b/tools/client-updates/src/client-updates.conf.example new file mode 100644 index 00000000..8bdce432 --- /dev/null +++ b/tools/client-updates/src/client-updates.conf.example @@ -0,0 +1,15 @@ +# The client-data directory +CLIENT_DATA_DIR="$HOME/tmwa-client-data" + +# The updates working directory +UPDATES_DIR="$HOME/client-updates" + +# The git branch used for generating the updates +# This allows for more complex setups, where e.g a branch is used for merging +# from various other branches. It's used on the testing server +# Defaults to master +CLIENT_DATA_BRANCH=master + +# Local directory served by the web server, +# where the update files will be copied +UPDATES_PUBLISH_DIR="$HOME/www/tmwupdate" diff --git a/tools/client-updates/src/makefile b/tools/client-updates/src/makefile new file mode 100644 index 00000000..00acaf0d --- /dev/null +++ b/tools/client-updates/src/makefile @@ -0,0 +1,9 @@ +all: adler32 + +adler32: adler32.c + gcc -lz -o $@ $< + +clean: + rm -f adler32 + +.PHONY: clean -- cgit v1.2.3-70-g09d2