3 # Usage: ./gen-arcade-patch [private RSA]
5 # Generates a full arcade patch from the assets data, then signs the patch
6 # with the Private.rsa file given on the command line.
10 # work directory - this forms the root dir of the final patch
11 TMP_DIR
="/tmp/.tmp-patch"
13 # arcade patch data that we copy wholesale to the temp dir
14 PATCH_DATA_DIR
="assets/arcade-patch"
16 # values that aren't really magical, just used in a few places
17 OITG_BINARY
="src/openitg"
18 CONFIG_HEADER
="src/config.h"
20 # default to private.rsa in CWD (for the sake of a default value)
21 PRIVATE_RSA
=${1-private.rsa}
23 # include the simple helper routines
26 # exit immediately on nonzero exit code
29 # set this for loquacious and slightly redundant verbosity
34 echo "Usage: $0 [private RSA key]"
38 if ! [ -f
"$PRIVATE_RSA" ]; then print_usage
; fi
40 # clean up after ourselves on exit
41 trap "rm -rf $TMP_DIR" EXIT
42 trap "echo \"Failed! \"" ERR
45 # see if we have all the functions and files we need here
48 echo "Checking dependencies..."
53 has_file
"$OITG_BINARY" "%s doesn't exist! Please build it."
54 has_file
"$CONFIG_HEADER" "Why do you have a binary, but not config.h?"
55 has_file
"$VERIFY_SIG_PATH" "%s is missing; try checking out the repo again?"
56 has_file
"$PRIVATE_RSA" "RSA key \"%s\" not found! (failed sanity check)"
59 # warn the user if the util doesn't exist
60 has_file
"assets/utilities/itg2-util/src/itg2ac-util" "cd assets/utilities/itg2-util && ./autogen.sh && ./configure && make"
63 # build the signature verification program if it hasn't been built
64 # - we usually make them build our utilities, but this is simple
67 if ! [ -f
"${VERIFY_SIG_PATH%.*}.class" ]; then
68 echo "SignFile not built yet. building now..."
70 javac
"$VERIFY_SIG_FILE"
75 # actually build the patch here
78 OITG_DATE
="`date +%m-%d-%Y`"
79 OITG_VERSION
="`git describe`"
82 echo "'git describe' failed! Are you working in a Git repo?"
86 # sanity check - make sure this build is actually for arcades
89 grep "#define ITG_ARCADE 1" "$CONFIG_HEADER" &> /dev
/null
92 echo "Your config.h says this isn't an arcade build. Aborting."
100 echo "Copying base patch data..."
101 cp -a
$PATCH_DATA_DIR/* "$TMP_DIR"
103 echo "Generating patch.zip..."
104 .
/gen-patch-zip.sh
"$TMP_DIR/patch.zip" &> /dev
/null
106 echo "Copying and stripping binary..."
107 cp -L
"$OITG_BINARY" "$TMP_DIR"
108 strip
--strip-unneeded
"$TMP_DIR/openitg"
110 echo "Reticulating splines..."
112 # replace the placeholders in patch.xml with our actual data
113 sed -r
-i
-e
"s/OITG_VERSION/$OITG_VERSION/g" "$TMP_DIR/patch.xml"
114 sed -r
-i
-e
"s/OITG_DATE/$OITG_DATE/g" "$TMP_DIR/patch.xml"
116 echo "Zipping patch data..."
118 # NOTE: the "ITG 2 " prefix is required for the patches to be seen by itg/openitg
119 PATCH_OUTPUT_FILE
="ITG 2 OpenITG-$OITG_VERSION.itg"
120 TEMP_SIG_FILE
="$TMP_DIR/.sig"
122 # delete this if it exists, so we don't just "update"
123 rm -f
"$PATCH_OUTPUT_FILE"
127 zip -r
"$CWD/$PATCH_OUTPUT_FILE" * &> /dev
/null
130 echo "Signing and appending signature..."
132 java
-classpath
$VERIFY_SIG_DIR SignFile
"$PATCH_OUTPUT_FILE" "$PRIVATE_RSA" "$TEMP_SIG_FILE"
133 cat "$TEMP_SIG_FILE" >> "$PATCH_OUTPUT_FILE"
135 echo "Done: $PATCH_OUTPUT_FILE"