Verified Commit 83a68cb1 authored by Mattia Rizzolo's avatar Mattia Rizzolo
Browse files

schroot-create: umount all directories mounted below the schroot directory while cleaning up



it seems sometimes we call cleanup() without first umounting /proc, in case of errors

Signed-off-by: Mattia Rizzolo's avatarMattia Rizzolo <mattia@debian.org>
parent 73bb8bd2
...@@ -55,6 +55,10 @@ TMPLOG=$(mktemp --tmpdir=$TMPDIR schroot-create-XXXXXXXX) ...@@ -55,6 +55,10 @@ TMPLOG=$(mktemp --tmpdir=$TMPDIR schroot-create-XXXXXXXX)
cleanup() { cleanup() {
cd cd
if [ -d "$SCHROOT_TARGET" ]; then if [ -d "$SCHROOT_TARGET" ]; then
local i
for i in $(findmnt -l -c | awk '{print $1}' | grep "^$SCHROOT_TARGET"); do
sudo umount "$i"
done
sudo rm -rf --one-file-system "$SCHROOT_TARGET" || ( echo "Warning: $SCHROOT_TARGET could not be fully removed during cleanup." ; ls "$SCHROOT_TARGET" -la ) sudo rm -rf --one-file-system "$SCHROOT_TARGET" || ( echo "Warning: $SCHROOT_TARGET could not be fully removed during cleanup." ; ls "$SCHROOT_TARGET" -la )
fi fi
rm -f "$TMPLOG" rm -f "$TMPLOG"
...@@ -149,9 +153,7 @@ bootstrap() { ...@@ -149,9 +153,7 @@ bootstrap() {
robust_chroot_apt update robust_chroot_apt update
if [ -n "$1" ] ; then if [ -n "$1" ] ; then
for d in proc ; do sudo mount --bind /proc $SCHROOT_TARGET/proc
sudo mount --bind /$d $SCHROOT_TARGET/$d
done
set -x set -x
robust_chroot_apt update robust_chroot_apt update
# first, (if), install diffoscope with all recommends... # first, (if), install diffoscope with all recommends...
...@@ -183,10 +185,7 @@ bootstrap() { ...@@ -183,10 +185,7 @@ bootstrap() {
sudo chroot $SCHROOT_TARGET dpkg -l diffoscope sudo chroot $SCHROOT_TARGET dpkg -l diffoscope
echo echo
fi fi
# umount in reverse order than how they were mounted earlier sudo umount -l $SCHROOT_TARGET/proc
for d in proc ; do
sudo umount -l $SCHROOT_TARGET/$d
done
# configure sudo inside just like outside # configure sudo inside just like outside
echo "jenkins ALL=NOPASSWD: ALL" | sudo tee -a $SCHROOT_TARGET/etc/sudoers.d/jenkins >/dev/null echo "jenkins ALL=NOPASSWD: ALL" | sudo tee -a $SCHROOT_TARGET/etc/sudoers.d/jenkins >/dev/null
sudo chroot $SCHROOT_TARGET chown root.root /etc/sudoers.d/jenkins sudo chroot $SCHROOT_TARGET chown root.root /etc/sudoers.d/jenkins
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment