From a5ab84fdac4da07838cbd8c501d0109aee437936 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 182fc1b..5973368 100755 --- a/tomb +++ b/tomb @@ -305,10 +305,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." @@ -317,6 +351,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