summaryrefslogtreecommitdiff
path: root/client/client-updates/src/client-updates-gen
diff options
context:
space:
mode:
authorVincent Petithory <vincent.petithory@gmail.com>2013-01-20 23:22:56 +0100
committerVincent Petithory <vincent.petithory@gmail.com>2013-01-20 23:22:56 +0100
commitfa2192520e55ed384d838741697d1ee8ff571f52 (patch)
tree11dc118168dc4df428ce0af9af488b33fbd1328b /client/client-updates/src/client-updates-gen
parent93b5fb8cd41c3330bad339129a330d1fa738019d (diff)
downloadtools-fa2192520e55ed384d838741697d1ee8ff571f52.tar.gz
tools-fa2192520e55ed384d838741697d1ee8ff571f52.tar.bz2
tools-fa2192520e55ed384d838741697d1ee8ff571f52.tar.xz
tools-fa2192520e55ed384d838741697d1ee8ff571f52.zip
Add Client updates tools to generate zip updates.
Diffstat (limited to 'client/client-updates/src/client-updates-gen')
-rwxr-xr-xclient/client-updates/src/client-updates-gen68
1 files changed, 68 insertions, 0 deletions
diff --git a/client/client-updates/src/client-updates-gen b/client/client-updates/src/client-updates-gen
new file mode 100755
index 0000000..76c0ed3
--- /dev/null
+++ b/client/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="<update type=\"data\" file=\"${update_basename}.zip\" hash=\"${hash}\" />"
+
+sed -i '$d' 'release/resources.xml'
+echo " $xmlentry" >> 'release/resources.xml'
+echo '</updates>' >> '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