]> git.ipfire.org Git - thirdparty/dracut.git/commitdiff
fallback to old ismounted, if findmnt is not installed
authorHarald Hoyer <harald@redhat.com>
Thu, 20 Sep 2012 08:36:13 +0000 (10:36 +0200)
committerHarald Hoyer <harald@redhat.com>
Thu, 20 Sep 2012 08:36:13 +0000 (10:36 +0200)
modules.d/30convertfs/convertfs.sh
modules.d/99base/dracut-lib.sh
modules.d/99base/module-setup.sh

index d1d25aab38ece9ec41791ab5277d8c59698a569d..137664a830f60fc454740b8000e85b178f13591e 100755 (executable)
@@ -73,13 +73,35 @@ if [[ ! -e "$testfile" ]]; then
 fi
 rm -f "$testfile"
 
-ismounted() {
-    while read a m a; do
-        [[ "$m" = "$1" ]] && return 0
+find_mount() {
+    local dev mnt etc wanted_dev
+    wanted_dev="$(readlink -e -q $1)"
+    while read dev mnt etc; do
+        [ "$dev" = "$wanted_dev" ] && echo "$dev" && return 0
     done < /proc/mounts
     return 1
 }
 
+# usage: ismounted <mountpoint>
+# usage: ismounted /dev/<device>
+if command -v findmnt >/dev/null; then
+    ismounted() {
+        findmnt "$1" > /dev/null 2>&1
+    }
+else
+    ismounted() {
+        if [ -b "$1" ]; then
+            find_mount "$1" > /dev/null && return 0
+            return 1
+        fi
+
+        while read a m a; do
+            [ "$m" = "$1" ] && return 0
+        done < /proc/mounts
+        return 1
+    }
+fi
+
 # clean up after ourselves no matter how we die.
 cleanup() {
     echo "Something failed. Move back to the original state"
index 6fd4e0affaee22bca41c17aebbe49f92952b2244..1d90010a153496a829259bb392d221b108e1f784 100755 (executable)
@@ -452,11 +452,34 @@ udevproperty() {
     fi
 }
 
+find_mount() {
+    local dev mnt etc wanted_dev
+    wanted_dev="$(readlink -e -q $1)"
+    while read dev mnt etc; do
+        [ "$dev" = "$wanted_dev" ] && echo "$dev" && return 0
+    done < /proc/mounts
+    return 1
+}
+
 # usage: ismounted <mountpoint>
 # usage: ismounted /dev/<device>
-ismounted() {
-    findmnt "$1" > /dev/null
-}
+if command -v findmnt >/dev/null; then
+    ismounted() {
+        findmnt "$1" > /dev/null 2>&1
+    }
+else
+    ismounted() {
+        if [ -b "$1" ]; then
+            find_mount "$1" > /dev/null && return 0
+            return 1
+        fi
+
+        while read a m a; do
+            [ "$m" = "$1" ] && return 0
+        done < /proc/mounts
+        return 1
+    }
+fi
 
 wait_for_if_up() {
     local cnt=0
index 6cc4ad2eff9b8e4a6934bb1b00e93f5bf9ca92bd..2bcb6a1b8c65f64010a60119ec98ccdcac7e9d97 100755 (executable)
@@ -13,11 +13,12 @@ depends() {
 
 install() {
     local _d
-    dracut_install mount mknod mkdir pidof sleep chroot findmnt\
+    dracut_install mount mknod mkdir pidof sleep chroot \
         sed ls flock cp mv dmesg rm ln rmmod mkfifo umount readlink setsid
     inst $(command -v modprobe) /sbin/modprobe
 
-    dracut_install -o less
+    dracut_install -o findmnt less
+
     if [ ! -e "${initdir}/bin/sh" ]; then
         dracut_install bash
         (ln -s bash "${initdir}/bin/sh" || :)