fixed lookup for mounted tombs

better parsing of mount output when looking for mounted tombs and bind hooks

fixes parsing also for Debian 7 where somehow mount output has changed
This commit is contained in:
Jaromil 2013-05-15 12:00:23 +02:00
parent 85e36178df
commit 148be7283b

113
src/tomb
View File

@ -1700,6 +1700,61 @@ resize_tomb() {
# }}} # }}}
# print out an array of mounted tombs (internal use)
# format is semi-colon separated list of attributes
# if 1st arg is supplied, then list only that tomb
# Positions in array:
# 1 = full mapper path
# 2 = mountpoint
# 3 = filesystem type
# 4 = mount options
# 5 = tomb name
list_tomb_mounts() {
if [ "$1" = "" ]; then
# list all open tombs
mount -l |
awk '
BEGIN { main="" }
/^\/dev\/mapper\/tomb/ {
if(main==$1) next;
print $1 ";" $3 ";" $5 ";" $6 ";" $7
main=$1
}
'
else
# list a specific tomb
mount -l |
awk -vtomb="[$1]" '
BEGIN { main="" }
/^\/dev\/mapper\/tomb/ {
if($7!=tomb) next;
if(main==$1) next;
print $1 ";" $3 ";" $5 ";" $6 ";" $7
main=$1
}
'
fi
}
# print out an array of mounted bind hooks (internal use)
# format is semi-colon separated list of attributes
# needs an argument: name of tomb whose hooks belong
list_tomb_binds() {
if [ "$1" = "" ]; then
_failure "internal error: list_tomb_binds called without argument."; fi
mount -l |
awk -vtomb="$1" '
BEGIN { main="" }
/^\/dev\/mapper\/tomb/ {
if($7!=tomb) next;
if(main=="") { main=$1; next; }
if(main==$1)
print $1 ";" $3 ";" $5 ";" $6 ";" $7
}
'
}
# {{{ - Index # {{{ - Index
# index files in all tombs for search # index files in all tombs for search
# $1 is optional, to specify a tomb # $1 is optional, to specify a tomb
@ -1707,24 +1762,15 @@ index_tombs() {
{ command -v updatedb > /dev/null } || { { command -v updatedb > /dev/null } || {
die "Cannot index tombs on this system: updatedb not installed" } die "Cannot index tombs on this system: updatedb not installed" }
if [ $1 ]; then mounted_tombs=(`list_tomb_mounts $1`)
# list a specific tomb { test ${#mounted_tombs} = 0 } && {
mounted_tombs=`mount -l | if [ $1 ]; then die "There seems to be no open tomb engraved as [$1]"
awk -vtomb="[$1]" '/^\/dev\/mapper\/tomb/ { if($7==tomb) print $1 ";" $3 ";" $5 ";" $6 ";" $7 }'` else die "I can't see any open tomb, may they all rest in peace."
else
# list all open tombs
mounted_tombs=`mount -l |
awk '/^\/dev\/mapper\/tomb/ { print $1 ";" $3 ";" $5 ";" $6 ";" $7 }'`
fi
if ! [ $mounted_tombs ]; then
if [ $1 ]; then
die "There seems to be no open tomb engraved as [$1]"
else
die "I can't see any open tomb, may they all rest in peace."
fi
fi fi
}
yes "Creating and updating search indexes" yes "Creating and updating search indexes"
for t in ${(f)mounted_tombs}; do for t in ${mounted_tombs}; do
mapper=`basename ${t[(ws:;:)1]}` mapper=`basename ${t[(ws:;:)1]}`
tombname=${t[(ws:;:)5]} tombname=${t[(ws:;:)5]}
tombmount=${t[(ws:;:)2]} tombmount=${t[(ws:;:)2]}
@ -1741,8 +1787,7 @@ search_tombs() {
die "Cannot index tombs on this system: updatedb not installed" } die "Cannot index tombs on this system: updatedb not installed" }
# list all open tombs # list all open tombs
mounted_tombs=(`mount -l | mounted_tombs=(`list_tomb_mounts $1`)
awk '/^\/dev\/mapper\/tomb/ { print $1 ";" $3 ";" $5 ";" $6 ";" $7 }'`)
{ test ${#mounted_tombs} = 0 } && { { test ${#mounted_tombs} = 0 } && {
die "I can't see any open tomb, may they all rest in peace." } die "I can't see any open tomb, may they all rest in peace." }
yes "Searching for: $fg_bold[white]${=PARAM}$fg_no_bold[white]" yes "Searching for: $fg_bold[white]${=PARAM}$fg_no_bold[white]"
@ -1767,30 +1812,13 @@ search_tombs() {
# list all tombs mounted in a readable format # list all tombs mounted in a readable format
# $1 is optional, to specify a tomb # $1 is optional, to specify a tomb
list_tombs() { list_tombs() {
if [ $1 ]; then
# list a specific tomb
mounted_tombs=`mount -l |
awk -vtomb="[$1]" '/^\/dev\/mapper\/tomb/ { if($7==tomb) print $1 ";" $3 ";" $5 ";" $6 ";" $7 }'`
else
# list all open tombs # list all open tombs
mounted_tombs=`mount -l | mounted_tombs=(`list_tomb_mounts $1`)
awk '/^\/dev\/mapper\/tomb/ { print $1 ";" $3 ";" $5 ";" $6 ";" $7 }'` { test ${#mounted_tombs} = 0 } && {
fi die "I can't see any ${1:-open} tomb, may they all rest in peace." }
# 1 = full mapper path
# 2 = mountpont
# 3 = filesystem
# 4 = mount options
# 5 = name
if ! [ $mounted_tombs ]; then for t in ${mounted_tombs}; do
if [ $1 ]; then
die "There seems to be no open tomb engraved as [$1]"
else
die "I can't see any open tomb, may they all rest in peace."
fi
fi
for t in ${(f)mounted_tombs}; do
mapper=`basename ${t[(ws:;:)1]}` mapper=`basename ${t[(ws:;:)1]}`
tombname=${t[(ws:;:)5]} tombname=${t[(ws:;:)5]}
tombmount=${t[(ws:;:)2]} tombmount=${t[(ws:;:)2]}
@ -1858,9 +1886,8 @@ list_tombs() {
fi fi
# now check hooks # now check hooks
mtomb=`sed 's:\/:\\\/:g' <<< $tombmount` mounted_hooks=(`list_tomb_binds $tombname`)
mounted_hooks=`mount | awk "/^$mtomb/"' {print $1 ";" $3}'` for h in ${mounted_hooks}; do
for h in ${(f)mounted_hooks}; do
print -n "$fg_no_bold[green]$tombname" print -n "$fg_no_bold[green]$tombname"
print -n "$fg_no_bold[white] hooks " print -n "$fg_no_bold[white] hooks "
print -n "$fg_bold[white]`basename ${h[(ws:;:)1]}`" print -n "$fg_bold[white]`basename ${h[(ws:;:)1]}`"