VirtualBox

source: vbox/trunk/src/VBox/Installer/linux/runasroot.sh@ 36713

Last change on this file since 36713 was 36681, checked in by vboxsync, 14 years ago

Installers/linux: more autorun hacking

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 3.2 KB
Line 
1#!/bin/sh
2# $Id: runasroot.sh 36681 2011-04-15 10:17:02Z vboxsync $
3## @file
4# VirtualBox privileged execution helper script for Linux and Solaris
5#
6
7#
8# Copyright (C) 2009-2011 Oracle Corporation
9#
10# This file is part of VirtualBox Open Source Edition (OSE), as
11# available from http://www.virtualbox.org. This file is free software;
12# you can redistribute it and/or modify it under the terms of the GNU
13# General Public License (GPL) as published by the Free Software
14# Foundation, in version 2 as it comes in the "COPYING" file of the
15# VirtualBox OSE distribution. VirtualBox OSE is distributed in the
16# hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
17#
18
19#include sh-utils.sh
20
21ostype=`uname -s`
22if test "$ostype" != "Linux" && test "$ostype" != "SunOS" ; then
23 echo "Linux/Solaris not detected."
24 exit 1
25fi
26
27HAS_TERMINAL=""
28case "$1" in "--has-terminal")
29 shift
30 HAS_TERMINAL="yes"
31 ;;
32esac
33
34case "$#" in "2"|"3")
35 ;;
36 *)
37 echo "Usage: `basename $0` DESCRIPTION COMMAND [ADVICE]" >&2
38 echo >&2
39 echo "Attempt to execute COMMAND with root privileges, displaying DESCRIPTION if" >&2
40 echo "possible and displaying ADVICE if possible if no su(1)-like tool is available." >&2
41 exit 1
42 ;;
43esac
44
45DESCRIPTION=$1
46COMMAND=$2
47ADVICE=$3
48PATH=$PATH:/bin:/usr/bin:/usr/local/bin:/sbin:/usr/sbin:/usr/local/sbin:/usr/X11/bin
49
50case "$ostype" in SunOS)
51 PATH=$PATH:/usr/sfw/bin:/usr/gnu/bin:/usr/xpg4/bin:/usr/xpg6/bin:/usr/openwin/bin:/usr/ucb
52 GKSU_SWITCHES="-au root"
53 ;;
54 *)
55 GKSU_SWITCHES=""
56 ;;
57esac
58
59case "$DISPLAY" in ?*)
60 KDESUDO="`mywhich kdesudo`"
61 case "$KDESUDO" in ?*)
62 eval "`quotify "$KDESUDO"` --comment `quotify "$DESCRIPTION"` -- $COMMAND"
63 exit
64 ;;
65 esac
66
67 GKSU="`mywhich gksu`"
68 case "$GKSU" in ?*)
69 # Older gksu does not grok --description nor '--' and multiple args.
70 # @todo which versions do?
71 # "$GKSU" --description "$DESCRIPTION" -- "$@"
72 # Note that $GKSU_SWITCHES is NOT quoted in the following
73 "$GKSU" $GKSU_SWITCHES "$COMMAND"
74 exit
75 ;;
76 esac
77 ;;
78esac # $DISPLAY
79
80# pkexec may work for ssh console sessions as well if the right agents
81# are installed. However it is very generic and does not allow for any
82# custom messages. Thus it comes after gksu.
83## @todo should we insist on either a display or a terminal?
84# case "$DISPLAY$HAS_TERMINAL" in ?*)
85PKEXEC="`mywhich pkexec`"
86case "$PKEXEC" in ?*)
87 eval "\"$PKEXEC\" $COMMAND"
88 exit
89 ;;
90esac
91# ;;S
92#esac
93
94case "$HAS_TERMINAL" in ?*)
95 SU="`mywhich su`"
96 case "$SU" in ?*)
97 "$SU" - root -c "$COMMAND"
98 exit
99 ;;
100 esac
101 ;;
102esac
103
104# The ultimate fallback is running 'su -' within an xterm. We use the
105# title of the xterm to tell what is going on.
106case "$DISPLAY" in ?*)
107 SU="`mywhich su`"
108 case "$SU" in ?*)
109 getxterm
110 case "$gxtpath" in ?*)
111 "$gxtpath" "$gxttitle" "$DESCRIPTION - su" "$gxtexec" su - root -c "$COMMAND"
112 exit
113 ;;
114 esac
115 esac
116esac # $DISPLAY
117
118# Failure...
119case "$DISPLAY" in ?*)
120 echo "Unable to locate 'pkexec', 'gksu' or 'su+xterm'. $ADVICE" >&2
121 ;;
122 *)
123 echo "Unable to locate 'pkexec'. $ADVICE" >&2
124 ;;
125esac
126
127exit 1
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette