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