vboxconfig.sh revision e64031e20c39650a7bc902a3e1aba613b9415dee
# $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)?
# "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
}
# 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 $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 $modname >/dev/null 2>&1
fi
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
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
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 /etc/devlink.vbox /etc/devlink.tab
# Create the device link
/usr/sbin/devfsadm -i "$MOD_VBOXDRV"
load_module "drv/$MOD_VBOXNET" "$DESC_VBOXNET" "$FATALOP"
fi
load_module "drv/$MOD_VBOXFLT" "$DESC_VBOXFLT" "$FATALOP"
fi
# 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 /etc/devlink.vbox /etc/devlink.tab
# Create the device link
/usr/sbin/devfsadm -i "$MOD_VBOXUSBMON"
if test $? -ne 0; then
errorprint "Failed to create device link for $MOD_VBOXUSBMON."
exit 1
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."
fi
fi
else
errorprint "Failed to create device link for $MOD_VBOXDRV."
exit 1
fi
return $?
}
# remove_all([fatal])
# failure: depends on [fatal]
{
fatal=$1
# Remove vboxdrv from devlink.tab
devlinkfound=`cat /etc/devlink.tab | grep vboxdrv`
mv -f /etc/devlink.vbox /etc/devlink.tab
fi
# Remove vboxusbmon from devlink.tab
mv -f /etc/devlink.vbox /etc/devlink.tab
fi
# No separate VBI since 3.1
# unload_module "$MOD_VBI" "$DESC_VBI" "$fatal"
# remove devlinks
fi
rm -f /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
# stop and unregister webservice SMF
subprint "Unloaded: Web service"
else
fi
fi
# stop and unregister zoneaccess SMF
subprint "Unloaded: Zone access service"
else
fi
fi
# unplumb all vboxnet instances
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
$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
if test -f /var/svc/manifest/application/virtualbox/virtualbox-webservice.xml || test -f /var/svc/manifest/application/virtualbox/virtualbox-zoneaccess.xml; then
infoprint "Configuring services..."
fi
# Web service
if test -f /var/svc/manifest/application/virtualbox/virtualbox-webservice.xml; then
subprint "Loaded: Web service"
else
fi
fi
# Zone access service
if test -f /var/svc/manifest/application/virtualbox/virtualbox-zoneaccess.xml; then
subprint "Loaded: Zone access service"
else
fi
fi
# Install python bindings
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
# Update boot archive
infoprint "Updating the boot archive..."
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...
# 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 "$?"