summaryrefslogtreecommitdiff
path: root/tools/client-updates/src/client-updates-gen
diff options
context:
space:
mode:
Diffstat (limited to 'tools/client-updates/src/client-updates-gen')
-rwxr-xr-xtools/client-updates/src/client-updates-gen68
1 files changed, 68 insertions, 0 deletions
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="<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