Changeset 36658 in vbox for trunk/src/VBox/Installer
- Timestamp:
- Apr 12, 2011 3:40:51 PM (14 years ago)
- Location:
- trunk/src/VBox/Installer/linux
- Files:
-
- 1 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Installer/linux/runasroot.sh
r36626 r36658 1 1 #!/bin/sh 2 # $Id$ 2 3 ## @file 3 4 # VirtualBox privileged execution helper script for Linux and Solaris … … 16 17 # 17 18 18 # Deal with differing "which" semantics 19 mywhich() { 20 which "$1" 2>/dev/null | grep -v "no $1" 21 } 22 23 # Get the name and execute switch for a useful terminal emulator 24 # 25 # Sets $gxtpath to the emulator path or empty 26 # Sets $gxttitle to the "title" switch for that emulator 27 # Sets $gxtexec to the "execute" switch for that emulator 28 # May clobber $gtx* 29 # Calls mywhich 30 getxterm() { 31 # gnome-terminal uses -e differently to other emulators 32 for gxti in "gnome-terminal --title -x" "konsole --title -e" "xterm -T -e"; do 33 set $gxti 34 gxtpath="`mywhich $1`" 35 case "$gxtpath" in ?*) 36 gxttitle=$2 37 gxtexec=$3 38 return 39 ;; 40 esac 41 done 42 } 43 44 # Quotes its argument by inserting '\' in front of every character save 45 # for 'A-Za-z0-9/'. Prints the result to stdout. 46 quotify() { 47 echo $1 | sed -e 's/\([^a-zA-Z0-9/]\)/\\\1/g' 48 } 19 #include sh-utils.sh 49 20 50 21 ostype=`uname -s` -
trunk/src/VBox/Installer/linux/sh-utils.sh
r36626 r36658 1 #!/bin/sh 1 # $Id$ 2 # Shell script include file 2 3 ## @file 3 # VirtualBox privileged execution helper script for Linux and Solaris4 # Shell script routines which are likely to be useful for different scripts 4 5 # 5 6 … … 45 46 # for 'A-Za-z0-9/'. Prints the result to stdout. 46 47 quotify() { 47 echo $1| sed -e 's/\([^a-zA-Z0-9/]\)/\\\1/g'48 echo "$1" | sed -e 's/\([^a-zA-Z0-9/]\)/\\\1/g' 48 49 } 49 50 ostype=`uname -s`51 if test "$ostype" != "Linux" && test "$ostype" != "SunOS" ; then52 echo "Linux/Solaris not detected."53 exit 154 fi55 56 case "$#" in "2"|"3")57 ;;58 *)59 echo "Usage: `basename $0` DESCRIPTION COMMAND [ADVICE]" >&260 echo >&261 echo "Attempt to execute COMMAND with root privileges, displaying DESCRIPTION if" >&262 echo "possible and displaying ADVICE if possible if no su(1)-like tool is available." >&263 exit 164 ;;65 esac66 67 DESCRIPTION=$168 COMMAND=$269 ADVICE=$370 PATH=$PATH:/bin:/usr/bin:/usr/local/bin:/sbin:/usr/sbin:/usr/local/sbin:/usr/X11/bin71 72 case "$ostype" in SunOS)73 PATH=$PATH:/usr/sfw/bin:/usr/gnu/bin:/usr/xpg4/bin:/usr/xpg6/bin:/usr/openwin/bin:/usr/ucb74 GKSU_SWITCHES="-au root"75 ;;76 *)77 GKSU_SWITCHES=""78 ;;79 esac80 81 case "$DISPLAY" in ?*)82 KDESUDO="`mywhich kdesudo`"83 case "$KDESUDO" in ?*)84 eval "`quotify "$KDESUDO"` --comment `quotify "$DESCRIPTION"` -- $COMMAND"85 exit86 ;;87 esac88 89 GKSU="`mywhich gksu`"90 case "$GKSU" in ?*)91 # Older gksu does not grok --description nor '--' and multiple args.92 # @todo which versions do?93 # "$GKSU" --description "$DESCRIPTION" -- "$@"94 # Note that $GKSU_SWITCHES is NOT quoted in the following95 "$GKSU" $GKSU_SWITCHES "$COMMAND"96 exit97 ;;98 esac99 ;;100 esac # $DISPLAY101 102 # pkexec may work for ssh console sessions as well if the right agents103 # are installed. However it is very generic and does not allow for any104 # custom messages. Thus it comes after gksu.105 PKEXEC="`mywhich pkexec`"106 case "$PKEXEC" in ?*)107 eval "\"$PKEXEC\" $COMMAND"108 exit109 ;;110 esac111 112 # The ultimate fallback is running 'su -' within an xterm. We use the113 # title of the xterm to tell what is going on.114 case "$DISPLAY" in ?*)115 SU="`mywhich su`"116 case "$SU" in ?*)117 getxterm118 case "$gxtpath" in ?*)119 "$gxtpath" "$gxttitle" "$DESCRIPTION - su" "$gxtexec" su - root -c "$COMMAND"120 exit121 ;;122 esac123 esac124 esac # $DISPLAY125 126 # Failure...127 case "$DISPLAY" in ?*)128 echo "Unable to locate 'pkexec', 'gksu' or 'su+xterm'. $ADVICE" >&2129 ;;130 *)131 echo "Unable to locate 'pkexec'. $ADVICE" >&2132 ;;133 esac134 135 exit 1
Note:
See TracChangeset
for help on using the changeset viewer.