Olaf Bohlen
2022-11-30 6d157502483546354c81ca7f7f6e00234f8170ad
initial
2 files added
73 ■■■■■ changed files
.gitignore 1 ●●●● patch | view | raw | blame | history
destroy.sh 72 ●●●●● patch | view | raw | blame | history
.gitignore
New file
@@ -0,0 +1 @@
*~
destroy.sh
New file
@@ -0,0 +1,72 @@
#!/bin/bash
# olbohlen@eenfach.de 2022-11-30, rewrite of previous destroy scripts
NOOP=""
FAST=""
DEBUG=/usr/bin/true
# get arguments
while getopts dfn argv 2>/dev/null; do
    case ${argv} in
    n)
        # sim-mode
        NOOP=/usr/bin/true
        ;;
    d)
        # debug mode
        DEBUG=""
        ;;
    f)
        # fast mode, no sleep (till Brooklyn)
        FAST=/usr/bin/true
        ;;
    *)
        cat <<EOF
Usage: $0 [ -nd ]
  -n    no-operation
  -d    debug output
EOF
        ;;
    esac
done
# destroy partitions, partition headers
RHTINSTDEV=$(lsblk -firnp | awk '$4~/RHTINST/ { print $1}' | sed -e 's,[0-9]*$,,')
DEVLIST=$(lsblk -irnp | awk '$6~/^disk$/ { print $1 }' | grep -v ${RHTINSTDEV})
printf "Going to wipe following disks:\n%s" "${DEVLIST}"
${FAST} printf "Hit C-c now to cancel...sleeping for 10 seconds...\n"
${FAST} sleep 10
for dev in ${DEVLIST}; do
    # get partition table
    partout=$(parted ${dev} unit B print)
    disksize=$(printf "%s" "${partout}" | awk '$0~/^Disk \/dev\/.*B$/ { print $NF}')
    printf "wiping partition headers on %s...\n" "${dev}"
    for poffset in $(printf "%s" "${partout}" | awk '$1~/^[0-9]*$/ && $2~/B$/ { print $2 }'); do
    printf "64MB NULL at %s..." ${poffset}
    ${DEBUG} echo dd if=/dev/zero of=${dev} obs=1024 seek=$(( ${poffset%%B} / 1024 )) count=$(( 64 * 1024 * 1024 ))
    ${NOOP} dd if=/dev/zero of=${dev} obs=1024 seek=$(( ${poffset%%B} / 1024 )) count=$(( 64 * 1024 * 1024 ))
    printf "done\n"
    done
    printf "wiping last 64MB on disk to kill GPT backup..."
    ${DEBUG} echo dd if=/dev/zero of=${dev} obs=1024 seek=$(( ${disksize%%B} - ( 64 * 1024 * 1024 ) / 1024 )) count=$(( 64 * 1024 * 1024 ))
    ${NOOP} dd if=/dev/zero of=${dev} obs=1024 seek=$(( ${disksize%%B} - ( 64 * 1024 * 1024 ) / 1024 )) count=$(( 64 * 1024 * 1024 ))
    printf "done\n"
    printf "now wiping the first 64MB on disk to kill the GPT..."
    ${DEBUG} dd if=/dev/zero of=${dev} obs=1024 count=$(( 64 * 1024 * 1024 ))
    ${NOOP} dd if=/dev/zero of=${dev} obs=1024 count=$(( 64 * 1024 * 1024 ))
done
printf "Partition and Filesystem headers should be clean now stopping system"
${FAST} printf " in 10 seconds\n"
${FAST} sleep 10
${NOOP} poweroff