Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chroot improvements #2198

Merged
merged 2 commits into from
Feb 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions misc-tools/dj_make_chroot.in
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,11 @@ if [ -n "$WORKDIR" ] && [ -d "$WORKDIR" ]; then
rm -rf "$WORKDIR"
fi

# Add indication to interactive shell that the user is in the chroot
for bashrc in "root/.bashrc" "etc/bash.bashrc"; do
echo 'PS1=(chroot)$PS1' >> "$CHROOTDIR/$bashrc"
done

rm -f "$CHROOTDIR/etc/resolv.conf"
cp /etc/resolv.conf /etc/hosts /etc/hostname "$CHROOTDIR/etc" || true
cp /etc/ssl/certs/ca-certificates.crt "$CHROOTDIR/etc/ssl/certs/" || true
Expand Down
20 changes: 18 additions & 2 deletions misc-tools/dj_run_chroot.in
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,19 @@ trap cleanup EXIT
# Default directory where the chroot tree lives:
CHROOTDIR="@judgehost_chrootdir@"

# Gather which dirs will be mounted during judgement.
# (optional lib64 only needed for amd64 architecture)
SUBDIRMOUNTS="etc usr lib bin"
if [ "$(uname -m)" = "x86_64" ]; then
SUBDIRMOUNTS="$SUBDIRMOUNTS lib64"
fi

CONCAT_SUBDIRMOUNTS=""
for subdir in $SUBDIRMOUNTS
do
CONCAT_SUBDIRMOUNTS="${SUBDIRMOUNTS:+${CONCAT_SUBDIRMOUNTS}, }${subdir}"
done

usage()
{
cat <<EOF
Expand All @@ -44,6 +57,9 @@ into the chroot tree, and then e.g. run:

sudo dj_run_chroot "dpkg -i /path/inside/chroot/package_x.y.z_amd64.deb"

Beware that only [$CONCAT_SUBDIRMOUNTS] are mounted inside the chroot!
For the current list see the chroot-start-stop.sh in case of issues.

EOF
}

Expand Down Expand Up @@ -93,9 +109,9 @@ mount --bind /dev/pts "$CHROOTDIR/dev/pts"
# Prevent perl locale warnings in the chroot:
export LC_ALL=C

[ -n "$INTERACTIVE" ] && echo "Entering chroot in '$CHROOTDIR'."

if [ -n "$INTERACTIVE" ]; then
echo "Entering chroot in '$CHROOTDIR'."
echo "Only [$CONCAT_SUBDIRMOUNTS] will be mounted during judgement. See chroot-start-stop.sh for the current list."
chroot "$CHROOTDIR"
else
chroot "$CHROOTDIR" /bin/sh -c "$*"
Expand Down
Loading