Created
May 25, 2017 04:00
-
-
Save lonehack/47b972026f88db0d966fe3c3df7cc2e2 to your computer and use it in GitHub Desktop.
Linux shellscript for secure wipe drive
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
YELLOW="\033[1;33m" | |
RED="\033[1;31m" | |
WHITE="\033[1;37m" | |
ENDCOLOR="\033[0m" | |
if [ $USER != root ]; then | |
echo -e $RED"Error: must be root"$ENDCOLOR | |
echo "command : sudo $0" | |
echo -e $YELLOW"Exiting..."$ENDCOLOR | |
exit 0 | |
fi | |
#################################################################### | |
## Functions | |
#################################################################### | |
warning () { | |
echo -e $RED"WARNING!! This program is dangerous!"$ENDCOLOR | |
echo -e $YELLOW"It will wipe your drive data completely"$ENDCOLOR | |
echo -e $RED"Wiped data will can't be recovered!"$ENDCOLOR | |
} | |
notice () { | |
echo "It will running in long time" | |
echo "depending on capacity of your drive" | |
echo -e $RED"Please, don't remove drive while program running!"$ENDCOLOR | |
} | |
end_wipe () { | |
echo -e $YELLOW"Exiting...."$ENDCOLOR | |
exit 0 | |
} | |
wipe_drive () { | |
# Unmount drive | |
sudo umount $part | |
# Wiping drive | |
echo -e $YELLOW"Starting to wipe drive $part...."$ENDCOLOR | |
echo -e $YELLOW"[1/3] Overwriting $part with zeros binary...."$ENDCOLOR | |
dd if=/dev/zero of=$part bs=1M | |
echo -e $YELLOW"[1/3] Overwrite done!"$ENDCOLOR | |
echo -e $YELLOW"[2/3] Overwriting $part with random binary...."$ENDCOLOR | |
dd if=/dev/urandom of=$part bs=1M | |
echo -e $YELLOW"[2/3] Overwrite done!"$ENDCOLOR | |
echo -e $YELLOW"[3/3] Overwriting $part with zeros binary...."$ENDCOLOR | |
dd if=/dev/zero of=$part bs=1M | |
echo -e $YELLOW"[3/3] Overwrite done!"$ENDCOLOR | |
echo -e $YELLOW"Wiping drive $part done!"$ENDCOLOR | |
} | |
#################################################################### | |
## Main | |
#################################################################### | |
warning | |
read -rsp $'Are you sure to run the program? <y/N>\n' -n 1 key | |
if [[ "$key" =~ ^[Yy]$ ]]; then | |
# y pressed | |
echo -e $YELLOW"Listing available drive...,"$ENDCOLOR | |
df -T | |
TRY=3 | |
while [ $TRY -gt 0 ] ; do | |
echo -e $RED"Chose drive carefully!"$ENDCOLOR | |
echo -e $WHITE"Type drive (/dev/sdXX) to wipe, then press [ENTER] :"$ENDCOLOR | |
read part | |
# Check drive existance | |
if df -T|grep $part; then | |
warning | |
notice | |
echo -e "Are you sure to wipe $RED$part$ENDCOLOR?" | |
read -rs -n 1 key | |
if [[ "$key" =~ ^[Yy]$ ]]; then | |
# y pressed | |
wipe_drive | |
echo -e $YELLOW"Drive $ENDCOLOR$RED$part$ENDCOLOR$YELLOW securely wiped!"$ENDCOLOR | |
exit 0 | |
else | |
end_wipe | |
fi | |
else | |
echo -e $RED"Error : drive $ENDCOLOR$YELLOW$part$ENDCOLOR$RED not found/mounted!"$ENDCOLOR | |
echo "Mount the drive first then type again" | |
TRY=`expr $TRY - 1` | |
fi | |
done | |
echo -e $RED"Too much error! Exiting program...."$ENDCOLOR | |
exit 0 | |
else | |
end_wipe | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment