VirtualBox

source: vbox/trunk/src/VBox/Additions/solaris/Installer/postinstall.sh

Last change on this file was 101937, checked in by vboxsync, 7 months ago

Additions/solaris/{Installer,vboxms,vboxservice}: Add support for the
Solaris Guest Additions to be installed into an alternate root path
('pkgad -R'). This also enables the Solaris GAs to be installed in an
automated fashion when building Solaris images using the distribution
constructor (aka the distro_const(8) utility).

  • Property svn:eol-style set to LF
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 17.7 KB
Line 
1#!/bin/sh
2# $Id: postinstall.sh 101937 2023-11-07 12:15:59Z vboxsync $
3## @file
4# VirtualBox postinstall script for Solaris Guest Additions.
5#
6
7#
8# Copyright (C) 2008-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# The contents of this file may alternatively be used under the terms
27# of the Common Development and Distribution License Version 1.0
28# (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
29# in the VirtualBox distribution, in which case the provisions of the
30# CDDL are applicable instead of those of the GPL.
31#
32# You may elect to license modified versions of this file under the
33# terms and conditions of either the GPL or the CDDL or both.
34#
35# SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
36#
37
38# LC_ALL should take precedence over LC_* and LANG but whatever...
39LC_ALL=C
40export LC_ALL
41
42LANG=C
43export LANG
44
45# "Remote" installs ('pkgadd -R') can skip many of the steps below.
46REMOTE_INST=0
47BASEDIR_OPT=""
48if test "x${PKG_INSTALL_ROOT:-/}" != "x/"; then
49 BASEDIR_OPT="-R $PKG_INSTALL_ROOT"
50 REMOTE_INST=1
51fi
52export REMOTE_INST
53export BASEDIR_OPT
54
55# uncompress(directory, file)
56# Updates package metadata and uncompresses the file.
57uncompress_file()
58{
59 if test -z "$1" || test -z "$2"; then
60 echo "missing argument to uncompress_file()"
61 return 1
62 fi
63
64 # Remove compressed path from the pkg
65 /usr/sbin/removef $BASEDIR_OPT $PKGINST "$1/$2.Z" 1>/dev/null
66
67 # Add uncompressed path to the pkg
68 /usr/sbin/installf $BASEDIR_OPT -c none $PKGINST "$1/$2" f
69
70 # Uncompress the file (removes compressed file when done)
71 uncompress -f "$1/$2.Z" > /dev/null 2>&1
72}
73
74# uncompress_files(directory_with_*.Z_files)
75uncompress_files()
76{
77 for i in "${1}/"*.Z; do
78 uncompress_file "${1}" "`basename \"${i}\" .Z`"
79 done
80}
81
82solaris64dir="amd64"
83solaris32dir="i386"
84vboxadditions_path="${PKG_INSTALL_ROOT}/opt/VirtualBoxAdditions"
85vboxadditions32_path=$vboxadditions_path/$solaris32dir
86vboxadditions64_path=$vboxadditions_path/$solaris64dir
87
88# get the current zone
89currentzone=`zonename`
90# get what ISA the guest is running
91cputype=`isainfo -k`
92if test "$cputype" = "amd64"; then
93 isadir=$solaris64dir
94else
95 isadir=""
96fi
97
98vboxadditionsisa_path=$vboxadditions_path/$isadir
99
100
101# uncompress if necessary
102if test -f "$vboxadditions32_path/VBoxClient.Z" || test -f "$vboxadditions64_path/VBoxClient.Z"; then
103 echo "Uncompressing files..."
104 if test -f "$vboxadditions32_path/VBoxClient.Z"; then
105 uncompress_files "$vboxadditions32_path"
106 fi
107 if test -f "$vboxadditions64_path/VBoxClient.Z"; then
108 uncompress_files "$vboxadditions64_path"
109 fi
110fi
111
112
113if test "$currentzone" = "global"; then
114 # vboxguest.sh would've been installed, we just need to call it.
115 echo "Configuring VirtualBox guest kernel module..."
116 # stop all previous modules (vboxguest, vboxfs) and load vboxguest
117 # ('vboxguest.sh start' only starts vboxguest).
118 if test "$REMOTE_INST" -eq 0; then
119 $vboxadditions_path/vboxguest.sh stopall silentunload
120 fi
121 $vboxadditions_path/vboxguest.sh start
122
123 # Figure out group to use for /etc/devlink.tab (before Solaris 11 SRU6
124 # it was always using group sys)
125 group=sys
126 if [ -f /etc/dev/reserved_devnames ]; then
127 # Solaris 11 SRU6 and later use group root (check a file which isn't
128 # tainted by VirtualBox install scripts and allow no other group)
129 refgroup=`LC_ALL=C /usr/bin/ls -lL /etc/dev/reserved_devnames | awk '{ print $4 }' 2>/dev/null`
130 if [ $? -eq 0 -a "x$refgroup" = "xroot" ]; then
131 group=root
132 fi
133 unset refgroup
134 fi
135
136 sed -e '/name=vboxguest/d' ${PKG_INSTALL_ROOT}/etc/devlink.tab > ${PKG_INSTALL_ROOT}/etc/devlink.vbox
137 echo "type=ddi_pseudo;name=vboxguest \D" >> ${PKG_INSTALL_ROOT}/etc/devlink.vbox
138 chmod 0644 ${PKG_INSTALL_ROOT}/etc/devlink.vbox
139 chown root:$group ${PKG_INSTALL_ROOT}/etc/devlink.vbox
140 mv -f ${PKG_INSTALL_ROOT}/etc/devlink.vbox ${PKG_INSTALL_ROOT}/etc/devlink.tab
141
142 # create the device link
143 /usr/sbin/devfsadm $BASEDIR_OPT -i vboxguest
144fi
145
146# create links
147echo "Creating links..."
148if test "$currentzone" = "global"; then
149 /usr/sbin/installf $BASEDIR_OPT -c none $PKGINST /dev/vboxguest=../devices/pci@0,0/pci80ee,cafe@4:vboxguest s
150 /usr/sbin/installf $BASEDIR_OPT -c none $PKGINST /dev/vboxms=../devices/pseudo/vboxms@0:vboxms s
151fi
152
153# check if X.Org exists (snv_130 and higher have /usr/X11/* as /usr/*)
154if test -f "${PKG_INSTALL_ROOT}/usr/bin/Xorg"; then
155 xorgbin="${PKG_INSTALL_ROOT}/usr/bin/Xorg"
156elif test -f "${PKG_INSTALL_ROOT}/usr/X11/bin/Xorg"; then
157 xorgbin="${PKG_INSTALL_ROOT}/usr/X11/bin/Xorg"
158else
159 xorgbin=""
160 retval=0
161fi
162
163# Install Xorg components to the required places
164if test ! -z "$xorgbin"; then
165 xorgversion_long=`$xorgbin -version 2>&1 | grep "X Window System Version"`
166 xorgversion=`/usr/bin/expr "${xorgversion_long}" : 'X Window System Version \([^ ]*\)'`
167 if test -z "$xorgversion_long"; then
168 xorgversion_long=`$xorgbin -version 2>&1 | grep "X.Org X Server"`
169 xorgversion=`/usr/bin/expr "${xorgversion_long}" : 'X.Org X Server \([^ ]*\)'`
170 fi
171
172 # "X.Y.Z" - strip off all numerics after the 2nd '.' character, e.g. "1.11.3" -> "1.11"
173 # The second sed invocation removes all '.' characters, e.g. "1.11" -> "111".
174 fileversion=`echo $xorgversion | sed "s/\.[0-9]*//2" | sed "s/\.//"`
175 vboxvideo_src="vboxvideo_drv_$fileversion.so"
176
177 # Handle exceptions now where the X.org version does not exactly match the file-version.
178 case "$xorgversion" in
179 1.5.99 )
180 vboxvideo_src="vboxvideo_drv_16.so"
181 ;;
182 7.2.* )
183 vboxvideo_src="vboxvideo_drv_71.so"
184 ;;
185 6.9.* )
186 vboxvideo_src="vboxvideo_drv_70.so"
187 ;;
188 esac
189
190 retval=0
191 if test -z "$vboxvideo_src"; then
192 echo "*** Unknown version of the X Window System installed."
193 echo "*** Failed to install the VirtualBox X Window System drivers."
194
195 # Exit as partially failed installation
196 retval=2
197 elif test ! -f "$vboxadditions32_path/$vboxvideo_src" && test ! -f "$vboxadditions64_path/$vboxvideo_src"; then
198 if test ! -f "${PKG_INSTALL_ROOT}/usr/lib/xorg/modules/drivers/vboxvideo_drv.so"; then
199 # Xorg 1.19 and later (delivered first in st_006) already contain a driver
200 # for vboxvideo so advise users to install the required package if it isn't
201 # already present.
202 echo "As of X.Org Server 1.19, the VirtualBox graphics driver (vboxvideo) is part"
203 echo "of Solaris. Please install the package pkg:/x11/server/xorg/driver/xorg-video-vboxvideo"
204 echo "from the package repository for the vboxvideo_drv.so graphics driver."
205 fi
206 else
207 echo "Installing video driver for X.Org $xorgversion..."
208
209 # Determine destination paths (snv_130 and above use "/usr/lib/xorg", older use "/usr/X11/lib"
210 vboxvideo32_dest_base="${PKG_INSTALL_ROOT}/usr/lib/xorg/modules/drivers"
211 if test ! -d $vboxvideo32_dest_base; then
212 vboxvideo32_dest_base="${PKG_INSTALL_ROOT}/usr/X11/lib/modules/drivers"
213 fi
214
215 vboxvideo64_dest_base=$vboxvideo32_dest_base/$solaris64dir
216
217 # snv_163 drops 32-bit support completely, and uses 32-bit locations for the 64-bit stuff. Ugly.
218 # We try to detect this by looking at bitness of "vesa_drv.so", and adjust our destination paths accordingly.
219 # We do not rely on using Xorg -version's ABI output because some builds (snv_162 iirc) have 64-bit ABI with
220 # 32-bit file locations.
221 if test -f "$vboxvideo32_dest_base/vesa_drv.so"; then
222 bitsize=`file "$vboxvideo32_dest_base/vesa_drv.so" | grep -i "32-bit"`
223 skip32="no"
224 else
225 echo "* Warning vesa_drv.so missing. Assuming Xorg ABI is 64-bit..."
226 fi
227
228 if test -z "$bitsize"; then
229 skip32="yes"
230 vboxvideo64_dest_base=$vboxvideo32_dest_base
231 fi
232
233 # Make sure destination path exists
234 if test ! -d $vboxvideo64_dest_base; then
235 echo "*** Missing destination paths for video module. Aborting."
236 echo "*** Failed to install the VirtualBox X Window System driver."
237
238 # Exit as partially failed installation
239 retval=2
240 else
241 # 32-bit x11 drivers
242 if test "$skip32" = "no" && test -f "$vboxadditions32_path/$vboxvideo_src"; then
243 vboxvideo_dest="$vboxvideo32_dest_base/vboxvideo_drv.so"
244 /usr/sbin/installf $BASEDIR_OPT -c none $PKGINST "$vboxvideo_dest" f
245 cp "$vboxadditions32_path/$vboxvideo_src" "$vboxvideo_dest"
246
247 # Removing redundant names from pkg and files from disk
248 /usr/sbin/removef $BASEDIR_OPT $PKGINST $vboxadditions32_path/vboxvideo_drv_* 1>/dev/null
249 rm -f $vboxadditions32_path/vboxvideo_drv_*
250 fi
251
252 # 64-bit x11 drivers
253 if test -f "$vboxadditions64_path/$vboxvideo_src"; then
254 vboxvideo_dest="$vboxvideo64_dest_base/vboxvideo_drv.so"
255 /usr/sbin/installf $BASEDIR_OPT -c none $PKGINST "$vboxvideo_dest" f
256 cp "$vboxadditions64_path/$vboxvideo_src" "$vboxvideo_dest"
257
258 # Removing redundant names from pkg and files from disk
259 /usr/sbin/removef $BASEDIR_OPT $PKGINST $vboxadditions64_path/vboxvideo_drv_* 1>/dev/null
260 rm -f $vboxadditions64_path/vboxvideo_drv_*
261 fi
262
263 # Some distros like Indiana have no xorg.conf, deal with this
264 if test ! -f '${PKG_INSTALL_ROOT}/etc/X11/xorg.conf' && \
265 test ! -f '${PKG_INSTALL_ROOT}/etc/X11/.xorg.conf'; then
266
267 # Xorg 1.3.x+ should use the modeline-less Xorg confs while older should
268 # use ones with all the video modelines in place. Argh.
269 xorgconf_file="solaris_xorg_modeless.conf"
270 xorgconf_unfit="solaris_xorg.conf"
271 case "$xorgversion" in
272 7.1.* | 7.2.* | 6.9.* | 7.0.* )
273 xorgconf_file="solaris_xorg.conf"
274 xorgconf_unfit="solaris_xorg_modeless.conf"
275 ;;
276 esac
277
278 /usr/sbin/removef $BASEDIR_OPT $PKGINST $vboxadditions_path/$xorgconf_file 1>/dev/null
279 mv -f $vboxadditions_path/$xorgconf_file ${PKG_INSTALL_ROOT}/etc/X11/.xorg.conf
280
281 /usr/sbin/removef $BASEDIR_OPT $PKGINST $vboxadditions_path/$xorgconf_unfit 1>/dev/null
282 rm -f $vboxadditions_path/$xorgconf_unfit
283 fi
284
285 # Check for VirtualBox graphics card
286 # S10u10's prtconf doesn't support the '-d' option, so let's use -v even though it's slower.
287 is_vboxgraphics=`${PKG_INSTALL_ROOT}/usr/sbin/prtconf -v | grep -i pci80ee,beef`
288 if test "$?" -eq 0; then
289 drivername="vboxvideo"
290 else
291 # Check for VMware graphics card
292 is_vmwaregraphics=`${PKG_INSTALL_ROOT}/usr/sbin/prtconf -v | grep -i pci15ad,405`
293 if test "$?" -eq 0; then
294 echo "Configuring X.Org to use VMware SVGA graphics driver..."
295 drivername="vmware"
296 fi
297 fi
298
299 # Adjust xorg.conf with video driver sections if a supported graphics card is found
300 if test ! -z "$drivername"; then
301 $vboxadditions_path/x11config15sol.pl "$drivername"
302 else
303 # No supported graphics card found, do nothing.
304 echo "## No supported graphics card found. Skipped configuring of X.org drivers."
305 fi
306 fi
307 fi
308
309
310 # Setup our VBoxClient
311 echo "Configuring client..."
312 vboxclient_src=$vboxadditions_path
313 vboxclient_dest="${PKG_INSTALL_ROOT}/usr/share/gnome/autostart"
314 clientinstalled=0
315 if test -d "$vboxclient_dest"; then
316 /usr/sbin/installf $BASEDIR_OPT -c none $PKGINST $vboxclient_dest/vboxclient.desktop=$vboxadditions_path/vboxclient.desktop s
317 clientinstalled=1
318 fi
319 vboxclient_dest="${PKG_INSTALL_ROOT}/usr/dt/config/Xsession.d"
320 if test -d "$vboxclient_dest"; then
321 /usr/sbin/installf $BASEDIR_OPT -c none $PKGINST $vboxclient_dest/1099.vboxclient=$vboxadditions_path/1099.vboxclient s
322 clientinstalled=1
323 fi
324
325 # Try other autostart locations if none of the above ones work
326 if test $clientinstalled -eq 0; then
327 vboxclient_dest="${PKG_INSTALL_ROOT}/etc/xdg/autostart"
328 if test -d "$vboxclient_dest"; then
329 /usr/sbin/installf $BASEDIR_OPT -c none $PKGINST $vboxclient_dest/1099.vboxclient=$vboxadditions_path/1099.vboxclient s
330 clientinstalled=1
331 else
332 echo "*** Failed to configure client, couldn't find any autostart directory!"
333 # Exit as partially failed installation
334 retval=2
335 fi
336 fi
337else
338 echo "(*) X.Org not found, skipped configuring X.Org guest additions."
339fi
340
341
342# Shared Folder kernel module (different for S10 & Nevada)
343osverstr=`uname -r`
344vboxfsmod="vboxfs"
345vboxfsunused="vboxfs_s10"
346if test "$osverstr" = "5.10"; then
347 vboxfsmod="vboxfs_s10"
348 vboxfsunused="vboxfs"
349fi
350
351# Move the appropriate module to kernel/fs & remove the unused module name from pkg and file from disk
352# 64-bit shared folder module
353if test -f "$vboxadditions64_path/$vboxfsmod"; then
354 echo "Installing 64-bit shared folders module..."
355 /usr/sbin/installf $BASEDIR_OPT -c none $PKGINST "/usr/kernel/fs/$solaris64dir/vboxfs" f
356 mv -f $vboxadditions64_path/$vboxfsmod ${PKG_INSTALL_ROOT}/usr/kernel/fs/$solaris64dir/vboxfs
357 /usr/sbin/removef $BASEDIR_OPT $PKGINST $vboxadditions64_path/$vboxfsmod 1>/dev/null
358 /usr/sbin/removef $BASEDIR_OPT $PKGINST $vboxadditions64_path/$vboxfsunused 1>/dev/null
359 rm -f $vboxadditions64_path/$vboxfsunused
360fi
361
362# 32-bit shared folder module
363if test -f "$vboxadditions32_path/$vboxfsmod"; then
364 echo "Installing 32-bit shared folders module..."
365 /usr/sbin/installf $BASEDIR_OPT -c none $PKGINST "/usr/kernel/fs/vboxfs" f
366 mv -f $vboxadditions32_path/$vboxfsmod ${PKG_INSTALL_ROOT}/usr/kernel/fs/vboxfs
367 /usr/sbin/removef $BASEDIR_OPT $PKGINST $vboxadditions32_path/$vboxfsmod 1>/dev/null
368 /usr/sbin/removef $BASEDIR_OPT $PKGINST $vboxadditions32_path/$vboxfsunused 1>/dev/null
369 rm -f $vboxadditions32_path/$vboxfsunused
370fi
371
372# Add a group "vboxsf" for Shared Folders access
373# All users which want to access the auto-mounted Shared Folders have to
374# be added to this group.
375if test "$REMOTE_INST" -eq 0; then
376 groupadd vboxsf >/dev/null 2>&1
377fi
378
379# Move the pointer integration module to kernel/drv & remove the unused module name from pkg and file from disk
380
381# Finalize
382/usr/sbin/removef $BASEDIR_OPT -f $PKGINST
383/usr/sbin/installf $BASEDIR_OPT -f $PKGINST
384
385
386if test "$currentzone" = "global"; then
387 /usr/sbin/devfsadm $BASEDIR_OPT -i vboxguest
388
389 # Setup VBoxService and vboxmslnk and start the services automatically
390 echo "Configuring VBoxService and vboxmslnk services (this might take a while)..."
391 cmax=32
392 cslept=0
393 success=0
394 sync
395
396 if test "$REMOTE_INST" -eq 0; then
397 # Since S11 the way to import a manifest is via restarting manifest-import which is asynchronous and can
398 # take a while to complete, using disable/enable -s doesn't work either. So we restart it, and poll in
399 # 1 second intervals to see if our service has been successfully imported and timeout after 'cmax' seconds.
400 /usr/sbin/svcadm restart svc:system/manifest-import:default
401 /usr/bin/svcs virtualbox/vboxservice >/dev/null 2>&1 && /usr/bin/svcs virtualbox/vboxmslnk >/dev/null 2>&1
402 while test "$?" -ne 0;
403 do
404 sleep 1
405 cslept=`expr $cslept + 1`
406 if test "$cslept" -eq "$cmax"; then
407 success=1
408 break
409 fi
410 /usr/bin/svcs virtualbox/vboxservice >/dev/null 2>&1 && /usr/bin/svcs virtualbox/vboxmslnk >/dev/null 2>&1
411 done
412 if test "$success" -eq 0; then
413 echo "Enabling services..."
414 /usr/sbin/svcadm enable -s virtualbox/vboxservice
415 /usr/sbin/svcadm enable -s virtualbox/vboxmslnk
416 else
417 echo "## Service import failed."
418 echo "## See /var/svc/log/system-manifest-import:default.log for details."
419 # Exit as partially failed installation
420 retval=2
421 fi
422 fi
423
424 # Update boot archive
425 BOOTADMBIN=/sbin/bootadm
426 if test -x "$BOOTADMBIN"; then
427 if test -h "${PKG_INSTALL_ROOT}/dev/vboxguest"; then
428 echo "Updating boot archive..."
429 $BOOTADMBIN update-archive $BASEDIR_OPT > /dev/null
430 else
431 echo "## Guest kernel module doesn't seem to be up. Skipped explicit boot-archive update."
432 fi
433 else
434 echo "## $BOOTADMBIN not found/executable. Skipped explicit boot-archive update."
435 fi
436fi
437
438echo "Done."
439if test "$REMOTE_INST" -eq 0; then
440 if test $retval -eq 0; then
441 if test ! -z "$xorgbin"; then
442 echo "Please re-login to activate the X11 guest additions."
443 fi
444 echo "If you have just un-installed the previous guest additions a REBOOT is required."
445 fi
446fi
447exit $retval
448
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use