| 1 |
#!/bin/bash |
| 2 |
# Evaluate given command while running with DATALAD_TESTS_TEMP_DIR pointing to |
| 3 |
# that temporary filesystem mounted using nfs |
| 4 |
|
| 5 |
set -e |
| 6 |
|
| 7 |
fs=nfs |
| 8 |
# TODO: nfs and mount options? |
| 9 |
|
| 10 |
set -u |
| 11 |
tmp=$(mktemp -u "${TMPDIR:-/tmp}/datalad-nfs-XXXXX") |
| 12 |
|
| 13 |
|
| 14 |
uid=$(id -u) |
| 15 |
mntorig="$tmp.orig" |
| 16 |
mntpoint="$tmp.nfs" |
| 17 |
|
| 18 |
echo "I: mounting $mntorig under $mntpoint via $fs" |
| 19 |
|
| 20 |
set -x |
| 21 |
|
| 22 |
mkdir -p "$mntpoint" |
| 23 |
mkdir -p "$mntorig" |
| 24 |
|
| 25 |
if ! dpkg -l nfs-kernel-server | grep '^ii.*nfs-kernel-server'; then |
| 26 |
sudo apt-get install -y nfs-kernel-server |
| 27 |
fi |
| 28 |
|
| 29 |
sudo exportfs -o rw "localhost:$mntorig" |
| 30 |
sudo mount -t "$fs" "localhost:$mntorig" "$mntpoint" |
| 31 |
|
| 32 |
# should how it was mounted |
| 33 |
sudo mount | grep "$mntpoint" | sed -e 's,^,I: ,g' |
| 34 |
|
| 35 |
# Run the actual command |
| 36 |
echo "I: running $@" |
| 37 |
TMPDIR="$mntpoint" DATALAD_TESTS_TEMP_DIR="$mntpoint" "$@" |
| 38 |
ret=$? |
| 39 |
|
| 40 |
echo "I: done, unmounting" |
| 41 |
sudo umount "$mntpoint" |
| 42 |
sudo exportfs -u "localhost:$mntorig" |
| 43 |
|
| 44 |
rm -rf "$mntpoint" "$mntorig" |
| 45 |
exit "$ret" |