diff options
Diffstat (limited to 'scripts/contrib/ddimage')
| -rwxr-xr-x | scripts/contrib/ddimage | 49 |
1 files changed, 35 insertions, 14 deletions
diff --git a/scripts/contrib/ddimage b/scripts/contrib/ddimage index 956699c05d..ab929957a5 100755 --- a/scripts/contrib/ddimage +++ b/scripts/contrib/ddimage @@ -1,32 +1,47 @@ #!/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/disk2" # 1MB blocksize BLOCKSIZE=1048576 -function usage() { +usage() { echo "Usage: $(basename $0) IMAGE DEVICE" } -function image_details() { +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 "" } -function device_details() { +device_details() { DEV=$1 BLOCK_SIZE=512 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)" @@ -39,7 +54,7 @@ function device_details() { echo " model: UNKNOWN" fi if [ -f "/sys/class/block/$DEV/size" ]; then - echo " size: $[$(cat /sys/class/block/$DEV/size)*BLOCK_SIZE] bytes" + echo " size: $(($(cat /sys/class/block/$DEV/size) * $BLOCK_SIZE)) bytes" else echo " size: UNKNOWN" fi @@ -61,10 +76,12 @@ if [ ! -e "$IMAGE" ]; then fi -if [ "${BLACKLIST_DEVICES/${DEVICE}/ERROR}" != "$BLACKLIST_DEVICES" ]; then - echo "ERROR: Device $DEVICE is blacklisted" - exit 1 -fi +for i in ${BLACKLIST_DEVICES}; do + if [ "$i" = "$DEVICE" ]; then + echo "ERROR: Device $DEVICE is blacklisted" + exit 1 + fi +done if [ ! -w "$DEVICE" ]; then echo "ERROR: Device $DEVICE does not exist or is not writable" @@ -83,5 +100,9 @@ if [ "$RESPONSE" != "y" ]; then fi echo "Writing image..." -dd if="$IMAGE" of="$DEVICE" bs="$BLOCKSIZE" +if which pv >/dev/null 2>&1; then + pv "$IMAGE" | dd of="$DEVICE" bs="$BLOCKSIZE" +else + dd if="$IMAGE" of="$DEVICE" bs="$BLOCKSIZE" +fi sync |
