mirror of
https://github.com/Llewellynvdm/Tomb.git
synced 2024-11-21 20:15:13 +00:00
list_tomb_mounts: simplify the function
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.
This commit is contained in:
parent
0b25ba6d68
commit
6df1cdeab9
26
tomb
26
tomb
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user