#! /bin/sh
sudo shred -v -n1 -z /dev/sdX
# -n number of overwrites (default: 3)
# -z set all bits to zero after last iteration
hdparm -I /dev/sdX
hdparm --user-master u --security-set-pass $pw /dev/sdX
time hdparm --user-master u --security-erase $pw /dev/sdX
# https://ata.wiki.kernel.org/index.php/ATA_Secure_Erase
df -h
lsusb
sudo fdisk -l
mount /dev/sdX /var/mountpoint
umount /dev/sdX
# permanent: /etc/fstab
diskutil list
diskutil unmountDisk /dev/disk2
sudo dd bs=1m if=image.img of=/dev/rdisk2 conv=sync # SIGINFO signal (press Ctrl+T) for status
# on macOS /dev/diskN works better than raw disk (also adapter has to blink through entire process!), format FAT32 first, then dd
# sudo dd bs=4m if=image.img of=/dev/disk2 && sync
sudo diskutil eject /dev/rdisk2