mirror of
https://github.com/flatcar/scripts.git
synced 2025-09-27 00:21:44 +02:00
commit
f4b4570bb4
@ -39,7 +39,7 @@ delete_prompt() {
|
|||||||
|
|
||||||
# Only prompt if both stdin and stdout are a tty. If either is not a tty,
|
# Only prompt if both stdin and stdout are a tty. If either is not a tty,
|
||||||
# then the user may not be present, so we shouldn't bother prompting.
|
# then the user may not be present, so we shouldn't bother prompting.
|
||||||
if [ -t 0 -a -t 1 -a "${USER}" != 'chrome-bot' ]; then
|
if [ -t 0 -a -t 1 ]; then
|
||||||
read -p "Would you like to delete the output directory (y/N)? " SURE
|
read -p "Would you like to delete the output directory (y/N)? " SURE
|
||||||
SURE="${SURE:0:1}" # Get just the first character.
|
SURE="${SURE:0:1}" # Get just the first character.
|
||||||
else
|
else
|
||||||
|
57
common.sh
57
common.sh
@ -172,61 +172,8 @@ cmp_ver() {
|
|||||||
return $?
|
return $?
|
||||||
}
|
}
|
||||||
|
|
||||||
# Directory locations inside the dev chroot; try the new default,
|
# repo source root inside the chroot, usually mounted from the outside.
|
||||||
# falling back to user specific paths if the upgrade has yet to
|
CHROOT_TRUNK_DIR="/mnt/host/source"
|
||||||
# happen.
|
|
||||||
_user="${USER}"
|
|
||||||
[[ ${USER} == "root" ]] && _user="${SUDO_USER}"
|
|
||||||
_CHROOT_TRUNK_DIRS=( "/home/${_user}/trunk" /mnt/host/source )
|
|
||||||
unset _user
|
|
||||||
|
|
||||||
_process_mount_pt() {
|
|
||||||
# Given 4 arguments; the root path, the variable to set,
|
|
||||||
# the old location, and the new; finally, forcing the upgrade is doable
|
|
||||||
# via if a 5th arg is provided.
|
|
||||||
# This will then try to migrate the old to new if we can do so right now
|
|
||||||
# (else leaving symlinks in place w/in the new), and will set $1 to the
|
|
||||||
# new location.
|
|
||||||
local base=${1:-/} var=$2 old=$3 new=$4 force=${5:-false}
|
|
||||||
local _sudo=$([[ ${USER} != "root" ]] && echo sudo)
|
|
||||||
local val=${new}
|
|
||||||
if [[ -L ${base}/${new} ]] || [[ ! -e ${base}/${new} ]]; then
|
|
||||||
# Ok, it's either a symlink or this is the first run. Upgrade if we can-
|
|
||||||
# specifically, if we're outside the chroot and we can rmdir the old.
|
|
||||||
# If we cannot rmdir the old, that's due to a mount being bound to that
|
|
||||||
# point (even if we can't see it, it's there)- thus fallback to adding
|
|
||||||
# compat links.
|
|
||||||
if ${force} || ( [[ ${INSIDE_CHROOT} -eq 0 ]] && \
|
|
||||||
${_sudo} rmdir "${base}/${old}" 2>/dev/null ); then
|
|
||||||
${_sudo} rm -f "${base}/${new}" || :
|
|
||||||
${_sudo} mkdir -p "${base}/${new}" "$(dirname "${base}/${old}" )"
|
|
||||||
${_sudo} ln -s "${new}" "${base}/${old}"
|
|
||||||
else
|
|
||||||
if [[ ! -L ${base}/${new} ]]; then
|
|
||||||
# We can't do the upgrade right now; install compatibility links.
|
|
||||||
${_sudo} mkdir -p "$(dirname "${base}/${new}")" "${base}/${old}"
|
|
||||||
${_sudo} ln -s "${old}" "${base}/${new}"
|
|
||||||
fi
|
|
||||||
val=${old}
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
eval "${var}=\"${val}\""
|
|
||||||
}
|
|
||||||
|
|
||||||
set_chroot_trunk_dir() {
|
|
||||||
# This takes two optional arguments; the first being the path to the chroot
|
|
||||||
# base; this is only used by enter_chroot. The second argument is whether
|
|
||||||
# or not to force the new pathways; this is only used by make_chroot. Passing
|
|
||||||
# a non-null value for $2 forces the new paths.
|
|
||||||
if [[ ${INSIDE_CHROOT} -eq 0 ]] && [[ -z ${1-} ]]; then
|
|
||||||
# Can't do the upgrade, thus skip trying to do so.
|
|
||||||
CHROOT_TRUNK_DIR="${_CHROOT_TRUNK_DIRS[1]}"
|
|
||||||
return
|
|
||||||
fi
|
|
||||||
_process_mount_pt "$1" CHROOT_TRUNK_DIR "${_CHROOT_TRUNK_DIRS[@]}" ${2:+true}
|
|
||||||
}
|
|
||||||
|
|
||||||
set_chroot_trunk_dir
|
|
||||||
|
|
||||||
# Construct a list of possible locations for the source tree. This list is
|
# Construct a list of possible locations for the source tree. This list is
|
||||||
# based on various environment variables and globals that may have been set
|
# based on various environment variables and globals that may have been set
|
||||||
|
@ -99,10 +99,6 @@ FUSE_DEVICE="/dev/fuse"
|
|||||||
LOCKFILE="${FLAGS_chroot}/.enter_chroot.lock"
|
LOCKFILE="${FLAGS_chroot}/.enter_chroot.lock"
|
||||||
MOUNTED_PATH=$(readlink -f "$FLAGS_chroot")
|
MOUNTED_PATH=$(readlink -f "$FLAGS_chroot")
|
||||||
|
|
||||||
# Reset the depot tools/internal trunk pathways to what they'll
|
|
||||||
# be w/in the chroot.
|
|
||||||
set_chroot_trunk_dir "${FLAGS_chroot}"
|
|
||||||
|
|
||||||
|
|
||||||
setup_mount() {
|
setup_mount() {
|
||||||
# If necessary, mount $source in the host FS at $target inside the
|
# If necessary, mount $source in the host FS at $target inside the
|
||||||
@ -235,6 +231,7 @@ setup_env() {
|
|||||||
# Do this early as it's slow and only needs basic mounts (above).
|
# Do this early as it's slow and only needs basic mounts (above).
|
||||||
generate_locales &
|
generate_locales &
|
||||||
|
|
||||||
|
mkdir -p "${FLAGS_chroot}/${CHROOT_TRUNK_DIR}"
|
||||||
setup_mount "${FLAGS_trunk}" "--rbind" "${CHROOT_TRUNK_DIR}"
|
setup_mount "${FLAGS_trunk}" "--rbind" "${CHROOT_TRUNK_DIR}"
|
||||||
|
|
||||||
debug "Setting up referenced repositories if required."
|
debug "Setting up referenced repositories if required."
|
||||||
|
@ -154,15 +154,9 @@ init_setup () {
|
|||||||
ln -sf "${CHROOT_TRUNK_DIR}/src/third_party/portage-stable" \
|
ln -sf "${CHROOT_TRUNK_DIR}/src/third_party/portage-stable" \
|
||||||
"${FLAGS_chroot}"/"${PORTAGE_STABLE_OVERLAY}"
|
"${FLAGS_chroot}"/"${PORTAGE_STABLE_OVERLAY}"
|
||||||
|
|
||||||
# Some operations need an mtab.
|
|
||||||
ln -sfT /proc/mounts "${FLAGS_chroot}/etc/mtab"
|
|
||||||
|
|
||||||
# Set up sudoers. Inside the chroot, the user can sudo without a password.
|
# Set up sudoers. Inside the chroot, the user can sudo without a password.
|
||||||
# (Safe enough, since the only way into the chroot is to 'sudo chroot', so
|
# (Safe enough, since the only way into the chroot is to 'sudo chroot', so
|
||||||
# the user's already typed in one sudo password...)
|
# the user's already typed in one sudo password...)
|
||||||
# Make sure the sudoers.d subdir exists as older stage3 base images lack it.
|
|
||||||
mkdir -p "${FLAGS_chroot}/etc/sudoers.d"
|
|
||||||
|
|
||||||
# Setup proxied vars.
|
# Setup proxied vars.
|
||||||
load_environment_whitelist
|
load_environment_whitelist
|
||||||
local extended_whitelist=(
|
local extended_whitelist=(
|
||||||
@ -173,14 +167,10 @@ init_setup () {
|
|||||||
|
|
||||||
cat > "${FLAGS_chroot}/etc/sudoers.d/90_cros" <<EOF
|
cat > "${FLAGS_chroot}/etc/sudoers.d/90_cros" <<EOF
|
||||||
Defaults env_keep += "${extended_whitelist[*]}"
|
Defaults env_keep += "${extended_whitelist[*]}"
|
||||||
%adm ALL=(ALL) ALL
|
|
||||||
root ALL=(ALL) ALL
|
|
||||||
${SUDO_USER} ALL=NOPASSWD: ALL
|
${SUDO_USER} ALL=NOPASSWD: ALL
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
find "${FLAGS_chroot}/etc/"sudoers* -type f -exec chmod 0440 {} +
|
chmod 0440 "${FLAGS_chroot}/etc/sudoers.d/90_cros"
|
||||||
# Fix bad group for some.
|
|
||||||
chown -R root:root "${FLAGS_chroot}/etc/"sudoers*
|
|
||||||
|
|
||||||
# Create directories referred to by our conf files.
|
# Create directories referred to by our conf files.
|
||||||
mkdir -p -m 775 "${FLAGS_chroot}/var/lib/portage/pkgs" \
|
mkdir -p -m 775 "${FLAGS_chroot}/var/lib/portage/pkgs" \
|
||||||
@ -222,19 +212,8 @@ EOF
|
|||||||
sudo ln -s "${CHROOT_TRUNK_DIR}"/chromite "${python_path}"
|
sudo ln -s "${CHROOT_TRUNK_DIR}"/chromite "${python_path}"
|
||||||
done
|
done
|
||||||
|
|
||||||
# Select a small set of locales for the user if they haven't done so
|
# Create ~/trunk symlink, it must point to CHROOT_TRUNK_DIR
|
||||||
# already. This makes glibc upgrades cheap by only generating a small
|
ln -sfT "${CHROOT_TRUNK_DIR}" "$FLAGS_chroot/home/${SUDO_USER}/trunk"
|
||||||
# set of locales. The ones listed here are basically for the buildbots
|
|
||||||
# which always assume these are available. This works in conjunction
|
|
||||||
# with `cros_sdk --enter`.
|
|
||||||
# http://crosbug.com/20378
|
|
||||||
local localegen="$FLAGS_chroot/etc/locale.gen"
|
|
||||||
if ! grep -q -v -e '^#' -e '^$' "${localegen}" ; then
|
|
||||||
cat <<EOF >> "${localegen}"
|
|
||||||
en_US ISO-8859-1
|
|
||||||
en_US.UTF-8 UTF-8
|
|
||||||
EOF
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Automatically change to scripts directory.
|
# Automatically change to scripts directory.
|
||||||
echo 'cd ${CHROOT_CWD:-~/trunk/src/scripts}' \
|
echo 'cd ${CHROOT_CWD:-~/trunk/src/scripts}' \
|
||||||
@ -244,11 +223,6 @@ EOF
|
|||||||
echo ". ~/trunk/src/scripts/bash_completion" \
|
echo ". ~/trunk/src/scripts/bash_completion" \
|
||||||
| user_append "$FLAGS_chroot/home/${SUDO_USER}/.bashrc"
|
| user_append "$FLAGS_chroot/home/${SUDO_USER}/.bashrc"
|
||||||
|
|
||||||
if [[ "${SUDO_USER}" = "chrome-bot" ]]; then
|
|
||||||
# Copy ssh keys, so chroot'd chrome-bot can scp files from chrome-web.
|
|
||||||
cp -rp ~/.ssh "$FLAGS_chroot/home/${SUDO_USER}/"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ -f ${SUDO_HOME}/.gitconfig ]]; then
|
if [[ -f ${SUDO_HOME}/.gitconfig ]]; then
|
||||||
# Copy .gitconfig into chroot so repo and git can be used from inside.
|
# Copy .gitconfig into chroot so repo and git can be used from inside.
|
||||||
# This is required for repo to work since it validates the email address.
|
# This is required for repo to work since it validates the email address.
|
||||||
@ -322,11 +296,6 @@ else
|
|||||||
# Set up users, if needed, before mkdir/mounts below.
|
# Set up users, if needed, before mkdir/mounts below.
|
||||||
init_users
|
init_users
|
||||||
|
|
||||||
# Reset internal vars to force them to the 'inside the chroot' value;
|
|
||||||
# since user directories now exist, this can do the upgrade in place.
|
|
||||||
set_chroot_trunk_dir "${FLAGS_chroot}" poppycock
|
|
||||||
mkdir -p "${FLAGS_chroot}/${CHROOT_TRUNK_DIR}" "${FLAGS_chroot}/run"
|
|
||||||
|
|
||||||
# Run all the init stuff to setup the env.
|
# Run all the init stuff to setup the env.
|
||||||
init_setup
|
init_setup
|
||||||
fi
|
fi
|
||||||
|
Loading…
x
Reference in New Issue
Block a user