1 | #!/bin/sh
|
---|
2 | # $Id: autorun.sh 106061 2024-09-16 14:03:52Z vboxsync $
|
---|
3 | ## @file
|
---|
4 | # VirtualBox Guest Additions installation script for *nix guests
|
---|
5 | #
|
---|
6 |
|
---|
7 | #
|
---|
8 | # Copyright (C) 2009-2024 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 |
|
---|
29 | PATH=$PATH:/bin:/sbin:/usr/sbin
|
---|
30 |
|
---|
31 | # Deal with differing "which" semantics
|
---|
32 | mywhich() {
|
---|
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
|
---|
43 | getxterm() {
|
---|
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.
|
---|
59 | quotify() {
|
---|
60 | echo "$1" | sed -e 's/\([^a-zA-Z0-9/]\)/\\\1/g'
|
---|
61 | }
|
---|
62 |
|
---|
63 | ostype=`uname -s`
|
---|
64 | if test "$ostype" != "Linux" && test "$ostype" != "SunOS" ; then
|
---|
65 | echo "Linux/Solaris not detected."
|
---|
66 | exit 1
|
---|
67 | fi
|
---|
68 |
|
---|
69 | # The below is GNU-specific. See VBox.sh for the longer Solaris/OS X version.
|
---|
70 | TARGET=`readlink -e -- "${0}"` || exit 1
|
---|
71 | path="${TARGET%/[!/]*}"
|
---|
72 | # 32-bit or 64-bit?
|
---|
73 | case `uname -m` in
|
---|
74 | i[3456789]86|x86|i86pc)
|
---|
75 | arch='x86'
|
---|
76 | ;;
|
---|
77 | x86_64|amd64|AMD64)
|
---|
78 | arch='amd64'
|
---|
79 | ;;
|
---|
80 | aarch64)
|
---|
81 | arch='arm64'
|
---|
82 | ;;
|
---|
83 | *)
|
---|
84 | echo "Unknown architecture `uname -m`."
|
---|
85 | exit 1
|
---|
86 | ;;
|
---|
87 | esac
|
---|
88 |
|
---|
89 | # execute the installer
|
---|
90 | if test "$ostype" = "Linux"; then
|
---|
91 |
|
---|
92 | # Specify path to the architecture specific installer.
|
---|
93 | if test "$arch" = "arm64"; then
|
---|
94 | installer="$path/VBoxLinuxAdditions-arm64.run"
|
---|
95 | else
|
---|
96 | installer="$path/VBoxLinuxAdditions.run"
|
---|
97 | fi
|
---|
98 |
|
---|
99 | # Proceed to installation.
|
---|
100 | if test -f "$installer"; then
|
---|
101 | getxterm
|
---|
102 | case "$gxtpath" in ?*)
|
---|
103 | TITLE="VirtualBox Guest Additions installation"
|
---|
104 | BINARY="`quotify "$installer"`"
|
---|
105 | exec "$gxtpath" "$gxttitle" "$TITLE" "$gxtexec" /bin/sh "$path/runasroot.sh" --has-terminal "$TITLE" "/bin/sh $BINARY --xwin" "Please try running "\""$installer"\"" manually."
|
---|
106 | exit
|
---|
107 | ;;
|
---|
108 | *)
|
---|
109 | echo "Unable to start installation process with elevated privileges automatically. Please try running "\""$installer"\"" manually."
|
---|
110 | exit
|
---|
111 | ;;
|
---|
112 | esac
|
---|
113 | fi
|
---|
114 |
|
---|
115 | # else: unknown failure
|
---|
116 | echo "Linux guest additions installer not found -- try to start it manually."
|
---|
117 | exit 1
|
---|
118 |
|
---|
119 | elif test "$ostype" = "SunOS"; then
|
---|
120 |
|
---|
121 | # check for combined package
|
---|
122 | installfile="$path/VBoxSolarisAdditions.pkg"
|
---|
123 | if test -f "$installfile"; then
|
---|
124 |
|
---|
125 | # check for pkgadd bin
|
---|
126 | pkgaddbin=pkgadd
|
---|
127 | found=`which pkgadd | grep "no pkgadd"`
|
---|
128 | if test ! -z "$found"; then
|
---|
129 | if test -f "/usr/sbin/pkgadd"; then
|
---|
130 | pkgaddbin=/usr/sbin/pkgadd
|
---|
131 | else
|
---|
132 | echo "Could not find pkgadd."
|
---|
133 | exit 1
|
---|
134 | fi
|
---|
135 | fi
|
---|
136 |
|
---|
137 | # check for pfexec
|
---|
138 | pfexecbin=pfexec
|
---|
139 | found=`which pfexec | grep "no pfexec"`
|
---|
140 | if test ! -z "$found"; then
|
---|
141 | # Use su and prompt for password
|
---|
142 | echo "Could not find pfexec."
|
---|
143 | subin=`which su`
|
---|
144 | else
|
---|
145 | idbin=/usr/xpg4/bin/id
|
---|
146 | if test ! -x "$idbin"; then
|
---|
147 | found=`which id 2> /dev/null`
|
---|
148 | if test ! -x "$found"; then
|
---|
149 | echo "Failed to find a suitable user id executable."
|
---|
150 | exit 1
|
---|
151 | else
|
---|
152 | idbin=$found
|
---|
153 | fi
|
---|
154 | fi
|
---|
155 |
|
---|
156 | # check if pfexec can get the job done
|
---|
157 | if test "$idbin" = "/usr/xpg4/bin/id"; then
|
---|
158 | userid=`$pfexecbin $idbin -u`
|
---|
159 | else
|
---|
160 | userid=`$pfexecbin $idbin | cut -f1 -d'(' | cut -f2 -d'='`
|
---|
161 | fi
|
---|
162 | if test $userid != "0"; then
|
---|
163 | # pfexec exists but user has no pfexec privileges, switch to using su and prompting password
|
---|
164 | subin=`which su`
|
---|
165 | fi
|
---|
166 | fi
|
---|
167 |
|
---|
168 | # create temporary admin file for autoinstall
|
---|
169 | TMPFILE=`mktemp -q /tmp/vbox.XXXXXX`
|
---|
170 | if [ -z $TMPFILE ]; then
|
---|
171 | echo "Unable to create a temporary file"
|
---|
172 | exit 1
|
---|
173 | fi
|
---|
174 | echo "basedir=default
|
---|
175 | runlevel=nocheck
|
---|
176 | conflict=quit
|
---|
177 | setuid=nocheck
|
---|
178 | action=nocheck
|
---|
179 | partial=quit
|
---|
180 | instance=unique
|
---|
181 | idepend=quit
|
---|
182 | rdepend=quit
|
---|
183 | space=quit
|
---|
184 | mail=
|
---|
185 | " > $TMPFILE
|
---|
186 |
|
---|
187 | # check gnome-terminal, use it if it exists.
|
---|
188 | if test -f "/usr/bin/gnome-terminal"; then
|
---|
189 | # use su/pfexec
|
---|
190 | if test -z "$subin"; then
|
---|
191 | /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'"
|
---|
192 | else
|
---|
193 | /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'"
|
---|
194 | fi
|
---|
195 | elif test -f "/usr/X11/bin/xterm"; then
|
---|
196 | # use xterm
|
---|
197 | if test -z "$subin"; then
|
---|
198 | /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"
|
---|
199 | else
|
---|
200 | /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"
|
---|
201 | fi
|
---|
202 | else
|
---|
203 | echo "No suitable terminal not found. -- install additions using pkgadd -d."
|
---|
204 | fi
|
---|
205 | rm -r $TMPFILE
|
---|
206 |
|
---|
207 | exit 0
|
---|
208 | fi
|
---|
209 |
|
---|
210 | echo "Solaris guest additions installer not found -- try to start them manually."
|
---|
211 | exit 1
|
---|
212 | fi
|
---|
213 |
|
---|