summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorErich Eckner <git@eckner.net>2019-04-18 11:25:17 +0200
committerErich Eckner <git@eckner.net>2019-04-18 11:25:17 +0200
commit1ad8a39de9ba2999e465a408011370dcd811dbb8 (patch)
tree70aec1dcf8cdd5602236900255d56aabc12ad96a
parent7b05d3bb153e10cd864d3a6da6fd4e990e8dce23 (diff)
downloadmount-crypts-1ad8a39de9ba2999e465a408011370dcd811dbb8.tar.xz
skip already (un)mounted devices
-rwxr-xr-xmount-crypts13
1 files changed, 12 insertions, 1 deletions
diff --git a/mount-crypts b/mount-crypts
index e1efc50..08b1975 100755
--- a/mount-crypts
+++ b/mount-crypts
@@ -5,6 +5,7 @@ maxWait=60
while [ $i -le $(sed "s/#.*$//" /etc/crypttab | grep -vc '^ *$') ]; do
s="$(sed "s/#.*$//" /etc/crypttab | grep -v '^ *$' | tail -n$i | head -n1 | sed "s/ */ /g")"
+ i=$((i+1))
name=$(echo $s | awk '{print $1}')
device=$(echo $s | awk '{print $2}')
key=$(echo $s | awk '{print $3}')
@@ -12,16 +13,26 @@ while [ $i -le $(sed "s/#.*$//" /etc/crypttab | grep -vc '^ *$') ]; do
sleep 1
maxWait=$[${maxWait}-1]
done
+ if cryptsetup status "${name}" 2>&1 >/dev/null; then
+ is_mounted=true
+ else
+ is_mounted=false
+ fi
if [ "$1" == "-u" ]; then
+ if ! ${is_mounted}; then
+ continue
+ fi
if ! /usr/sbin/cryptsetup luksClose "${name}"; then
>&2 echo "FEHLER: cryptsetup luksClose $name"
exit 1
fi
else
+ if ${is_mounted}; then
+ continue
+ fi
if ! /usr/sbin/cryptsetup luksOpen "${device}" "${name}" --key-file "${key}"; then
>&2 echo "FEHLER: cryptsetup luksOpen ${device} ${name} --key-file ${key}"
exit 1
fi
fi
- i=$((i+1))
done