disk_wiper/wiper_new.sh

115 lines
2.6 KiB
Bash
Raw Normal View History

2022-11-12 17:08:10 +01:00
#!/usr/bin/bash
lsscsi
echo "- - -"
read -p 'Disk to wipe: ' disk
if [ -z $disk ]; then
echo "YOU HAVE TO INPUT THE DISK. like: sda"
exit
else
echo "wiping $1"
fi
system_serial=$(dmidecode -s system-serial-number)
disk_model=$(smartctl -i /dev/$disk | grep "Model" | sed -e 's/Device Model://g' | sed -e 's/Model Number://g' | xargs)
disk_serial=$(smartctl -i /dev/$disk | grep "Serial Number:" | sed -e 's/Serial Number://g' | xargs)
#disk_info=$(hdparm -i /dev/$disk | grep Model | sed -e 's/ Model=//g')
#disk_model=$(echo $disk_info | cut -d ',' -f 1)
#disk_serial=$(echo $disk_info | cut -d ',' -f 3 | tr -d " SerialNo=")
start_date=$(date)
if [[ ${disk} != *"nvme"* ]];then
#disk is not NVME
disk_rot=$(cat /sys/block/$disk/queue/rotational)
if [[ "$disk_rot" == 1 ]]; then
disk_type="HDD"
#DEBUG:
echo "shred -v -n 1 -z /dev/$disk"
elif [[ "$disk_rot" == 0 ]]; then
disk_type="SSD"
echo "shred -v -n 1 -z /dev/$disk"
else
disk_type="unknown"
exit
fi
else
disk_type="Nvme (SSD)"
nvme_disk=$(echo $disk | sed -e 's/n1//g')
#DEBUG:
echo "nvme sanitize /dev/$nvme_disk -a 2"
fi
echo ""
echo ""
echo ""
echo ""
sleep 3
#test sanitization:
disk_test=$(dd if=/dev/$disk bs=1k count=1024 status=none skip=10240 iflag=skip_bytes | tr --squeeze-repeats "\000" | tr -d '\0')
if [ -z "$disk_test" ]; then
#echo "empty disk"
disk_status="Zeroed-Empty"
else
#echo "NOT EMPTY"
disk_status="NON-Zeroed-StillContainsData"
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
echo "!!!!!! WARNING !!!!!!"
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
echo "!!! disk still contains data !!!"
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
read -p "Are you sure? " -n 1 -r
echo # (optional) move to a new line
if [[ $REPLY =~ ^[Yy]$ ]]
then
echo "continuing"
else
exit
fi
fi
end_date=$(date)
echo "- - -"
echo "System serial: "$system_serial
echo "Disk model: "$disk_model
echo "Disk serial: "$disk_serial
echo "Disk type: "$disk_type
echo "Disk status: "$disk_status
echo "Disk has been wiped with 1 random pass and one last zeroing"
echo "Started on: "$start_date
echo "Ended on: "$end_date
sign=$(echo "$start_date"_"$end_date"_"$system_serial"_"$disk_model"_"$disk_serial" | sha1sum | tr -d " -")
echo "- - -"
echo "Operation signature: "$sign
echo "- - -"
echo "Validation: $start_date"_"$end_date"_"$system_serial"_"$disk_model"_"$disk_serial"_"$disk_type"_"$disk_status"_"$sign"
echo "start-date _ end-date _ system-serial _ disk-model _ disk-serial _ disk-type _ disk-status _ sign"
qr "$start_date"_"$end_date"_"$system_serial"_"$disk_model"_"$disk_serial"_"$disk_type"_"$disk_status"_"$sign"