Xu Xiaodong avatar Xu Xiaodong committed edc138a

fix bugs

Comments (0)

Files changed (2)

85-usbmount.rules

 # Rules for USBmount -*- conf -*-
 
-KERNEL=="sd*", DRIVERS=="sbp2",		ACTION=="add",	RUN+="/usr/share/usbmount/usbmount add"
-KERNEL=="sd*", SUBSYSTEMS=="usb",	ACTION=="add",	RUN+="/usr/share/usbmount/usbmount add"
-KERNEL=="ub*", SUBSYSTEMS=="usb",	ACTION=="add",	RUN+="/usr/share/usbmount/usbmount add"
-KERNEL=="sd*",				ACTION=="remove",	RUN+="/usr/share/usbmount/usbmount remove"
-KERNEL=="ub*",				ACTION=="remove",	RUN+="/usr/share/usbmount/usbmount remove"
+KERNEL=="sd*", DRIVERS=="sbp2",         ACTION=="add",  RUN+="/usr/share/usbmount/usbmount add"
+KERNEL=="sd*", SUBSYSTEMS=="usb",       ACTION=="add",  RUN+="/usr/share/usbmount/usbmount add"
+KERNEL=="ub*", SUBSYSTEMS=="usb",       ACTION=="add",  RUN+="/usr/share/usbmount/usbmount add"
+KERNEL=="sd*",                          ACTION=="remove",       RUN+="/usr/share/usbmount/usbmount remove"
+KERNEL=="ub*",                          ACTION=="remove",       RUN+="/usr/share/usbmount/usbmount remove"
 
 # Add: copy usb data into hard drive : start
 SRC=/media/usb/books
-DESC=/home/xiaodong
+DESC=/home/xiaodong/demo
 DATE=$(date +'%F %T')
 LOG=/var/log/usbcopy.log
 # Add: copy usb data into hard drive : end
   log debug "trying to acquire lock /var/run/usbmount/.mount.lock"
   lockfile-create --retry 3 /var/run/usbmount/.mount || \
     { log err "cannot acquire lock /var/run/usbmount/.mount.lock"; exit 1; }
-    trap '( lockfile-remove /var/run/usbmount/.mount )' 0
-    log debug "acquired lock /var/run/usbmount/.mount.lock"
+  trap '( lockfile-remove /var/run/usbmount/.mount )' 0
+  log debug "acquired lock /var/run/usbmount/.mount.lock"
 
-    # Grab device information from device and "divide it"
-    #   FIXME: improvement: implement mounting by label (notice that labels
-    #   can contain spaces, which makes things a little bit less comfortable).
-    DEVINFO=$(/sbin/blkid -p $DEVNAME)
-    FSTYPE=$(echo "$DEVINFO" | sed 's/.*TYPE="\([^"]*\)".*/\1/g; s/[[:blank:]]*//g;')
-    UUID=$(echo "$DEVINFO"   | sed 's/.*UUID="\([^"]*\)".*/\1/g; s/[[:blank:]]*//g;')
-    USAGE=$(echo "$DEVINFO"  | sed 's/.*USAGE="\([^"]*\)".*/\1/g; s/[[:blank:]]*//g;')
+  # Grab device information from device and "divide it"
+  #   FIXME: improvement: implement mounting by label (notice that labels
+  #   can contain spaces, which makes things a little bit less comfortable).
+  DEVINFO=$(/sbin/blkid -p $DEVNAME)
+  FSTYPE=$(echo "$DEVINFO" | sed 's/.*TYPE="\([^"]*\)".*/\1/g; s/[[:blank:]]*//g;')
+  UUID=$(echo "$DEVINFO"   | sed 's/.*UUID="\([^"]*\)".*/\1/g; s/[[:blank:]]*//g;')
+  USAGE=$(echo "$DEVINFO"  | sed 's/.*USAGE="\([^"]*\)".*/\1/g; s/[[:blank:]]*//g;')
 
-    if ! echo $USAGE | egrep -q "(filesystem|disklabel)"; then
-      log info "$DEVNAME does not contain a filesystem or disklabel"
-      exit 1
-    fi
+  if ! echo $USAGE | egrep -q "(filesystem|disklabel)"; then
+    log info "$DEVNAME does not contain a filesystem or disklabel"
+    exit 1
+  fi
 
-    # Try to use specifications in /etc/fstab first.
-    if egrep -q "^[[:blank:]]*$DEVNAME" /etc/fstab; then
-      log info "executing command: mount $DEVNAME"
-      mount $DEVNAME || log err "mount by DEVNAME wan't successful; return code $?"
+  # Try to use specifications in /etc/fstab first.
+  if egrep -q "^[[:blank:]]*$DEVNAME" /etc/fstab; then
+    log info "executing command: mount $DEVNAME"
+    mount $DEVNAME || log err "mount by DEVNAME wan't successful; return code $?"
 
-    elif grep -q "^[[:blank:]]*UUID=$UUID" /etc/fstab; then
-      log info "executing command: mount -U $UUID"
-      mount -U $UUID || log err "mount by UUID wan't successful; return code $?"
+  elif grep -q "^[[:blank:]]*UUID=$UUID" /etc/fstab; then
+    log info "executing command: mount -U $UUID"
+    mount -U $UUID || log err "mount by UUID wan't successful; return code $?"
 
-    else
-      log debug "$DEVNAME contains filesystem type $FSTYPE"
+  else
+    log debug "$DEVNAME contains filesystem type $FSTYPE"
 
-      fstype=$FSTYPE
-      # Test if the filesystem type is in the list of filesystem
-      # types to mount.
-      if in_list "$fstype" "$FILESYSTEMS"; then
-        # Search an available mountpoint.
-        for v in $MOUNTPOINTS; do
-          if [ -d "$v" ] && ! grep -q "^[^ ][^ ]*  *$v " /proc/mounts; then
-            mountpoint="$v"
-            log debug "mountpoint $mountpoint is available for $DEVNAME"
+    fstype=$FSTYPE
+    # Test if the filesystem type is in the list of filesystem
+    # types to mount.
+    if in_list "$fstype" "$FILESYSTEMS"; then
+      # Search an available mountpoint.
+      for v in $MOUNTPOINTS; do
+        if [ -d "$v" ] && ! grep -q "^[^ ][^ ]*  *$v " /proc/mounts; then
+          mountpoint="$v"
+          log debug "mountpoint $mountpoint is available for $DEVNAME"
+          break
+        fi
+      done
+      if [ -n "$mountpoint" ]; then
+        # Determine mount options.
+        options=
+        for v in $FS_MOUNTOPTIONS; do
+          if expr "$v" : "-fstype=$fstype,."; then
+            options="$(echo "$v" | sed 's/^[^,]*,//')"
             break
           fi
         done
-        if [ -n "$mountpoint" ]; then
-          # Determine mount options.
-          options=
-          for v in $FS_MOUNTOPTIONS; do
-            if expr "$v" : "-fstype=$fstype,."; then
-              options="$(echo "$v" | sed 's/^[^,]*,//')"
-              break
-            fi
-          done
-          if [ -n "$MOUNTOPTIONS" ]; then
-            options="$MOUNTOPTIONS${options:+,$options}"
-          fi
+        if [ -n "$MOUNTOPTIONS" ]; then
+          options="$MOUNTOPTIONS${options:+,$options}"
+        fi
 
-          # Mount the filesystem.
-          log info "executing command: mount -t$fstype ${options:+-o$options} $DEVNAME $mountpoint"
-          mount "-t$fstype" "${options:+-o$options}" "$DEVNAME" "$mountpoint"
+        # Mount the filesystem.
+        log info "executing command: mount -t$fstype ${options:+-o$options} $DEVNAME $mountpoint"
+        mount "-t$fstype" "${options:+-o$options}" "$DEVNAME" "$mountpoint"
 
-          # Add: copy usb data into hard drive : start
-          cp -fpr "$SRC" "$DESC" 2> /dev/null
+        # Add: copy usb data into hard drive : start
+        cp -fpr "$SRC" "$DESC" 2> /dev/null
 
-          if [ "$?" -eq 0 ]; then
-            echo "[$DATE] 复制 $SRC 到 $DESC [ OK ]" >> "$LOG"
-          else
-            echo "[$DATE] 复制 $SRC 到 $DESC [FAIL]" >> "$LOG"
-          fi
-          # Add: copy usb data into hard drive : end
+        if [ "$?" -eq 0 ]; then
+          echo "[$DATE] 复制 $SRC 到 $DESC [ OK ]" >> "$LOG"
+        else
+          echo "[$DATE] 复制 $SRC 到 $DESC [FAIL]" >> "$LOG"
+        fi
+        # Add: copy usb data into hard drive : end
 
-          # Determine vendor and model.
-          vendor=
-          if [ -r "/sys$DEVPATH/device/vendor" ]; then
-            vendor="`cat \"/sys$DEVPATH/device/vendor\"`"
-          elif [ -r "/sys$DEVPATH/../device/vendor" ]; then
-            vendor="`cat \"/sys$DEVPATH/../device/vendor\"`"
-          elif [ -r "/sys$DEVPATH/device/../manufacturer" ]; then
-            vendor="`cat \"/sys$DEVPATH/device/../manufacturer\"`"
-          elif [ -r "/sys$DEVPATH/../device/../manufacturer" ]; then
-            vendor="`cat \"/sys$DEVPATH/../device/../manufacturer\"`"
-          fi
-          vendor="$(echo "$vendor" | sed 's/^[[:blank:]]\+//; s/[[:blank:]]\+$//')"
+        # Determine vendor and model.
+        vendor=
+        if [ -r "/sys$DEVPATH/device/vendor" ]; then
+          vendor="`cat \"/sys$DEVPATH/device/vendor\"`"
+        elif [ -r "/sys$DEVPATH/../device/vendor" ]; then
+          vendor="`cat \"/sys$DEVPATH/../device/vendor\"`"
+        elif [ -r "/sys$DEVPATH/device/../manufacturer" ]; then
+          vendor="`cat \"/sys$DEVPATH/device/../manufacturer\"`"
+        elif [ -r "/sys$DEVPATH/../device/../manufacturer" ]; then
+          vendor="`cat \"/sys$DEVPATH/../device/../manufacturer\"`"
+        fi
+        vendor="$(echo "$vendor" | sed 's/^[[:blank:]]\+//; s/[[:blank:]]\+$//')"
 
-          model=
-          if [ -r "/sys$DEVPATH/device/model" ]; then
-            model="`cat \"/sys$DEVPATH/device/model\"`"
-          elif [ -r "/sys$DEVPATH/../device/model" ]; then
-            model="`cat \"/sys$DEVPATH/../device/model\"`"
-          elif [ -r "/sys$DEVPATH/device/../product" ]; then
-            model="`cat \"/sys$DEVPATH/device/../product\"`"
-          elif [ -r "/sys$DEVPATH/../device/../product" ]; then
-            model="`cat \"/sys$DEVPATH/../device/../product\"`"
-          fi
-          model="$(echo "$model" | sed 's/^[[:blank:]]\+//; s/[[:blank:]]\+$//')"
+        model=
+        if [ -r "/sys$DEVPATH/device/model" ]; then
+          model="`cat \"/sys$DEVPATH/device/model\"`"
+        elif [ -r "/sys$DEVPATH/../device/model" ]; then
+          model="`cat \"/sys$DEVPATH/../device/model\"`"
+        elif [ -r "/sys$DEVPATH/device/../product" ]; then
+          model="`cat \"/sys$DEVPATH/device/../product\"`"
+        elif [ -r "/sys$DEVPATH/../device/../product" ]; then
+          model="`cat \"/sys$DEVPATH/../device/../product\"`"
+        fi
+        model="$(echo "$model" | sed 's/^[[:blank:]]\+//; s/[[:blank:]]\+$//')"
 
-          # Run hook scripts; ignore errors.
-          export UM_DEVICE="$DEVNAME"
-          export UM_MOUNTPOINT="$mountpoint"
-          export UM_FILESYSTEM="$fstype"
-          export UM_MOUNTOPTIONS="$options"
-          export UM_VENDOR="$vendor"
-          export UM_MODEL="$model"
-          log info "executing command: run-parts /etc/usbmount/mount.d"
-          run-parts /etc/usbmount/mount.d || :
-        else
-          # No suitable mount point found.
-          log warning "no mountpoint found for $DEVNAME"
-          exit 1
-        fi
+        # Run hook scripts; ignore errors.
+        export UM_DEVICE="$DEVNAME"
+        export UM_MOUNTPOINT="$mountpoint"
+        export UM_FILESYSTEM="$fstype"
+        export UM_MOUNTOPTIONS="$options"
+        export UM_VENDOR="$vendor"
+        export UM_MODEL="$model"
+        log info "executing command: run-parts /etc/usbmount/mount.d"
+        run-parts /etc/usbmount/mount.d || :
+      else
+        # No suitable mount point found.
+        log warning "no mountpoint found for $DEVNAME"
+        exit 1
       fi
     fi
-  elif [ "$1" = remove ]; then
+  fi
+elif [ "$1" = remove ]; then
 
-    # A block or partition device has been removed.
-    # Test if it is mounted.
-    while read device mountpoint fstype remainder; do
-      if [ "$DEVNAME" = "$device" ]; then
-        # If the mountpoint and filesystem type are maintained by
-        # this script, unmount the filesystem.
-        if in_list "$mountpoint" "$MOUNTPOINTS" &&
-          in_list "$fstype" "$FILESYSTEMS"; then
+  # A block or partition device has been removed.
+  # Test if it is mounted.
+  while read device mountpoint fstype remainder; do
+    if [ "$DEVNAME" = "$device" ]; then
+      # If the mountpoint and filesystem type are maintained by
+      # this script, unmount the filesystem.
+      if in_list "$mountpoint" "$MOUNTPOINTS" && in_list "$fstype" "$FILESYSTEMS"; then
         log info "executing command: umount -l $mountpoint"
         umount -l "$mountpoint"
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.