Last active
June 23, 2023 15:18
-
-
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.
This file contains hidden or 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 | |
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 "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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