Resolve cryptic awk-based code docuplication
authorSebastian Pipping <sebastian@pipping.org>
Fri, 27 Jul 2012 22:42:55 +0000 (00:42 +0200)
committerSebastian Pipping <sebastian@pipping.org>
Fri, 27 Jul 2012 22:42:55 +0000 (00:42 +0200)
defaults/initrd.scripts

index ac32c8a3eeb90ef80030f0285e822c608527844f..082d44d14b60b97654aef2155a1f511c909883ce 100755 (executable)
@@ -298,6 +298,11 @@ run_shell() {
        /bin/ash
 }
 
+fs_type_in_use() {
+       fs_type=$1
+       cut -d ' ' -f 3 < /proc/mounts | fgrep -q "${fs_type}"
+}
+
 mount_devfs () {
        # Use devtmpfs if enabled in kernel,
        # else tmpfs. Always run mdev just in case
@@ -307,13 +312,13 @@ mount_devfs () {
        fi
 
        # Options copied from /etc/init.d/udev-mount, should probably be kept in sync
-       if awk 'BEGIN{m=0;} /devtmpfs/{if($3 == "devtmpfs") {m=1;} } END { exit m;}' /proc/mounts; then
+       if ! fs_type_in_use devtmpfs; then
                mount -t $devfs -o "exec,nosuid,mode=0755,size=10M" udev /dev \
                        || bad_msg "Failed to mount /dev as ${devfs}"
        fi
 
        # http://git.busybox.net/busybox/plain/docs/mdev.txt
-       if awk 'BEGIN{m=0;} /devpts/{if($3 == "devpts") {m=1;} } END { exit m;}' /proc/mounts; then
+       if ! fs_type_in_use devpts; then
                mkdir -m 0755 /dev/pts
                mount -t devpts -o gid=5,mode=0620 devpts /dev/pts  || bad_msg "Failed to mount /dev/pts"
        fi