vboxconfig.sh revision 395d92a7732aad3c0b9baecedfabba5113b84485
# $Id$
#
# VirtualBox Configuration Script, Solaris host.
#
# Copyright (C) 2009-2010 Oracle Corporation
#
# This file is part of VirtualBox Open Source Edition (OSE), as
# available from http://www.virtualbox.org. This file is free software;
# General Public License (GPL) as published by the Free Software
# Foundation, in version 2 as it comes in the "COPYING" file of the
# VirtualBox OSE distribution. VirtualBox OSE is distributed in the
# hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
#
# Never use exit 2 or exit 20 etc., the return codes are used in
# SRv4 postinstall procedures which carry special meaning. Just use exit 1 for failure.
# LC_ALL should take precedence over LC_* and LANG but whatever...
LC_ALL=C
export LC_ALL
LANG=C
export LANG
DIR_MOD_64="$DIR_MOD_32/amd64"
# Default paths, these will be overridden by 'which' if they don't exist
# "vboxdrv" is also used in sed lines here (change those as well if it ever changes)
DESC_VBOXDRV="Host"
DESC_VBOXNET="NetAdapter"
DESC_VBOXFLT="NetFilter (STREAMS)"
DESC_VBOXBOW="NetFilter (Crossbow)"
DESC_VBOXUSBMON="USBMonitor"
DESC_VBOXUSB="USB"
{
echo 1>&2 "$1"
fi
}
subprint()
{
echo 1>&2 " - $1"
fi
}
{
echo 1>&2 " * Warning!! $1"
fi
}
{
echo 1>&2 "## $1"
}
{
echo 1>&2 "$1"
}
{
helpprint "VirtualBox Configuration Script"
helpprint "usage: $0 <operation> [options]"
helpprint "<operation> must be one of the following:"
helpprint " --postinstall Perform full post installation procedure"
helpprint " --preremove Perform full pre remove procedure"
helpprint " --installdrivers Only install the drivers"
helpprint " --removedrivers Only remove the drivers"
helpprint " --setupdrivers Setup drivers, reloads existing drivers"
helpprint "[options] are one or more of the following:"
helpprint " --silent Silent mode"
helpprint " --fatal Don't continue on failure (required for postinstall)"
helpprint " --ips This is an IPS package postinstall/preremove"
}
# find_bin_path()
# !! failure is always fatal
{
if test -z "$1"; then
errorprint "missing argument to find_bin_path()"
exit 1
fi
binfilename=`basename $1`
binfilepath=`which $binfilename 2> /dev/null`
echo "$binfilepath"
return 0
else
errorprint "$1 missing or is not an executable"
exit 1
fi
}
# find_bins()
# !! failure is always fatal
{
# Search only for binaries that might be in different locations
fi
fi
fi
fi
fi
fi
fi
fi
fi
fi
fi
fi
fi
}
# check_root()
# !! failure is always fatal
{
# Don't use "-u" option as some id binaries don't support it, instead
# rely on "uid=101(username) gid=10(groupname) groups=10(staff)" output
errorprint "This script must be run with administrator privileges."
exit 1
fi
}
# get_sysinfo
# cannot fail
{
PKGFMRI=`$BIN_PKG $BASEDIR_PKGOPT contents -H -t set -a name=pkg.fmri -o pkg.fmri pkg:/system/kernel 2> /dev/null`
# Perhaps this is old pkg without '-a' option and/or system/kernel is missing and it's part of 'entire'
# Try fallback.
# Perhaps entire is conflicting. Try using opensolaris/entire.
# Last fallback try.
PKGFMRI=`$BIN_PKG $BASEDIR_PKGOPT contents -H -t set -o pkg.fmri opensolaris.org/entire | head -1 2> /dev/null`
fi
fi
# The format is "5.11-0.161" or "5.11-0.175.0.0.0.1.0"
else
errorprint "Failed to parse the Solaris kernel version."
exit 1
fi
else
errorprint "Failed to detect the Solaris kernel version."
exit 1
fi
else
# S11 without 'pkg' ?? Something's wrong... bail.
errorprint "Solaris $HOST_OS_MAJOR_VERSION detected without executable $BIN_PKG !? Confused."
exit 1
fi
# Use uname to verify it's S10.
# Major version is S10, Minor version is no longer relevant (or used), use uname -v so it gets something
# like "Generic_blah" for purely cosmetic purposes
else
# Remote installs from S10 local.
BIN_PKGCHK=`which pkgchk 2> /dev/null`
errorprint "Failed to find an executable pkgchk binary $BIN_PKGCHK."
errorprint "Cannot determine Solaris version on remote target $PKG_INSTALL_ROOT"
exit 1
fi
REMOTE_S10=`$BIN_PKGCHK -l -p /kernel/amd64/genunix $BASEDIR_PKGOPT 2> /dev/null | grep SUNWckr | tr -d ' \t'`
HOST_OS_MAJORVERSION="5.10"
else
errorprint "Remote target $PKG_INSTALL_ROOT is not Solaris 10."
errorprint "Will not attempt to install to an unidentified remote target."
exit 1
fi
fi
fi
}
# check_zone()
# !! failure is always fatal
{
errorprint "This script must be run from the global zone."
exit 1
fi
}
# check_isa()
# !! failure is always fatal
{
currentisa=`uname -i`
errorprint "VirtualBox cannot run under xVM Dom0! Fatal Error, Aborting installation!"
exit 1
fi
}
# check_module_arch()
# !! failure is always fatal
{
errorprint "VirtualBox works only on i386/amd64 hosts, not $cputype"
exit 1
fi
}
# update_boot_archive()
# cannot fail
{
infoprint "Updating the boot archive..."
else
fi
}
# module_added(modname)
# returns 1 if added, 0 otherwise
{
if test -z "$1"; then
errorprint "missing argument to module_added()"
exit 1
fi
# Add a space at end of module name to make sure we have a perfect match to avoid
# any substring matches: e.g "vboxusb" & "vboxusbmon"
return 1
fi
return 0
}
# module_loaded(modname)
# returns 1 if loaded, 0 otherwise
{
if test -z "$1"; then
errorprint "missing argument to module_loaded()"
exit 1
fi
modname=$1
# modinfo should now work properly since we prevent module autounloading.
return 1
fi
return 0
}
# add_driver(modname, moddesc, fatal, nulloutput, [driverperm])
# failure: depends on "fatal"
{
if test -z "$1" || test -z "$2"; then
errorprint "missing argument to add_driver()"
exit 1
fi
modname="$1"
moddesc="$2"
fatal="$3"
nullop="$4"
modperm="$5"
else
fi
else
$BIN_ADDDRV $BASEDIR_OPT $modname >/dev/null 2>&1
else
fi
fi
if test $? -ne 0; then
exit 1
fi
return 1
fi
return 0
}
# rem_driver(modname, moddesc, [fatal])
# failure: depends on [fatal]
{
if test -z "$1" || test -z "$2"; then
errorprint "missing argument to rem_driver()"
exit 1
fi
modname=$1
moddesc=$2
fatal=$3
else
$BIN_REMDRV $BASEDIR_OPT $modname >/dev/null 2>&1
fi
# for remote installs, don't bother with return values of rem_drv
if test $? -eq 0; then
return 0
else
exit 1
fi
return 1
fi
fi
}
# unload_module(modname, moddesc, [fatal])
# failure: fatal
{
if test -z "$1" || test -z "$2"; then
errorprint "missing argument to unload_module()"
exit 1
fi
# No-OP for non-root installs
return 0
fi
modname=$1
moddesc=$2
fatal=$3
if test $? -eq 0; then
else
exit 1
fi
return 1
fi
fi
return 0
}
# load_module(modname, moddesc, [fatal])
# failure: fatal
{
if test -z "$1" || test -z "$2"; then
errorprint "missing argument to load_module()"
exit 1
fi
# No-OP for non-root installs
return 0
fi
modname=$1
moddesc=$2
fatal=$3
if test $? -eq 0; then
return 0
else
exit 1
fi
return 1
fi
}
{
load_module "drv/$MOD_VBOXFLT" "$DESC_VBOXFLT" "$FATALOP"
else
# For custom pkgs that optionally ship this module, let's not fail but just warn
warnprint "$DESC_VBOXFLT installation requested but not shipped in this package."
fi
}
{
load_module "drv/$MOD_VBOXBOW" "$DESC_VBOXBOW" "$FATALOP"
else
# For custom pkgs that optionally ship this module, let's not fail but just warn
warnprint "$DESC_VBOXBOW installation requested but not shipped in this package."
fi
}
# install_drivers()
# !! failure is always fatal
{
if test -n "_HARDENED_"; then
add_driver "$MOD_VBOXDRV" "$DESC_VBOXDRV" "$FATALOP" "not-$NULLOP" "'* 0600 root sys'"
else
add_driver "$MOD_VBOXDRV" "$DESC_VBOXDRV" "$FATALOP" "not-$NULLOP" "'* 0666 root sys'"
fi
load_module "drv/$MOD_VBOXDRV" "$DESC_VBOXDRV" "$FATALOP"
else
errorprint "Extreme error! Missing $DIR_CONF/vboxdrv.conf, aborting."
return 1
fi
# Add vboxdrv to devlink.tab
else
errorprint "Missing $PKG_INSTALL_ROOT/etc/devlink.tab, aborting install"
return 1
fi
# Create the device link for non-remote installs
/usr/sbin/devfsadm -i "$MOD_VBOXDRV"
errorprint "Failed to create device link for $MOD_VBOXDRV."
exit 1
fi
fi
# Load VBoxNetAdp
load_module "drv/$MOD_VBOXNET" "$DESC_VBOXNET" "$FATALOP"
fi
# If both vboxinst_vboxbow and vboxinst_vboxflt exist, bail.
if test -f "$PKG_INSTALL_ROOT/etc/vboxinst_vboxflt" && test -f "$PKG_INSTALL_ROOT/etc/vboxinst_vboxbow"; then
errorprint "Force-install files '$PKG_INSTALL_ROOT/etc/vboxinst_vboxflt' and '$PKG_INSTALL_ROOT/etc/vboxinst_vboxbow' both exist."
errorprint "Cannot load $DESC_VBOXFLT and $DESC_VBOXBOW drivers at the same time."
return 1
fi
# If the force-install files exists, install blindly
infoprint "here"
else
# If host is S10 or S11 (< snv_159) or vboxbow isn't shipped, then load vboxflt
if test "$HOST_OS_MAJORVERSION" = "5.10" || test "$HOST_OS_MINORVERSION" -lt 159 || test ! -f "$DIR_CONF/vboxbow.conf"; then
else
# For S11 snv_159+ load vboxbow
fi
fi
# Load VBoxUSBMon, VBoxUSB
# For VirtualBox 3.1 the new USB code requires Nevada > 123
# Add a group "vboxuser" (8-character limit) for USB access.
# All users which need host USB-passthrough support will have to be added to this group.
add_driver "$MOD_VBOXUSBMON" "$DESC_VBOXUSBMON" "$FATALOP" "not-$NULLOP" "'* 0666 root sys'"
load_module "drv/$MOD_VBOXUSBMON" "$DESC_VBOXUSBMON" "$FATALOP"
# Add vboxusbmon to devlink.tab
sed -e '/name=vboxusbmon/d' "$PKG_INSTALL_ROOT/etc/devlink.tab" > "$PKG_INSTALL_ROOT/etc/devlink.vbox"
# Create the device link for non-remote installs
/usr/sbin/devfsadm -i "$MOD_VBOXUSBMON"
if test $? -ne 0; then
errorprint "Failed to create device link for $MOD_VBOXUSBMON."
exit 1
fi
fi
# Add vboxusb if present
# This driver is special, we need it in the boot-archive but since there is no
# USB device to attach to now (it's done at runtime) it will fail to attach so
load_module "drv/$MOD_VBOXUSB" "$DESC_VBOXUSB" "$FATALOP"
fi
else
warnprint "Solaris 5.11 build 124 or higher required for USB support. Skipped installing USB support."
else
warnprint "Failed to determine Solaris 5.11 snv version. Skipped installing USB support."
fi
fi
fi
return $?
}
# remove_drivers([fatal])
# failure: depends on [fatal]
{
fatal=$1
# Remove vboxdrv from devlink.tab
fi
# Remove vboxusbmon from devlink.tab
sed -e '/name=vboxusbmon/d' "$PKG_INSTALL_ROOT/etc/devlink.tab" > "$PKG_INSTALL_ROOT/etc/devlink.vbox"
fi
fi
# remove devlinks
rm -f "$PKG_INSTALL_ROOT/dev/vboxdrv"
fi
rm -f "$PKG_INSTALL_ROOT/dev/vboxusbmon"
fi
fi
# remove netmask configuration
else
fi
fi
if test $UPDATEBOOTARCHIVE -eq 1; then
fi
return 0
}
# install_python_bindings(pythonbin)
# remarks: changes pwd
# failure: non fatal
{
# The python binary might not be there, so just exit silently
if test -z "$1"; then
return 0
fi
if test -z "$2"; then
errorprint "missing argument to install_python_bindings"
exit 1
fi
pythonbin=$1
pythondesc=$2
export VBOX_INSTALL_PATH
subprint "Installed: Bindings for $pythondesc"
fi
return 0
fi
return 1
}
# stop_process(processname)
# failure: depends on [fatal]
{
if test -z "$1"; then
errorprint "missing argument to stop_process()"
exit 1
fi
procname=$1
sleep 2
exit 1
fi
else
fi
fi
}
# start_service(servicename, shortFMRI pretty printing, full FMRI, log-file path)
# failure: non-fatal
{
if test -z "$1" || test -z "$2" || test -z "$3" || test -z "$4"; then
errorprint "missing argument to enable_service()"
exit 1
fi
# Since S11 the way to import a manifest is via restarting manifest-import which is asynchronous and can
# take a while to complete, using disable/enable -s doesn't work either. So we restart it, and poll in
# 1 second intervals to see if our service has been successfully imported and timeout after 'cmax' seconds.
cmax=32
cslept=0
success=0
while test $? -ne 0;
do
sleep 1
success=1
break
fi
done
$BIN_SVCADM enable -s "$3"
subprint "Loaded: $1"
return 0
else
warnprint "Refer $4 for details."
fi
else
warnprint "Refer /var/svc/log/system-manifest-import:default.log for details."
fi
return 1
}
# stop_service(servicename, shortFMRI-suitable for grep, full FMRI)
# failure: non fatal
{
if test -z "$1" || test -z "$2" || test -z "$3"; then
errorprint "missing argument to stop_service()"
exit 1
fi
$BIN_SVCADM disable -s "$3"
# Don't delete the manifest, this is handled by the manifest class action
# $BIN_SVCCFG delete "$3"
subprint "Unloaded: $1"
else
fi
fi
}
# cleanup_install([fatal])
# failure: depends on [fatal]
{
fatal=$1
# No-Op for remote installs
return 0
fi
# stop the services
stop_service "Web service" "virtualbox/webservice" "svc:/application/virtualbox/webservice:default"
stop_service "Balloon control service" "virtualbox/balloonctrl" "svc:/application/virtualbox/balloonctrl:default"
stop_service "Autostart service" "virtualbox/autostart" "svc:/application/virtualbox/autostart:default"
stop_service "Zone access service" "virtualbox/zoneaccess" "svc:/application/virtualbox/zoneaccess:default"
# unplumb all vboxnet instances for non-remote installs
inst=0
while test $inst -ne $MOD_VBOXNET_INST; do
errorprint "VirtualBox NetAdapter 'vboxnet$inst' couldn't be unplumbed (probably in use)."
exit 1
fi
fi
fi
# unplumb vboxnet0 ipv6
errorprint "VirtualBox NetAdapter 'vboxnet$inst' IPv6 couldn't be unplumbed (probably in use)."
exit 1
fi
fi
fi
done
# Stop our other daemons, non-fatal
}
# postinstall()
# !! failure is always fatal
{
infoprint "Detected Solaris $HOST_OS_MAJORVERSION Version $HOST_OS_MINORVERSION"
infoprint "Loading VirtualBox kernel modules..."
# add all vboxnet instances as static to nwam
inst=0
networkn=56
done
fi
# plumb and configure vboxnet0 for non-remote installs
# S11 175a renames vboxnet0 as 'netX', undo this and rename it back
if test $? -ne 0; then
errorprint "Failed to rename vanity interface ($vanityname) to vboxnet0"
fi
fi
fi
$BIN_IFCONFIG vboxnet0 192.168.56.1 netmask 255.255.255.0 up
# a copy of the actual file, repair that behaviour here.
else
fi
# add the netmask to stay persistent across host reboots
if test -f $nmaskfile; then
if test $recreatelink -eq 1; then
fi
fi
inst=0
networkn=56
done
if test $recreatelink -eq 1; then
elif test $recreatelink -eq 2; then
warnprint "VirtualBox installers incorrectly overwrote. Now the contents"
fi
fi
else
# Should this be fatal?
warnprint "Failed to bring up vboxnet0!!"
fi
fi
fi
|| test -f "$PKG_INSTALL_ROOT/var/svc/manifest/application/virtualbox/virtualbox-autostart.xml"; then
infoprint "Configuring services..."
subprint "Skipped for targetted installs."
else
# Start ZoneAccess service, other services are disabled by default.
start_service "Zone access service" "virtualbox/zoneaccess" "svc:/application/virtualbox/zoneaccess:default" \
fi
fi
# Update mime and desktop databases to get the right menu entries
# and icons. There is still some delay until the GUI picks it up,
# but that cannot be helped.
infoprint "Installing MIME types and icons..."
/usr/bin/update-desktop-database -q 2>/dev/null
else
subprint "Skipped for targetted installs."
fi
fi
# Install python bindings for non-remote installs
if test -f "$DIR_VBOXBASE/sdk/installer/vboxapisetup.py" || test -h "$DIR_VBOXBASE/sdk/installer/vboxapisetup.py"; then
infoprint "Installing Python bindings..."
install_python_bindings "$PYTHONBIN" "Python 2.4"
fi
install_python_bindings "$PYTHONBIN" "Python 2.5"
fi
install_python_bindings "$PYTHONBIN" "Python 2.6"
fi
# remove files installed by Python build
warnprint "No suitable Python version found. Required Python 2.4, 2.5 or 2.6."
warnprint "Skipped installing the Python bindings."
fi
else
warnprint "Python not found, skipped installed Python bindings."
fi
fi
else
warnprint "Skipped installing Python bindings. Run, as root, 'vboxapisetup.py install' manually from the booted system."
fi
return 0
else
errorprint "Failed to install drivers"
exit 666
fi
return 1
}
# preremove([fatal])
# failure: depends on [fatal]
{
fatal=$1
return 0;
fi
return 1
}
# And it begins...
if test "x${PKG_INSTALL_ROOT:=/}" != "x/"; then
fi
# Get command line options
while test $# -gt 0;
do
case "$1" in
drvop="$1"
;;
--fatal)
;;
--silent)
;;
--ips)
;;
--altkerndir)
# Use alternate kernel driver config folder (dev only)
;;
--help)
exit 1
;;
*)
break
;;
esac
shift
done
--postinstall)
;;
--preremove)
;;
;;
;;
--setupdrivers)
infoprint "Installing VirtualBox drivers:"
;;
*)
exit 1
esac
exit "$?"