<commit_before>#!/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}."<commit_msg>generate_omaha_config.sh: correct DMG file name.<commit_after>#!/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 <|COMPONENT|> <|DMG_BASE|> <|CONFIG_NAME|>
#
# Generates Omaha server configuration for |COMPONENT|. |COMPONENT| must be
# a bundle. |DMG_BASE| is the file name part of the DMG file in which
# |COMPONENT| will be distributed. |CONFIG_NAME| is the friendly name for the
# Omaha configuration.
#
# All parameters are required. |generate_config| will |die| when a param is
# missing, empty, or invalid.
generate_config() {
  local readonly COMPONENT="$1"
  file_exists "${COMPONENT}" || die "${COMPONENT} does not exist."
  local readonly DMG_BASE="$2"
  [[ -n "${DMG_BASE}" ]] || die "empty DMG_BASE in ${FUNCNAME}."
  local readonly CONFIG_NAME="$3"
  [[ -n "${CONFIG_NAME}" ]] || die "empty CONFIG_NAME in ${FUNCNAME}."

  # Read the application ID and version from |COMPONENT|.
  local readonly 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}."

  # TODO(tomfinegan): Integrate the DMG build and config generation, and pass
  #                   the actual DMG file name around instead of this building
  #                   it nonsense.
  # Build |DMG_FILE| using |VERSION| and |DMG_BASE|.
  local readonly DMG_FILE="${DMG_BASE}_${VERSION}.dmg"
  file_exists "${DMG_FILE}" || die "${DMG_FILE} does not exist."

  # 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}."

  cat <<__END_CONFIG
# Autogenerated Omaha config for ${CONFIG_NAME}
AppId: "${BUNDLE_ID}"
ConfigName: "${CONFIG_NAME}"

Rule {
  Test {Version: "[-${VERSION})"}

  Update {
    Codebase: "https://dl.google.com/dl/webmquicktime/${DMG_FILE}"
    Hash: "${OMAHA_HASH}"
    Size: "${DMG_SIZE}"
  }
}
__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" "WebM QuickTime Installer" \
    > "${CONFIG_FILE}"
debuglog "Done, wrote config to ${CONFIG_FILE}."
{'fraction_non_alphanumeric': 0.15261437908496733, 'fraction_numerical': 0.0058823529411764705, 'mean_word_length': 4.148023549201009, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 10, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1555007', 'n_tokens_mistral': 2128, 'n_tokens_neox': 2066, 'n_words': 662}