summaryrefslogtreecommitdiff
path: root/tools/hal-luks-setup
blob: 83bd92cfecbdb8de8d33b7f01b007c5477b3d261 (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
53
54
55
56
#!/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.

. hal-functions

locked_out() {
	echo "org.freedesktop.Hal.Device.InterfaceLocked" >&2
	echo "Enclosing drive/volume is locked" >&2
	exit 1
}

unknown_error() {
        echo "org.freedesktop.Hal.Device.UnknownError" >&2
        echo "Missing or empty environment variable(s)." >&2
        echo "This script should be started by hald." >&2
        exit 1
}

if [ -z "$HAL_PROP_BLOCK_DEVICE" ] || [ -z "$HAL_PROP_INFO_UDI" ] || [ -z "$HAL_PROP_VOLUME_UUID" ] ; then
    unknown_error
fi

# Respect the same locks as Mount()/Unmount() etc.
if [ -n "$HAL_METHOD_INVOKED_BY_SYSTEMBUS_CONNECTION_NAME" ] ; then
    hal-is-caller-locked-out --udi $HAL_PROP_INFO_UDI \
        --interface org.freedesktop.Hal.Device.Volume \
        --caller "$HAL_METHOD_INVOKED_BY_SYSTEMBUS_CONNECTION_NAME"
    RET=$?
    if [ "$RET" != "0" ] ; then
        locked_out
    fi
    hal-is-caller-locked-out --udi $HAL_PROP_BLOCK_STORAGE_DEVICE \
        --interface org.freedesktop.Hal.Device.Storage \
        --caller "$HAL_METHOD_INVOKED_BY_SYSTEMBUS_CONNECTION_NAME"
    RET=$?
    if [ "$RET" != "0" ] ; then
        locked_out
    fi
fi

IS_HOTPLUGGABLE=`hal-get-property --udi $HAL_PROP_BLOCK_STORAGE_DEVICE --key storage.hotpluggable`
if [ "$IS_HOTPLUGGABLE" == "true" ] ; then
    ACTION="org.freedesktop.hal.storage.crypto-setup-removable"
elif [ "$IS_HOTPLUGGABLE" == "false" ] ; then
    ACTION="org.freedesktop.hal.storage.crypto-setup-fixed"
else
    unknown_error
fi

hal_check_priv $ACTION
hal_exec_backend