--- /dev/null
+#!/bin/bash
+
+#
+# audiorip
+#
+# Shell script to rip an audio CD-ROM.
+#
+# To use this, first create a directory for the mp3s, and cd to that
+# directory. Then run this script. This script also saves lossless copies of
+# the mp3s in a directory ending with [LL].
+#
+# One of these days I'm going to rewrite this in Ruby or some other language,
+# and include more advanced features, like the ability to rip multiple
+# CD-ROMs at once. For now, this script works, and is a good example of
+# using getopts with bash.
+#
+# Colin McCabe
+#
+
+wav_to_mp3()
+{
+ for i in *.wav; do
+ lame -q $2 -b $1 "$i"
+ done
+}
+
+usage()
+{
+ cat <<EOF
+audiorip: a CD-ripping script
+-h: this help message
+-d [cdrom device]
+-s [start track]
+-e [end track]
+-N: don't run cdparanoia
+EOF
+}
+
+start_track=0
+end_track=0
+no_cdparanoia=0
+cd_dev=/dev/sr0
+while getopts "d:e:hNs:" flag
+do
+ case $flag in
+ d) cd_dev=$OPTARG;;
+
+ e) end_track=$OPTARG
+ if [ $end_track == 0 ]; then
+ echo "must give non-zero numeric argument";
+ exit 1
+ fi;;
+
+ h) usage
+ exit 0;;
+
+ N) no_cdparanoia=1;;
+
+ s) start_track=$OPTARG
+ if [ $start_track == 0 ]; then
+ echo "must give non-zero numeric argument";
+ exit 1
+ fi;;
+
+ *)
+ echo
+ usage
+ exit 1;;
+ esac
+ #echo "$flag" $OPTIND $OPTARG
+done
+
+########### checks ###########
+if [ $UID -eq 0 ]; then
+ echo "DON'T run this as root! chmod the device file to yourself instead."
+ exit 1
+fi
+
+########### directory stuff ###########
+base_dir=`pwd | sed 's|^\(.*\)/\([^/]*\)$|\1|'`
+trailing_dir=`pwd | sed 's|^\(.*\)/\([^/]*\)$|\2|'`
+lossless_dir="${base_dir}/${trailing_dir} [LL]"
+echo "base_dir = \"${base_dir}\""
+echo "lossless_dir = \"${lossless_dir}\""
+mkdir -p "${lossless_dir}"
+
+############# cdparanoia ###############
+if [ ${no_cdparanoia} -eq 0 ]; then
+ if [ ${start_track} -ne 0 ]; then
+ if [ ${end_track} -ne 0 ]; then
+ span="${start_track}-${end_track}"
+ else
+ span="${start_track}-"
+ fi
+ else
+ if [ ${end_track} -ne 0 ]; then
+ span="-${end_track}"
+ else
+ span=
+ fi
+ fi
+ nice -1 cdparanoia -B -d ${cd_dev} ${span}
+ if [ $? -ne 0 ]; then
+ echo "cdparanoia failed; aborting."
+ exit 1
+ fi
+fi
+
+############# mp3 ###############
+wav_to_mp3 192 1
+
+############# flac ###############
+mv *.wav "${lossless_dir}/"
+cd "${lossless_dir}"
+flac *.wav
+flac -t *.flac && rm -f *.wav