fix(image): clean partial mounts and refuse mounted export deletion
This commit is contained in:
@@ -7,10 +7,27 @@ fi
|
||||
root=$1
|
||||
python3 /hydra-source/hydra/image.py configure "$root" --source /hydra-source
|
||||
# This is a separate rootfs inside the assembly container, never the host root.
|
||||
mounted=()
|
||||
cleanup_mounts() {
|
||||
status=$?
|
||||
trap - EXIT
|
||||
cleanup_failed=0
|
||||
for ((index=${#mounted[@]}-1; index>=0; index--)); do
|
||||
umount "${mounted[index]}" || cleanup_failed=1
|
||||
done
|
||||
if ((cleanup_failed)); then
|
||||
echo 'configure-rootfs: temporary mount cleanup failed; refusing success' >&2
|
||||
status=1
|
||||
fi
|
||||
exit "$status"
|
||||
}
|
||||
trap cleanup_mounts EXIT
|
||||
mount --bind /dev "$root/dev"
|
||||
mounted+=("$root/dev")
|
||||
mount -t proc proc "$root/proc"
|
||||
mounted+=("$root/proc")
|
||||
mount --bind /sys "$root/sys"
|
||||
trap 'umount "$root/sys" "$root/proc" "$root/dev"' EXIT
|
||||
mounted+=("$root/sys")
|
||||
for group in wheel kvm video render audio; do
|
||||
chroot "$root" getent group "$group" >/dev/null || chroot "$root" groupadd -r "$group"
|
||||
done
|
||||
|
||||
Reference in New Issue
Block a user