Chromium Code Reviews
|
| OLD | NEW |
|---|---|
| (Empty) | |
| 1 #!/bin/sh | |
| 2 | |
| 3 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
| 4 # Use of this source code is governed by a BSD-style license that can be | |
| 5 # found in the LICENSE file. | |
| 6 | |
|
Mark Mentovai
2012/04/24 20:13:11
I like to run scripts under |set -e| to make them
garykac
2012/04/24 22:31:12
Done.
| |
| 7 # This script signs the Chromoting binaries, builds the Chrome Remote Desktop | |
| 8 # installer and then packages it into a .dmg. It requires that Iceberg be | |
| 9 # installed (for 'freeze'). | |
| 10 # | |
| 11 # usage: sign_and_build.sh output_dir input_dir codesign_keychain codesign_id | |
| 12 # | |
| 13 # The final disk image (dmg) is placed in |output_dir|. | |
| 14 | |
| 15 # Binaries to sign. | |
| 16 ME2ME_HOST=PrivilegedHelperTools/org.chromium.chromoting.me2me_host | |
| 17 | |
| 18 # Iceberg creates this directory to write its output. | |
| 19 PKG_DIR=build | |
| 20 | |
| 21 # The Chromoting Host installer is a meta-package that consists of 3 | |
| 22 # components: | |
| 23 # * Chromoting Host Service package | |
| 24 # * Chromoting Host Uninstaller package | |
| 25 # * Keystone package(GoogleSoftwareUpdate - for Official builds only) | |
| 26 PKGPROJ_HOST='ChromotingHost.packproj' | |
| 27 PKGPROJ_HOST_SERVICE='ChromotingHostService.packproj' | |
| 28 PKGPROJ_HOST_UNINSTALLER='ChromotingHostUninstaller.packproj' | |
| 29 | |
| 30 # Final mpkg name (for Official builds). | |
| 31 PKG_FINAL='ChromeRemoteDesktopHost.mpkg' | |
| 32 | |
| 33 DMG_TEMP=dmg_tmp | |
| 34 DMG_NAME='Chrome Remote Desktop' | |
| 35 DMG_DIR="${DMG_TEMP}/${DMG_NAME}" | |
| 36 DMG_FILENAME='Chrome Remote Desktop.dmg' | |
| 37 | |
| 38 ME="$(basename "${0}")" | |
| 39 readonly ME | |
| 40 | |
| 41 err() { | |
| 42 echo "[$(date +'%Y-%m-%d %H:%M:%S%z')]: ${@}" >&2 | |
| 43 } | |
| 44 | |
| 45 err_exit() { | |
| 46 err "${@}" | |
| 47 exit 1 | |
| 48 } | |
| 49 | |
| 50 # shell_safe_path ensures that |path| is safe to pass to tools as a | |
| 51 # command-line argument. If the first character in |path| is "-", "./" is | |
| 52 # prepended to it. The possibly-modified |path| is output. | |
| 53 shell_safe_path() { | |
| 54 local path="${1}" | |
| 55 if [[ "${path:0:1}" = "-" ]]; then | |
| 56 echo "./${path}" | |
| 57 else | |
| 58 echo "${path}" | |
| 59 fi | |
| 60 } | |
| 61 | |
| 62 verify_empty_dir() { | |
| 63 local dir="${1}" | |
| 64 if [[ ! -d "${dir}" ]]; then | |
| 65 mkdir "${dir}" | |
| 66 fi | |
| 67 | |
| 68 shopt -s nullglob dotglob | |
| 69 local dir_contents=("${dir}"/*) | |
| 70 shopt -u nullglob dotglob | |
| 71 | |
| 72 if [[ ${#dir_contents[@]} -ne 0 ]]; then | |
| 73 err "output directory must be empty" | |
| 74 exit 1 | |
| 75 fi | |
| 76 } | |
| 77 | |
| 78 sign_binaries() { | |
| 79 local input_dir="${1}" | |
| 80 local keychain="${2}" | |
| 81 local id="${3}" | |
| 82 | |
| 83 me2me_host="${input_dir}/${ME2ME_HOST}" | |
| 84 if [[ ! -f "${me2me_host}" ]]; then | |
| 85 err_exit "Input file doesn't exist: ${me2me_host}" | |
| 86 fi | |
| 87 | |
| 88 echo Signing "${me2me_host}" | |
| 89 codesign -vv -s "${id}" --keychain "${keychain}" "${me2me_host}" | |
| 90 if [[ ${?} != 0 ]]; then | |
|
Mark Mentovai
2012/04/24 20:13:11
If you were using |set -e|, you could get rid of t
garykac
2012/04/24 22:31:12
Done.
| |
| 91 err_exit "Unable to sign: ${me2me_host}" | |
| 92 fi | |
| 93 | |
| 94 # Verify signing. | |
| 95 codesign -v "${me2me_host}" | |
| 96 if [[ ${?} != 0 ]]; then | |
| 97 err_exit "Not properly signed: ${me2me_host}" | |
| 98 fi | |
| 99 } | |
| 100 | |
| 101 build_package() { | |
| 102 local pkg="${1}" | |
| 103 echo "Building .pkg from ${pkg}" | |
| 104 freeze "${pkg}" | |
| 105 if [[ ${?} != 0 ]]; then | |
| 106 err_exit "Unable to build package: ${pkg}" | |
| 107 fi | |
| 108 } | |
| 109 | |
| 110 build_packages() { | |
| 111 local input_dir="${1}" | |
| 112 build_package "${input_dir}/${PKGPROJ_HOST_SERVICE}" | |
| 113 build_package "${input_dir}/${PKGPROJ_HOST_UNINSTALLER}" | |
| 114 build_package "${input_dir}/${PKGPROJ_HOST}" | |
| 115 } | |
| 116 | |
| 117 build_dmg() { | |
| 118 local input_dir="${1}" | |
| 119 local output_dir="${2}" | |
| 120 | |
| 121 # Create the .dmg. | |
|
Mark Mentovai
2012/04/24 20:13:11
It’s advisable to use pkg-dmg instead of this (as
garykac
2012/04/24 22:31:12
OK, I'll make a follow-up cl and send it to you fo
Mark Mentovai
2012/04/24 22:58:19
garykac wrote:
| |
| 122 echo "Building .dmg..." | |
| 123 mkdir -p "${input_dir}/${DMG_DIR}/${PKG_FINAL}" | |
| 124 # Copy .mpkg installer. | |
| 125 ditto "${input_dir}/${PKG_DIR}/${PKG_FINAL}" \ | |
| 126 "${input_dir}/${DMG_DIR}/${PKG_FINAL}" | |
| 127 # Copy .keystone_install script to top level of .dmg. | |
| 128 # Keystone calls this script during upgrades. | |
| 129 cp "${input_dir}/Scripts/keystone_install.sh" \ | |
| 130 "${input_dir}/${DMG_DIR}/.keystone_install" | |
| 131 # Build the .dmg from the directory. | |
| 132 hdiutil create "${output_dir}/${DMG_FILENAME}" \ | |
| 133 -srcfolder "${input_dir}/${DMG_DIR}" -ov -quiet | |
| 134 | |
| 135 if [[ ${?} != 0 || ! -f "${output_dir}/${DMG_FILENAME}" ]]; then | |
| 136 err_exit "Unable to create disk image: ${DMG_FILENAME}" | |
| 137 fi | |
| 138 } | |
| 139 | |
| 140 usage() { | |
| 141 echo "Usage: ${ME}: output_dir input_dir codesign_keychain codesign_id" >&2 | |
| 142 } | |
| 143 | |
| 144 main() { | |
| 145 local output_dir="$(shell_safe_path "${1}")" | |
| 146 local input_dir="$(shell_safe_path "${2}")" | |
| 147 local codesign_keychain="$(shell_safe_path "${3}")" | |
| 148 local codesign_id="${4}" | |
| 149 | |
| 150 verify_empty_dir "${output_dir}" | |
| 151 | |
| 152 sign_binaries "${input_dir}" "${codesign_keychain}" "${codesign_id}" | |
| 153 build_packages "${input_dir}" | |
|
Mark Mentovai
2012/04/24 20:13:11
You’re not signing the package?
Or does that just
garykac
2012/04/24 22:31:12
First step is to get the binaries signed since the
Mark Mentovai
2012/04/24 22:58:19
garykac wrote:
| |
| 154 build_dmg "${input_dir}" "${output_dir}" | |
| 155 } | |
| 156 | |
| 157 if [[ ${#} -ne 4 ]]; then | |
| 158 usage | |
| 159 exit 1 | |
| 160 fi | |
| 161 | |
| 162 main "${@}" | |
| 163 exit ${?} | |
| OLD | NEW |