Makefile: add pickrand
[cmccabe-bin] / nero.sh
1 #!/usr/bin/env bash
2
3 die() {
4     echo $@
5     exit 1
6 }
7
8 my_uname=$(uname -a)
9 case "${my_uname}" in
10     Darwin*) ;;
11     *)die "This script only works on MacOS"
12 esac
13
14 usage() {
15     cat <<EOF
16 nero.sh: CD-R burning tool for MacOS.
17
18 -d [directory]      Create a data CD using the given directory
19 -k                  Skip cleanup
20 -h                  Show this help message
21 -m [directory]      Create a music CD using the given directory
22 EOF
23 }
24
25 data_dir=""
26 skip_cleanup=0
27 music_dir=""
28 while getopts "d:khm:" flag; do
29     case $flag in
30         d) data_dir="${OPTARG}";;
31         k) skip_cleanup=1;;
32         h) usage; exit 0;;
33         m) music_dir="${OPTARG}";;
34         *) usage; exit 1;;
35     esac
36 done
37 shift $OPTIND
38 [[ $# -ne 0 ]] || die "unknown arguments at end. -h for help."
39
40 if [[ $data_dir != "" ]]; then
41     [[ $music_dir != "" ]] && die "You must specify only one of -d and -m"
42     temp_dir="`mktemp -d`"
43     echo "== created temporary directory $temp_dir"
44     if [[ $skip_cleanup == 1 ]]; then
45         echo "== will not install cleanup hook"
46     else
47         function remove_iso_temp {
48             echo "== removing $temp_dir"
49             rm -rf -- "${temp_dir}"
50         }
51         trap remove_iso_temp EXIT
52     fi
53     echo "== creating ${temp_dir}/iso"
54     hdiutil makehybrid -iso -joliet -o "${temp_dir}/temp" "${data_dir}" || die "iso creation failed"
55     echo "== burning ${temp_dir}/temp.iso"
56     hdiutil burn "${temp_dir}/temp.iso"
57 else
58     [[ $music_dir == "" ]] && die "You must specify one of -d and -m"
59     echo "== burning music cd..."
60     drutil burn -audio "${music_dir}"
61 fi