Package: backupninja
Followup-For: Bug #870214
Tags: patch

The lsblk approach doesn't actually identified partitioned
device-mapped devices, such as dmcrypt volumes or LVs. It's arguably
much cleaner, and maybe there's a better approach, but meanwhile,
I've got so fed up with this (and #818879) that I wrote a parser for
sfdisk output. Please forgive me.

Patch attached.

-- 
 .''`.   martin f. krafft <madduck@d.o> @martinkrafft
: :'  :  proud Debian developer
`. `'`   http://people.debian.org/~madduck
  `-  Debian - when you have better things to do than fixing systems
--- sys.distrib	2017-09-06 00:01:25.000000000 +1200
+++ sys	2018-02-20 14:57:10.852105834 +1300
@@ -605,9 +605,44 @@
 # here we use sfdisk to dump a listing of all the partitions.
 # these files can be used to directly partition a disk of the same size.
 
+sfdisk_list_devices_with_partitions() {
+  LC_ALL=C $SFDISK -l 2>/dev/null |
+     while read w1 w2 rest; do
+        printf >&2 '%-30s < %s\n' "\"$state+$disk+$w1+$w2\"" "$w1 $w2 $rest"
+        case "$state+$disk+$w1+$w2" in
+           (++Disk+*) # new Disk stanza encountered
+              echo >&2 "  [ New disk stanza: ${w2%:}"
+              disk="${w2%:}" # consumes trailing ':'
+              state=disk
+              ;;
+           (disk+*++*) # end of stanza, clear state
+              echo >&2 "  ] Clear state."
+              state= disk=
+              ;;
+           (disk++*+*)
+              echo >&2 "  . Skipping (post-commit)..."
+              ;;
+           (disk+*+Disklabel+type:|*+Disk+identifier:) # commit
+              echo >&2 "  ! Committing disk stanza: $disk"
+              echo "$disk"
+              disk=
+              ;;
+           (++*+*)
+              echo >&2 "    Skipping..."
+              ;;
+           (disk+*+*+*)
+              echo >&2 "  . Skipping (pre-commit)..."
+              ;;
+           (*) # error condition
+              echo >&2 "  X Invalid state: $disk+$w1+$w2"
+              ;;
+        esac
+     done
+}
+
 if [ "$partitions" == "yes" ]; then
    if [ "$dosfdisk" == "yes" ]; then
-      devices=`LC_ALL=C $SFDISK -l 2>/dev/null | grep "^Disk /dev" | /usr/bin/awk '{print $2}' | cut -d: -f1`
+      devices=$(sfdisk_list_devices_with_partitions 2>/dev/null)
       if [ "$devices" == "" ]; then
          warning "No harddisks found"
       fi

Attachment: digital_signature_gpg.asc
Description: Digital GPG signature (see http://martin-krafft.net/gpg/sig-policy/999bbcc4/current)

Reply via email to