[Pkg-sysvinit-devel] Bug#359717: bash workaround
Zenaan Harkness
zen at freedbms.net
Wed Jul 31 01:24:50 UTC 2013
If using bash, this is what I've come to in my local bashlib,
over the last few years:
isMounted () {
# make sure a target/ arg is passed in:
[ -z "$1" ] && return 1
# turn target into fully qualified filename/ location
# (not doing so can cause problems with some of the tests I've tried,
# eg perhaps the one currently used see below):
DIR=`readlink -f "$1"`
# Option 1, from: http://arstechnica.com/civis//viewtopic.php?f=16&t=1174539
#
#grep -q "$DIR" /proc/mounts
#[ $? -eq 0 ] && return 0 # Alternatively: "return $?", I guess
# or alt alternative, make sure no other commands like echo follow :)
# From url: "For more robust bash scripting, using $? is preferred as it
# allows you to detect extra error conditions (like the command not
# existing, or you gave it syntactically invalid arguments, etc.)"
# Option 2:
#
# The following seemed unsophisticated, and clunky, when the /bin/mountpoint
# command is installed by default, thus option 3 below. But as can be seen
# with option 3, the "sophisticated" option is in fact buggy. I emailed
# this bug to initscripts maintainer, debian and ubuntu, on 20101029.
# See also: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=359717
# See also: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=622595
# See also: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=460898
#mount | grep "on ${DIR} type" > /dev/null && return 0
#mount | grep -q "on ${DIR} type" && return 0
mount | grep -q "on ${DIR} type"
# Option 3:
#
# The following (off the web, and a standard command in debian)
# fails for a directory mounted on itself,
# which is needed prior to mount --make-rshared /directory.
#mountpoint -q ${DIR}
}
More information about the Pkg-sysvinit-devel
mailing list