Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

add gen-arcade-patch.sh (tested and working so far), fixes for gen-pa…

…tch-zip.sh, removed old generate-patch.sh
  • Loading branch information...
commit 357140b8d19ff154cd0fe5de858d98bab8fabf74 1 parent 6233700
Mark vyhd authored
Showing with 221 additions and 81 deletions.
  1. +67 −0 common.sh
  2. +131 −0 gen-arcade-patch.sh
  3. +23 −19 gen-patch-zip.sh
  4. +0 −62 generate-patch.sh
67 common.sh
View
@@ -0,0 +1,67 @@
+# common.sh - defines common operations so we can quickly check the
+# sanity of the environment our scripts run in.
+
+# Somewhat counterintuitively, these return 0 if true and 1 if false.
+# That's so we can set -e and do sanity checking quickly.
+
+#
+# global constants, relative to the repository root
+#
+
+ASSETS_DIR="assets"
+
+ITG2_UTIL_DIR="$ASSETS_DIR/utilities/itg2-util/src"
+ITG2_UTIL_FILE="itg2ac-util"
+ITG2_UTIL_PATH="$ITG2_UTIL_DIR/$ITG2_UTIL_FILE"
+
+VERIFY_SIG_DIR="src/verify_signature/java"
+VERIFY_SIG_FILE="SignFile.java"
+VERIFY_SIG_PATH="$VERIFY_SIG_DIR/$VERIFY_SIG_FILE"
+
+#
+# generic sanity checking functions and their generic error messages
+#
+
+COMMAND_ERROR="Command \"%s\" not found! Please fix that so we can continue."
+FILE_ERROR="File \"%s\" not found! We need that to continue; please find it."
+
+# has_command [cmd] [error] - if cmd cannot be found, display "error" if
+# supplied, (which may use %s to get the cmd name) or use a generic error.
+function has_command
+{
+ if [ -z "$1" ]; then
+ echo "$0: no command given to check!"
+ return 1
+ fi
+
+ set +e
+ which $1 &> /dev/null
+ RET="$?"
+ set -e
+
+ if [ $RET -eq 0 ]; then return 0; fi
+
+ # use the custom error message if we have it
+ printf "${2-$COMMAND_ERROR}\n" $1
+ return 1
+}
+
+# has_file [file] [error] - has_command, but for files. Same rules apply.
+function has_file
+{
+ if [ -z "$1" ]; then
+ echo "$0: no file given to check!"
+ return 1
+ fi
+
+ set +e
+ file "$1" &> /dev/null
+ RET=$?
+ set -e
+
+ if [ $RET -eq 0 ]; then return 0; fi
+
+ # use the custom error message if we have it
+ printf "${2-$FILE_ERROR}\n" $1
+ return 1
+}
131 gen-arcade-patch.sh
View
@@ -0,0 +1,131 @@
+#!/bin/bash
+
+# Usage: ./gen-arcade-patch [private RSA]
+#
+# Generates a full arcade patch from the assets data, then signs the patch
+# with the Private.rsa file given on the command line.
+
+# written by vyhd/pat
+
+# work directory - this forms the root dir of the final patch
+TMP_DIR="/tmp/.tmp-patch"
+
+# arcade patch data that we copy wholesale to the temp dir
+PATCH_DATA_DIR="assets/arcade-patch"
+
+# values that aren't really magical, just used in a few places
+OITG_BINARY="src/openitg"
+CONFIG_HEADER="src/config.h"
+
+# default to private.rsa in CWD (for the sake of a default value)
+PRIVATE_RSA=${1-private.rsa}
+
+# include the simple helper routines
+source common.sh
+
+# exit immediately on nonzero exit code
+set -e
+set -u
+# set this for loquacious and slightly redundant verbosity
+# set -x
+
+function print_usage
+{
+ echo "Usage: $0 [private RSA key]"
+ exit 0
+}
+
+if ! [ -f "$PRIVATE_RSA" ]; then print_usage; fi
+
+# clean up after ourselves on exit
+trap "rm -rf $TMP_DIR" EXIT
+trap "echo \"Failed! \"" ERR
+
+#
+# see if we have all the functions and files we need here
+#
+
+echo "Checking dependencies..."
+
+has_command javac
+has_command java
+
+has_file "$OITG_BINARY" "%s doesn't exist! Please build it."
+has_file "$CONFIG_HEADER" "Why do you have a binary, but not config.h?"
+has_file "$VERIFY_SIG_PATH" "%s is missing; try checking out the repo again?"
+has_file "$PRIVATE_RSA" "RSA key \"%s\" not found! (failed sanity check)"
+
+#
+# build the signature verification program if it hasn't been built
+# - we usually make them build our utilities, but this is simple
+#
+
+if ! [ -f "${VERIFY_SIG_PATH%.*}.class" ]; then
+ echo "SignFile not built yet. building now..."
+ cd "$VERIFY_SIG_DIR"
+ javac "$VERIFY_SIG_FILE"
+ cd -
+fi
+
+#
+# actually build the patch here
+#
+
+OITG_DATE="`date +%m-%d-%Y`"
+OITG_VERSION="`git describe`"
+
+if [ $? -ne 0 ]; then
+ echo "'git describe' failed! Are you working in a Git repo?"
+ exit 1
+fi
+
+# sanity check - make sure this build is actually for arcades
+set +e
+
+grep "#define ITG_ARCADE 1" "$CONFIG_HEADER" &> /dev/null
+
+if [ $? -ne 0 ]; then
+ echo "Your config.h says this isn't an arcade build. Aborting."
+ exit 1
+fi
+
+set -e
+
+mkdir -p "$TMP_DIR"
+
+echo "Copying base patch data..."
+cp -a $PATCH_DATA_DIR/* "$TMP_DIR"
+
+echo "Generating patch.zip..."
+./gen-patch-zip.sh "$TMP_DIR/patch.zip" &> /dev/null
+
+echo "Copying and stripping binary..."
+cp -L "$OITG_BINARY" "$TMP_DIR"
+strip --strip-unneeded "$TMP_DIR/openitg"
+
+echo "Reticulating splines..."
+
+# replace the placeholders in patch.xml with our actual data
+sed -r -i -e "s/OITG_VERSION/$OITG_VERSION/g" "$TMP_DIR/patch.xml"
+sed -r -i -e "s/OITG_DATE/$OITG_DATE/g" "$TMP_DIR/patch.xml"
+
+echo "Zipping patch data..."
+
+PATCH_OUTPUT_FILE="ITG 2 OpenITG-$OITG_VERSION.itg"
+TEMP_SIG_FILE="$TMP_DIR/.sig"
+
+# delete this if it exists, so we don't just "update"
+rm -f "$PATCH_OUTPUT_FILE"
+
+CWD="`pwd`"
+cd "$TMP_DIR"
+zip -r "$CWD/$PATCH_OUTPUT_FILE" * &> /dev/null
+cd - &> /dev/null
+
+echo "Signing and appending signature..."
+
+java -classpath $VERIFY_SIG_DIR SignFile "$PATCH_OUTPUT_FILE" "$PRIVATE_RSA" "$TEMP_SIG_FILE"
+cat "$TEMP_SIG_FILE" >> "$PATCH_OUTPUT_FILE"
+
+echo "Done: $PATCH_OUTPUT_FILE"
+exit 0
42 gen-patch-zip.sh
View
@@ -1,24 +1,23 @@
#!/bin/bash
-set -e
-set -u
+# Usage: gen-patch-zip [out-file]
+#
+# Generates an encrypted patch ZIP for all releases. If out-file is
+# specified, the encrypted patch ZIP is output to that file. Otherwise, the
+# patch ZIP is output to ./patch.zip.
+# -- vyhd
-# the data containing all the patch data to be zipped (relative to CWD)
-PATCH_DIR="assets/patch-data"
+set -e
-# the patch file containing the above (relative to CWD)
-PATCH_FILE="patch.zip"
+# include convenience functions and constants
+source common.sh
-# utility file to be used for encrypting the patch
-ENCRYPT_DIR="assets/utilities/itg2-util/src"
-ENCRYPT_FILE="itg2ac-util" # hurr hurr hurr
-ENCRYPTER="$ENCRYPT_DIR/$ENCRYPT_FILE"
+# the path containing the game data to be used for the patch
+PATCH_DIR="$ASSETS_DIR/patch-data"
-if [ ! -f "$ENCRYPTER" ]; then
- echo "$ENCRYPT_FILE must be built before using this script!"
- echo "please cd on over to $ENCRYPT_DIR and build it."
- exit 1
-fi
+# the patch file containing our data, using ./patch.zip by default.
+# if we have an argument, zip and encrypt into that file instead.
+PATCH_FILE=${1:-patch.zip}
# does in-place encryption (well, using a temp file)
function encrypt-patch {
@@ -30,18 +29,23 @@ function encrypt-patch {
fi
# leave this visible in case it throws an error
- "$ENCRYPTER" -p "$1" "$TMP_FILE"
+ $ITG2_UTIL_PATH -p "$1" "$TMP_FILE"
mv "$TMP_FILE" "$1"
}
-# delete the patch file if it exists, or zip
-# complains about an invalid structure.
-if [ -f "$PATCH_FILE" ]; then rm "$PATCH_FILE"; fi
+# Require that the encryption file actually exists
+has_file "$ITG2_UTIL_PATH" "$ITG2_UTIL_FILE must be built in $ITG2_UTIL_DIR first."
+
+# delete the patch file if it exists, or zip will try to update it
+rm -f "$PATCH_FILE"
# we need this so we can put patch.zip in the CWD
CWD=`pwd`
+# mild hack: wipe that CWD if we're using an absolute path
+if [ ${PATCH_FILE:0:1} == "/" ]; then CWD=""; fi
+
cd "$PATCH_DIR"
echo "Zipping files into $PATCH_FILE..."
zip -rq "$CWD/$PATCH_FILE" ./*/
62 generate-patch.sh
View
@@ -1,62 +0,0 @@
-#!/bin/sh
-
-if [ "`which javac`x" = "x" ]; then
- echo "javac missing"
- exit 1
-fi
-if [ "`which java`x" = "x" ]; then
- echo "java missing"
- exit 1
-fi
-if [ ! -f src/openitg ]; then
- echo "where's the OpenITG binary?"
- exit 1
-fi
-
-TIMESTAMP=`date +%s`
-GIT_DESCRIBE=`git describe`
-PATCH_OUTPUT_FILE="ITG 2 OpenITG-$GIT_DESCRIBE.itg"
-
-# arcade patch.zip utility
-if [ ! -f assets/utilities/itg2-util/src/itg2ac-util ]; then
- (
- cd assets/utilities/itg2-util
- aclocal && autoconf && autoheader && automake --add-missing
- ./configure
- make
- )
-fi
-
-# machine revision signer
-if [ ! -f src/verify_signature/java/SignFile.class ]; then
- (
- cd src/verify_signature/java
- javac SignFile.java
- )
-fi
-
-# generate patch.zip file
-rm -f assets/patch-data/patch-dec.zip assets/patch-data/patch.zip
-(
- cd assets/patch-data/patch-dec
- zip -0 -r ../patch-dec.zip *
- ../../utilities/itg2-util/src/itg2ac-util -p ../patch-dec.zip ../patch.zip
-)
-
-# move everything into a zip file
-rm -f openitg-tmp.itg
-(
- cd assets/patch-data
- sed -r -i -e "s/<Revision>.+?<\/Revision>/<Revision>$TIMESTAMP<\/Revision>/" patch.xml
- zip -r "../../$PATCH_OUTPUT_FILE" * -x 'patch-dec/*' patch-dec.zip
-)
-
-# ..including the binary
-(
- cd src
- zip "../$PATCH_OUTPUT_FILE" openitg
-)
-
-# sign .itg file
-java -classpath src/verify_signature/java SignFile "$PATCH_OUTPUT_FILE" OpenITG-Private.rsa openitg-tmp.sig
-cat openitg-tmp.sig >>"$PATCH_OUTPUT_FILE"
Please sign in to comment.
Something went wrong with that request. Please try again.