]> gitweb.fluxo.info Git - utils-cdrecord.git/commitdiff
Adding mass-ripper
authorSilvio Rhatto <rhatto@riseup.net>
Sun, 23 Nov 2014 14:34:32 +0000 (12:34 -0200)
committerSilvio Rhatto <rhatto@riseup.net>
Sun, 23 Nov 2014 14:34:32 +0000 (12:34 -0200)
mass-ripper [new file with mode: 0755]

diff --git a/mass-ripper b/mass-ripper
new file mode 100755 (executable)
index 0000000..781380c
--- /dev/null
@@ -0,0 +1,69 @@
+#!/bin/bash
+#
+# mass-ripper: sequentially copy CDs and DVDs.
+#
+
+# Parameters
+BASENAME="`basename $0`"
+DRIVE="$1"
+ITERATION="1"
+INFO="0"
+MOUNT="/media/cdrom"
+
+# Disk drive
+if [ -z "$DRIVE" ]; then
+  DRIVE="/dev/sr0"
+fi
+
+# Set sudo config
+if [ "`whoami`" != 'root' ]; then
+  sudo="sudo"
+fi
+
+# Greeter
+echo "Mass CD/DVD copier, press Ctrl-C to abort..."
+
+# Thanks http://askubuntu.com/questions/197662/how-do-i-auto-copy-cd-contents-on-insertion
+while true; do
+  # Print just once per disk
+  if [ "$INFO" == "0" ]; then
+    echo "Waiting for disk #$ITERATION..."
+  fi
+
+  # Check if media is available
+  #HAS_MEDIA=$(grep $DRIVE /proc/self/mounts)
+  HAS_MEDIA=$(udisks --show-info $DRIVE | grep "has media" | cut -d : -f 2 | sed -e 's/ //g')
+
+  # If it doesn't exist, loop until it does with 1 second pause
+  if [ "$HAS_MEDIA" == "0" ]; then
+    #echo -ne "."
+    INFO="1"
+    sleep 1
+  else
+    echo "Got it! Mounting..."
+    mkdir -p cdrom            || exit 1
+    $sudo mount $DRIVE $MOUNT || exit 1
+    #mkdir -p $ITERATION      || exit 1
+
+    echo "Copying data..."
+    cp -vr $MOUNT $ITERATION  || exit 1
+
+    echo "Fixing permissions..."
+    find $ITERATION/ -type d -exec chmod 755 {} \;
+    find $ITERATION/ -type f -exec chmod 644 {} \;
+
+    echo "Umounting..."
+    $sudo umount $MOUNT
+
+    # Eject the CD with suitable pauses to avoid any buffer problems
+    echo "Ejecting media..."
+    sleep 1
+    eject $DRIVE
+    sleep 2
+
+    # Increase counter
+    let ITERATION++
+    INFO="0"
+  fi
+  # Still looping! Go back and wait for another CD!
+done