Skip to content

Instantly share code, notes, and snippets.

@gustavorv86
Last active June 23, 2023 15:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gustavorv86/697d4791e07480312508a6453e7836ea to your computer and use it in GitHub Desktop.
Save gustavorv86/697d4791e07480312508a6453e7836ea to your computer and use it in GitHub Desktop.
dd (disk dump) wrapper. Prevents you from mistakenly writing to your computer's devices. Allows you to write only to the last removable connected device.
#!/bin/bash
BLACKLIST_DEVICES="/dev/sda /dev/sdb /dev/sdc /dev/sdd"
DD_BIN="/usr/bin/dd"
main() {
for arg in $@; do
for dev in $BLACKLIST_DEVICES; do
if [[ "$arg" == *"$dev"* ]]; then
echo "ERROR: device is locked."
return 1
fi
done
done
echo "INFO: command, $DD_BIN $@."
read -p "Execute command [y/N]: " opt
if [ "$opt" == "y" ]; then
$DD_BIN $@
return $?
else
echo "INFO: command aborted."
return 1
fi
}
main "$@"
@gustavorv86
Copy link
Author

Install

cp dd-wrapper.sh /usr/local/bin
[ -f /etc/bashrc ] && echo "alias dd='/usr/local/bin/dd-wrapper.sh'" >> /etc/bashrc
[ -f /etc/bash.bashrc ] && echo "alias dd='/usr/local/bin/dd-wrapper.sh'" >> /etc/bash.bashrc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment