Make sure to unset tmp_dm_path_ (credits to Christian).
[grml-crypt.git] / grml-crypt
index a205033..5dcace5 100755 (executable)
@@ -211,10 +211,25 @@ function actionStop
   dm_path_=`echo $dm_path_ |awk '{print $1}'` || die "could not get devicemapper name for $tmp_"
   dprint "dm_path_=\"$dm_path_\""
 
+  # check for symlinks
+  unset tmp_dm_path_
+  for dmapper in /dev/mapper/grml-crypt* ; do
+    link=$(readlink -f "$dmapper")
+    dprint "looping device mapper devices, dmapper=$dmapper => link=$link"
+    if [ "$link" = "$dm_path_" ] ; then
+      tmp_dm_path_="$dmapper"
+    fi
+  done
+
+  if [ -n "$tmp_dm_path_" ] ; then
+    dm_path_="$tmp_dm_path_"
+    unset tmp_dm_path_
+  fi
+
   dm_name_="${dm_path_##*/}"
   dprint "dm_name_=\"$dm_name_\""
 
-  dmsetup info $dm_name_ >/dev/null ||die "$dm_name_ is not aktive"
+  dmsetup info $dm_name_ >/dev/null ||die "$dm_name_ is not active"
   device_=`$CRYPTSETUP_ status $dm_name_ |awk '/device:/{print $2}'` || \
     die "could not get underlying device of $dm_path_"
   dprint "device_=\"$device_\""
@@ -224,7 +239,7 @@ function actionStop
   echo "$device_" |grep loop &>/dev/null && execute "losetup -d $device_" \
     die "could not delete loop device $device_" || \
     execute "losetup -d $device_ &>/dev/null" eprint "could not delete loop device $device_, \
-this device could possible not be a loop device => maybe bogus error"
+this device possibly is not a loop device => maybe bogus error"
   notice "$mp_ successfully unmountet/closed/deleted"
 }