VirtualBox

source: vbox/trunk/src/VBox/Additions/linux/installer/autorun.sh@ 36638

Last change on this file since 36638 was 36626, checked in by vboxsync, 14 years ago

Installer/linux: fix quoting in the Additions auto-installer

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 6.1 KB
Line 
1#!/bin/sh
2#
3# VirtualBox Guest Additions installation script for *nix guests
4#
5
6#
7# Copyright (C) 2009-2010 Oracle Corporation
8#
9# This file is part of VirtualBox Open Source Edition (OSE), as
10# available from http://www.virtualbox.org. This file is free software;
11# you can redistribute it and/or modify it under the terms of the GNU
12# General Public License (GPL) as published by the Free Software
13# Foundation, in version 2 as it comes in the "COPYING" file of the
14# VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15# hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16#
17
18PATH=$PATH:/bin:/sbin:/usr/sbin
19
20# Deal with differing "which" semantics
21mywhich() {
22 which "$1" 2>/dev/null | grep -v "no $1"
23}
24
25# Get the name and execute switch for a useful terminal emulator
26#
27# Sets $gxtpath to the emulator path or empty
28# Sets $gxttitle to the "title" switch for that emulator
29# Sets $gxtexec to the "execute" switch for that emulator
30# May clobber $gtx*
31# Calls mywhich
32getxterm() {
33 # gnome-terminal uses -e differently to other emulators
34 for gxti in "gnome-terminal --title -x" "konsole --title -e" "xterm -T -e"; do
35 set $gxti
36 gxtpath="`mywhich $1`"
37 case "$gxtpath" in ?*)
38 gxttitle=$2
39 gxtexec=$3
40 return
41 ;;
42 esac
43 done
44}
45
46# Quotes its argument by inserting '\' in front of every character save
47# for 'A-Za-z0-9/'. Prints the result to stdout.
48quotify() {
49 echo "$1" | sed -e 's/\([^a-zA-Z0-9/]\)/\\\1/g'
50}
51
52ostype=`uname -s`
53if test "$ostype" != "Linux" && test "$ostype" != "SunOS" ; then
54 echo "Linux/Solaris not detected."
55 exit 1
56fi
57
58# 32-bit or 64-bit?
59path=`dirname $0`
60case `uname -m` in
61 i[3456789]86|x86|i86pc)
62 arch='x86'
63 ;;
64 x86_64|amd64|AMD64)
65 arch='amd64'
66 ;;
67 *)
68 echo "Unknown architecture `uname -m`."
69 exit 1
70 ;;
71esac
72
73# execute the installer
74if test "$ostype" = "Linux"; then
75 for i in "$path/VBoxLinuxAdditions.run" \
76 "$path/VBoxLinuxAdditions-$arch.run"; do
77 if test -f "$i"; then
78 getxterm
79 case "$gxtpath" in ?*)
80 TITLE="VirtualBox Guest Additions installation"
81 TITLE_QUOTED=`quotify "$TITLE"`
82 BINARY=`quotify $i`
83 exec /bin/sh "$path/runasroot.sh" \
84 "$TITLE" \
85 "$gxtpath $gxttitle $TITLE_QUOTED $gxtexec $BINARY --xwin" \
86 "Please try running $i manually."
87 exit
88 ;;
89 esac
90 fi
91 done
92
93 # else: unknown failure
94 echo "Linux guest additions installer not found -- try to start them manually."
95 exit 1
96
97elif test "$ostype" = "SunOS"; then
98
99 # check for combined package
100 installfile="$path/VBoxSolarisAdditions.pkg"
101 if test -f "$installfile"; then
102
103 # check for pkgadd bin
104 pkgaddbin=pkgadd
105 found=`which pkgadd | grep "no pkgadd"`
106 if test ! -z "$found"; then
107 if test -f "/usr/sbin/pkgadd"; then
108 pkgaddbin=/usr/sbin/pkgadd
109 else
110 echo "Could not find pkgadd."
111 exit 1
112 fi
113 fi
114
115 # check for pfexec
116 pfexecbin=pfexec
117 found=`which pfexec | grep "no pfexec"`
118 if test ! -z "$found"; then
119 # Use su and prompt for password
120 echo "Could not find pfexec."
121 subin=`which su`
122 else
123 idbin=/usr/xpg4/bin/id
124 if test ! -x "$idbin"; then
125 found=`which id 2> /dev/null`
126 if test ! -x "$found"; then
127 echo "Failed to find a suitable user id executable."
128 exit 1
129 else
130 idbin=$found
131 fi
132 fi
133
134 # check if pfexec can get the job done
135 if test "$idbin" = "/usr/xpg4/bin/id"; then
136 userid=`$pfexecbin $idbin -u`
137 else
138 userid=`$pfexecbin $idbin | cut -f1 -d'(' | cut -f2 -d'='`
139 fi
140 if test $userid != "0"; then
141 # pfexec exists but user has no pfexec privileges, switch to using su and prompting password
142 subin=`which su`
143 fi
144 fi
145
146 # create temporary admin file for autoinstall
147 echo "basedir=default
148runlevel=nocheck
149conflict=quit
150setuid=nocheck
151action=nocheck
152partial=quit
153instance=unique
154idepend=quit
155rdepend=quit
156space=quit
157mail=
158" > /tmp/vbox.autoinstall
159
160 # check gnome-terminal, use it if it exists.
161 if test -f "/usr/bin/gnome-terminal"; then
162 # use su/pfexec
163 if test -z "$subin"; then
164 /usr/bin/gnome-terminal --title "Installing VirtualBox Additions" --command "/bin/sh -c '$pfexecbin $pkgaddbin -G -d $installfile -n -a /tmp/vbox.autoinstall SUNWvboxguest; /bin/echo press ENTER to close this window; /bin/read; /bin/rm -f /tmp/vbox.autoinstall'"
165 else
166 /usr/bin/gnome-terminal --title "Installing VirtualBox Additions: Root password required." --command "/bin/sh -c '$subin - root -c \"$pkgaddbin -G -d $installfile -n -a /tmp/vbox.autoinstall SUNWvboxguest\"; /bin/echo press ENTER to close this window; /bin/read; /bin/rm -f /tmp/vbox.autoinstall'"
167 fi
168 elif test -f "/usr/X11/bin/xterm"; then
169 # use xterm
170 if test -z "$subin"; then
171 /usr/X11/bin/xterm -title "Installing VirtualBox Additions" -e "$pfexecbin $pkgaddbin -G -d $installfile -n -a /tmp/vbox.autoinstall SUNWvboxguest; /bin/echo press ENTER to close this window; /bin/read; /bin/rm -f /tmp/vbox.autoinstall"
172 else
173 /usr/X11/bin/xterm -title "Installing VirtualBox Additions: Root password required." -e "$subin - root -c \"$pkgaddbin -G -d $installfile -n -a /tmp/vbox.autoinstall SUNWvboxguest\"; /bin/echo press ENTER to close this window; /bin/read; /bin/rm -f /tmp/vbox.autoinstall"
174 fi
175 else
176 echo "No suitable terminal not found. -- install additions using pkgadd -d."
177 rm -f /tmp/vbox.autoinstall
178 fi
179
180 exit 0
181 fi
182
183 echo "Solaris guest additions installer not found -- try to start them manually."
184 exit 1
185fi
186
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