Add 'wiper.sh'
This commit is contained in:
parent
caf976a230
commit
97bde4e360
1 changed files with 122 additions and 0 deletions
122
wiper.sh
Normal file
122
wiper.sh
Normal file
|
@ -0,0 +1,122 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
#prerequisites
|
||||
#apt-get install pv smartmontools
|
||||
|
||||
REQUIRED_PKG="pv"
|
||||
PKG_OK=$(dpkg-query -W --showformat='${Status}\n' $REQUIRED_PKG|grep "install ok installed")
|
||||
echo Checking for $REQUIRED_PKG: $PKG_OK
|
||||
if [ "" = "$PKG_OK" ]; then
|
||||
echo "No $REQUIRED_PKG. Setting up $REQUIRED_PKG."
|
||||
sudo apt-get --yes install $REQUIRED_PKG
|
||||
fi
|
||||
|
||||
REQUIRED_PKG="smartmontools"
|
||||
PKG_OK=$(dpkg-query -W --showformat='${Status}\n' $REQUIRED_PKG|grep "install ok installed")
|
||||
echo Checking for $REQUIRED_PKG: $PKG_OK
|
||||
if [ "" = "$PKG_OK" ]; then
|
||||
echo "No $REQUIRED_PKG. Setting up $REQUIRED_PKG."
|
||||
sudo apt-get --yes install $REQUIRED_PKG
|
||||
fi
|
||||
|
||||
#collect data about disk type:
|
||||
disk_type=$(smartctl -a /dev/$1 | grep -i "Rotation Rate:" | cut -d':' -f2 | tr -d " ")
|
||||
|
||||
#store if the disk is an ssd:
|
||||
if [[ $disk_type == *"SolidStateDevice"* ]]; then
|
||||
disk_ssd=1
|
||||
# echo "disk is ssd"
|
||||
elif [[ $disk_type == *"rpm"* ]]; then
|
||||
disk_ssd=0
|
||||
# echo "disk is not ssd"
|
||||
else
|
||||
echo "disk type unknown, exiting"
|
||||
exit
|
||||
fi
|
||||
|
||||
#check for disk errors, differntiating by device type since smart output is different between sata and sas drives:
|
||||
if smartctl -a /dev/$1 | grep -q "SATA"; then
|
||||
#echo "Type of disk: SATA"
|
||||
if smartctl -a /dev/$1 | grep -q "No Errors Logged"; then
|
||||
echo "SATA no errors, conitnuing"
|
||||
else
|
||||
sata_model=$(smartctl -a /dev/$1 | grep -i "Device Model:" | cut -d':' -f2 | tr -d " ")
|
||||
sata_serial=$(smartctl -a /dev/$1 | grep -i "Serial number:" | cut -d':' -f2 | tr -d " ")
|
||||
echo "!!! ERRORS !!!"
|
||||
echo "SATA errors, aborting!!!"
|
||||
echo "NO WIPING NEEDED, JUST DESTROY THE DISK MECHANICALLY"
|
||||
echo "!!! EXITING !!!"
|
||||
echo ""
|
||||
echo "Model: $sata_model"
|
||||
echo "Serial: $sata_serial"
|
||||
exit
|
||||
fi
|
||||
elif smartctl -a /dev/$1 | grep -q "SAS"; then
|
||||
#echo "Type of disk: SAS"
|
||||
sas_errors=$(smartctl -a /dev/$1 | grep "Elements in grown defect list" | cut -d':' -f2 | tr -d " ")
|
||||
if [ "$sas_errors" -gt 0 ]; then
|
||||
sas_vendor=$(smartctl -a /dev/$1 | grep -i "Vendor:" | cut -d':' -f2 | tr -d " ")
|
||||
sas_model=$(smartctl -a /dev/$1 | grep -i "Product:" | cut -d':' -f2 | tr -d " ")
|
||||
sas_serial=$(smartctl -a /dev/$1 | grep -i "Serial number:" | cut -d':' -f2 | tr -d " ")
|
||||
echo "!!! ERRORS !!!"
|
||||
echo "Elements in grown defect list: " $sas_errors
|
||||
echo "NO WIPING NEEDED, JUST DESTROY THE DISK MECHANICALLY"
|
||||
echo "!!! EXITING !!!"
|
||||
echo ""
|
||||
echo "Vendor: $sas_vendor"
|
||||
echo "Model: $sas_model"
|
||||
echo "Serial: $sas_serial"
|
||||
exit
|
||||
else
|
||||
echo "SAS no errors, continuing"
|
||||
fi
|
||||
else
|
||||
echo "the disk type is none of the expected ones, exiting"
|
||||
exit
|
||||
fi
|
||||
|
||||
|
||||
#warning if is an ssd
|
||||
if [ "$disk_ssd" -eq 1 ]; then
|
||||
echo "WARNING, DISK IS AN SSD, Remember that sectors are reallocated thus unwanted data might remain on the sectors"
|
||||
#else
|
||||
# echo "disk is not an ssd, continuing"
|
||||
fi
|
||||
|
||||
#calculate disk bytes:
|
||||
disk_blocks=$(cat /proc/partitions | grep -w $1 | tr -s ' ' | cut -d " " -f4);
|
||||
disk_bytes=$(( 1024*disk_blocks ))
|
||||
|
||||
|
||||
|
||||
echo "wiping $1"
|
||||
|
||||
echo "random pass n1:"
|
||||
openssl enc -pbkdf2 -pass pass:"$(dd if=/dev/urandom bs=128 count=1 2>/dev/null | base64)" -nosalt </dev/zero | pv --progress --eta --rate --bytes --size $disk_bytes | dd of=/dev/$1 bs=2M oflag=direct iflag=fullblock
|
||||
#openssl enc -aes-256-ctr -pass pass:"$(dd if=/dev/urandom bs=128 count=1 2>/dev/null | base64)" -nosalt </dev/zero | pv --progress --eta --rate --bytes --size $disk_bytes | dd of=/dev/$1 bs=1M
|
||||
|
||||
echo "random pass n2:"
|
||||
openssl enc -pbkdf2 -pass pass:"$(dd if=/dev/urandom bs=128 count=1 2>/dev/null | base64)" -nosalt </dev/zero | pv --progress --eta --rate --bytes --size $disk_bytes | dd of=/dev/$1 bs=2M oflag=direct iflag=fullblock
|
||||
|
||||
echo "zeroing pass:"
|
||||
dd if=/dev/zero of=/dev/$1 bs=1M status=progress oflag=direct
|
||||
|
||||
echo "!!! FINISHED wiping $1 !!!"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#OLD:
|
||||
#echo "wiping $1"
|
||||
#
|
||||
#echo "random pass n1:"
|
||||
#dd if=/dev/random of=/dev/$1 bs=1M status=progress oflag=direct
|
||||
#
|
||||
#echo "random pass n2:"
|
||||
#dd if=/dev/random of=/dev/$1 bs=1M status=progress oflag=direct
|
||||
#
|
||||
#echo "zeroing pass:"
|
||||
#dd if=/dev/zero of=/dev/$1 bs=1M status=progress oflag=direct
|
||||
#
|
||||
#echo "!!! FINISHED wiping $1 !!!"
|
Loading…
Reference in a new issue