add check on blockdevice

This commit is contained in:
Tobias Powalowski 2024-08-13 23:25:12 +02:00
parent 0e47c265fc
commit 8798835dd1
2 changed files with 29 additions and 21 deletions

View file

@ -22,9 +22,13 @@ echo -e "\e[91mWARNING: 10 seconds for hitting CTRL+C to stop the process on $*
sleep 10 sleep 10
#shellcheck disable=SC2068 #shellcheck disable=SC2068
for i in $@; do for i in $@; do
if [[ -b "${i}" ]]; then
echo -e "\e[1mSTEP 1/2:\e[m Cleaning ${i} filesystem signatures..." echo -e "\e[1mSTEP 1/2:\e[m Cleaning ${i} filesystem signatures..."
wipefs -f -a "${i}" wipefs -f -a "${i}"
echo -e "\e[1mSTEP 2/2:\e[m Cleaning ${i} partition table..." echo -e "\e[1mSTEP 2/2:\e[m Cleaning ${i} partition table..."
dd if=/dev/zero of="${i}" bs=1M count=10 dd if=/dev/zero of="${i}" bs=1M count=10
echo -e "\e[1mFinished ${i}.\e[m" echo -e "\e[1mFinished ${i}.\e[m"
else
echo -e "\e[1m\e[91mError: ${i} not a valid blockdevice! \e[m"
fi
done done

View file

@ -16,16 +16,17 @@ _usage()
################################################## ##################################################
[[ -z "${1}" ]] && _usage [[ -z "${1}" ]] && _usage
_root_check _root_check
echo -e "\e[91mWARNING: 10 seconds for hitting CTRL+C to stop the process on ${1} now! \e[m" if [[ -b "${1}" ]]; then
sleep 10 echo -e "\e[91mWARNING: 10 seconds for hitting CTRL+C to stop the process on ${1} now! \e[m"
# clean partitiontable sleep 10
echo -e "\e[1mRestoring USB STICK...\e[m" # clean partitiontable
echo -e "\e[1mSTEP 1/3:\e[m Cleaning partition table..." echo -e "\e[1mRestoring USB STICK...\e[m"
dd if=/dev/zero of="${1}" bs=512 count=2048 echo -e "\e[1mSTEP 1/3:\e[m Cleaning partition table..."
wipefs -a "${1}" dd if=/dev/zero of="${1}" bs=512 count=2048
# create new MBR and partition on <DEVICE> wipefs -a "${1}"
echo -e "\e[1mSTEP 2/3:\e[m Create new MBR and partitiontable..." # create new MBR and partition on <DEVICE>
fdisk "${1}" <<EOF echo -e "\e[1mSTEP 2/3:\e[m Create new MBR and partitiontable..."
fdisk "${1}" <<EOF
n n
p p
1 1
@ -35,9 +36,12 @@ t
b b
w w
EOF EOF
# wait for partitiontable to be resynced # wait for partitiontable to be resynced
sleep 5 sleep 5
# create FAT32 filesystem on <device-partition> # create FAT32 filesystem on <device-partition>
echo -e "\e[1mSTEP 3/3:\e[m Create FAT32 filesystem..." echo -e "\e[1mSTEP 3/3:\e[m Create FAT32 filesystem..."
mkfs.vfat -F32 "${1}"1 mkfs.vfat -F32 "${1}"1
echo -e "\e[1mFinished.\e[m" echo -e "\e[1mFinished.\e[m"
else
echo -e "\e[1m\e[91mError: ${1} not a valid blockdevice! \e[m"
fi