Preparing for 2.2 release
[clinton/abcde.git] / abcde
diff --git a/abcde b/abcde
index a447509..9ac7733 100755 (executable)
--- a/abcde
+++ b/abcde
 # Copyright for this work is to expire January 1, 2010, after which it
 # shall be public domain.
 
 # Copyright for this work is to expire January 1, 2010, after which it
 # shall be public domain.
 
-VERSION="2.1pre2.2.0"
+VERSION="2.2.0"
 
 usage ()
 {
 echo "This is abcde v$VERSION."
 echo "Usage: abcde [options] [tracks]"
 echo "Options:"
 
 usage ()
 {
 echo "This is abcde v$VERSION."
 echo "Usage: abcde [options] [tracks]"
 echo "Options:"
-echo "-1    Encode the whole CD in a single file"
-echo "-a    Actions to perform (cddb,read,normalize,encode,tag,move,playlist,clean)"
-echo "-A    Experimental actions (retag, transcode)"
-echo "-b    Batch mode: enable album normalization and nogap encoding"
-echo "-c    Specify a configuration file (overrides system and user config files)"
-echo "-C    Specify discid to resume from (only needed if you no longer have the cd)"
-echo "-d    Specify CDROM device to grab"
-echo "-D    Debugging mode (equivalent to sh -x abcde)"
-#echo "-f    Force the use of a local CDDB entry. Otherwise use an empty template"
-echo "-h    This help information"
+echo "-1     Encode the whole CD in a single file"
+echo "-a <action1[,action2]...>"
+echo "       Actions to perform (cddb,read,normalize,encode,tag,move,playlist,clean)"
+echo "-A     Experimental actions (retag, transcode)"
+echo "-b     Batch mode: enable album normalization and nogap encoding"
+echo "-c <file>"
+echo "       Specify a configuration file (overrides system and user config files)"
+echo "-C <discid#>"
+echo "       Specify discid to resume from (only needed if you no longer have the cd)"
+echo "-d <device>"
+echo "       Specify CDROM device to grab"
+echo "-D     Debugging mode (equivalent to sh -x abcde)"
+echo "-h     This help information"
 #echo "-i    Tag files while encoding, when possible (local only) -NWY-"
 #echo "-i    Tag files while encoding, when possible (local only) -NWY-"
-echo "-j    Number of encoder processes to run at once"
-echo "-k    Keep the wav tracks for later use"
-echo "-l    Use low disk space algorithm"
-echo "-L    Use local CDDB storage directory"
-echo "-n    No lookup. Don't query CDDB, just create and use template"
-echo "-N    Noninteractive. Never prompt for anything"
-echo "-m    Modify playlist to include CRLF endings, to comply with some players"
-echo "-o    Output file type(s) (ogg,mp3,flac,spx,mpc). Defaults to ogg"
-echo "-p    Pad track numbers with 0's (if less than 10 tracks)"
-echo "-r    [host1,host2...] Also encode on these remote hosts"
-echo "-R    Add replaygain values to the tag info (ogg,flac)"
-echo "-s    Start the track numbering at a given number"
-echo "-S    Set the CD speed"
+echo "-j <#> Number of encoder processes to run at once (localhost)"
+echo "-k     Keep the wav tracks for later use"
+echo "-l     Use low disk space algorithm"
+echo "-L     Use local CDDB storage directory"
+echo "-n     No lookup. Don't query CDDB, just create and use template"
+echo "-N     Noninteractive. Never prompt for anything"
+echo "-m     Modify playlist to include CRLF endings, to comply with some players"
+echo "-o <type1[,type2]...>"
+echo "       Output file type(s) (ogg,mp3,flac,spx,mpc). Defaults to ogg"
+echo "-p     Pad track numbers with 0's (if less than 10 tracks)"
+#echo "-P    Use UNIX pipes to read+encode without wav files"
+echo "-r <host1[,host2]...>"
+echo "       Also encode on these remote hosts"
+echo "-R     Add replaygain values to the tag info (only for ogg,flac)"
+echo "-S <#> Set the CD speed"
 #echo "-t    File types to preprocess (wav)"
 #echo "-T    Set postprocessing options"
 #echo "-t    File types to preprocess (wav)"
 #echo "-T    Set postprocessing options"
-echo "-v    Show version number and exit"
-echo "-V    Be a bit more verbose about what is happening behind the scenes"
-echo "-x    Eject CD after all tracks are read"
+echo "-t <#> Start the track numbering at a given number"
+echo "-T <#> Same as -t but modifies tag numbering"
+echo "-v     Show version number and exit"
+echo "-V     Be a bit more verbose about what is happening behind the scenes"
+echo "-x     Eject CD after all tracks are read"
+echo "-w <comment>"
+echo "       Add a comment to the CD tracks"
+echo "-W <#> Contatenate CDs: -T #01 -w \"CD #\"" 
+echo ""
 echo "Tracks is a space-delimited list of tracks to grab."
 echo "Ranges specified with hyphens are allowed."
 }
 echo "Tracks is a space-delimited list of tracks to grab."
 echo "Ranges specified with hyphens are allowed."
 }
@@ -275,6 +286,13 @@ do_tag ()
 {
        COMMENTOUTPUT="$(eval echo ${COMMENT})"
        run_command '' echo "Tagging track $1 of $TRACKS: $TRACKNAME..."
 {
        COMMENTOUTPUT="$(eval echo ${COMMENT})"
        run_command '' echo "Tagging track $1 of $TRACKS: $TRACKNAME..."
+       # If we want to start the tracks with a given number, we need to modify the
+       # TRACKNUM value before evaluation
+       if [ -n "$STARTTRACKNUMBER" -a -n "$STARTTRACKNUMBERTAG" ] ; then
+               # Get the trackpadding from the current track
+               CURRENTTRACKPADDING=$(echo -n $UTRACKNUM | wc -c)
+               TRACKNUM=$( printf %0.${CURRENTTRACKPADDING}d $(expr ${UTRACKNUM} + ${STARTTRACKNUMBER} - 1 ))
+       fi
        for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
        do
        case "$OUTPUT" in
        for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
        do
        case "$OUTPUT" in
@@ -332,7 +350,7 @@ do_tag ()
                        if [ -n "$CDGENRE" ]; then
                        echo GENRE="$CDGENRE"
                 fi     
                        if [ -n "$CDGENRE" ]; then
                        echo GENRE="$CDGENRE"
                 fi     
-               echo TRACKNUMBER=$1
+               echo TRACKNUMBER=${TRACKNUM:-$1}
                echo CDDB=$CDDBDISCID
                if [ "$(eval echo ${COMMENT})" != "" ]; then
                        case "$COMMENTOUTPUT" in
                echo CDDB=$CDDBDISCID
                if [ "$(eval echo ${COMMENT})" != "" ]; then
                        case "$COMMENTOUTPUT" in
@@ -955,35 +973,6 @@ do_discid ()
        
        # Create the discid file
        echo "$TRACKINFO" > "$ABCDETEMPDIR/discid"
        
        # Create the discid file
        echo "$TRACKINFO" > "$ABCDETEMPDIR/discid"
-
-       # Determine what actions are to be done from $ACTIONS and set the
-       # following environment variables for them:
-       DOCDDB=n
-       DOREAD=n
-       DONORMALIZE=n
-       DOPREPROCESS=n
-       DOENCODE=n
-       DOPOSTPROCESS=n
-       DOTAG=n
-       DOMOVE=n
-       DOPLAYLIST=n
-       DOCLEAN=n
-
-       for ACTION in $(echo $ACTIONS | tr , \ )
-       do
-               case $ACTION in
-               cddb) DOCDDB=y;;
-               read) DOREAD=y;;
-               normalize) DONORMALIZE=y; DOREAD=y;;
-               preprocess) DOPREPROCESS=y; DOREAD=y;;
-               encode) DOENCODE=y; DOREAD=y;;
-               postprocess) DOPREPROCESS=y; DOENCODE=y; DOREAD=y;;
-               tag) DOTAG=y; DOREAD=y; DOENCODE=y; DOCDDB=y;;
-               move) DOMOVE=y; DOTAG=y; DOREAD=y; DOENCODE=y; DOCDDB=y;;
-               playlist) DOCDDB=y; DOPLAYLIST=y;;
-               clean) DOCLEAN=y;;
-               esac
-       done
 }
 
 # do_cddbparse
 }
 
 # do_cddbparse
@@ -1017,36 +1006,35 @@ do_localcddb ()
                USELOCALRESP="y"
                
                # If the user has selected to check a local CDDB repo, we proceed with it
                USELOCALRESP="y"
                
                # If the user has selected to check a local CDDB repo, we proceed with it
-               if [ "$CDDBUSELOCAL" = "y" ]; then
-                       if [ -r "${CDDBLOCALFILE}" ]; then
-                               # List out disc title/author and contents
-                               do_cddbparse "${CDDBLOCALFILE}"
-                               echo -n "Locally cached CDDB entry found, use it? [y/n] (y): "
-                               if [ "$INTERACTIVE" = "y" ]; then
+               if [ -r "${CDDBLOCALFILE}" ]; then
+                       # List out disc title/author and contents
+                       do_cddbparse "${CDDBLOCALFILE}"
+                       echo -n "Locally cached CDDB entry found, use it? [y/n] (y): "
+                       if [ "$INTERACTIVE" = "y" ]; then
+                               read USELOCALRESP
+                               while [ "$USELOCALRESP" != "y" ] && [ "$USELOCALRESP" != "n" ] && [ "$USELOCALRESP" != "" ] ; do
+                                       echo -n 'Invalid selection. Please answer "y" or "n": '
                                        read USELOCALRESP
                                        read USELOCALRESP
-                                       while [ "$USELOCALRESP" != "y" ] && [ "$USELOCALRESP" != "n" ] && [ "$USELOCALRESP" != "" ] ; do
-                                               echo -n 'Invalid selection. Please answer "y" or "n": '
-                                               read USELOCALRESP
-                                       done
-                                       [ x"$USELOCALRESP" = "x" ] && USELOCALRESP="y"
-                               else
-                                       echo "y" >&2
-                               fi
-                               if [ "$USELOCALRESP" = "y" ]; then
-                               #echo "Using local copy of CDDB data"
-                                       cp "${CDDBLOCALFILE}" "$ABCDETEMPDIR/cddbread.1"
-                                       echo 999 > "$ABCDETEMPDIR/cddbquery" # Assuming 999 isn't used by CDDB
-                                       echo cddb-readcomplete >> "$ABCDETEMPDIR/status"
-                                       do_cddbparse "${CDDBLOCALFILE}" > "$ABCDETEMPDIR/cddbchoices"
-                                       echo cddb-choice=1 >> "$ABCDETEMPDIR/status"
-                                       CDDBLOCALSUCCESS="y"
-                               else
-                                       #echo "Not using local copy of CDDB data"
-                                       CDDBLOCALSUCCESS="n"
-                               fi
+                               done
+                               [ x"$USELOCALRESP" = "x" ] && USELOCALRESP="y"
+                       else
+                               echo "y" >&2
+                       fi
+                       if [ "$USELOCALRESP" = "y" ]; then
+                       #echo "Using local copy of CDDB data"
+                               cp "${CDDBLOCALFILE}" "$ABCDETEMPDIR/cddbread.1"
+                               echo 999 > "$ABCDETEMPDIR/cddbquery" # Assuming 999 isn't used by CDDB
+                               echo cddb-readcomplete >> "$ABCDETEMPDIR/status"
+                               do_cddbparse "${CDDBLOCALFILE}" > "$ABCDETEMPDIR/cddbchoices"
+                               echo cddb-choice=1 >> "$ABCDETEMPDIR/status"
+                               CDDBLOCALSUCCESS="y"
                        else
                        else
+                               #echo "Not using local copy of CDDB data"
                                CDDBLOCALSUCCESS="n"
                        fi
                                CDDBLOCALSUCCESS="n"
                        fi
+                       CDDBLOCALSUCCESS="y"
+               else
+                       CDDBLOCALSUCCESS="n"
                fi
        fi
 }
                fi
        fi
 }
@@ -1278,6 +1266,7 @@ do_cddbedit ()
                                        # I'll take CDDB read #3 for $400, Alex
                                        echo -n "Which entry would you like abcde to use (0 for none)? [0-$CDDBCHOICES]: " >&2
                                        read CDDBCHOICE
                                        # I'll take CDDB read #3 for $400, Alex
                                        echo -n "Which entry would you like abcde to use (0 for none)? [0-$CDDBCHOICES]: " >&2
                                        read CDDBCHOICE
+                                       [ X"$CDDBCHOICE" = "X" ] && CDDBCHOICE=1
                                        # Make sure we get a valid choice
                                        CDCHOICENUM=$(echo $CDDBCHOICE | xargs printf %d 2>/dev/null)
                                        while [ $CDCHOICENUM -lt 0 ] || [ $CDCHOICENUM -gt $CDDBCHOICES ]; do
                                        # Make sure we get a valid choice
                                        CDCHOICENUM=$(echo $CDDBCHOICE | xargs printf %d 2>/dev/null)
                                        while [ $CDCHOICENUM -lt 0 ] || [ $CDCHOICENUM -gt $CDDBCHOICES ]; do
@@ -1308,6 +1297,10 @@ do_cddbedit ()
                                if [ "$USELOCALRESP" = "y" ]; then :; else
                                        if [ -n "$CHOICE" ] ; then
                                                case $CDDBCHOICES in
                                if [ "$USELOCALRESP" = "y" ]; then :; else
                                        if [ -n "$CHOICE" ] ; then
                                                case $CDDBCHOICES in
+                                                       0) 
+                                                       UNKNOWNDISK=y
+                                                       echo "Selected template."
+                                                       ;;
                                                        1) cat "$ABCDETEMPDIR/cddbchoices" ;;
                                                        *)
                                                        echo "Selected: #$CHOICE"
                                                        1) cat "$ABCDETEMPDIR/cddbchoices" ;;
                                                        *)
                                                        echo "Selected: #$CHOICE"
@@ -1612,7 +1605,7 @@ do_cdread ()
                cddafs)
                        # Find the track's mounted path
                        REALTRACKNUM=$(expr $UTRACKNUM + 0)
                cddafs)
                        # Find the track's mounted path
                        REALTRACKNUM=$(expr $UTRACKNUM + 0)
-                       FILEPATH=$(mount | grep "$CDROM on" | sed 's/^[^ ]* on \([^(]*\) (.*/\1/')
+                       FILEPATH=$(mount | grep "$CDROM on" | sed 's/^[^ ]* on \(.*\) (.*/\1/')
                        FILEPATH=$(find "$FILEPATH" | grep "/$REALTRACKNUM ");
                        # If the file exists, copy it
                        if [ -e "$FILEPATH" ] ; then
                        FILEPATH=$(find "$FILEPATH" | grep "/$REALTRACKNUM ");
                        # If the file exists, copy it
                        if [ -e "$FILEPATH" ] ; then
@@ -1657,7 +1650,31 @@ if [ x"$EXTRAVERBOSE" != "x" ]; then
 fi
 }
 
 fi
 }
 
+# User-redefinable functions
+# Custom filename munging:
+mungefilename ()
+{
+       echo "$@" | sed s,:,\ -,g | tr \ /\* __+ | tr -d \'\"\?\[:cntrl:\]
+}
+
+# Custom genre munging:
+mungegenre ()
+{
+       echo $CDGENRE | tr "[:upper:]" "[:lower:]"
+}
+
+# pre_read
+# Empty pre_read function, to be defined in the configuration file.
+pre_read ()
+{
+:
+}
+
+###############################################################################
+# End of functions
+#
 # Start of execution
 # Start of execution
+###############################################################################
 
 # Builtin defaults
 CDDBURL="http://freedb.freedb.org/~cddb/cddb.cgi"
 
 # Builtin defaults
 CDDBURL="http://freedb.freedb.org/~cddb/cddb.cgi"
@@ -1776,26 +1793,6 @@ MAXPROCS=1
 # List of actions to perform - by default, run to completion
 ACTIONS=cddb,read,encode,tag,move,clean
 
 # List of actions to perform - by default, run to completion
 ACTIONS=cddb,read,encode,tag,move,clean
 
-# User-redefinable functions
-# Custom filename munging:
-mungefilename ()
-{
-       echo "$@" | sed s,:,\ -,g | tr \ /\* __+ | tr -d \'\"\?\[:cntrl:\]
-}
-
-# Custom genre munging:
-mungegenre ()
-{
-       echo $CDGENRE | tr "[:upper:]" "[:lower:]"
-}
-
-# pre_read
-# Empty pre_read function, to be defined in the configuration file.
-pre_read ()
-{
-:
-}
-
 # Asume fetch if under FreeBSD. curl is used for Mac OS X. wget is used for Linux/OpenBSD/NetBSD.
 # Let's use these checkings to determine the OS flavour, which will be used later
 if [ X$(uname) = "XFreeBSD" ] ; then
 # Asume fetch if under FreeBSD. curl is used for Mac OS X. wget is used for Linux/OpenBSD/NetBSD.
 # Let's use these checkings to determine the OS flavour, which will be used later
 if [ X$(uname) = "XFreeBSD" ] ; then
@@ -1837,7 +1834,7 @@ if [ -r $HOME/.abcde.conf ]; then
 fi
 
 # By this time, we need some HTTPGETOPTS already defined.
 fi
 
 # By this time, we need some HTTPGETOPTS already defined.
-# If the user has defined its own, we should not be empty.
+# If the user has defined a non-default HTTPGET method, we should not be empty.
 
 if [ "$HTTPGETOPTS" = "" ] ; then
        case $HTTPGET in
 
 if [ "$HTTPGETOPTS" = "" ] ; then
        case $HTTPGET in
@@ -1867,7 +1864,7 @@ fi
 
 # Parse command line options
 #while getopts 1a:bc:C:d:Dhj:klLnNo:pr:S:t:T:vVx opt ; do
 
 # Parse command line options
 #while getopts 1a:bc:C:d:Dhj:klLnNo:pr:S:t:T:vVx opt ; do
-while getopts 1a:A:bc:C:d:Dhj:klLnNo:pr:Rs:S:vVx opt ; do
+while getopts 1a:A:bc:C:d:Dhj:klLnNo:pr:Rs:S:t:T:vVxw:W: opt ; do
        case "$opt" in
                1) ONETRACK=y ;;
                a) ACTIONS="$OPTARG" ;;
        case "$opt" in
                1) ONETRACK=y ;;
                a) ACTIONS="$OPTARG" ;;
@@ -1878,24 +1875,27 @@ while getopts 1a:A:bc:C:d:Dhj:klLnNo:pr:Rs:S:vVx opt ; do
                d) CDROM="$OPTARG" ;;
                D) set -x ;;
                h) usage; exit ;;
                d) CDROM="$OPTARG" ;;
                D) set -x ;;
                h) usage; exit ;;
-               f) FORCECDDBUSELOCAL=y ;;
+#              f) FORCECDDBUSELOCAL=y ;;
                i) INLINETAG=y ;;
                j) MAXPROCS="$OPTARG" ;;
                k) KEEPWAVS=y ;;
                l) LOWDISK=y ;;
                i) INLINETAG=y ;;
                j) MAXPROCS="$OPTARG" ;;
                k) KEEPWAVS=y ;;
                l) LOWDISK=y ;;
-               L) CDDBUSELOCAL="y" ;;
-               n) CDDBAVAIL="n" ;;
-               N) INTERACTIVE="n" ;;
+               L) CDDBUSELOCAL=y ;;
+               n) CDDBAVAIL=n ;;
+               N) INTERACTIVE=n ;;
                m) DOSPLAYLIST=y ;;
                o) OUTPUTTYPE="$OPTARG" ;;
                m) DOSPLAYLIST=y ;;
                o) OUTPUTTYPE="$OPTARG" ;;
-               p) PADTRACKS="y" ;;
+               p) PADTRACKS=y ;;
+               P) USEPIPES=y ;;
                r) REMOTEHOSTS="$OPTARG" ;;
                R) REPLAYGAIN=y ;;
                s) STARTTRACKNUMBER="$OPTARG" ;;
                S) CDSPEEDVALUE="$OPTARG" ;;
                r) REMOTEHOSTS="$OPTARG" ;;
                R) REPLAYGAIN=y ;;
                s) STARTTRACKNUMBER="$OPTARG" ;;
                S) CDSPEEDVALUE="$OPTARG" ;;
-               t) PREPROCESSFORMATS="$OPTARG"
-                  PREPROCESS=y ;;
-               T) POSTPROCESSFORMATS="$OPTARG" ;;
+#              t) PREPROCESSFORMATS="$OPTARG"
+#                 PREPROCESS=y ;;
+#              T) POSTPROCESSFORMATS="$OPTARG" ;;
+               t) STARTTRACKNUMBER="$OPTARG" ;;
+               T) STARTTRACKNUMBER="$OPTARG" ; STARTTRACKNUMBERTAG="y" ;;
                v) 
                   echo "This is abcde v$VERSION."
                   echo "Usage: abcde [options] [tracks]"
                v) 
                   echo "This is abcde v$VERSION."
                   echo "Usage: abcde [options] [tracks]"
@@ -1904,6 +1904,8 @@ while getopts 1a:A:bc:C:d:Dhj:klLnNo:pr:Rs:S:vVx opt ; do
                   ;;
                V) EXTRAVERBOSE="y" ;;
                x) EJECTCD="y" ;;
                   ;;
                V) EXTRAVERBOSE="y" ;;
                x) EJECTCD="y" ;;
+               w) COMMENT="$OPTARG" ;;
+               W) STARTTRACKNUMBER="${OPTARG}01" ; STARTTRACKNUMBERTAG="y" ; COMMENT="CD${OPTARG}" ;;
                ?) usage; exit ;;
        esac
 done
                ?) usage; exit ;;
        esac
 done
@@ -1938,6 +1940,40 @@ else
        done
 fi
 
        done
 fi
 
+# List of valid actions: cddb,read,normalize,encode,tag,move,playlist,clean
+# List of experimental actions: retag,transcode
+
+# Determine what actions are to be done from $ACTIONS and set the
+# following environment variables for them:
+DOCDDB=n
+DOREAD=n
+DONORMALIZE=n
+DOPREPROCESS=n
+DOENCODE=n
+DOPOSTPROCESS=n
+DOTAG=n
+DOMOVE=n
+DOPLAYLIST=n
+DOCLEAN=n
+
+for ACTION in $(echo $ACTIONS | tr , \ )
+do
+       case $ACTION in
+       cddb) DOCDDB=y;;
+       read) DOREAD=y;;
+       normalize) DONORMALIZE=y; DOREAD=y;;
+#      preprocess) DOPREPROCESS=y; DOREAD=y;;
+       encode) DOENCODE=y; DOREAD=y;;
+#      postprocess) DOPREPROCESS=y; DOENCODE=y; DOREAD=y;;
+       tag) DOTAG=y; DOREAD=y; DOENCODE=y; DOCDDB=y;;
+       move) DOMOVE=y; DOTAG=y; DOREAD=y; DOENCODE=y; DOCDDB=y;;
+       playlist) DOCDDB=y; DOPLAYLIST=y;;
+       clean) DOCLEAN=y;;
+       esac
+done
+
+# Sanity checks:
+
 # At this point a CDROM has to be defined, so we check it exists.
 if [ "$CDROM" != "" ] ; then 
        if [ "$CDROMREADERSYNTAX" = "cdda2wav" ] && [ "$NEEDCDROMID" = "y" ] ; then
 # At this point a CDROM has to be defined, so we check it exists.
 if [ "$CDROM" != "" ] ; then 
        if [ "$CDROMREADERSYNTAX" = "cdda2wav" ] && [ "$NEEDCDROMID" = "y" ] ; then
@@ -1992,14 +2028,14 @@ for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
 do
        case $OUTPUT in
                ogg)  [ "$OGGENCODERSYNTAX" = "default" ] && OGGENCODERSYNTAX=oggenc
 do
        case $OUTPUT in
                ogg)  [ "$OGGENCODERSYNTAX" = "default" ] && OGGENCODERSYNTAX=oggenc
-                     echo $ACTIONS | grep tag > /dev/null 2>&1 && NEEDCOMMENTER=y
-                     if [ "$REPLAYGAIN" = "y" ]; then NEEDVORBISGAIN=y; fi
+                     [ "$DOTAG" = "y" ] && NEEDCOMMENTER=y
+                     [ "$REPLAYGAIN" = "y" ] && NEEDVORBISGAIN=y
                        ;;
                mp3)  [ "$MP3ENCODERSYNTAX" = "default" ] && MP3ENCODERSYNTAX=lame
                        ;;
                mp3)  [ "$MP3ENCODERSYNTAX" = "default" ] && MP3ENCODERSYNTAX=lame
-                     echo $ACTIONS | grep tag > /dev/null 2>&1 && NEEDTAGGER=y
+                     [ "$DOTAG" = "y" ] && NEEDTAGGER=y
                        ;;
                flac) [ "$FLACENCODERSYNTAX" = "default" ] && FLACENCODERSYNTAX=flac
                        ;;
                flac) [ "$FLACENCODERSYNTAX" = "default" ] && FLACENCODERSYNTAX=flac
-                     echo $ACTIONS | grep tag > /dev/null 2>&1 && NEEDMETAFLAC=y
+                     [ "$DOTAG" = "y" ] && NEEDMETAFLAC=y
                        ;;
                spx) [ "$SPEEXENCODERSYNTAX" = "default" ] && SPEEXENCODERSYNTAX=speexenc ;;
                mpc) [ "$MPPENCODERSYNTAX" = "default" ] && MPPENCODERSYNTAX=mppenc ;;
                        ;;
                spx) [ "$SPEEXENCODERSYNTAX" = "default" ] && SPEEXENCODERSYNTAX=speexenc ;;
                mpc) [ "$MPPENCODERSYNTAX" = "default" ] && MPPENCODERSYNTAX=mppenc ;;
@@ -2089,9 +2125,9 @@ fi
 
 # Don't check for stuff if it's not needed
 if [ "$REMOTEHOSTS" ]; then NEEDDISTMP3=y; fi
 
 # Don't check for stuff if it's not needed
 if [ "$REMOTEHOSTS" ]; then NEEDDISTMP3=y; fi
-if echo $ACTIONS | grep normalize > /dev/null 2>&1 ; then NEEDNORMALIZER=y; fi
-if [ "$EJECTCD" = "y" ]; then NEEDEJECT=y; fi
-if echo $ACTIONS | grep cddb > /dev/null 2>&1 ; then NEEDHTTPGET=y ; fi
+[ "$DONORMALIZE" = "y" ] && NEEDNORMALIZER=y
+[ "$EJECTCD" = "y" ] && NEEDEJECT=y
+[ ! "$CDDBAVAIL" = "n" ] && [ "$DOCDDB" = "y" ] && NEEDHTTPGET=y
 
 if [ X"$CDSPEEDVALUE" != "X" ]; then
        case "$CDROMREADERSYNTAX" in
 
 if [ X"$CDSPEEDVALUE" != "X" ]; then
        case "$CDROMREADERSYNTAX" in
@@ -2127,10 +2163,7 @@ HTTPGET="$HTTPGET $HTTPGETOPTS"
 
 # Here it used to say:
 # One thousand lines in, we can start doing stuff with things
 
 # Here it used to say:
 # One thousand lines in, we can start doing stuff with things
-# Well, right now we are at line 2116 ;)
-
-# List of valid actions: cddb,read,normalize,encode,tag,playlist,move,clean
-# List of experimental actions: retag,transcode
+# Well, right now we are at line 2157 ;)
 
 # Export needed things so they can be read in this subshell
 export CDDBTOOL ABCDETEMPDIR TRACKQUEUE LOWDISK EJECTCD EJECT EJECTOPTS
 
 # Export needed things so they can be read in this subshell
 export CDDBTOOL ABCDETEMPDIR TRACKQUEUE LOWDISK EJECTCD EJECT EJECTOPTS
@@ -2151,11 +2184,14 @@ if [ "$DOCDDB" = "y" ]; then
        if [ $CDDBUSELOCAL = "y" ]; then
                do_localcddb
        fi
        if [ $CDDBUSELOCAL = "y" ]; then
                do_localcddb
        fi
-       ## FIXME ## ! is non-portable
-       if ! checkstatus cddb-choice > /dev/null && [ ! "$CDDBLOCALSUCCESS" = "y" ] ; then
-               do_cddbstat
-               do_cddbquery
-               do_cddbread
+       if checkstatus cddb-choice > /dev/null; then
+               :
+       else 
+               if [ ! "$CDDBLOCALSUCCESS" = "y" ] ; then
+                       do_cddbstat
+                       do_cddbquery
+                       do_cddbread
+               fi
        fi
        do_cddbedit
 
        fi
        do_cddbedit
 
@@ -2182,7 +2218,7 @@ if [ "$STRIPDATATRACKS" = "y" ] && [ ! "$ONETRACK" = "y" ]; then
                                vecho "Querying the CD to obtain a list of valid audio tracks..."
                                $CDROMREADER -Q > $ABCDETEMPDIR/cdparanoia-query 2>&1
                                # Obtain a list of valid audio tracks from the results of the query
                                vecho "Querying the CD to obtain a list of valid audio tracks..."
                                $CDROMREADER -Q > $ABCDETEMPDIR/cdparanoia-query 2>&1
                                # Obtain a list of valid audio tracks from the results of the query
-                               CDTRACKQUEUE=$( cat $ABCDETEMODIR/cdparanoia- | egrep '^[[:space:]]+[[:digit:]]' | awk '{print $1}' | tr -d "." | tr '\n' ' ' )
+                               CDTRACKQUEUE=$( cat $ABCDETEMPDIR/cdparanoia-query | egrep '^[[:space:]]+[[:digit:]]' | awk '{print $1}' | tr -d "." | tr '\n' ' ' )
                        fi
                        # Obtain the track padding value from the before-processing list and pad the CD list
                        TRACKNUMPADDING=$( echo $TRACKQUEUE | awk '{print $1}' | tr -d " \n" | wc -c )
                        fi
                        # Obtain the track padding value from the before-processing list and pad the CD list
                        TRACKNUMPADDING=$( echo $TRACKQUEUE | awk '{print $1}' | tr -d " \n" | wc -c )