fix: improve mtm-ddwipe argument handling and timing output

This commit is contained in:
2026-04-27 23:17:16 +02:00
parent 08d6ccde0d
commit b01e72cba6
Executable → Regular
+36 -32
View File
@@ -1,14 +1,13 @@
#!/bin/bash #!/bin/bash
declare -r DEV="${1}" VERSION="0.0.3"
declare STARTDATE="" STARTDATE=""
declare STARTDATESTRING="" STARTDATESTRING=""
show_help() { show_help() {
echo "Usage: mtm-ddwipe DEVICE" echo "Usage: mtm-ddwipe DEVICE"
echo ""
echo "Wipe a block device." echo "Wipe a block device."
echo "Version: 0.0.3" echo "Version: ${VERSION}"
} }
check_args() { check_args() {
@@ -21,6 +20,11 @@ check_args() {
show_help show_help
exit 1 exit 1
;; ;;
-*)
echo "Invalid option."
show_help
exit 1
;;
esac esac
} }
@@ -42,15 +46,33 @@ confirm_wipe() {
lsblk "${1}" lsblk "${1}"
echo "" echo ""
read -r -p "Wipe ${1} (y/[n])? " CHOICE read -r -p "Wipe ${1} (y/[n])? " CHOICE
case "${CHOICE}" in case "${CHOICE}" in
y|Y ) echo "";; y|Y)
* ) echo ""
;;
*)
echo "Canceled" echo "Canceled"
exit 1 exit 1
;; ;;
esac esac
} }
print_time() {
echo ""
echo "Start date :"
echo "${STARTDATESTRING}"
ENDDATE=$(date +%s)
echo ""
echo "End date :"
date
CALCTIME=$((ENDDATE-STARTDATE))
echo ""
echo "Total time :"
date -d@${CALCTIME} -u +%H:%M:%S
}
wipe_dev() { wipe_dev() {
STARTDATE=$(date +%s) STARTDATE=$(date +%s)
STARTDATESTRING="$(date)" STARTDATESTRING="$(date)"
@@ -67,8 +89,6 @@ wipe_dev() {
echo "" echo ""
echo "dd zero" echo "dd zero"
if ! dd if=/dev/zero of="${1}" bs=1M status=progress; then if ! dd if=/dev/zero of="${1}" bs=1M status=progress; then
# Need check if dd has all writed, if yes, return no error
# echo "Error wiping device ${1}, use phisical destroy !"
echo "Wiped with dd, check if full size is writed." echo "Wiped with dd, check if full size is writed."
echo "Otherwise use a mechanical destruction of the device." echo "Otherwise use a mechanical destruction of the device."
print_time print_time
@@ -80,25 +100,9 @@ wipe_dev() {
echo "Device ${1} wiped." echo "Device ${1} wiped."
} }
print_time() { check_args "${1}"
echo "" check_dev_exist "${1}"
echo "Start date :" check_dev_block "${1}"
echo "${STARTDATESTRING}" confirm_wipe "${1}"
wipe_dev "${1}"
ENDDATE=$(date +%s)
echo ""
echo "End date :"
date
CALCTIME=$((ENDDATE-STARTDATE))
echo ""
echo "Total time :"
date -d@${CALCTIME} -u +%H:%M:%S
}
check_args "${DEV}"
check_dev_exist "${DEV}"
check_dev_block "${DEV}"
confirm_wipe "${DEV}"
wipe_dev "${DEV}"
print_time print_time