Write bootable image to USB device
Quoting

Some recommended double-quotes were missed here:


cut -d' ' -f1 /proc/mounts | grep -Fxq $(realpath "$1") &amp;&amp; die "$1: is mounted"



Should be like this:

cut -d' ' -f1 /proc/mounts | grep -Fxq "$(realpath "$1")" &amp;&amp; die "$1: is mounted"




This will break for example if $outfile contains spaces:


exec dd $ddflags $outfile



You could make it safe by using an array:

ddargs=(conv=nocreat,fsync oflag=dsync bs=1M status=progress "of=$1")

exec dd "${ddargs[@]}"


Safety tip

set -eu is a nice safeguard, I also like to add -o pipefail:

set -euo pipefail


Cosmetic issues

There is an unnecessary trailing ; in exit 1;