From b01e72cba6f27f85d7cefd30aa32f5532d31f454 Mon Sep 17 00:00:00 2001 From: MatMoul Date: Mon, 27 Apr 2026 23:17:16 +0200 Subject: [PATCH] fix: improve mtm-ddwipe argument handling and timing output --- mtm-ddwipe | 68 +++++++++++++++++++++++++++++------------------------- 1 file changed, 36 insertions(+), 32 deletions(-) mode change 100755 => 100644 mtm-ddwipe diff --git a/mtm-ddwipe b/mtm-ddwipe old mode 100755 new mode 100644 index 148c9b6..0d4afda --- a/mtm-ddwipe +++ b/mtm-ddwipe @@ -1,14 +1,13 @@ #!/bin/bash -declare -r DEV="${1}" -declare STARTDATE="" -declare STARTDATESTRING="" +VERSION="0.0.3" +STARTDATE="" +STARTDATESTRING="" show_help() { echo "Usage: mtm-ddwipe DEVICE" - echo "" echo "Wipe a block device." - echo "Version: 0.0.3" + echo "Version: ${VERSION}" } check_args() { @@ -21,6 +20,11 @@ check_args() { show_help exit 1 ;; + -*) + echo "Invalid option." + show_help + exit 1 + ;; esac } @@ -42,15 +46,33 @@ confirm_wipe() { lsblk "${1}" echo "" read -r -p "Wipe ${1} (y/[n])? " CHOICE - case "${CHOICE}" in - y|Y ) echo "";; - * ) + case "${CHOICE}" in + y|Y) + echo "" + ;; + *) echo "Canceled" exit 1 - ;; + ;; 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() { STARTDATE=$(date +%s) STARTDATESTRING="$(date)" @@ -67,8 +89,6 @@ wipe_dev() { echo "" echo "dd zero" 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 "Otherwise use a mechanical destruction of the device." print_time @@ -80,25 +100,9 @@ wipe_dev() { echo "Device ${1} wiped." } -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 -} - -check_args "${DEV}" -check_dev_exist "${DEV}" -check_dev_block "${DEV}" -confirm_wipe "${DEV}" -wipe_dev "${DEV}" +check_args "${1}" +check_dev_exist "${1}" +check_dev_block "${1}" +confirm_wipe "${1}" +wipe_dev "${1}" print_time