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";
|
||||
runtimeInputs = with prev; [
|
||||
zfs
|
||||
gnugrep
|
||||
gawk
|
||||
coreutils
|
||||
];
|
||||
|
||||
text = ''
|
||||
#!/bin/sh -x
|
||||
#!/bin/sh
|
||||
|
||||
if [[ "$#" -eq "0" ]]; then
|
||||
echo "no arguments passed"
|
||||
exit 1
|
||||
fi
|
||||
if [[ "$#" -eq "0" ]]; then
|
||||
echo "no arguments passed"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
TARGETS=$(echo "$@" | sort | uniq)
|
||||
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
|
||||
MOUNTED=$(zfs list -o mountpoint,mounted -H | awk '$NF == "yes" {$NF=""; print $0}' | sed 's/[[:space:]]*$//')
|
||||
|
||||
FOUND=$(printf "%s\n%s" "$TARGETS" "$MOUNTED" | sort | uniq -c | awk '$1 == "2" {print $2}' | sort)
|
||||
MISSING=$(printf "%s\n%s" "$FOUND" "$TARGETS" | sort | uniq -u | sort)
|
||||
MISSING=""
|
||||
for target in "$@"; do
|
||||
if ! echo "$MOUNTED" | grep -Fxq "$target"; then
|
||||
MISSING="$MISSING $target"
|
||||
fi
|
||||
done
|
||||
|
||||
echo "FAILURE, missing: $MISSING" 1>&2
|
||||
exit 1
|
||||
if [[ -n "$MISSING" ]]; then
|
||||
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("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("systemctl start foobar")
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user