diff options
author | Filipp Lepalaan <filipp@mac.com> | 2010-08-16 20:07:40 +0300 |
---|---|---|
committer | Filipp Lepalaan <filipp@mac.com> | 2010-08-16 20:07:40 +0300 |
commit | 999290053325e064d88760f5c52c98043d62d52c (patch) | |
tree | d0d39fc26b104828a4282c9fa1784a7119f6d82d /cyclone.sh | |
parent | 105a08740f6b9184f5344e68f680624b815ab27c (diff) | |
download | mtk-999290053325e064d88760f5c52c98043d62d52c.tar.gz mtk-999290053325e064d88760f5c52c98043d62d52c.tar.bz2 mtk-999290053325e064d88760f5c52c98043d62d52c.zip |
added cyclone
Diffstat (limited to 'cyclone.sh')
-rwxr-xr-x | cyclone.sh | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/cyclone.sh b/cyclone.sh new file mode 100755 index 0000000..f77225a --- /dev/null +++ b/cyclone.sh @@ -0,0 +1,42 @@ +#!/usr/bin/env bash +# clone all partitions of a drive +# and try not to waste space +# @author Filipp Lepalaan <filipp@mcare.fi> + +if [[ $USER != "root" ]]; then + echo "Insufficient privileges!" 2>&1 + exit 1 +fi + +if [[ $# -lt 2 ]]; then + echo "Usage: $(basename $0) source destination" 2>&1 + exit 1 +fi + +SOURCE=$1 +TARGET=$2 + +TMPFILE="/tmp/$(uuidgen)" + +# Get size of source +diskutil info -plist $SOURCE > "${TMPFILE}".plist +SOURCE_SIZE=`defaults read $TMPFILE TotalSize` + +# Get size of destination +diskutil info -plist $TARGET > $TMPFILE +TARGET_SIZE=`defaults read $TMPFILE TotalSize` +rm $TMPFILE + +if [[ $TARGET_SIZE < $SOURCE_SIZE ]]; then + echo "Warning: target drive is smaller than source!" 2>&1 +fi + +if [[ $TARGET_SIZE == $SOURCE_SIZE ]]; then + echo "Drives are identical, cloning with dd..." + diskutil quiet unmountDisk $SOURCE + diskutil quiet unmountDisk $TARGET + dd bs=16m if="/dev/r${SOURCE}" of="/dev/r${TARGET}" conv=noerror,sync + diskutil quiet mountDisk $SOURCE + diskutil quiet mountDisk $TARGET + exit 0 +fi |