Fork me on GitHub

Differences

This shows you the differences between two versions of the page.

developer:mounting_attached_backup_devices [2010/04/19 22:45]
henri
developer:mounting_attached_backup_devices [2018/10/18 23:59] (current)
admin [USB Device Support Tools]
Line 23: Line 23:
 \\ \\  \\ \\ 
 <file> <file>
-##!/usr/bin/env ruby+ 
 +#!/usr/bin/env ruby
 # #
 # (C)2009 Henri Shustak # (C)2009 Henri Shustak
Line 34: Line 35:
 # This is a script to detect attached but unmounted volumes by Volume name and mount them. # This is a script to detect attached but unmounted volumes by Volume name and mount them.
 # Tested on the following versions of Mac OS X :  # Tested on the following versions of Mac OS X : 
-#                         - 10.6.1  Intel Ruby version 1.8.7  +#                         - 10.12.6 intel 
-#                         - 10.4.4  PPC +#                         
-#                         - 10.4.11 PPC+
 # #
 # #
Line 42: Line 42:
 #                    If this happens re-partition the disk and try again. #                    If this happens re-partition the disk and try again.
 # #
-# Version 0.3.1+# Version 0.3.
 +#
 # #
 +# Version History
 +#  0.3.2 - Added support for USB-Hubs and macOS 10.12.6 - made it a bit messy
 # #
 # Note : Using a (list of) UUID('s) is generally a good approach to mounting devices.  # Note : Using a (list of) UUID('s) is generally a good approach to mounting devices. 
Line 76: Line 79:
  
 # Build a list of detachable USB drives. # Build a list of detachable USB drives.
-system_profiler_output = `system_profiler SPUSBDataType`+system_profiler_output = `system_profiler SPUSBDataType | grep -A 1 "Removable Media: Yes" | grep "BSD Name" | sed 's/^ *//g'`
  
 # Add detachable FireWire drives to the list # Add detachable FireWire drives to the list
Line 87: Line 90:
 #system_profiler_output = system_profiler_output + `system_profiler SPSerialATADataType` #system_profiler_output = system_profiler_output + `system_profiler SPSerialATADataType`
  
-device = system_profiler_output.split("Volumes:")+device = system_profiler_output.split("BSD Name: ")
 device.each { |d| device.each { |d|
-    volume = d.split("Detachable Drive") +    if d.to_s.include? "disk" 
-    volume.each { |v| +        disks << "/dev/" + d 
-        #puts v.inspect +    end
-        disk_name = v.split(/: Yes\n\s{10,18}BSD Name: /) +
-        # uncomment the line below if you are only interested non removable drives +
-        #disk_name = disk_name + v.split(/: No\n\s{10,18}BSD Name: /) +
-        disk_name.each { |d+
-            devname = d.split("\n")[0] +
-            if devname.to_s.include? "disk" +
-                disks << "/dev/" + devname +
-            end +
-        } +
-    }+
 } }
 +
  
  
Line 111: Line 105:
 $disk_hash = {} $disk_hash = {}
 disks.each { |d| disks.each { |d|
-    partitions_list `diskutil list #{d} | grep -e "disk*[0-9]s*[0-9]" | awk '{print $NF}'`+    diskcom "diskutil list #{d}"  
 +    partitions_list = `#{diskcom}` 
 +    partitions_list = `echo "#{partitions_list}" | grep -e "disk*[0-9]s*[0-9]" | awk '{print $NF}'`
     partitions = partitions_list.split("\n")     partitions = partitions_list.split("\n")
     partitions.each { |p|     partitions.each { |p|
Line 135: Line 131:
 def get_device def get_device
     if $disk_hash.has_value? $volume_name_to_mount     if $disk_hash.has_value? $volume_name_to_mount
-        device_to_mount = $disk_hash.index $volume_name_to_mount.to_s+        device_to_mount = $disk_hash.key $volume_name_to_mount.to_s
         return device_to_mount         return device_to_mount
     else     else
Line 185: Line 181:
 result = mount_first_volume_with_name result = mount_first_volume_with_name
 exit result exit result
 +
  
 </file> </file>