Olaf Bohlen
2022-11-30 6d157502483546354c81ca7f7f6e00234f8170ad
commit | author | age
6d1575 1 #!/bin/bash
OB 2 # olbohlen@eenfach.de 2022-11-30, rewrite of previous destroy scripts
3
4 NOOP=""
5 FAST=""
6 DEBUG=/usr/bin/true
7
8 # get arguments
9 while getopts dfn argv 2>/dev/null; do
10     case ${argv} in
11     n)
12         # sim-mode
13         NOOP=/usr/bin/true
14         ;;
15     d)
16         # debug mode
17         DEBUG=""
18         ;;
19     f)
20         # fast mode, no sleep (till Brooklyn)
21         FAST=/usr/bin/true
22         ;;
23     *)
24         cat <<EOF
25 Usage: $0 [ -nd ]
26   -n    no-operation
27   -d    debug output
28 EOF
29         ;;
30     esac
31 done
32
33
34 # destroy partitions, partition headers
35
36 RHTINSTDEV=$(lsblk -firnp | awk '$4~/RHTINST/ { print $1}' | sed -e 's,[0-9]*$,,')
37
38 DEVLIST=$(lsblk -irnp | awk '$6~/^disk$/ { print $1 }' | grep -v ${RHTINSTDEV})
39
40 printf "Going to wipe following disks:\n%s" "${DEVLIST}"
41
42 ${FAST} printf "Hit C-c now to cancel...sleeping for 10 seconds...\n"
43 ${FAST} sleep 10
44
45 for dev in ${DEVLIST}; do
46     # get partition table
47     partout=$(parted ${dev} unit B print)
48
49     disksize=$(printf "%s" "${partout}" | awk '$0~/^Disk \/dev\/.*B$/ { print $NF}')
50
51     printf "wiping partition headers on %s...\n" "${dev}"
52     for poffset in $(printf "%s" "${partout}" | awk '$1~/^[0-9]*$/ && $2~/B$/ { print $2 }'); do
53     printf "64MB NULL at %s..." ${poffset}
54     ${DEBUG} echo dd if=/dev/zero of=${dev} obs=1024 seek=$(( ${poffset%%B} / 1024 )) count=$(( 64 * 1024 * 1024 ))
55     ${NOOP} dd if=/dev/zero of=${dev} obs=1024 seek=$(( ${poffset%%B} / 1024 )) count=$(( 64 * 1024 * 1024 ))
56     printf "done\n"
57     done
58
59     printf "wiping last 64MB on disk to kill GPT backup..."
60     ${DEBUG} echo dd if=/dev/zero of=${dev} obs=1024 seek=$(( ${disksize%%B} - ( 64 * 1024 * 1024 ) / 1024 )) count=$(( 64 * 1024 * 1024 ))
61     ${NOOP} dd if=/dev/zero of=${dev} obs=1024 seek=$(( ${disksize%%B} - ( 64 * 1024 * 1024 ) / 1024 )) count=$(( 64 * 1024 * 1024 ))
62     printf "done\n"
63     printf "now wiping the first 64MB on disk to kill the GPT..."
64     ${DEBUG} dd if=/dev/zero of=${dev} obs=1024 count=$(( 64 * 1024 * 1024 ))
65     ${NOOP} dd if=/dev/zero of=${dev} obs=1024 count=$(( 64 * 1024 * 1024 ))
66
67 done
68 printf "Partition and Filesystem headers should be clean now stopping system"
69 ${FAST} printf " in 10 seconds\n"
70 ${FAST} sleep 10
71 ${NOOP} poweroff
72