mirror of
https://github.com/flatcar/scripts.git
synced 2025-08-09 22:16:58 +02:00
sudo takes 150ms per invocation on Goobuntu, and with 10 invocations in enter_chroot.sh, this means that we're wasting a lot of time, every time cros_sdk is invoked. Cutting these unnecessary invocations reduces the time required to run enter_chroot.sh from 2.3s to 0.8s. CL:36618 is the companion change that updates cros_sdk to invoke sudo unshare -m prior to calling enter_chroot.sh. Summary of changes: 1. Remove all calls to sudo and just run the commands directly. - Remove the mount queue and any sudo_multi optimizations. - Rename sudo_chroot -> bare_chroot because we don't run sudo anymore there. - Remove code for validating sudo timestamp. 2. Allow the scripts to work as root: - Ensure that files created by cros_sdk that previously were owned by the user still are owned by the user (either using chown or cp -p). - Use $SUDO_USER to find the user's account. - Use $SUDO_HOME instead of $HOME to find the user's home dir. - Remove outdated code for disabling automount on Lucid, which doesn't work when run as root. - Update code for calculating the user's git username to use sudo to switch to the user. Also move it to make_chroot.sh so that this change doesn't impact performance. 3. Cleanup - Remove environment syncer process in favor of just syncing once when chroot is entered. - Remove teardown and instead rely on unshare to unmount the mounts. To make sure that outside processes never notice the mounts, we use mount -n. This also ensures that /etc/mtab never contains stale mounts. - Remove path-overrides, since it is no longer needed. BUG=chromium-os:35714, chromium-os:35679 TEST=Trybot runs. CQ-DEPEND=CL:36618 Change-Id: I919a8aadb08fafde97348e8511573c28fdd47186 Reviewed-on: https://gerrit.chromium.org/gerrit/36619 Tested-by: David James <davidjames@chromium.org> Reviewed-by: Mike Frysinger <vapier@chromium.org> Commit-Ready: David James <davidjames@chromium.org>
43 lines
1.1 KiB
Makefile
43 lines
1.1 KiB
Makefile
# Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
|
|
# Use of this source code is governed by a BSD-style license that can be
|
|
# found in the LICENSE file.
|
|
|
|
# Note that this script is invoked by make_chroot in addition
|
|
# to normal upgrade pathways.
|
|
|
|
if [ "${UID:-$(id -u)}" != 0 ]; then
|
|
# Note that since we're screwing w/ sudo variables, this script
|
|
# explicitly bounces up to root for everything it does- that way
|
|
# if anyone introduces a temp depriving in the sudo setup, it can't break
|
|
# mid upgrade.
|
|
load_environment_whitelist
|
|
exec sudo bash -e "${VERSION_HOOKS_DIR}/45_rewrite_sudoers.d" \
|
|
/ "${USER}" "${ENVIRONMENT_WHITELIST[@]}"
|
|
exit 1
|
|
fi
|
|
|
|
# Reaching here means we're root.
|
|
|
|
if [ $# -lt 2 ]; then
|
|
echo "Invoked with wrong number of args; expected root USER [variables]*"
|
|
exit 1
|
|
fi
|
|
|
|
root=$1
|
|
username=$2
|
|
shift
|
|
shift
|
|
set -- "${@}" CROS_WORKON_SRCROOT PORTAGE_USERNAME
|
|
|
|
cat > "${root}/etc/sudoers.d/90_cros" <<EOF
|
|
Defaults env_keep += "${*}"
|
|
%adm ALL=(ALL) ALL
|
|
root ALL=(ALL) ALL
|
|
${username} ALL=NOPASSWD: ALL
|
|
EOF
|
|
|
|
chmod 0440 "${root}/etc/sudoers.d/90_cros"
|
|
chown root:root "${root}/etc/sudoers.d/90_cros"
|
|
|
|
exit 0
|