Fork me on GitHub

Differences

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

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
developer:mounting_attached_backup_devices [2010/04/19 21:41]
henri
developer:mounting_attached_backup_devices [2018/10/18 23:59]
admin [USB Device Support Tools]
Line 15: Line 15:
 ===== Support for Mac OS X Devices ===== ===== Support for Mac OS X Devices =====
 \\ \\ \\ \\
 +
 ==== USB Device Support Tools ==== ==== USB Device Support Tools ====
  
Line 22: Line 23:
 \\ \\  \\ \\ 
 <​file>​ <​file>​
-##​!/​usr/​bin/​env ruby+ 
 +#​!/​usr/​bin/​env ruby
 # #
 # (C)2009 Henri Shustak # (C)2009 Henri Shustak
Line 33: 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 41: 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.2
 # #
 +#
 +# 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. ​
 #        That is not how this script works. This script mounts volumes via the volume name. #        That is not how this script works. This script mounts volumes via the volume name.
 #        This approach allows you to add additional devices into a rotation set without #        This approach allows you to add additional devices into a rotation set without
-#        altering this script. However, it is extremely important to be aware of the +#        altering ​this script or the way you call this script. However, it is extremely ​ 
-#        ​potential problems which may arise by using the volume name to mount a device +#        ​important to be aware of the potential problems which may arise by using the 
-#        ​before you use this script in any kind of production setting.+#        ​volume name to mount a device before you use this script in any kind 
 +#        ​of production setting.
 # #
  
Line 74: 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 85: 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 109: 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 133: 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 183: Line 181:
 result = mount_first_volume_with_name result = mount_first_volume_with_name
 exit result exit result
 +
  
 </​file>​ </​file>​