| OLD | NEW |
| 1 #!/bin/sh | 1 #!/bin/bash -p |
| 2 | 2 |
| 3 # Copyright (c) 2009 The Chromium Authors. All rights reserved. | 3 # Copyright (c) 2009 The Chromium Authors. All rights reserved. |
| 4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
| 5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
| 6 | 6 |
| 7 # This script creates sign.sh, the script that will be used to sign the | 7 # This script creates sign_app.sh and sign_versioned_dir.sh, the scripts that |
| 8 # application bundle and inner bundles. It also creates auxiliary files that | 8 # will be used to sign the application bundle and inner bundles. It also |
| 9 # sign.sh needs to do its job, such as the custom resource rules used to sign | 9 # creates auxiliary files that these scripts need to do their jobs, such as |
| 10 # the outermost application bundle. These files are placed in the Packaging | 10 # the custom resource rules used to sign the outermost application bundle. |
| 11 # directory next to the .app bundle. The packaging system is expected to run | 11 # The build places these in the "${mac_product_name} Packaging" directory next |
| 12 # sign.sh to sign everything. | 12 # to the .app bundle. The packaging system is expected to run these scripts to |
| 13 # sign everything. |
| 13 | 14 |
| 14 set -e | 15 set -eu |
| 15 | 16 |
| 16 if [ $# -ne 3 ] ; then | 17 # Environment sanitization. Set a known-safe PATH. Clear environment variables |
| 17 echo "usage: ${0} PACKAGING_DIR MAC_PRODUCT_NAME VERSION" >& 2 | 18 # that might impact the interpreter's operation. The |bash -p| invocation |
| 19 # on the #! line takes the bite out of BASH_ENV, ENV, and SHELLOPTS (among |
| 20 # other features), but clearing them here ensures that they won't impact any |
| 21 # shell scripts used as utility programs. SHELLOPTS is read-only and can't be |
| 22 # unset, only unexported. |
| 23 export PATH="/usr/bin:/bin:/usr/sbin:/sbin" |
| 24 unset BASH_ENV CDPATH ENV GLOBIGNORE IFS POSIXLY_CORRECT |
| 25 export -n SHELLOPTS |
| 26 |
| 27 ME="$(basename "${0}")" |
| 28 readonly ME |
| 29 |
| 30 if [[ ${#} -ne 3 ]]; then |
| 31 echo "usage: ${ME} packaging_dir mac_product_name version" >& 2 |
| 18 exit 1 | 32 exit 1 |
| 19 fi | 33 fi |
| 20 | 34 |
| 21 PACKAGING_DIR="${1}" | 35 packaging_dir="${1}" |
| 22 MAC_PRODUCT_NAME="${2}" | 36 mac_product_name="${2}" |
| 23 VERSION="${3}" | 37 version="${3}" |
| 24 | 38 |
| 25 INPUT_DIR="$(dirname "${0}")" | 39 script_dir="$(dirname "${0}")" |
| 26 SIGN_SH_IN_FILE="${INPUT_DIR}/sign.sh.in" | 40 in_files=( |
| 27 SIGN_SH_FILE="${PACKAGING_DIR}/sign.sh" | 41 "${script_dir}/sign_app.sh.in" |
| 28 BROWSER_APP_RULES_IN_FILE="${INPUT_DIR}/app_resource_rules.plist.in" | 42 "${script_dir}/sign_versioned_dir.sh.in" |
| 29 BROWSER_APP_RULES_FILE="${PACKAGING_DIR}/app_resource_rules.plist" | 43 "${script_dir}/app_resource_rules.plist.in" |
| 44 ) |
| 30 | 45 |
| 31 # Double-backslash each dot: one backslash belongs in the regular expression, | 46 # Double-backslash each dot: one backslash belongs in the regular expression, |
| 32 # and the other backslash tells sed not to treat the first backslash | 47 # and the other backslash tells sed not to treat the first backslash |
| 33 # specially. | 48 # specially. |
| 34 VERSION_REGEX="$(echo "${VERSION}" | sed -e 's/\./\\\\./g')" | 49 version_regex="$(echo "${version}" | sed -e 's/\./\\\\./g')" |
| 35 | 50 |
| 36 mkdir -p "${PACKAGING_DIR}" | 51 mkdir -p "${packaging_dir}" |
| 37 sed -e "s/@MAC_PRODUCT_NAME@/${MAC_PRODUCT_NAME}/g" \ | |
| 38 -e "s/@VERSION@/${VERSION}/g" \ | |
| 39 -e "s/@VERSION_REGEX@/${VERSION_REGEX}/g" \ | |
| 40 < "${SIGN_SH_IN_FILE}" \ | |
| 41 > "${SIGN_SH_FILE}" | |
| 42 chmod +x "${SIGN_SH_FILE}" | |
| 43 | 52 |
| 44 sed -e "s/@MAC_PRODUCT_NAME@/${MAC_PRODUCT_NAME}/g" \ | 53 for in_file in "${in_files[@]}"; do |
| 45 -e "s/@VERSION@/${VERSION}/g" \ | 54 out_file="${packaging_dir}/$(basename "${in_file:0:${#in_file} - 3}")" |
| 46 -e "s/@VERSION_REGEX@/${VERSION_REGEX}/g" \ | 55 sed -e "s/@MAC_PRODUCT_NAME@/${mac_product_name}/g" \ |
| 47 < "${BROWSER_APP_RULES_IN_FILE}" \ | 56 -e "s/@VERSION@/${version}/g" \ |
| 48 > "${BROWSER_APP_RULES_FILE}" | 57 -e "s/@VERSION_REGEX@/${version_regex}/g" \ |
| 58 < "${in_file}" \ |
| 59 > "${out_file}" |
| 60 |
| 61 if [[ "${out_file: -3}" = ".sh" ]]; then |
| 62 chmod +x "${out_file}" |
| 63 fi |
| 64 done |
| OLD | NEW |