Clone code

This commit is contained in:
xdrm-brackets 2017-01-20 10:42:31 +01:00
parent 94d4b50330
commit 212c95b3a7
1 changed files with 46 additions and 4 deletions

View File

@ -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 #