xref: /titanic_52/usr/src/cmd/hal/tools/hal-functions.sh (revision 2a8d6eba033e4713ab12b61178f0513f1f075482)
1# -*-Shell-script-*-
2#
3# hal-functions.sh:	This file contains functions to be used by most or all
4#                       hal shell scripts
5# hal-system-lcd-get-brightness.sh
6#
7# Licensed under the Academic Free License version 2.1
8#
9
10hal_check_priv() {
11    if [ "$HAVE_POLKIT" = "1" -a -n $HAL_METHOD_INVOKED_BY_SYSTEMBUS_CONNECTION_NAME ]; then
12        ACTION=$1
13        PK_RESULT=`hal-is-caller-privileged --udi $UDI --action $ACTION \
14            --caller $HAL_METHOD_INVOKED_BY_SYSTEMBUS_CONNECTION_NAME`
15        RET=$?
16        if [ "$RET" != "0" ]; then
17            echo "org.freedesktop.Hal.Device.Error" >&2
18            echo "Cannot determine if caller is privileged" >&2
19            exit 1
20        fi
21        if [ "$PK_RESULT" != "yes" ] ;then
22            echo "org.freedesktop.Hal.Device.PermissionDeniedByPolicy" >&2
23            echo "$ACTION $PK_RESULT <-- (action, result)" >&2
24            exit 1
25        fi
26    fi
27}
28
29hal_call_backend() {
30    PROGRAM=`basename $0`
31    if [ -n "$HALD_UNAME_S" -a -x ./$HALD_UNAME_S/$PROGRAM-$HALD_UNAME_S ]; then
32        ./$HALD_UNAME_S/$PROGRAM-$HALD_UNAME_S $@
33    else
34        echo "org.freedesktop.Hal.Device.UnknownError" >&2
35        echo "No back-end for your operating system" >&2
36        exit 1
37    fi
38}
39
40hal_exec_backend() {
41    PROGRAM=`basename $0`
42    if [ -n "$HALD_UNAME_S" -a -x ./$HALD_UNAME_S/$PROGRAM-$HALD_UNAME_S ]; then
43        exec ./$HALD_UNAME_S/$PROGRAM-$HALD_UNAME_S $@
44    else
45        echo "org.freedesktop.Hal.Device.UnknownError" >&2
46        echo "No back-end for your operating system" >&2
47        exit 1
48    fi
49}
50