diff --git a/.continue/rules/project.md b/.continue/rules/project.md index f757333..6fade88 100644 --- a/.continue/rules/project.md +++ b/.continue/rules/project.md @@ -16,8 +16,9 @@ description: mtm-ddwipe project conventions - Keep the host and line-number removal behavior intact. - `mtm-ddwipe` must print a usage line and support `-h`/`--help`. - Validate that wipe targets are real block devices before operating on them. -- Prefer explicit, short confirmation prompts before destructive operations. +- Keep short, explicit confirmation prompts before destructive operations. - Keep error and help messages short, clear, and in English. +- Keep help text concise and usage-first. # Project identity - Main script: `mtm-ddwipe` diff --git a/mtm-ddwipe b/mtm-ddwipe index 79a14f1..148c9b6 100755 --- a/mtm-ddwipe +++ b/mtm-ddwipe @@ -5,21 +5,35 @@ declare STARTDATE="" declare STARTDATESTRING="" show_help() { - echo "ddwipe dev (/dev/sdX)" + echo "Usage: mtm-ddwipe DEVICE" echo "" - echo "Version : 0.0.3" + echo "Wipe a block device." + echo "Version: 0.0.3" } check_args() { - if [ "${1}" == "" ]; then - show_help - exit 1 - fi + case "${1}" in + -h|--help) + show_help + exit 0 + ;; + "") + show_help + exit 1 + ;; + esac } check_dev_exist() { if [ ! -e "${1}" ]; then - echo "${1} is missing." + echo "Missing device." + exit 1 + fi +} + +check_dev_block() { + if [ ! -b "${1}" ]; then + echo "Not a block device." exit 1 fi } @@ -27,7 +41,7 @@ check_dev_exist() { confirm_wipe() { lsblk "${1}" echo "" - read -r -p "Wipe ${1} (y/[n])?" CHOICE + read -r -p "Wipe ${1} (y/[n])? " CHOICE case "${CHOICE}" in y|Y ) echo "";; * ) @@ -63,7 +77,7 @@ wipe_dev() { fi fi echo "" - echo "Device ${1} wipped !" + echo "Device ${1} wiped." } print_time() { @@ -84,6 +98,7 @@ print_time() { check_args "${DEV}" check_dev_exist "${DEV}" +check_dev_block "${DEV}" confirm_wipe "${DEV}" wipe_dev "${DEV}" print_time