1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
|
#!/bin/bash
# Evaluate given command while running with DATALAD_TESTS_TEMP_DIR pointing to
# that temporary filesystem mounted using loop device
set -e
fs=${DATALAD_TESTS_TEMP_FS:-vfat}
size=${DATALAD_TESTS_TEMP_FSSIZE:-10}
set -u
tmp=$(mktemp -u "${TMPDIR:-/tmp}/datalad-fs-XXXXX")
echo "I: $fs of $size: $tmp"
uid=$(id -u)
mntimage="$tmp.img"
mntpoint="$tmp"
dd if=/dev/zero "of=$mntimage" bs=1032192c "count=$size"
loop=$(sudo losetup --find --show "$mntimage")
sudo "mkfs.$fs" "$loop"
mkdir -p "$mntpoint"
sudo mount -o "uid=$uid" "$loop" "$mntpoint"
# Run the actual command
echo "I: running $*"
set +e
TMPDIR="$mntpoint" DATALAD_TESTS_TEMP_DIR="$mntpoint" "$@"
ret=$?
echo "I: done, unmounting"
sudo umount "$mntpoint"
sudo losetup -d "$loop"
rm -rf "$mntpoint" "$mntimage"
exit "$ret"
|