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
+44 -40
View File
@@ -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
}
@@ -43,7 +47,9 @@ confirm_wipe() {
echo ""
read -r -p "Wipe ${1} (y/[n])? " CHOICE
case "${CHOICE}" in
y|Y ) echo "";;
y|Y)
echo ""
;;
*)
echo "Canceled"
exit 1
@@ -51,35 +57,6 @@ confirm_wipe() {
esac
}
wipe_dev() {
STARTDATE=$(date +%s)
STARTDATESTRING="$(date)"
echo "Begin wiping device ${1}"
echo ""
echo "Start date :"
echo "${STARTDATESTRING}"
echo ""
echo "blkdiscard secure"
if ! blkdiscard -f -p 500M -s -v "${1}"; then
echo ""
echo "blkdiscard zero"
if ! blkdiscard -f -p 500M -z -v "${1}"; then
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
exit 1
fi
fi
fi
echo ""
echo "Device ${1} wiped."
}
print_time() {
echo ""
echo "Start date :"
@@ -96,9 +73,36 @@ print_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}"
wipe_dev() {
STARTDATE=$(date +%s)
STARTDATESTRING="$(date)"
echo "Begin wiping device ${1}"
echo ""
echo "Start date :"
echo "${STARTDATESTRING}"
echo ""
echo "blkdiscard secure"
if ! blkdiscard -f -p 500M -s -v "${1}"; then
echo ""
echo "blkdiscard zero"
if ! blkdiscard -f -p 500M -z -v "${1}"; then
echo ""
echo "dd zero"
if ! dd if=/dev/zero of="${1}" bs=1M status=progress; then
echo "Wiped with dd, check if full size is writed."
echo "Otherwise use a mechanical destruction of the device."
print_time
exit 1
fi
fi
fi
echo ""
echo "Device ${1} wiped."
}
check_args "${1}"
check_dev_exist "${1}"
check_dev_block "${1}"
confirm_wipe "${1}"
wipe_dev "${1}"
print_time