[Usbmount-commit] r59 - usbmount/trunk

Rogério Brito rbrito-guest at alioth.debian.org
Wed Oct 21 04:12:01 UTC 2009


Author: rbrito-guest
Date: 2009-10-21 04:12:01 +0000 (Wed, 21 Oct 2009)
New Revision: 59

Modified:
   usbmount/trunk/usbmount
Log:
Introduction of mounting by UUID.

Refactoring the code for legibility.


Modified: usbmount/trunk/usbmount
===================================================================
--- usbmount/trunk/usbmount	2009-10-21 04:10:53 UTC (rev 58)
+++ usbmount/trunk/usbmount	2009-10-21 04:12:01 UTC (rev 59)
@@ -77,7 +77,7 @@
 
 umask 022
 
-if test "$1" = add; then
+if [ "$1" = "add" ]; then
 
     # Acquire lock.
     log debug "trying to acquire lock /var/run/usbmount/.mount.lock"
@@ -91,20 +91,23 @@
     # 20 seconds.  Thanks to Peter Stelmachovic for his help with
     # debugging this.
     log debug "testing whether $DEVNAME is readable"
-    read_success=no
-    for t in 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19; do
+    read_success=no; T=0; RETRIES=20
+    while [ $T -lt $RETRIES ]; do
 	if dd if="$DEVNAME" of=/dev/null bs=512 count=1; then
 	    read_success=yes
 	    break
 	fi
-	log debug "attempt $t to read from $DEVNAME failed"
+	T=$((T + 1));
+	log debug "attempt $T to read from $DEVNAME failed"
 	sleep 1
     done
-    if test "$read_success" != yes; then
-	log err "cannot read from $DEVNAME"
+
+    if [ "$read_success" != "yes" ]; then
+	log err "could not read from $DEVNAME for $RETRIES seconds; aborting"
 	exit 1
     fi
 
+    UUID=$(/sbin/blkid "$DEVNAME" | sed -e 's/.*UUID="\([^"]*\)".*/\1/g; s/\s*//g;')
     # Test if the device has an /etc/fstab entry. In that case, we will
     # mount it using the regular mount command.
     if grep -q "^[ 	]*$DEVNAME" /etc/fstab; then
@@ -114,13 +117,20 @@
 	log info "executing command: mount $DEVNAME"
 	mount "$DEVNAME"
 
-    # Test if the device contains a filesystem.  If it doesn't, no
-    # further action is required, but calling vol_id has the side effect
-    # that the partition table is read and partition devices are created.
+    # Test if the device has an /etc/fstab entry with its UUID, in this
+    # case we will mount it with a mount command on the mount point
+    elif grep -q $UUID /etc/fstab; then
+        log debug "$DEVNAME has an /etc/fstab entry, with UUID $UUID, using that"
+
+        MOUNT_POINT="`grep $UUID /etc/fstab|awk '{print $2}'`"
+        log info "executing command: mount $MOUNT_POINT"
+	mount "$DEVNAME"
+
+    # Test if the device contains a filesystem.
     elif /sbin/blkid -p -o udev "$DEVNAME" | egrep -q '^ID_FS_USAGE=(filesystem|disklabel)$'; then
 	log debug "$DEVNAME contains a filesystem or disklabel"
 
-	fstype="`/sbin/blkid -s TYPE -o value \"$DEVNAME\"`"
+	fstype=$(/sbin/blkid -s TYPE -o value "$DEVNAME" | sed -e 's/\s*//g;')
 	log debug "$DEVNAME contains filesystem type $fstype"
 
 	# Test if the filesystem type is in the list of filesystem
@@ -155,24 +165,25 @@
 
 		# Determine vendor and model.
 		vendor=
-		if test -r "/sys$DEVPATH/device/vendor"; then
+		if [ -r "/sys$DEVPATH/device/vendor" ]; then
 		    vendor="`cat \"/sys$DEVPATH/device/vendor\"`"
-		elif test -r "/sys$DEVPATH/../device/vendor"; then
+		elif [ -r "/sys$DEVPATH/../device/vendor" ]; then
 		    vendor="`cat \"/sys$DEVPATH/../device/vendor\"`"
-		elif test -r "/sys$DEVPATH/device/../manufacturer"; then
+		elif [ -r "/sys$DEVPATH/device/../manufacturer" ]; then
 		    vendor="`cat \"/sys$DEVPATH/device/../manufacturer\"`"
-		elif test -r "/sys$DEVPATH/../device/../manufacturer"; then
+		elif [ -r "/sys$DEVPATH/../device/../manufacturer" ]; then
 		    vendor="`cat \"/sys$DEVPATH/../device/../manufacturer\"`"
 		fi
 		vendor="`echo \"$vendor\" | sed 's/^ *//; s/ *$//'`"
+
 		model=
-		if test -r "/sys$DEVPATH/device/model"; then
+		if [ -r "/sys$DEVPATH/device/model" ]; then
 		    model="`cat \"/sys$DEVPATH/device/model\"`"
-		elif test -r "/sys$DEVPATH/../device/model"; then
+		elif [ -r "/sys$DEVPATH/../device/model" ]; then
 		    model="`cat \"/sys$DEVPATH/../device/model\"`"
-		elif test -r "/sys$DEVPATH/device/../product"; then
+		elif [ -r "/sys$DEVPATH/device/../product" ]; then
 		    model="`cat \"/sys$DEVPATH/device/../product\"`"
-		elif test -r "/sys$DEVPATH/../device/../product"; then
+		elif [ -r "/sys$DEVPATH/../device/../product" ]; then
 		    model="`cat \"/sys$DEVPATH/../device/../product\"`"
 		fi
 		model="`echo \"$model\" | sed 's/^ *//; s/ *$//'`"
@@ -201,7 +212,7 @@
     # A block or partition device has been removed.
     # Test if it is mounted.
     while read device mountpoint fstype remainder; do
-	if test "$DEVNAME" = "$device"; then
+	if [ "$DEVNAME" = "$device" ]; then
 	    # If the mountpoint and filesystem type are maintained by
 	    # this script, unmount the filesystem.
 	    if in_list "$mountpoint" "$MOUNTPOINTS" \




More information about the Usbmount-commit mailing list