15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#!/bin/bash -p 25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# Copyright (c) 2009 The Chromium Authors. All rights reserved. 45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# Use of this source code is governed by a BSD-style license that can be 55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# found in the LICENSE file. 65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# This script creates sign_app.sh and sign_versioned_dir.sh, the scripts that 85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# will be used to sign the application bundle and inner bundles. It also 95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# creates auxiliary files that these scripts need to do their jobs, such as 105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# the custom resource rules used to sign the outermost application bundle. 115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# The build places these in the "${mac_product_name} Packaging" directory next 125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# to the .app bundle. The packaging system is expected to run these scripts to 135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# sign everything. 145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)set -eu 165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# Environment sanitization. Set a known-safe PATH. Clear environment variables 185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# that might impact the interpreter's operation. The |bash -p| invocation 195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# on the #! line takes the bite out of BASH_ENV, ENV, and SHELLOPTS (among 205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# other features), but clearing them here ensures that they won't impact any 215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# shell scripts used as utility programs. SHELLOPTS is read-only and can't be 225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# unset, only unexported. 235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)export PATH="/usr/bin:/bin:/usr/sbin:/sbin" 245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)unset BASH_ENV CDPATH ENV GLOBIGNORE IFS POSIXLY_CORRECT 255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)export -n SHELLOPTS 265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)ME="$(basename "${0}")" 285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)readonly ME 295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)if [[ ${#} -ne 3 ]]; then 315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) echo "usage: ${ME} packaging_dir mac_product_name version" >& 2 325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) exit 1 335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)fi 345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)packaging_dir="${1}" 365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)mac_product_name="${2}" 375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)version="${3}" 385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)script_dir="$(dirname "${0}")" 405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)in_files=( 415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) "${script_dir}/sign_app.sh.in" 425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) "${script_dir}/sign_versioned_dir.sh.in" 435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) "${script_dir}/app_resource_rules.plist.in" 445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)) 455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# Double-backslash each dot: one backslash belongs in the regular expression, 475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# and the other backslash tells sed not to treat the first backslash 485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# specially. 495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)version_regex="$(echo "${version}" | sed -e 's/\./\\\\./g')" 505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)mkdir -p "${packaging_dir}" 525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)for in_file in "${in_files[@]}"; do 545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) out_file="${packaging_dir}/$(basename "${in_file:0:${#in_file} - 3}")" 555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) sed -e "s/@MAC_PRODUCT_NAME@/${mac_product_name}/g" \ 565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) -e "s/@VERSION@/${version}/g" \ 575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) -e "s/@VERSION_REGEX@/${version_regex}/g" \ 585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) < "${in_file}" \ 595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) > "${out_file}" 605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if [[ "${out_file: -3}" = ".sh" ]]; then 625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) chmod +x "${out_file}" 635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) fi 645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)done 65