<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array">
    <added>
      <filename>LICENSE</filename>
    </added>
  </added>
  <modified type="array">
    <modified>
      <diff>@@ -60,6 +60,11 @@ while [ -z $MKVFILE ]; do
 	
 	case &quot;$1&quot; in
 	
+		&quot;--debug&quot; )
+			# Echo commands rather than executing them
+			DEBUG=1
+		;;
+		
 		&quot;-e&quot; | &quot;--external&quot; )
 			EXTERNAL=1
 			# Don't allow -d or -n switches if they're already set
@@ -190,27 +195,45 @@ WD=&quot;/tmp&quot;
 
 # If the track id wasn't specified via command line then search for the first DTS audio track
 if [ -z $DTSTRACK ]; then
-	DTSTRACK=$(mkvmerge -i &quot;$MKVFILE&quot; | grep -m 1 &quot;audio (A_DTS)&quot; | cut -d: -f1 | cut -d&quot; &quot; -f3)
-	
-	# Check to make sure there is a DTS track in the MVK
-	if [ -z $DTSTRACK ]; then
-		echo &quot;ERROR: There are no DTS tracks in '$MKVFILE'.&quot;
-		exit
+	if [ -z $DEBUG ]; then
+		echo &quot;&quot;
+		echo &quot;Find first DTS track in MKV file&quot;
+		echo &quot;&gt; mkvmerge -i \&quot;$MKVFILE\&quot; | grep -m 1 \&quot;audio (A_DTS)\&quot; | cut -d: -f1 | cut -d &quot; &quot; -f3)&quot;
+	else
+		DTSTRACK=$(mkvmerge -i &quot;$MKVFILE&quot; | grep -m 1 &quot;audio (A_DTS)&quot; | cut -d: -f1 | cut -d&quot; &quot; -f3)
+		
+		# Check to make sure there is a DTS track in the MVK
+		if [ -z $DTSTRACK ]; then
+			echo &quot;ERROR: There are no DTS tracks in '$MKVFILE'.&quot;
+			exit
+		fi
 	fi
 else
 	# Checks to make sure the command line argument track id is valid
-	VALID=$(mkvmerge -i &quot;$MKVFILE&quot; | grep &quot;Track ID $DTSTRACK: audio (A_DTS)&quot;)
-	
-	if [ -z $VALID ]; then
-		echo &quot;ERROR: Track ID '$DTSTRACK' is not a DTS track and/or does not exist.&quot;
-		exit
+	if [-z $DEBUG ]; then
+		echo &quot;&quot;
+		echo &quot;Checking to see if DTS track specified via arguments is valid&quot;
+		echo &quot;&gt; mkvmerge -i \&quot;$MKVFILE\&quot; | grep \&quot;Track ID $DTSTRACK: audio (A_DTS)\&quot;&quot;
 	else
-		echo &quot;INFO: Using alternate DTS track with ID '$DTSTRACK'&quot;
+		VALID=$(mkvmerge -i &quot;$MKVFILE&quot; | grep &quot;Track ID $DTSTRACK: audio (A_DTS)&quot;)
+		
+		if [ -z $VALID ]; then
+			echo &quot;ERROR: Track ID '$DTSTRACK' is not a DTS track and/or does not exist.&quot;
+			exit
+		else
+			echo &quot;INFO: Using alternate DTS track with ID '$DTSTRACK'&quot;
+		fi
 	fi
 fi
 
 # Get the language for the DTS track specified
-DTSLANG=$(mkvinfo &quot;$MKVFILE&quot; | grep -A 12 &quot;Track number: $DTSTRACK&quot; | tail -n 1 | cut -d&quot; &quot; -f5)
+if [ -z $DEBUG ]; then
+	echo &quot;&quot;
+	echo &quot;Extract language from selected DTS track.&quot;
+	echo &quot;&gt; mkvinfo \&quot;$MKVFILE\&quot; | grep -A 12 \&quot;Track number: $DTSTRACK\&quot; | tail -n 1 | cut -d\&quot; \&quot; -f5&quot;
+else
+	DTSLANG=$(mkvinfo &quot;$MKVFILE&quot; | grep -A 12 &quot;Track number: $DTSTRACK&quot; | tail -n 1 | cut -d&quot; &quot; -f5)
+fi
 
 # Setup temporary files
 DTSFILE=&quot;$WD/$NAME.dts&quot;
@@ -218,19 +241,31 @@ AC3FILE=&quot;$WD/$NAME.ac3&quot;
 NEWFILE=&quot;$WD/$NAME.new.mkv&quot;
 
 # Extract the DTS track
-mkvextract tracks &quot;$MKVFILE&quot; $DTSTRACK:&quot;$DTSFILE&quot;
+if [ -z $DEBUG ]; then
+	echo &quot;&quot;
+	echo &quot;Extract DTS file from MKV.&quot;
+	echo &quot;&gt; mkvextract tracks \&quot;$MKVFILE\&quot; $DTSTRACK:\&quot;$DTSFILE\&quot;&quot;
+else
+	mkvextract tracks &quot;$MKVFILE&quot; $DTSTRACK:&quot;$DTSFILE&quot;
+fi
 
 # Check to make sure the extraction completed successfully
-if [ $? -ne 0 ]; then
+if [ $? -ne 0 -a ! -z $DEBUG ]; then
 	echo &quot;ERROR: Extracting the DTS track failed.&quot;
 	exit
 fi
 
 # Convert DTS to AC3
-dcadec -o wavall &quot;$DTSFILE&quot; | aften - &quot;$AC3FILE&quot;
+if [ -z $DEBUG ]; then
+	echo &quot;&quot;
+	echo &quot;Converting DTS to AC3.&quot;
+	echo &quot;dcadec -o wavall \&quot;$DTSFILE\&quot; | aften - \&quot;$AC3FILE\&quot;&quot;
+else
+	dcadec -o wavall &quot;$DTSFILE&quot; | aften - &quot;$AC3FILE&quot;
+fi
 
 # Check to make sure the conversion completed successfully
-if [ $? -ne 0 ]; then
+if [ $? -ne 0 -a ! -z $DEBUG ]; then
 	echo &quot;ERROR: Converting the DTS to AC3 failed.&quot;
 	
 	rm -f &quot;$DTSFILE&quot; #clean up
@@ -240,7 +275,13 @@ fi
 
 # Remove DTS file unless explicitly keeping DTS track
 if [ -z $KEEPDTS ]; then
-	rm -f &quot;$DTSFILE&quot;
+	if [ -z $DEBUG ]; then
+		echo &quot;&quot;
+		echo &quot;Removing temporary DTS file.&quot;
+		echo &quot;&gt; rm -f \&quot;$DTSFILE\&quot;&quot;
+	else
+		rm -f &quot;$DTSFILE&quot;
+	fi
 
 	if [ $? -ne 0 ]; then
 		echo &quot;WARNING: Could not delete temporary file '$DTSFILE'. Please do this manually after the script has completed.&quot;
@@ -251,7 +292,7 @@ fi
 MKVFILESIZE=$(du &quot;$MKVFILE&quot; | awk '{print $1}')
 AC3FILESIZE=$(du &quot;$AC3FILE&quot; | awk '{print $1}')
 WDFREESPACE=$(df &quot;$WD&quot; | tail -n 1 | awk '{print $4}')
-if [ $(($MKVFILESIZE + $AC3FILESIZE)) -gt $WDFREESPACE ]; then
+if [ $(($MKVFILESIZE + $AC3FILESIZE)) -gt $WDFREESPACE -a ! -z $DEBUG ]; then
 	echo &quot;ERROR: There is not enough free space on '$WD' to create the new file.&quot;
 	
 	rm -f &quot;$AC3FILE&quot; #clean up
@@ -301,9 +342,15 @@ else
 	CMD=&quot;$CMD \&quot;$AC3FILE\&quot;&quot;
 
 	# Run it!
-	$CMD
+	if [ -z $DEBUG ]; then
+		echo &quot;&quot;
+		echo &quot;Running main remux.&quot;
+		echo &quot;&gt; $CMD&quot;
+	else
+		$CMD
+	fi
 
-	if [ $? -ne 0 ]; then
+	if [ $? -ne 0 -a ! -z $DEBUG ]; then
 		echo &quot;ERROR: Merging the AC3 track back into the MKV failed.&quot;
 		
 		rm -f &quot;$AC3FILE&quot; #clean up
@@ -312,9 +359,14 @@ else
 	fi
 
 	# Delete AC3 file
-	rm -f &quot;$AC3FILE&quot;
+	if [ -z $DEBUG ]; then
+		echo &quot;&quot;
+		echo &quot;Removing temporary AC3 file.&quot;
+	else
+		rm -f &quot;$AC3FILE&quot;
+	fi
 	
-	if [ $? -ne 0 ]; then
+	if [ $? -ne 0 -a ! -z $DEBUG ]; then
 		echo &quot;WARNING: Could not delete temporary file '$AC3FILE'. Please do this manually after the script has completed.&quot;
 	fi
 fi
@@ -323,33 +375,54 @@ fi
 NEWFILEDEVICE=$(df &quot;$NEWFILE&quot; | tail -n 1 | cut -d&quot; &quot; -f1)
 DSTFILEDEVICE=$(df &quot;$DEST&quot; | tail -n 1 | cut -d&quot; &quot; -f1)
 
+echo &quot;Copying new file over old file. DO NOT POWER OFF OR KILL THIS PROCESS OR YOU WILL EXPERIENCE DATA LOSS!&quot;
+
 if [ &quot;$NEWFILEDEVICE&quot; = &quot;$DSTFILEDEVICE&quot; ]; then
 	# If we're working on the same device just move the file over the old one
-	echo &quot;Copying new file over old file. DO NOT POWER OFF OR KILL THIS PROCESS OR YOU WILL EXPERIENCE DATA LOSS!&quot;
-	mv &quot;$NEWFILE&quot; &quot;$MKVFILE&quot;
+	if [ -z $DEBUG]; then
+		echo &quot;&quot;
+		echo &quot;Moving old file over new one.&quot;
+		echo &quot;&gt; mv \&quot;$NEWFILE\&quot; \&quot;$MKVFILE\&quot;&quot;
+	else
+		mv &quot;$NEWFILE&quot; &quot;$MKVFILE&quot;
+	fi
 else
 	# Check there is enough free space for the new file
 	MKVFILEDIFF=$(($(du &quot;$NEWFILE&quot; | awk '{print $1}') - $MKVFILESIZE))
 	DESTFREESPACE=$(df &quot;$DEST&quot; | tail -n 1 | awk '{print $4}')
-	if [ $MKVFILEDIFF -gt $DESTFREESPACE ]; then
+	if [ $MKVFILEDIFF -gt $DESTFREESPACE -a ! -z $DEBUG ]; then
 		echo &quot;ERROR: There is not enough free space to copy the new MKV over the old one. Free up some space and then copy '$NEWFILE' over '$MKVFILE'.&quot;
 		exit
 	fi
 	
 	# Copy our new MKV with the AC3 over the old one OR if we're using the -e
 	# switch then this actually copies the AC3 file to the original directory
-	cp &quot;$NEWFILE&quot; &quot;$MKVFILE&quot;
+	if [ -z $DEBUG ]; then
+		echo &quot;&quot;
+		echo &quot;Copying new file over the old one.&quot;
+		echo &quot;&gt; cp \&quot;$NEWFILE\&quot; \&quot;$MKVFILE\&quot;&quot;
+	else
+		cp &quot;$NEWFILE&quot; &quot;$MKVFILE&quot;
+	fi
 	
 	# Check file sizes are equal to ensure the full file was copied
-	if [ [ $? -ne 0 ] -o [ $(du &quot;$NEWFILE&quot; | awk '{print $1}') -ne $(du &quot;$MKVFILE&quot; | awk '{print $1}') ] ]; then
+	OLDFILESIZE=$(du &quot;$NEWFILE&quot; | awk '{print $1}')
+	NEWFILESIZE=$(du &quot;$MKVFILE&quot; | awk '{print $1}')
+	if [ [ $? -ne 0 -o $OLDFILESIZE -ne $NEWFILESIZE ] -a ! -z $DEBUG ]; then
 		echo &quot;ERROR: There was an error copying the new MKV over the old one. You can perform this manually by copying '$NEWFILE' over '$MKVFILE'.&quot;
 		exit
 	fi
 	
 	# Remove new file in $WD
-	rm -f &quot;$NEWFILE&quot;
+	if [ -z $DEBUG ]; then
+		echo &quot;&quot;
+		echo &quot;Remove working file.&quot;
+		echo &quot;&gt; rm -f \&quot;$NEWFILE\&quot;&quot;
+	else
+		rm -f &quot;$NEWFILE&quot;
+	fi
 	
-	if [ $? -ne 0 ]; then
+	if [ $? -ne 0 -a ! -z $DEBUG ]; then
 		echo &quot;WARNING: Could not delete temporary file '$NEWFILE'. Please do this manually after the script has completed.&quot;
 	fi
 fi</diff>
      <filename>mkvdts2ac3.sh</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>4533709484ad5777ccd29b60ac7c256eee5cdd02</id>
    </parent>
  </parents>
  <author>
    <name>JakeWharton</name>
    <email>JakeWharton@GMail.com</email>
  </author>
  <url>http://github.com/JakeWharton/mkvdts2ac3/commit/7455b41477d90104f8be970e127ffee5d20fb6ef</url>
  <id>7455b41477d90104f8be970e127ffee5d20fb6ef</id>
  <committed-date>2009-04-13T10:22:25-07:00</committed-date>
  <authored-date>2009-04-13T10:22:25-07:00</authored-date>
  <message>Added debug flag to print commands rather than execute them.</message>
  <tree>01e1f0e6e2fae9818520601eaed68e5d156ec658</tree>
  <committer>
    <name>JakeWharton</name>
    <email>JakeWharton@GMail.com</email>
  </committer>
</commit>
