Awful
[openitg.git] / gen-patch-zip.sh
1 #!/bin/bash
2
3 # Usage: gen-patch-zip [out-file]
4 #
5 # Generates an encrypted patch ZIP for all releases. If out-file is
6 # specified, the encrypted patch ZIP is output to that file. Otherwise, the
7 # patch ZIP is output to ./patch.zip.
8 # -- vyhd
9
10 set -e
11
12 # include convenience functions and constants
13 source common.sh
14
15 # the path containing the game data to be used for the patch
16 PATCH_DIR="$ASSETS_DIR/patch-data"
17
18 # the patch file containing our data, using ./patch.zip by default.
19 # if we have an argument, zip and encrypt into that file instead.
20 PATCH_FILE=${1:-patch.zip}
21
22 # does in-place encryption (well, using a temp file)
23 function encrypt-patch {
24 TMP_FILE="/tmp/oitg-patch-enc-tmp"
25
26 if [ -z $1 ]; then
27 echo "you didn't give me anything to encrypt!"
28 return 1
29 fi
30
31 # leave this visible in case it throws an error
32 $ITG2_UTIL_PATH -p "$1" "$TMP_FILE"
33
34 mv "$TMP_FILE" "$1"
35 }
36
37 # Require that the encryption file actually exists
38 has_file "$ITG2_UTIL_PATH" "$ITG2_UTIL_FILE must be built in $ITG2_UTIL_DIR first."
39
40 # delete the patch file if it exists, or zip will try to update it
41 rm -f "$PATCH_FILE"
42
43 # we need this so we can put patch.zip in the CWD
44 CWD=`pwd`
45
46 # mild hack: wipe that CWD if we're using an absolute path
47 if [ ${PATCH_FILE:0:1} == "/" ]; then CWD=""; fi
48
49 cd "$PATCH_DIR"
50 echo "Zipping files into $PATCH_FILE..."
51 zip -rq "$CWD/$PATCH_FILE" ./*/
52 cd - 0&> /dev/null
53
54 echo "Encrypting patch data..."
55 encrypt-patch "$PATCH_FILE"
56
57 echo "Patch successfully created: $PATCH_FILE"