From 8504eafa48ec4713551b5c9c698d4ac99c8ea739 Mon Sep 17 00:00:00 2001 From: MatMoul Date: Tue, 7 May 2024 02:06:22 +0200 Subject: [PATCH] Identation and end status + 500M step --- mtm-ddwipe | 111 ++++++++++++++++++++++++++++------------------------- 1 file changed, 58 insertions(+), 53 deletions(-) diff --git a/mtm-ddwipe b/mtm-ddwipe index 1e47516..c0bd7e2 100755 --- a/mtm-ddwipe +++ b/mtm-ddwipe @@ -1,77 +1,82 @@ #!/bin/bash declare -r DEV="${1}" +declare STARTDATE="$(date)" show_help() { - echo "ddwipe dev (/dev/sdX)" - echo "" - echo "Version : 0.0.3" + echo "ddwipe dev (/dev/sdX)" + echo "" + echo "Version : 0.0.3" } check_args() { - if [ "${1}" == "" ]; then - show_help - exit 1 - fi + if [ "${1}" == "" ]; then + show_help + exit 1 + fi } check_dev_exist() { - if [ ! -e "${1}" ]; then - echo "${1} is missing." - exit 1 - fi + if [ ! -e "${1}" ]; then + echo "${1} is missing." + exit 1 + fi } confirm_wipe() { - lsblk "${1}" - echo "" - read -r -p "Wipe ${1} (y/[n])?" CHOICE - case "${CHOICE}" in - y|Y ) echo "";; - * ) - echo "Canceled" - exit 1 - ;; - esac + lsblk "${1}" + echo "" + read -r -p "Wipe ${1} (y/[n])?" CHOICE + case "${CHOICE}" in + y|Y ) echo "";; + * ) + echo "Canceled" + exit 1 + ;; + esac } wipe_dev() { - echo "Begin wiping device ${1}" - echo "" - echo "Start date :" - date - echo "" - echo "blkdiscard secure" - if ! blkdiscard -f -p 100G -s -v "${1}"; then - echo "" - echo "blkdiscard zero" - if ! blkdiscard -f -p 100G -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} wipped !" + echo "Begin wiping device ${1}" + echo "" + echo "Start date :" + echo "${STARTDATE}" + 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} wipped !" } print_time() { - ENDDATE=$(date +%s) - echo "" - echo "End date :" - date + echo "" + echo "Start date :" + echo "${STARTDATE}" + + ENDDATE=$(date +%s) + echo "" + echo "End date :" + date - CALCTIME=$((ENDDATE-STARTDATE)) - echo "" - echo "Total time :" - date -d@${CALCTIME} -u +%H:%M:%S + CALCTIME=$((ENDDATE-STARTDATE)) + echo "" + echo "Total time :" + date -d@${CALCTIME} -u +%H:%M:%S } check_args "${DEV}"