lock encrypted device after mount fail, _then_ abort

This commit is contained in:
alterNERDtive 2022-07-19 13:00:00 +02:00
parent c7238bec91
commit fe314c0857
Signed by: alterNERDtive
GPG key ID: 547787A4FE6533F1

View file

@ -45,7 +45,7 @@ init () {
if [[ ! -z "${dev}" ]] && udisksctl info -b ${dev} | grep -q org.freedesktop.UDisks2.Encrypted; then if [[ ! -z "${dev}" ]] && udisksctl info -b ${dev} | grep -q org.freedesktop.UDisks2.Encrypted; then
echo "Unlocking device ${dev} …" echo "Unlocking device ${dev} …"
local mountdev=$(udisksctl unlock -b "${dev}") local mountdev=$(udisksctl unlock -b "${dev}")
[[ $? != 0 ]] && echo "Error unlocking device ${dev}." && exit 1 [[ $? != 0 ]] && echo "Error unlocking device ${dev}, aborting …" && exit 1
mountdev="$(echo $mountdev | awk '{ print $4 }')" mountdev="$(echo $mountdev | awk '{ print $4 }')"
mountdev=${mountdev:0:-1} mountdev=${mountdev:0:-1}
@ -56,7 +56,11 @@ init () {
if [[ ! -z ${mountdev} ]]; then if [[ ! -z ${mountdev} ]]; then
echo "Mounting device ${mountdev} …" echo "Mounting device ${mountdev} …"
mountpath=$(udisksctl mount -b "${mountdev}") mountpath=$(udisksctl mount -b "${mountdev}")
[[ $? != 0 ]] && echo "Error mounting device ${mount}." && exit 1 if [[ $? != 0 ]]; then
echo "Error mounting device ${mount}, aborting …"
[[ "${mountdev}" != "${dev}" ]] && udisksctl lock -b ${dev}
exit 1
fi
mountpath="$(echo $mountpath | awk '{ print $4 }')" mountpath="$(echo $mountpath | awk '{ print $4 }')"
fi fi