Skip to content

Commit

Permalink
list_tomb_mounts: simplify the function
Browse files Browse the repository at this point in the history
previously it had dedicated cases for listing all tombs and a singular
one, which duplicated code.
The function got reworked, that it uses a different approach for
findmnt. Instead of filtering the general result, it now uses --source
on the tomb specific crypsetup mapper. Those are searched via general
globbing of the devices in /dev/mapper. This allows to combine the
previous separate cases.
Additionally remove the usage of _sudo for findmnt, as it is not
necessary.
  • Loading branch information
Narrat committed Aug 6, 2024
1 parent 18830a6 commit 252cb30
Showing 1 changed file with 5 additions and 21 deletions.
26 changes: 5 additions & 21 deletions tomb
Original file line number Diff line number Diff line change
Expand Up @@ -2756,34 +2756,18 @@ awk "/mapper/"' { print $2 ";" $3 ";" $4 ";" $5 }'`
#
# 5. tomb name
list_tomb_mounts() {
[[ -z "$1" ]] && {
# list all open tombs
_sudo findmnt -rvo SOURCE,TARGET,FSTYPE,OPTIONS,LABEL \
# execute in subshell to avoid ZSH non-POSIX behaviour if globbing doesn't match something
( for dev in /dev/mapper/tomb*$1.*; do
findmnt --source ${dev} -rnvo SOURCE,TARGET,FSTYPE,OPTIONS,LABEL \
| awk '
BEGIN { main="" }
/^\/dev\/mapper\/tomb/ {
if(main==$1) next;
print $1 ";" $2 ";" $3 ";(" $4 ");[" $5 "]"
main=$1
}
'
} || {
# list a specific tomb
# add square parens if not present (detection)
local tname
if [[ "${1[1]}" = "[" ]]; then tname="$1"
else tname="[$1]"; fi
_sudo findmnt -rvo SOURCE,TARGET,FSTYPE,OPTIONS,LABEL \
| awk -vtomb="$tname" '
BEGIN { main="" }
/^\/dev\/mapper\/tomb/ {
if("["$5"]"!=tomb) next;
{
if(main==$1) next;
print $1 ";" $2 ";" $3 ";(" $4 ");[" $5 "]"
main=$1
}
'
}
done ) 2>/dev/null
}

# list_tomb_binds
Expand Down

0 comments on commit 252cb30

Please sign in to comment.