VirtualBox

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

Last change on this file was 98103, checked in by vboxsync, 16 months ago

Copyright year updates by scm.

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

© 2023 Oracle
ContactPrivacy policyTerms of Use