vboxconfig.sh revision 8bdddb232888f7a6a08021867f7156622b62dc6f
# $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.
# S10 or OpenSoalris
# Which OpenSolaris version (snv_xxx or oi_xxx)?
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"
# No Separate VBI since (3.1)
#MOD_VBI=vbi
#DESC_VBI="Kernel Interface"
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
{
if test "$REMOTEINST" -eq 1 || test -z "$HOST_OS_MINORVERSION" || test -z "$HOST_OS_MAJORVERSION"; then
HOST_OS_MAJORVERSION="5.10"
else
HOST_OS_MAJORVERSION="5.11"
fi
fi
HOST_OS_MINORVERSION=`cat $PKG_INSTALL_ROOT/etc/release | tr ' ' '\n' | egrep 'snv_|oi_' | sed -e "s/snv_//" -e "s/oi_//" -e "s/[^0-9]//"`
else
fi
else
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
}
# 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
}
# 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
# Load VBoxNetFlt
load_module "drv/$MOD_VBOXFLT" "$DESC_VBOXFLT" "$FATALOP"
fi
# Load VBoxUSBMon, VBoxUSB
# For VirtualBox 3.1 the new USB code requires Nevada > 123
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
# 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
if test -f $PKG_INSTALL_ROOT/etc/devlink.tab; then
fi
# Remove vboxusbmon from devlink.tab
fi
fi
# No separate VBI since 3.1
# unload_module "$MOD_VBI" "$DESC_VBI" "$fatal"
# remove devlinks
fi
fi
fi
# remove netmask configuration
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
}
# cleanup_install([fatal])
# failure: depends on [fatal]
{
fatal=$1
# No-Op for remote installs
return 0
fi
# stop webservice
# Don't delete the manifest, this is handled by the manifest class action
# $BIN_SVCCFG delete svc:/application/virtualbox/webservice:default
subprint "Unloaded: Web service"
else
fi
fi
# stop balloonctrl
# Don't delete the manifest, this is handled by the manifest class action
# $BIN_SVCCFG delete svc:/application/virtualbox/balloonctrl:default
subprint "Unloaded: Balloon control service"
else
fi
fi
# stop zoneaccess service
# Don't delete the manifest, this is handled by the manifest class action
# $BIN_SVCCFG delete svc:/application/virtualbox/zoneaccess
subprint "Unloaded: Zone access service"
else
fi
fi
# 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 "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
$BIN_IFCONFIG vboxnet0 192.168.56.1 netmask 255.255.255.0 up
# add the netmask to stay persistent across host reboots
if test -f $nmaskfile; then
inst=0
networkn=56
done
fi
else
# Should this be fatal?
warnprint "Failed to bring up vboxnet0!!"
fi
fi
fi
if test -f $PKG_INSTALL_ROOT/var/svc/manifest/application/virtualbox/virtualbox-webservice.xml || test -f $PKG_INSTALL_ROOT/var/svc/manifest/application/virtualbox/virtualbox-zoneaccess.xml; then
infoprint "Configuring services..."
subprint "Skipped for targetted installs."
else
# Enable Zone access service for non-remote installs, other services (Webservice) are delivered disabled by the manifest class action
subprint "Loaded: Zone access service"
else
fi
fi
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.
if test -d $PKG_INSTALL_ROOT/usr/share/icons; then
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
# Update boot archive
infoprint "Updating the boot archive..."
else
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 "$?"