vboxconfig.sh revision a5dc49f41d7d9497f8c5d7daade92867636a090b
# $Id$
# Sun VirtualBox
# VirtualBox Configuration Script, Solaris host.
#
# Copyright (C) 2009 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)?
DIR_MOD_32="${BASEDIR}/platform/i86pc/kernel/drv"
# "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"
}
# check_bin_path()
# !! failure is always fatal
{
if test -z "$1"; then
errorprint "missing argument to check_bin_path()"
exit 1
fi
if test ! -x "$1"; then
errorprint "$1 missing or is not an executable"
exit 1
fi
return 0
}
# find_bins()
# !! failure is always fatal
{
# Search only for binaries that might be in different locations
BIN_IFCONFIG=`which ifconfig 2> /dev/null`
}
# 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 ${BASEDIR}/etc/release | tr ' ' '\n' | grep 'snv_' | sed -e "s/snv_//" -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" & "vbo $BASEDIR_OPT xusbmon"
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
mv -f ${BASEDIR}/etc/devlink.vbox ${BASEDIR}/etc/devlink.tab
else
errorprint "Missing ${BASEDIR}/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
mv -f ${BASEDIR}/etc/devlink.vbox ${BASEDIR}/etc/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 snv_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_all([fatal])
# failure: depends on [fatal]
{
fatal=$1
# Remove vboxdrv from devlink.tab
if test -f ${BASEDIR}/etc/devlink.tab; then
devlinkfound=`cat ${BASEDIR}/etc/devlink.tab | grep vboxdrv`
mv -f ${BASEDIR}/etc/devlink.vbox ${BASEDIR}/etc/devlink.tab
fi
# Remove vboxusbmon from devlink.tab
devlinkfound=`cat ${BASEDIR}/etc/devlink.tab | grep vboxusbmon`
mv -f ${BASEDIR}/etc/devlink.vbox ${BASEDIR}/etc/devlink.tab
fi
fi
# No separate VBI since 3.1
# unload_module "$MOD_VBI" "$DESC_VBI" "$fatal"
# remove devlinks
fi
rm -f ${BASEDIR}/dev/vboxusbmon
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
}
# 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 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
}
# 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 ${BASEDIR}/var/svc/manifest/application/virtualbox/virtualbox-webservice.xml || test -f ${BASEDIR}/var/svc/manifest/application/virtualbox/virtualbox-zoneaccess.xml; then
infoprint "Configuring services..."
subprint "Skipped for targetted installs."
fi
fi
# 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
# 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${BASEDIR}" != "x/"; then
BASEDIR_OPT="-b ${BASEDIR}"
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)
;;
*)
break
;;
esac
shift
done
--postinstall)
;;
--preremove)
;;
;;
;;
--setupdrivers)
;;
*)
errorprint "Invalid operation $drvop"
exit 1
esac
exit "$?"