Recover legacy code for systems using util-linux < 2.22

This commit is contained in:
hellekin 2015-02-08 19:34:32 -03:00 committed by Jaromil
parent de418d00c9
commit e4afe6aefa

46
tomb
View File

@ -306,10 +306,44 @@ _ensure_safe_swap() {
[[ -z "$swaps" ]] && return 0 # No swap partition is active [[ -z "$swaps" ]] && return 0 # No swap partition is active
_message "An active swap partition is detected..." _message "An active swap partition is detected..."
for s in $=swaps; do
{ _is_encrypted_block $s } \ # Issue #163
&& { r=2 } || { r=1; break } # lsblk --inverse appeared in util-linux 2.22
done # 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 if [[ $r -eq 2 ]]; then
_success "All your swaps are belong to crypt. Good." _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 "You can deactivate all swap partitions using the command:"
_warning " swapoff -a" _warning " swapoff -a"
_warning "But if you want to proceed like this, use the -f (force) flag." _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 fi
return $r return $r