From 8798835dd154e895ab4bc899d72cb998be86438b Mon Sep 17 00:00:00 2001 From: Tobias Powalowski Date: Tue, 13 Aug 2024 23:25:12 +0200 Subject: [PATCH] add check on blockdevice --- usr/bin/archboot-clean-blockdevice.sh | 14 +++++++---- usr/bin/archboot-restore-usbstick.sh | 36 +++++++++++++++------------ 2 files changed, 29 insertions(+), 21 deletions(-) diff --git a/usr/bin/archboot-clean-blockdevice.sh b/usr/bin/archboot-clean-blockdevice.sh index 0e420752b..536f231ba 100755 --- a/usr/bin/archboot-clean-blockdevice.sh +++ b/usr/bin/archboot-clean-blockdevice.sh @@ -22,9 +22,13 @@ echo -e "\e[91mWARNING: 10 seconds for hitting CTRL+C to stop the process on $* sleep 10 #shellcheck disable=SC2068 for i in $@; do - echo -e "\e[1mSTEP 1/2:\e[m Cleaning ${i} filesystem signatures..." - wipefs -f -a "${i}" - echo -e "\e[1mSTEP 2/2:\e[m Cleaning ${i} partition table..." - dd if=/dev/zero of="${i}" bs=1M count=10 - echo -e "\e[1mFinished ${i}.\e[m" + if [[ -b "${i}" ]]; then + echo -e "\e[1mSTEP 1/2:\e[m Cleaning ${i} filesystem signatures..." + wipefs -f -a "${i}" + echo -e "\e[1mSTEP 2/2:\e[m Cleaning ${i} partition table..." + dd if=/dev/zero of="${i}" bs=1M count=10 + echo -e "\e[1mFinished ${i}.\e[m" + else + echo -e "\e[1m\e[91mError: ${i} not a valid blockdevice! \e[m" + fi done diff --git a/usr/bin/archboot-restore-usbstick.sh b/usr/bin/archboot-restore-usbstick.sh index 24744fef6..5514b6423 100755 --- a/usr/bin/archboot-restore-usbstick.sh +++ b/usr/bin/archboot-restore-usbstick.sh @@ -16,16 +16,17 @@ _usage() ################################################## [[ -z "${1}" ]] && _usage _root_check -echo -e "\e[91mWARNING: 10 seconds for hitting CTRL+C to stop the process on ${1} now! \e[m" -sleep 10 -# clean partitiontable -echo -e "\e[1mRestoring USB STICK...\e[m" -echo -e "\e[1mSTEP 1/3:\e[m Cleaning partition table..." -dd if=/dev/zero of="${1}" bs=512 count=2048 -wipefs -a "${1}" -# create new MBR and partition on -echo -e "\e[1mSTEP 2/3:\e[m Create new MBR and partitiontable..." -fdisk "${1}" < + echo -e "\e[1mSTEP 2/3:\e[m Create new MBR and partitiontable..." + fdisk "${1}" < -echo -e "\e[1mSTEP 3/3:\e[m Create FAT32 filesystem..." -mkfs.vfat -F32 "${1}"1 -echo -e "\e[1mFinished.\e[m" + # wait for partitiontable to be resynced + sleep 5 + # create FAT32 filesystem on + echo -e "\e[1mSTEP 3/3:\e[m Create FAT32 filesystem..." + mkfs.vfat -F32 "${1}"1 + echo -e "\e[1mFinished.\e[m" +else + echo -e "\e[1m\e[91mError: ${1} not a valid blockdevice! \e[m" +fi