erase-disk.sh: add --crypy-prep flag
This commit is contained in:
parent
246e1ca9eb
commit
6dc6ca0e3f
|
@ -7,11 +7,12 @@ usage() {
|
||||||
echo "Securely erase DEVICE with PASSES passes"
|
echo "Securely erase DEVICE with PASSES passes"
|
||||||
echo
|
echo
|
||||||
echo "Flags:"
|
echo "Flags:"
|
||||||
echo " -h, --help \tDisplay this help message"
|
echo " -h, --help \t\tDisplay this help message"
|
||||||
|
echo " -c, --crypt-prep \tPrepare DEVICE for encryption"
|
||||||
echo
|
echo
|
||||||
echo "Options:"
|
echo "Options (must come after flags):"
|
||||||
echo " DEVICE \tThe device to erase"
|
echo " DEVICE \t\tThe device to erase"
|
||||||
echo " PASSES \tHow many times to erase DEVICE"
|
echo " PASSES \t\tHow many times to erase DEVICE"
|
||||||
echo
|
echo
|
||||||
echo "This script will securely erase a disk device with the specified amount"
|
echo "This script will securely erase a disk device with the specified amount"
|
||||||
echo "of passes (rounds). It does so by overwriting the specified device with"
|
echo "of passes (rounds). It does so by overwriting the specified device with"
|
||||||
|
@ -22,36 +23,45 @@ usage() {
|
||||||
echo "erase-disk.sh is licensed under The Unlicense."
|
echo "erase-disk.sh is licensed under The Unlicense."
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CRYPT=0
|
||||||
|
|
||||||
[ "$1" = "-h" -o "$1" = "--help" ] && usage && exit 0
|
[ "$1" = "-h" -o "$1" = "--help" ] && usage && exit 0
|
||||||
|
[ "$1" = "-c" -o "$1" = "--crypt-prep" ] && CRYPT=1 && shift
|
||||||
|
|
||||||
if [ $# -lt 2 ]; then
|
if [ $# -lt 2 ]; then
|
||||||
echo "ERROR: Not enough options!"
|
echo "=> ERROR: Not enough options!"
|
||||||
echo
|
echo
|
||||||
usage
|
usage
|
||||||
exit 1
|
exit 1
|
||||||
elif [ $# -gt 2 ]; then
|
elif [ $# -gt 2 ]; then
|
||||||
echo "ERROR: Too many options!"
|
echo "=> ERROR: Too many options!"
|
||||||
echo
|
echo
|
||||||
usage
|
usage
|
||||||
exit 1
|
exit 1
|
||||||
elif [ $(id -u) -ne 0 ]; then
|
elif [ $(id -u) -ne 0 ]; then
|
||||||
echo "ERROR: Must run as root!"
|
echo "=> ERROR: Must run as root!"
|
||||||
echo
|
echo
|
||||||
usage
|
usage
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "# Securely erasing the disk device $2"
|
echo "=> Securely erasing the disk device $2"
|
||||||
i=1
|
i=1
|
||||||
|
|
||||||
while [ $i -le $1 ]; do
|
while [ $i -le $1 ]; do
|
||||||
[ $i -eq 1 ] && if="/dev/urandom" || if="/dev/zero"
|
[ $i -eq 1 ] && if="/dev/urandom" || if="/dev/zero"
|
||||||
|
[ $CRYPT -eq 1 -a $i -eq $1 ] && if="/dev/urandom"
|
||||||
|
|
||||||
echo "\n- Begin pass $i with $if"
|
echo "\n -> Begin pass $i with $if"
|
||||||
dd if="$if" of="$2" status="progress"
|
dd if="$if" of="$2" status="progress"
|
||||||
|
|
||||||
echo "- Syncing I/O"
|
echo "\n -> Syncing I/O"
|
||||||
sync
|
sync
|
||||||
|
|
||||||
i=$(( i + 1 ))
|
i=$(( i + 1 ))
|
||||||
done
|
done
|
||||||
|
|
||||||
|
echo -n "\n=> Done! $2 securely erased"
|
||||||
|
[ $CRYPT -eq 1 ] && echo -n " and prepared for encryption"
|
||||||
|
echo "."
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue