34 lines
905 B
Nix
34 lines
905 B
Nix
final: prev: {
|
|
ensureZfsMounts = prev.writeShellApplication {
|
|
name = "zfsEnsureMounted";
|
|
runtimeInputs = with prev; [
|
|
zfs
|
|
gnugrep
|
|
gawk
|
|
coreutils
|
|
];
|
|
|
|
text = ''
|
|
#!/bin/sh -x
|
|
|
|
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
|
|
|
|
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)
|
|
|
|
echo "FAILURE, missing: $MISSING" 1>&2
|
|
exit 1
|
|
'';
|
|
};
|
|
}
|