Created
September 10, 2022 20:38
-
-
Save koonix/1a4b41907440a79972ca49f688ff06b9 to your computer and use it in GitHub Desktop.
burn a file or an iso to a cd or dvd.
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/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