diff options
-rwxr-xr-x | hdd-tree | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/hdd-tree b/hdd-tree new file mode 100755 index 0000000..78dda0a --- /dev/null +++ b/hdd-tree @@ -0,0 +1,90 @@ +#!/bin/bash + +drives=$( + find /dev -maxdepth 1 -regex '.*/sd[a-z]+' +) + +raids=$( + sed ' + 1d + s/^\(\S\+\) \+: \+\S\+ \+\(\S\+\) \+/\1 \2 / + t + d + ' /proc/mdstat \ + | sed ' + s/\[\S\+]//g + s/^\(\S\+\) \+\(\S\+\) \+\(\S\+\) \+/\1 \2 \3\n\1 \2 / + P + D + ' \ + | sed ' + s,^\(\S\+ \S\+ \)\(\S\+\)$,/dev/\1/dev/\2, + ' +) + +crypt_devices=$( + find /dev -maxdepth 1 -name 'dm-*' -exec cryptsetup status {} \; \ + | grep '^\S\|^\s*device:' \ + | sed ' + /^\S\+ / { + N + s,^\(\S\+\) .*\n\s*device:\s*\(\S\+\)$,\1 \2, + t + } + d + ' +) + +drives=$( + printf '%s\n' "${drives}" + printf '%s\n' "${raids}" \ + | cut -d' ' -f1 \ + | sort -u +) + +partitions=$( + find /dev -maxdepth 1 \ + | grep -F "${drives}" \ + | grep -vxF "${drives}" +) + +mounts=$( + mount \ + | grep -wF "$(printf '%s\n' "${partitions}" "${drives}")" \ + | awk '{print $3 " " $1}' +) + +printf 'digraph {\n' +printf 'rankdir=LR;\n' +printf '%s\n' "${drives}" \ + | sed ' + s/^.*$/"\0" [shape="trapezium"];/ + ' +printf '%s\n' "${raids}" \ + | cut -d' ' -f1,2 \ + | sort -u \ + | sed ' + s/^\(\S\+\) \(\S\+\)$/"\1" [label="\1\\n(\2)", shape="box"];/ + ' +printf '%s\n' "${raids}" \ + | cut -d' ' -f1,3 \ + | sed ' + s/^\(\S\+\) \(\S\+\)$/"\1" -> "\2";/ + ' +printf '%s\n' "${crypt_devices}" \ + | sed ' + s/^\(\S\+\) \(\S\+\)$/"\1" -> "\2";/ + ' +printf '%s\n' "${crypt_devices}" \ + | sed ' + s/^\(\S\+\) \S\+$/"\1" [shape="hexagon"];/ + ' +printf '%s\n' "${partitions}" \ + | sed ' + s/^\(.*[^0-9]\)[0-9]\+$/"\0" -> "\1";/ + ' +printf '%s\n' "${mounts}" \ + | sed ' + s/^\(\S\+\) \(\S\+\)$/"\1" -> "\2";/ + ' +printf '}\n' |