Etcher behind the scenes



More of a curiosity/educational question. I have been using etcher for a lot of my raspberry pi projects and am very happy with it. I’ve been curious as to what commands it is running in the background. I have tried using a combination of Mac OS diskutil, dd via brew, and dcfldd via brew. Although, I have not be able to get my images to run on the pi as consistently as etcher.

I have tried and am currently using the etcher cli (Thank you for that!) , but was also curious to see if i can write a quick script to replicate it as well in bash on my computer. I have tried the following:

    eval "sudo diskutil eraseDisk free UNTITLED $device"    
    eval "sudo diskutil eraseDisk FAT32 RASPBIAN MBRFormat $device"

    echo "Unmounting the disc in prep for image burn"
    eval "sudo diskutil unmountDisk $device"
    sudo dcfldd if=$IMAGE_NAME of=/dev/disk2 of=/dev/disk3 bs=4M statusinterval=1 sizeprobe=if
    echo "External drive Found: $device: Mounting Disk"
    eval "sudo diskutil mountDisk $device"
    echo "adding .ssh file here"
    echo "Ejecting the disks now..."
    eval "diskutil eject $which_disk"

Any guidance would be appreciated, I’m sure its something small that I’m missing.