summaryrefslogtreecommitdiff
path: root/scripts/xdg-su.in
blob: 9d0a847156469160fc91ece81fe7936ca69e3d0e (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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/bin/sh
#---------------------------------------------
#   xdg-su
#
#   Utility script to run a command as an alternate user, generally
#       the root user, with a graphical prompt for the root
#       password if needed
#
#   Refer to the usage() function below for usage.
#
#   Copyright 2006, Jeremy White <jwhite@codeweavers.com>
#   Copyright 2006, Kevin Krammer <kevin.krammer@gmx.at>
#
#   LICENSE:
#
#---------------------------------------------

examples()
{
cat << _EXAMPLES
_EXAMPLES
}

usage()
{
cat << _USAGE
_USAGE
}

#@xdg-utils-common@

su_kde()
{
    kdesu "$@"

    if [ $? -eq 0 ]; then
        exit_success
    else
        exit_failure_operation_failed
    fi
}

su_gnome()
{
    GSU=`which gnomesu 2>/dev/null`
    if [ $? -eq 0 ] ; then
        $GSU "$@"

        if [ $? -eq 0 ]; then
            exit_success
        else
            exit_failure_operation_failed
        fi
    else
        su_generic "$@"
    fi
}

su_generic()
{
    XSU=`which xsu 2>/dev/null`
    if [ $? -eq 0 ] ; then
        $XSU "$@"

        if [ $? -eq 0 ]; then
            exit_success
        else
            exit_failure_operation_failed
        fi
    else
        exit_failure_operation_impossible "Sorry, no graphical method available for invoking su" "$@"
    fi
}

[ x"$1" != x"" ] || exit_failure_arg_count

if [ x"$DE" = x"" ]; then
    XSU=`which xsu 2>/dev/null`
    if [ $? -eq 0 ] ; then
        DE=generic
    fi
fi

case "$DE" in
    kde)
    su_kde "$@"
    ;;

    gnome)
    su_gnome "$@"
    ;;

    generic)
    su_generic "$@"
    ;;

    *)
    exit_failure_operation_impossible "Sorry, no graphical method available for invoking su" "$@"
    ;;
esac