From 02e9dac13fad9705d35ccafc4624d02af1263e3d Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Sun, 23 Jul 2017 12:16:22 +0200 Subject: [PATCH] [fix] Fixed partition check before mounting it --- clone/clone | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/clone/clone b/clone/clone index 1fa991f..3d77d28 100755 --- a/clone/clone +++ b/clone/clone @@ -51,7 +51,7 @@ step1(){ mounted_partitions=$( cat /proc/mounts | awk '{print $1}' | grep "$DEV" ); # if nothing found -> next step - ls ${DEV}2 > /dev/null 2>&1 || $( echo "<<< done" && step2 ); + ls ${DEV}2 > /dev/null 2>&1 || (echo "<<< done"; step2); for mounted in $mounted_partitions; do @@ -111,12 +111,12 @@ step3(){ echo " - using gunzip"; ( dd if=$IMAGE_FILE | pv -s $(du -bs $IMAGE_FILE | gunzip | awk '{print $1}') | sudo dd of=$DEV bs=4M ) \ - || $( echo "<<< error: dd command failed" && exit ); + || (echo "<<< error: dd command failed"; exit); else ( dd if=$IMAGE_FILE | pv -s $(du -bs $IMAGE_FILE | awk '{print $1}') | sudo dd of=$DEV bs=4M ) \ - || $( echo "<<< error: dd command failed" && exit ); + || (echo "<<< error: dd command failed"; exit); fi; @@ -137,10 +137,18 @@ step3(){ step4(){ echo -e "\n>>> [4] Mounting partition ${DEV}2"; - test ! -f ${DEV}2 && ( echo "<<< error: device ${DEV}2 does not exist" && exit ); + count=0; + + while [ $count -lt 5 ] && [ ! -e ${DEV}2 ]; do + echo " * Waiting for ${DEV}2 to be ready (remaining `expr 5 - $count`s)"; + count=`expr $count + 1`; + sleep 1; + done; + + test $count -eq 5 && (echo "<<< error: can't find device ${DEV}2"; exit 1); # [1] Mount device partition - sudo mount ${DEV}2 /mnt || $( echo "<<< error: can't mount" && exit ); + sudo mount ${DEV}2 /mnt || (echo "<<< error: can't mount"; exit 1); echo "<<< done";