From 212c95b3a71785e8dbe59ee3fd6d214c5f4aeb6f Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Fri, 20 Jan 2017 10:42:31 +0100 Subject: [PATCH] Clone code --- clone/clone | 50 ++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 46 insertions(+), 4 deletions(-) diff --git a/clone/clone b/clone/clone index c9fecd5..cebb612 100755 --- a/clone/clone +++ b/clone/clone @@ -1,10 +1,52 @@ #!/bin/sh -# [1] check parameters (device, ESSID, WPA) -if [ $# -lt 3 ]; then - echo "Missing parameters : (device, ESSID, WPA)" && exit; -fi; +# [1] Check parameter : device file +#========================================================# +echo ">>> [1] Checking parameter : device"; +# (1) Check parameter existence # +test $# -lt 1 && echo "Missing parameter : device" && exit; + +# (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; + +echo "<<< done"; + + +# [2] Init device layout (gpt table) +#========================================================# + +echo "\n>>> [2] Checking for mounted partitions"; +# (1) List partitions of this device # +mounted_partitions=$( cat /proc/mounts | awk '{print $1}' | grep "$1" ); + +for mounted in $mounted_partitions; do + + read -p " (!) umount $mounted (y/n) [n]" unmount; + + test -n "$unmount" && test $unmount = "y" && sudo umount $mounted && echo "> unmounted"; +done; +echo "<<< done"; + + +# [3] Initialize GTP Table +#========================================================# +echo "\n>>> [3] Formatting disk"; + +# (1) Confirmation # +read -p" (!) Erase the whole disk ? it is irreversible! (y/n) [n]" confirm_format; +( test -z "$confirm_format" || test $confirm_format != "y" ) \ + && (echo "<<< aborting" && exit); + +# (2) Init gpt entry # +echo " ))) replace by real code ((("; +# echo -e "g\nw" | fdisk $1"; + + + +exit; # [2] Formatting USB #