Compare commits

..

No commits in common. "dev" and "0.0.3" have entirely different histories.
dev ... 0.0.3

View File

@ -1,89 +1,82 @@
#!/bin/bash #!/bin/bash
declare -r DEV="${1}" declare -r DEV="${1}"
declare STARTDATE=""
declare STARTDATESTRING=""
show_help() { show_help() {
echo "ddwipe dev (/dev/sdX)" echo "ddwipe dev (/dev/sdX)"
echo "" echo ""
echo "Version : 0.0.3" echo "Version : 0.0.3"
} }
check_args() { check_args() {
if [ "${1}" == "" ]; then if [ "${1}" == "" ]; then
show_help show_help
exit 1 exit 1
fi fi
} }
check_dev_exist() { check_dev_exist() {
if [ ! -e "${1}" ]; then if [ ! -e "${1}" ]; then
echo "${1} is missing." echo "${1} is missing."
exit 1 exit 1
fi fi
} }
confirm_wipe() { 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
} }
wipe_dev() { wipe_dev() {
STARTDATE=$(date +%s) echo "Begin wiping device ${1}"
STARTDATESTRING="$(date)" echo ""
echo "Begin wiping device ${1}" echo "Start date :"
echo "" date
echo "Start date :" echo ""
echo "${STARTDATESTRING}" echo "blkdiscard secure"
echo "" if ! blkdiscard -f -p 1G -s "${1}"; then
echo "blkdiscard secure" echo ""
if ! blkdiscard -f -p 500M -s -v "${1}"; then echo "blkdiscard zero"
echo "" if ! blkdiscard -f -p 1G -z "${1}"; then
echo "blkdiscard zero" echo ""
if ! blkdiscard -f -p 500M -z -v "${1}"; then echo "dd zero"
echo "" if ! dd if=/dev/zero of="${1}" bs=1M status=progress; then
echo "dd zero" # Need check if dd has all writed, if yes, return no error
if ! dd if=/dev/zero of="${1}" bs=1M status=progress; then # echo "Error wiping device ${1}, use phisical destroy !"
# Need check if dd has all writed, if yes, return no error echo "Wiped with dd, check if full size is writed."
# echo "Error wiping device ${1}, use phisical destroy !" echo "Otherwise use a mechanical destruction of the device."
echo "Wiped with dd, check if full size is writed." print_time
echo "Otherwise use a mechanical destruction of the device." exit 1
print_time fi
exit 1 fi
fi fi
fi echo ""
fi echo "Device ${1} wipped !"
echo ""
echo "Device ${1} wipped !"
} }
print_time() { print_time() {
echo "" ENDDATE=$(date +%s)
echo "Start date :" echo ""
echo "${STARTDATESTRING}" echo "End date :"
date
ENDDATE=$(date +%s) CALCTIME=$((ENDDATE-STARTDATE))
echo "" echo ""
echo "End date :" echo "Total time :"
date date -d@${CALCTIME} -u +%H:%M:%S
CALCTIME=$((ENDDATE-STARTDATE))
echo ""
echo "Total time :"
date -d@${CALCTIME} -u +%H:%M:%S
} }
check_args "${DEV}" check_args "${DEV}"
check_dev_exist "${DEV}" check_dev_exist "${DEV}"
confirm_wipe "${DEV}" confirm_wipe "${DEV}"
STARTDATE=$(date +%s)
wipe_dev "${DEV}" wipe_dev "${DEV}"
print_time print_time