summaryrefslogtreecommitdiff
path: root/tools/linux/hal-luks-remove-linux
blob: fc398e6da046eb45f0028a0dc5fcff0e7117c647 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/bin/bash

# Copyright (C) 2005 W. Michael Petullo <mike@flyn.org>
# Copyright (C) 2006 David Zeuthen <davidz@redhat.com>
# 
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2.

CRYPTSETUP=/sbin/cryptsetup

if [ ! -f $CRYPTSETUP ]; then
    echo org.freedesktop.Hal.Device.Volume.Crypto.CryptSetupMissing >&2
    echo Error remove $HAL_PROP_BLOCK_DEVICE - $CRYPTSETUP not found >&2
    exit 1
fi

echo LUKS cryptotext device $HAL_PROP_INFO_UDI is going away

# make sure that the cleartext volume is unmounted
CLEARTEXT_VOLUME_UDI=`hal-find-by-property --key volume.crypto_luks.clear.backing_volume --string $HAL_PROP_INFO_UDI`
RET=$?
if [ x$RET = x0 ]; then
    echo Attempting unmount of corresponding LUKS cleartext volume $CLEARTEXT_VOLUME_UDI
    # lazy unmount via D-BUS
    dbus-send --print-reply --system \
	      --dest=org.freedesktop.Hal \
	      $CLEARTEXT_VOLUME_UDI \
	      org.freedesktop.Hal.Device.Volume.Unmount \
	      array:string:lazy
fi

echo Tearing down LUKS cryptotext volume

if [ ! -f $CRYPTSETUP ]; then
	echo org.freedesktop.Hal.Device.Volume.Crypto.RemoveError >&2
	echo Error removing $HAL_PROP_BLOCK_DEVICE - $CRYPTSETUP not found >&2
	exit 1
fi

if [ -z $HAL_PROP_VOLUME_UUID ]; then
	echo org.freedesktop.Hal.Device.Volume.Crypto.RemoveError >&2
	echo Error determining UUID of $HAL_PROP_BLOCK_DEVICE >&2
	exit 1
fi

if ! $CRYPTSETUP luksClose luks_crypto_$HAL_PROP_VOLUME_UUID 2> /dev/null; then
	echo org.freedesktop.Hal.Device.Volume.Crypto.RemoveError >&2
	echo Error removing luks_crypto_$HAL_PROP_VOLUME_UUID >&2
	exit 1
fi

exit 0