Skip to contentSkip to conversation

ddimage: Support Mac OS

PATCH Superseded Darren Hart 2 participants 4 messages May 23, 2014 – May 27, 2014

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover ddimage: Support Mac OS

Darren Hart (1):
ddimage: Support Mac OS

 scripts/contrib/ddimage | 25 ++++++++++++++++++++-----
 1 file changed, 20 insertions(+), 5 deletions(-)
Signature · 1 line
1.9.1
#1 lore raw

PATCH 1/1 ddimage: Support Mac OS

Update the ddimage script to allow it to work on Mac OS too. The biggest difference is sysfs vs diskutil and in the syntax of the stat command between Mac OS and Linux, unfortunately. Workarounds using ls, cut, and columns got really fragile really quickly. Relying on stat and switching on uname seemed the more robust solution.

---
 scripts/contrib/ddimage | 25 ++++++++++++++++++++-----
 1 file changed, 20 insertions(+), 5 deletions(-)
scripts/contrib/ddimage +20 -5
index 93ebeaf..b66d0dd 100755
@@ -1,7 +1,8 @@
 #!/bin/sh
 
-#BLACKLIST_DEVICES="/dev/sda /dev/sdb /dev/sdc /dev/sdd /dev/sde"
-BLACKLIST_DEVICES="/dev/sda"
+# Default to avoiding the first two disks on typical Linux and Mac OS installs
+# Better safe than sorry :-)
+BLACKLIST_DEVICES="/dev/sda /dev/sdb /dev/disk1 /dev/disk3"
 
 # 1MB blocksize
 BLOCKSIZE=1048576
@@ -14,9 +15,15 @@ image_details() {
 	IMG=$1
 	echo "Image details"
 	echo "============="
-	echo "    image: $(stat --printf '%N\n' $IMG)"
-	echo "     size: $(stat -L --printf '%s bytes\n' $IMG)"
-	echo " modified: $(stat -L --printf '%y\n' $IMG)"
+	echo "    image: $(basename $IMG)"
+	# stat format is different on Mac OS and Linux
+	if [ "$(uname)" = "Darwin" ]; then
+		echo "     size: $(stat -L -f '%z bytes' $IMG)"
+		echo " modified: $(stat -L -f '%Sm' $IMG)"
+	else
+		echo "     size: $(stat -L -c '%s bytes' $IMG)"
+		echo " modified: $(stat -L -c '%y' $IMG)"
+	fi
 	echo "     type: $(file -L -b $IMG)"
 	echo ""
 }
@@ -27,6 +34,14 @@ device_details() {
 
 	echo "Device details"
 	echo "=============="
+
+	# Collect disk info using diskutil on Mac OS
+	if [ "$(uname)" = "Darwin" ]; then
+		diskutil info $DEVICE | egrep "(Device Node|Media Name|Total Size)"
+		return
+	fi
+
+	# Default / Linux information collection
 	echo "  device: $DEVICE"
 	if [ -f "/sys/class/block/$DEV/device/vendor" ]; then
 		echo "  vendor: $(cat /sys/class/block/$DEV/device/vendor)"
Signature · 1 line
1.9.1
#2 lore raw

Op 23 mei 2014, om 06:28 heeft Darren Hart <[email protected]> het volgende geschreven:

Quoted 16 lines

Update the ddimage script to allow it to work on Mac OS too. The biggest difference is sysfs vs diskutil and in the syntax of the stat command between Mac OS and Linux, unfortunately. Workarounds using ls, cut, and columns got really fragile really quickly. Relying on stat and switching on uname seemed the more robust solution.

---
scripts/contrib/ddimage | 25 ++++++++++++++++++++-----

1 file changed, 20 insertions(+), 5 deletions(-)
scripts/contrib/ddimage +0 -0
index 93ebeaf..b66d0dd 100755

scripts/contrib/ddimage line 5

Quoted 7 lines
scripts/contrib/ddimage +3 -2
@@ -1,7 +1,8 @@
 #!/bin/sh
 
-#BLACKLIST_DEVICES="/dev/sda /dev/sdb /dev/sdc /dev/sdd /dev/sde"
-BLACKLIST_DEVICES="/dev/sda"
+# Default to avoiding the first two disks on typical Linux and Mac OS installs
+# Better safe than sorry :-)
+BLACKLIST_DEVICES="/dev/sda /dev/sdb /dev/disk1 /dev/disk3"

s/disk3/disk2/

#3 lore raw
Quoted 22 lines · Koen Kooi

Op 23 mei 2014, om 06:28 heeft Darren Hart <[email protected]> het volgende geschreven:

Quoted 18 lines

Update the ddimage script to allow it to work on Mac OS too. The biggest difference is sysfs vs diskutil and in the syntax of the stat command between Mac OS and Linux, unfortunately. Workarounds using ls, cut, and columns got really fragile really quickly. Relying on stat and switching on uname seemed the more robust solution.

---
scripts/contrib/ddimage | 25 ++++++++++++++++++++-----

1 file changed, 20 insertions(+), 5 deletions(-)
scripts/contrib/ddimage +0 -0
index 93ebeaf..b66d0dd 100755
@@ -1,7 +1,8 @@
 #!/bin/sh
 
Quoted 8 lines

scripts/contrib/ddimage line 5

Quoted 6 lines
scripts/contrib/ddimage +1 -2
-#BLACKLIST_DEVICES="/dev/sda /dev/sdb /dev/sdc /dev/sdd /dev/sde"
-BLACKLIST_DEVICES="/dev/sda"
+# Default to avoiding the first two disks on typical Linux and Mac OS

installs

scripts/contrib/ddimage +2 -0
+# Better safe than sorry :-)
+BLACKLIST_DEVICES="/dev/sda /dev/sdb /dev/disk1 /dev/disk3"

s/disk3/disk2/

Bah, indeed. Local change snuck through in my patch. Thanks. Will correct.

Signature · 2 lines
Darren Hart					Open Source Technology Center
[email protected]				            Intel Corporation