Add Omaha config generation script.
Generates Omaha configuration data for full update disk image.
Change-Id: Idaeccd29446a6c50b2d26a443742f553a2ec3be0
diff --git a/installer/scripts/build/generate_omaha_config.sh b/installer/scripts/build/generate_omaha_config.sh
new file mode 100755
index 0000000..98c4856
--- /dev/null
+++ b/installer/scripts/build/generate_omaha_config.sh
@@ -0,0 +1,79 @@
+#!/bin/bash
+##
+## Copyright (c) 2012 The WebM project authors. All Rights Reserved.
+##
+## Use of this source code is governed by a BSD-style license
+## that can be found in the LICENSE file in the root of the source
+## tree. An additional intellectual property rights grant can be found
+## in the file PATENTS. All contributing project authors may
+## be found in the AUTHORS file in the root of the source tree.
+
+# A script to generate an Omaha config WebM QuickTime.
+#
+# Example:
+# generate_omaha_config.sh webmquicktime.config
+#
+set -e
+
+if [[ $(basename $(pwd)) != "installer" ]] || \
+ [[ $(basename $(dirname $(pwd))) != "webmquicktime" ]]; then
+ echo "$(basename $0) must be run from webmquicktime/installer"
+ exit 1
+fi
+
+source scripts/build/util.sh
+file_exists "$(which openssl)" || die "openssl does not exist in PATH."
+
+generate_config() {
+ local readonly COMPONENT="$1"
+ file_exists "${COMPONENT}" || die "${COMPONENT} does not exist."
+ local readonly DMG_FILE="$2"
+ file_exists "${DMG_FILE}" || die "${DMG_FILE} does not exist."
+ local readonly CONFIG_NAME="$3"
+ [[ -n "${CONFIG_NAME}" ]] || die "empty CONFIG_NAME in ${FUNCNAME}."
+
+ # Get the size of |DMG_FILE|.
+ local readonly DMG_SIZE="$(stat -f%z "${DMG_FILE}")"
+ [[ -n "${DMG_SIZE}" ]] || die "empty DMG_SIZE in ${FUNCNAME}."
+
+ # Generate the omaha hash (base64 encoded SHA1 hash of |DMG_FILE|).
+ local readonly OMAHA_HASH=$(openssl sha1 -binary "${DMG_FILE}" \
+ | openssl base64)
+ [[ -n "${OMAHA_HASH}" ]] || die "empty OMAHA_HASH in ${FUNCNAME}."
+
+ # Read the application ID and version from |COMPONENT|.
+ READ_PLIST="scripts/build/read_bundle_plist.sh"
+ file_exists "${READ_PLIST}" || die "${READ_PLIST} does not exist."
+ local readonly BUNDLE_ID=$(${READ_PLIST} "${COMPONENT}" id)
+ [[ -n "${BUNDLE_ID}" ]] || die "empty BUNDLE_ID in ${FUNCNAME}."
+ local readonly VERSION=$(${READ_PLIST} "${COMPONENT}" v)
+ [[ -n "${VERSION}" ]] || die "empty VERSION in ${FUNCNAME}."
+
+ cat <<__END_CONFIG
+# Autogenerated Omaha config for ${CONFIG_NAME}
+AppId: "${BUNDLE_ID}"
+ConfigName: "${CONFIG_NAME}"
+
+Rule {
+ Test {Version: "[-${VERSION})"}
+
+ Update {
+ Codebase: "http://dl.google.com/mac/download/${DMG_FILE}"
+ Hash: "${OMAHA_HASH}"
+ Size: "${DMG_SIZE}"
+ NeedsAdmin: "true"
+ }
+}
+__END_CONFIG
+}
+
+readonly CONFIG_FILE="$1"
+if [[ $# -lt 1 ]]; then
+ errorlog "usage: $(basename $0) <config file>"
+ die "config file is empty."
+fi
+
+generate_config "../build/Release/AWebM.component" \
+ "webm_quicktime_installer.dmg" "WebM QuickTime Installer" \
+ > "${CONFIG_FILE}"
+debuglog "Done, wrote config to ${CONFIG_FILE}."