From e4afe6aefabc32b38c1fb7a0dacc641f382294c1 Mon Sep 17 00:00:00 2001 From: hellekin Date: Sun, 8 Feb 2015 19:34:32 -0300 Subject: [PATCH] Recover legacy code for systems using util-linux < 2.22 --- tomb | 46 ++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 42 insertions(+), 4 deletions(-) diff --git a/tomb b/tomb index 0cbc64c..0eb3f15 100755 --- a/tomb +++ b/tomb @@ -306,10 +306,44 @@ _ensure_safe_swap() { [[ -z "$swaps" ]] && return 0 # No swap partition is active _message "An active swap partition is detected..." - for s in $=swaps; do - { _is_encrypted_block $s } \ - && { r=2 } || { r=1; break } - done + + # Issue #163 + # lsblk --inverse appeared in util-linux 2.22 + # but --version is not consistent... + local bug_163=0 + lsblk --help | grep -q '\-\-inverse' + if [[ $? -eq 0 ]]; then + for s in $=swaps; do + { _is_encrypted_block $s } \ + && { r=2 } || { r=1; break } + done + else + # Use legacy code that does not detect plain swaps on + # encrypted volumes. On such systems -f must be used. + bug_163=1 + for s in $=swaps; do + bone=$(sudo file $s) + if [[ "$bone" =~ "swap file" ]]; then + # It's a regular (unencrypted) swap file + r=1 + break + + elif [[ "$bone" =~ "symbolic link" ]]; then + # Might link to a block + r=1 + [[ "/dev/mapper" == "${s%/*}" ]] || { break } + is_crypt=$(sudo dmsetup status "$s" | awk '/crypt/ {print $3}') + [[ $is_crypt == "crypt" ]] && { r=2 } + + elif [[ "$bone" =~ "block special" ]]; then + # It's a block + r=1 + is_crypt=`sudo dmsetup status "$s" | awk '/crypt/ {print $3}'` + [[ $is_crypt == "crypt" ]] && { r=2 } || { break } + + fi + done + fi if [[ $r -eq 2 ]]; then _success "All your swaps are belong to crypt. Good." @@ -318,6 +352,10 @@ _ensure_safe_swap() { _warning "You can deactivate all swap partitions using the command:" _warning " swapoff -a" _warning "But if you want to proceed like this, use the -f (force) flag." + if [[ $bug_163 -eq 1 ]]; then + _warning "[#163] I cannot detect plain swaps on an encrypted volume." + _warning "[#163] Use -f, or upgrade util-linux to 2.22+." + fi fi return $r