From 10025571d961207241ce4cb015b0ace7b97ae6e8 Mon Sep 17 00:00:00 2001 From: Michael Marineau Date: Mon, 17 Feb 2014 12:42:22 -0800 Subject: [PATCH 1/2] fix(common): Disable parallel_emerge by default for most commands. I would like to phase out parallel_emerge so disable it for all commands other than build_image which is the only one that shows a noticeable benefit from it (~2 min with --fast, ~3 min with --nofast). --- build_image | 2 +- common.sh | 4 ++-- update_chroot | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/build_image b/build_image index 8649fe7c5f..f602f8c94e 100755 --- a/build_image +++ b/build_image @@ -47,7 +47,7 @@ show_help_if_requested "$@" # not needed for the typical developer workflow. DEFINE_integer build_attempt 1 \ "The build attempt for this image build." -DEFINE_boolean fast "${DEFAULT_FAST}" \ +DEFINE_boolean fast ${FLAGS_TRUE} \ "Use the parallel_emerge wrapper script." DEFINE_integer jobs "${NUM_JOBS}" \ "How many packages to build in parallel at maximum." diff --git a/common.sh b/common.sh index 61c7ce7cda..11b1803a76 100644 --- a/common.sh +++ b/common.sh @@ -392,8 +392,8 @@ if [[ -f ${GCLIENT_ROOT}/src/scripts/.default_board ]]; then fi fi -# Enable --fast by default. -DEFAULT_FAST=${FLAGS_TRUE} +# Disable --fast in most commands +DEFAULT_FAST=${FLAGS_FALSE} # Directory to store built images. Should be set by sourcing script when used. BUILD_DIR= diff --git a/update_chroot b/update_chroot index c3282df255..e310a665cf 100755 --- a/update_chroot +++ b/update_chroot @@ -113,7 +113,7 @@ fi # In first pass, update portage and toolchains. Lagged updates of both # can cause serious issues later. info "Updating basic system packages" -sudo -E ${EMERGE_CMD} ${EMERGE_FLAGS} \ +sudo -E ${EMERGE_CMD} --quiet ${EMERGE_FLAGS} \ dev-util/ccache \ sys-apps/portage \ sys-devel/crossdev \ From 16bc3521e5fb0f70b5e01e8f1b1f6637dbfb51de Mon Sep 17 00:00:00 2001 From: Michael Marineau Date: Mon, 17 Feb 2014 22:31:43 -0800 Subject: [PATCH 2/2] fix(make_chroot): Fix SDK setup w/ empty passwd and group files New baselayout 3 based SDKs define system files in separate read-only files so the normal group and passwd files don't exist yet. --- sdk_lib/make_chroot.sh | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/sdk_lib/make_chroot.sh b/sdk_lib/make_chroot.sh index 722f8ad79b..32d204129b 100755 --- a/sdk_lib/make_chroot.sh +++ b/sdk_lib/make_chroot.sh @@ -138,12 +138,17 @@ delete_existing() { } init_users () { - if grep -q "^${SUDO_USER}:[^:]*:${SUDO_UID}:${SUDO_GID}:" \ - "${FLAGS_chroot}/etc/passwd"; then + # make sure user/group database files exist + touch "${FLAGS_chroot}/etc/"{group,gshadow,passwd,shadow} + chmod 640 "${FLAGS_chroot}/etc/"{gshadow,shadow} + + # update or add developer user and group + local userent=$(bare_chroot getent passwd "${SUDO_USER}") || true + if [[ "${userent}" =~ ^[^:]*:[^:]*:${SUDO_UID}:${SUDO_GID}: ]]; then info "Updating ${SUDO_USER} (already exists in chroot)..." bare_chroot usermod -a -G "${DEFGROUPS}" \ -s /bin/bash -m -d "/home/${SUDO_USER}" "${SUDO_USER}" - elif grep -q "^${SUDO_USER}:" "${FLAGS_chroot}/etc/passwd"; then + elif [[ -n "${userent}" ]]; then die "User ${SUDO_USER} exists in chroot with different UID/GID" else info "Adding user ${SUDO_USER}..." @@ -152,27 +157,33 @@ init_users () { group_name=$(getent group "${SUDO_GID}" | cut -d: -f1) [[ -n "${group_name}" ]] || die "Looking up gid $SUDO_GID failed." - if grep -q "^${group_name}:[^:]*:${SUDO_GID}:" "${FLAGS_chroot}/etc/group" - then + local groupent=$(bare_chroot getent group "${group_name}") || true + if [[ "${groupent}" =~ ^[^:]*:[^:]*:${SUDO_GID}: ]]; then true # group/gid exists, don't need to add it - elif grep -q "^${group_name}:" "${FLAGS_chroot}/etc/group"; then + elif [[ -n "${groupent}" ]]; then die "Group ${group_name} exists in chroot with different GID" else bare_chroot groupadd -o -g "${SUDO_GID}" "${group_name}" fi + bare_chroot useradd -o \ + -G "${DEFGROUPS}" -g "${SUDO_GID}" -u "${SUDO_UID}" \ + -s /bin/bash -m -c "${full_name}" "${SUDO_USER}" + + # TODO(marineam): this can be removed once baselayout 3 is merged # We need the UID to match the host user's. This can conflict with # a particular chroot UID. At the same time, the added user has to # be a primary user for the given UID for sudo to work, which is # determined by the order in /etc/passwd. Let's put ourselves on top # of the file. - bare_chroot useradd -o \ - -G "${DEFGROUPS}" -g "${SUDO_GID}" -u "${SUDO_UID}" \ - -s /bin/bash -m -c "${full_name}" "${SUDO_USER}" # Because passwd generally isn't sorted and the entry ended up at the # bottom, it is safe to just take it and move it to top instead. - sed -e '1{h;d};$!{H;d};$G' -i "${FLAGS_chroot}/etc/group" - sed -e '1{h;d};$!{H;d};$G' -i "${FLAGS_chroot}/etc/passwd" + if [[ $(wc -l <"${FLAGS_chroot}/etc/passwd") -gt 1 ]]; then + sed -e '1{h;d};$!{H;d};$G' -i "${FLAGS_chroot}/etc/passwd" + fi + if [[ $(wc -l <"${FLAGS_chroot}/etc/group") -gt 1 ]]; then + sed -e '1{h;d};$!{H;d};$G' -i "${FLAGS_chroot}/etc/group" + fi fi }