summaryrefslogtreecommitdiff
path: root/client/client-updates/src/client-updates-gen
blob: 76c0ed34ec182cec76c6aa83082a3c262720ab9b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
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