[fix] minfixed exit management in main script
This commit is contained in:
parent
bad5b28848
commit
2ca4f7c211
48
clone/clone
48
clone/clone
|
@ -17,20 +17,28 @@ echo "<<< done";
|
||||||
# [!] Check parameter : device file
|
# [!] Check parameter : device file
|
||||||
#========================================================#
|
#========================================================#
|
||||||
echo ">>> [!] Checking parameter : device";
|
echo ">>> [!] Checking parameter : device";
|
||||||
|
|
||||||
# (1) Check parameter existence #
|
# (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 !!!!!!!!!! #
|
# (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=//');
|
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 "<<< done";
|
||||||
|
|
||||||
|
|
||||||
echo ">>> [!] Checking debian image";
|
echo ">>> [!] Checking debian image";
|
||||||
# (1) Check parameter existence #
|
# (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";
|
echo "<<< done";
|
||||||
|
|
||||||
|
@ -57,7 +65,12 @@ step1(){
|
||||||
|
|
||||||
read -p " (!) umount $mounted (y/n) [n]" unmount;
|
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;
|
done;
|
||||||
echo "<<< done";
|
echo "<<< done";
|
||||||
|
|
||||||
|
@ -76,8 +89,15 @@ step2(){
|
||||||
|
|
||||||
# (1) Confirmation #
|
# (1) Confirmation #
|
||||||
read -p" (!) Erase the whole disk ? it is irreversible! (y/n) [n]" confirm_format;
|
read -p" (!) Erase the whole disk ? it is irreversible! (y/n) [n]" confirm_format;
|
||||||
test -z "$confirm_format" && echo "<<< aborting" && exit;
|
if [ -z "$confirm_format" ]; then
|
||||||
test $confirm_format != "y" && echo "<<< aborting" && exit;
|
echo "<<< aborting";
|
||||||
|
exit 1;
|
||||||
|
fi;
|
||||||
|
|
||||||
|
if [ $confirm_format != "y" ]; then
|
||||||
|
echo "<<< aborting";
|
||||||
|
exit 1;
|
||||||
|
fi;
|
||||||
|
|
||||||
# (2) Init gpt entry #
|
# (2) Init gpt entry #
|
||||||
echo -e "g\nw" | sudo fdisk $DEV 2> /dev/null > /dev/null;
|
echo -e "g\nw" | sudo fdisk $DEV 2> /dev/null > /dev/null;
|
||||||
|
@ -100,8 +120,15 @@ step3(){
|
||||||
|
|
||||||
# (1) Confirmation #
|
# (1) Confirmation #
|
||||||
read -p" (!) Burn the whole disk ? it is irreversible! (y/n) [n]" confirm_burn;
|
read -p" (!) Burn the whole disk ? it is irreversible! (y/n) [n]" confirm_burn;
|
||||||
test -z "$confirm_burn" && echo "<<< aborting" && exit;
|
if [ -z "$confirm_burn" ]; then
|
||||||
test $confirm_burn != "y" && echo "<<< aborting" && exit;
|
echo "<<< aborting";
|
||||||
|
exit 1;
|
||||||
|
fi;
|
||||||
|
|
||||||
|
if [ $confirm_burn != "y" ]; then
|
||||||
|
echo "<<< aborting";
|
||||||
|
exit 1;
|
||||||
|
fi;
|
||||||
|
|
||||||
# (2) Burning image into disk #
|
# (2) Burning image into disk #
|
||||||
# if GZIP
|
# if GZIP
|
||||||
|
@ -145,7 +172,10 @@ step4(){
|
||||||
sleep 1;
|
sleep 1;
|
||||||
done;
|
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
|
# [1] Mount device partition
|
||||||
sudo mount ${DEV}2 /mnt || (echo "<<< error: can't mount"; exit 1);
|
sudo mount ${DEV}2 /mnt || (echo "<<< error: can't mount"; exit 1);
|
||||||
|
|
Loading…
Reference in New Issue