From 4411efeb87635fe2bd751cebef9f1a7be474bb44 Mon Sep 17 00:00:00 2001 From: Peter Mayo Date: Fri, 21 Sep 2012 04:41:27 -0400 Subject: [PATCH] Propagate Google API keys into the chroot. These are a new type of credential baked into chrome/chromium for developers without internal copies of ChromeOS, and not building internal versions of Chrome. We automatically move .googleapikeys into the chroot each time. We don't overwrite the destination, so that people can configure keys the way they want. If they just don't want to be bothered, the best thing happens the easiest way. Get Keys, put them in home. Keep working. BUG=chromium-os:34438 TEST=local Change-Id: I08e5970c6092f7b789aa5efef52db93841996d8f Reviewed-on: https://gerrit.chromium.org/gerrit/33771 Reviewed-by: Mike Frysinger Commit-Ready: Peter Mayo Tested-by: Peter Mayo --- sdk_lib/enter_chroot.sh | 32 ++++++++++++++++++++++++++++++++ sdk_lib/make_chroot.sh | 2 +- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/sdk_lib/enter_chroot.sh b/sdk_lib/enter_chroot.sh index 8e764444a0..619529d2ab 100755 --- a/sdk_lib/enter_chroot.sh +++ b/sdk_lib/enter_chroot.sh @@ -56,6 +56,8 @@ the command nor args should include single quotes. For example: Otherwise, provides an interactive shell. " +CROS_LOG_PREFIX=cros_sdk:enter_chroot + # Version of info from common.sh that only echos if --verbose is set. debug() { if [ $FLAGS_verbose -eq $FLAGS_TRUE ]; then @@ -212,6 +214,35 @@ copy_into_chroot_if_exists() { cp "$1" "${FLAGS_chroot}/$2" } +# Usage: promote_api_keys +# This takes care of getting the developer API keys into the chroot where +# chrome can build with them. It needs to take it from the places a dev +# is likely to put them, and recognize that older chroots may or may not +# have been used since the concept of keys got added, as well as before +# and after the developer decding to grab his own keys. +promote_api_keys() { + local destination="${FLAGS_chroot}/home/${USER}/.googleapikeys" + # Don't disturb existing keys. They could be set differently + if [[ -s "${destination}" ]]; then + return 0 + fi + if [[ -r "${HOME}/.googleapikeys" ]]; then + cp "${HOME}/.googleapikeys" "${destination}" + if [[ -s "${destination}" ]] ; then + info "Copied Google API keys into chroot." + fi + elif [[ -r "${HOME}/.gyp/include.gypi" ]]; then + local NAME="('google_(api_key|default_client_(id|secret))')" + local WS="[[:space:]]*" + local CONTENTS="('[^\\\\']*')" + sed -nr -e "/^${WS}${NAME}${WS}[:=]${WS}${CONTENTS}.*/{s//\1: \4,/;p;}" \ + "${HOME}/.gyp/include.gypi" >"${destination}" + if [[ -s "${destination}" ]]; then + info "Put discovered Google API keys into chroot." + fi + fi +} + setup_env() { # Validate sudo timestamp before entering the critical section so that we # don't stall for a password while we have the lockfile. @@ -433,6 +464,7 @@ setup_env() { for fn in "${FILES_TO_COPY_TO_CHROOT[@]}"; do copy_into_chroot_if_exists "${HOME}/${fn}" "/home/${USER}/${fn}" done + promote_api_keys # Make sure user's requested locales are available # http://crosbug.com/19139 diff --git a/sdk_lib/make_chroot.sh b/sdk_lib/make_chroot.sh index 6f957c9f8b..94dfe826c9 100755 --- a/sdk_lib/make_chroot.sh +++ b/sdk_lib/make_chroot.sh @@ -52,7 +52,7 @@ FLAGS "$@" || exit 1 eval set -- "${FLAGS_ARGV}" check_flags_only_and_allow_null_arg "$@" && set -- -CROS_LOG_PREFIX=cros_sdk +CROS_LOG_PREFIX=cros_sdk:make_chroot assert_not_root_user # Set the right umask for chroot creation.