improve ensureZfsMounted script
This commit is contained in:
parent
ff305c8c4c
commit
a2d622613d
32
overlays.nix
32
overlays.nix
@ -3,31 +3,31 @@ final: prev: {
|
|||||||
name = "zfsEnsureMounted";
|
name = "zfsEnsureMounted";
|
||||||
runtimeInputs = with prev; [
|
runtimeInputs = with prev; [
|
||||||
zfs
|
zfs
|
||||||
gnugrep
|
|
||||||
gawk
|
gawk
|
||||||
coreutils
|
coreutils
|
||||||
];
|
];
|
||||||
|
|
||||||
text = ''
|
text = ''
|
||||||
#!/bin/sh -x
|
#!/bin/sh
|
||||||
|
|
||||||
if [[ "$#" -eq "0" ]]; then
|
if [[ "$#" -eq "0" ]]; then
|
||||||
echo "no arguments passed"
|
echo "no arguments passed"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
TARGETS=$(echo "$@" | sort | uniq)
|
MOUNTED=$(zfs list -o mountpoint,mounted -H | awk '$NF == "yes" {$NF=""; print $0}' | sed 's/[[:space:]]*$//')
|
||||||
MOUNTED=$(zfs list -o mountpoint,mounted -H | awk '$2 == "yes" {print $1}' | sort | uniq)
|
|
||||||
NUM_MATCHED=$(echo "$MOUNTED" | grep -Ec "$(echo "$@" | tr ' ' '\|')") # does not properly handle paths with strings
|
|
||||||
if [[ "$NUM_MATCHED" -eq "$#" ]]; then
|
|
||||||
exit 0
|
|
||||||
fi
|
|
||||||
|
|
||||||
FOUND=$(printf "%s\n%s" "$TARGETS" "$MOUNTED" | sort | uniq -c | awk '$1 == "2" {print $2}' | sort)
|
MISSING=""
|
||||||
MISSING=$(printf "%s\n%s" "$FOUND" "$TARGETS" | sort | uniq -u | sort)
|
for target in "$@"; do
|
||||||
|
if ! echo "$MOUNTED" | grep -Fxq "$target"; then
|
||||||
|
MISSING="$MISSING $target"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
echo "FAILURE, missing: $MISSING" 1>&2
|
if [[ -n "$MISSING" ]]; then
|
||||||
exit 1
|
echo "FAILURE, missing:$MISSING" 1>&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@ -86,6 +86,15 @@ testPkgs.testers.runNixOSTest {
|
|||||||
|
|
||||||
machine.succeed("zfsEnsureMounted /mnt/test_mountpoint /mnt/test_mountpoint_dos")
|
machine.succeed("zfsEnsureMounted /mnt/test_mountpoint /mnt/test_mountpoint_dos")
|
||||||
|
|
||||||
|
machine.succeed("zfs create -o mountpoint='/mnt/test path with spaces' rpool/test3")
|
||||||
|
|
||||||
|
machine.succeed("zfsEnsureMounted '/mnt/test path with spaces'")
|
||||||
|
|
||||||
|
machine.succeed("echo 'ZFS output for escaped spaces:'; zfs list -o mountpoint,mounted -H | grep escaped")
|
||||||
|
|
||||||
|
machine.succeed("zfsEnsureMounted /mnt/test\\ escaped\\ spaces")
|
||||||
|
|
||||||
|
machine.succeed("zfsEnsureMounted /mnt/test_mountpoint '/mnt/test path with spaces' /mnt/test_mountpoint_dos")
|
||||||
|
|
||||||
machine.succeed("zfs create -o mountpoint=/mnt/foobar_data rpool/foobar")
|
machine.succeed("zfs create -o mountpoint=/mnt/foobar_data rpool/foobar")
|
||||||
machine.succeed("systemctl start foobar")
|
machine.succeed("systemctl start foobar")
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user