diff --git a/clone/clone b/clone/clone index b1db5a3..18addd6 100755 --- a/clone/clone +++ b/clone/clone @@ -17,20 +17,28 @@ echo "<<< done"; # [!] Check parameter : device file #========================================================# echo ">>> [!] Checking parameter : device"; + # (1) Check parameter existence # -test $# -lt 1 && echo "Missing parameter : device" && exit; +if [ $# -lt 1 ]; then + echo "Missing parameter : device"; exit 1; +fi # (2) Check USB and not a hard drive !!!!!!!!!! # device_type=$(udevadm info --query=all -n $1 | grep -E "ID_BUS" | awk '{print $2}' | sed 's/ID_BUS=//'); -test $device_type != "usb" && echo ">>> ERROR: device type is $device_type, \"usb\" expected." && exit; +if [ "$device_type" != "usb" ]; then + echo ">>> ERROR: device type is $device_type, \"usb\" expected."; exit 1; +fi; echo "<<< done"; echo ">>> [!] Checking debian image"; # (1) Check parameter existence # -test ! -e $IMAGE_FILE && echo -e "debian image '$IMAGE_FILE' not found" && exit; +if [ ! -e $IMAGE_FILE ]; then + echo -e "debian image '$IMAGE_FILE' not found"; + exit 1; +fi; echo "<<< done"; @@ -57,7 +65,12 @@ step1(){ read -p " (!) umount $mounted (y/n) [n]" unmount; - test -n "$unmount" && test $unmount = "y" && sudo umount $mounted 2> /dev/null > /dev/null && echo " > unmounted"; + if [ -n "$unmount" ] && [ $unmount = "y" ]; then + sudo umount $mounted 2> /dev/null > /dev/null \ + && echo " > unmounted" \ + || echo " > error"; + fi; + done; echo "<<< done"; @@ -76,8 +89,15 @@ step2(){ # (1) Confirmation # read -p" (!) Erase the whole disk ? it is irreversible! (y/n) [n]" confirm_format; - test -z "$confirm_format" && echo "<<< aborting" && exit; - test $confirm_format != "y" && echo "<<< aborting" && exit; + if [ -z "$confirm_format" ]; then + echo "<<< aborting"; + exit 1; + fi; + + if [ $confirm_format != "y" ]; then + echo "<<< aborting"; + exit 1; + fi; # (2) Init gpt entry # echo -e "g\nw" | sudo fdisk $DEV 2> /dev/null > /dev/null; @@ -100,8 +120,15 @@ step3(){ # (1) Confirmation # read -p" (!) Burn the whole disk ? it is irreversible! (y/n) [n]" confirm_burn; - test -z "$confirm_burn" && echo "<<< aborting" && exit; - test $confirm_burn != "y" && echo "<<< aborting" && exit; + if [ -z "$confirm_burn" ]; then + echo "<<< aborting"; + exit 1; + fi; + + if [ $confirm_burn != "y" ]; then + echo "<<< aborting"; + exit 1; + fi; # (2) Burning image into disk # # if GZIP @@ -145,7 +172,10 @@ step4(){ sleep 1; done; - test $count -eq 5 && (echo "<<< error: can't find device ${DEV}2"; exit 1); + if [ $count -eq 5 ]; then + echo "<<< error: can't find device ${DEV}2"; + exit 1; + fi; # [1] Mount device partition sudo mount ${DEV}2 /mnt || (echo "<<< error: can't mount"; exit 1);