Skip to content

Instantly share code, notes, and snippets.

@koonix
Created September 10, 2022 20:38
Show Gist options
  • Save koonix/1a4b41907440a79972ca49f688ff06b9 to your computer and use it in GitHub Desktop.
Save koonix/1a4b41907440a79972ca49f688ff06b9 to your computer and use it in GitHub Desktop.
burn a file or an iso to a cd or dvd.
#!/bin/sh
# burn a file or an iso to a dvd.
# requires the cdrtools package.
# usage: $ burn FILE [TITLE]
# config
speed=1 # leave blank for default speed
dev=/dev/sr0
tmp=~/.cache/burn
set -e
# check dependencies
for c in mkisofs cdrecord; do
command -v "$c" >/dev/null || exit 1
done
# check files
[ -b "${dev}" ] || exit 1
[ -f "${1:?}" ] || exit 1
[ -r "${1:?}" ] || exit 1
# create the iso
case "$1" in
*.iso)
iso="$1" ;;
*)
iso=${tmp:?}/$(basename "$1")-$RANDOM.iso
trap 'rm -rf "$tmp"' EXIT
mkdir "$tmp"
echo Creating ISO...
mkisofs -r -J -iso-level 3 ${2:+-V "$2"} -o "$iso" "$1" ;;
esac
# burn the iso
echo Burning to Disk...
cdrecord -v -eject ${speed:+speed=$speed} dev="$dev" "$iso"
echo Done.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment